getWtpAssoc

public static void getWtpAssoc(String QueTypeIN, EPMDocument epmIN, Folder epmFolderIN) throws WTException {
WTPart wtpListA[] = ObjectDependencyUtility.getAssociated((EPMDocument) epmIN);
if (wtpListA != null)
System.out.println("\tAssociated (.getAssociated) WTPart (wtpListA.length): " + wtpListA.length + "\n");
else
System.out.println("\tFOUND NO Associated (.getAssociated) WTParts: 0\n");


WTPart wtpListPA[] = ObjectDependencyUtility.getPassiveAssociated(epmIN);
if (wtpListPA != null)
System.out.println("\tPassive Associated (.getPassiveAssociated) WTPart (wtpListPA.length): " + wtpListPA.length + "\n");
else
System.out.println("\tFOUND NO Passive Associated (.getPassiveAssociated) WTParts: 0\n");


WTPart wtpListAA[] = ObjectDependencyUtility.getActiveAssociated(epmIN);
if (wtpListAA != null)
System.out.println("\tActive Associated (.getActiveAssociated) WTPart (wtpListAA.length): " + wtpListAA.length + "\n");
else
System.out.println("\tFOUND NO Active Associated (.getActiveAssociated) WTParts: 0\n");


// wtpAssoc =
// AssociateUtilities.getActiveAssociatedPart((EPMDocument)epmIN);


QueryResult qrAct = null;
QueryResult qrPas = null;


try {
if (VersionControlHelper.isLatestIteration(epmIN))
qrAct = PersistenceHelper.manager.navigate(epmIN, "buildTarget", wt.epm.build.EPMBuildRule.class);
else
qrAct = PersistenceHelper.manager.navigate(epmIN, "built", wt.build.BuildHistory.class);


System.out.println("\tFound Active Associated (build) WTPart (qrAct.size()): " + qrAct.size() + "\n");
} catch (Exception exception) {
System.out.println("\tFAILED (Exception) to Find Active Associated (build) WTPart (qrAct.size()): " + qrAct.size() + "\n");
// exception.printStackTrace();
}


try {
qrPas = StructHelper.service.navigateDescribes(epmIN, true);
System.out.println("\tFound Passive Associated (Describes) WTPart (qrPas.size()): " + qrPas.size() + "\n");
} catch (Exception exception) {
System.out.println("\tFAILED (Exception) to Find Passive Associated (Describes) WTPart (qrAct.size()): " + qrAct.size() + "\n");
// exception.printStackTrace();
}


if (wtpListA != null) { // Found wtpart associated to current epmdoc
// array element
for (int y = 0; y < wtpListA.length; y++) { // Loop through epmdoc
// (epmIN) associated
// wtpart array
WTPart wtpAssoc = null;
wtpAssoc = (WTPart) wtpListA[y];
wtpNo = wtpAssoc.getNumber();
wtpCont = wtpAssoc.getContainer();
wtpFolder = wt.folder.FolderHelper.getFolder(wtpAssoc);


epmNoIN = "";
epmNoIN = epmIN.getNumber();


LMObject = (LifeCycleManaged) wtpAssoc;
StStg = (String) LMObject.getLifeCycleState().toString();


System.out.println("\tAssociated WTPart Info: (" + y + ")");
System.out.println("\tWTPart Number: " + wtpAssoc.getNumber() + "| WTPart Name: " + wtpAssoc.getName());
System.out.println("\tWTPart Container: " + wtpCont.getName() + "| WTPart Folder: " + wtpFolder);
System.out.println("\tWTPart Version: " + wtpAssoc.getVersionIdentifier().getValue() + "." + wtpAssoc.getIterationIdentifier().getValue() + "| Life Cycle State: " + StStg + "\n");


// remove wtpart number extension


if (wtpNo.indexOf(".") > 0 && wtpNo != null) {
System.out.println("\tOrig WTPart String Number: " + wtpNo);
wtpNo = removeExt(wtpNo);
System.out.println("\tFinal WTPart String Number: " + wtpNo + "\n");
}


// remove epmdoc number extension


if (epmNoIN.indexOf(".") > 0 && epmNoIN != null) {
System.out.println("\tOrig EPMDoc String Number: " + epmNoIN);
epmNoIN = removeExt(epmNoIN);
System.out.println("\tFinal EPMDoc String Number: " + epmNoIN + "\n");
}


// check for short epmdoc number to be equal to wtpart short
// number


if (wtpNo.equals(epmNoIN)) { // epmdoc short number & wtpart are
// same number
System.out.println("\tEPMDoc: " + epmNoIN + " & WTPart " + wtpNo + " NUMBERS MATCH: \n");
} else { // epmdoc short number & wtpart are NOT same number
System.out.println("\tEPMDoc: " + epmNoIN + " & WTPart " + wtpNo + " NUMBERS DO NOT MATCH: \n");
WTPartMaster wtpMaster = (WTPartMaster) wtpAssoc.getMaster();
System.out.println("\tFound WTPart Master of " + wtpMaster.getNumber() + "\n");


if (QueTypeIN.equals("-rw")) {
try {
// check for existing wtpart with same number as
// short epmdoc number


WTPart newWtp0 = null;
newWtp0 = findWtpNoEQ(epmNoIN);


// if found, change wtpart number to be same as
// long/full epmdoc number


if (newWtp0 != null) {
// epmNoIN = epmNoIN+"_wtp";
epmNoIN = epmIN.getNumber();
System.out.println("\tFound Duplicate WTPart Number: " + epmIN.getNumber() + "\n");
System.out.println("\tUsing WTPart Number: " + epmNoIN + " instead.\n");
}


// change wtpart number to match short or long
// empdoc number


wt.fc.IdentificationObject idObj = wtpMaster.getIdentificationObject();
WTPartMasterIdentity wtpmID = (WTPartMasterIdentity) idObj;
wtpmID.setNumber(epmNoIN);
IdentityHelper.service.changeIdentity(wtpMaster, wtpmID);
System.out.println("\tIdentity Changed to: " + epmNoIN + "\n");
} catch (WTException wte) {
System.out.println("\tWTPart Number ( " + epmNoIN + ") Change FAILED:\n");
// wte.printStackTrace();
} catch (WTPropertyVetoException wtp) {
System.out.println("\tWTPart Number ( " + epmNoIN + ") Change FAILED:\n");
// wtp.printStackTrace();
}
}
}
}
} else {
System.out.println("\tNO Associated WTPart: \n");


epmNoIN3 = "";
epmNoIN3 = epmIN.getNumber();


try {
// generate short epmdoc number (without extension)


if (epmNoIN3.indexOf(".") > 0 && epmNoIN3 != null) {
System.out.println("\tOrig EPMDoc String Number: " + epmNoIN3);
epmNoIN3 = removeExt(epmNoIN3);
System.out.println("\tFinal EPMDoc String Number: " + epmNoIN3 + "\n");
}


// check for existing wtpart with same number as short epmdoc
// number


WTPart newWtp3 = null;
newWtp3 = findWtpNoEQ(epmNoIN3);


// Found wtpart with same short number as epmdoc without
// extension


if (newWtp3 != null) {
System.out.println("\tFound Non Associated WTPart NO: " + newWtp3.getNumber() + "\n\twith same Number as EPMDoc: " + epmNoIN3 + "\n");


// check if found wtpart has associated epmdoc


EPMDocument epmList3[] = ObjectDependencyUtility.getAssociated((WTPart) newWtp3);


// found epmdoc associated to wtpart, so exit to next wtpart
// array element


if (epmList3 != null && epmList3.length > 0) {
System.out.println("\tFound Associated EPMDoc length (epmList3.length): " + epmList3.length + "\n");
for (int y = 0; y < epmList3.length; y++) {
EPMDocument epmTop1 = null;
epmTop1 = (EPMDocument) epmList3[y];
System.out.println("\tFound Existing WTPart Association to (" + y + "): " + epmTop1.getNumber());
}
System.out.println("\n");
} else {
// check for existing wtpart with same number as long
// epmdoc number


epmNoIN4 = "";
epmNoIN4 = epmIN.getNumber();


WTPart newWtp4 = null;
newWtp4 = findWtpNoEQ(epmNoIN4);


if (newWtp4 != null) {
System.out.println("\tFound Non Associated WTPart NO: " + newWtp4.getNumber() + "\n\twith same Number as EPMDoc: " + epmNoIN4 + "\n");


// check if wtpart found has associated epmdoc, if
// so, leave loop


EPMDocument epmList4[] = ObjectDependencyUtility.getAssociated((WTPart) newWtp4);


if (epmList4 != null && epmList4.length > 0) {
System.out.println("\tFound Associated EPMDoc length (epmList4.length): " + epmList4.length + "\n");
for (int y = 0; y < epmList4.length; y++) {
EPMDocument epmTop4 = null;
epmTop4 = (EPMDocument) epmList4[y];
System.out.println("\tFound Existing WTPart Association to (" + y + "): " + epmTop4.getNumber());
}
System.out.println("\n");
} else if (QueTypeIN.equals("-rw")) { // wtpart
// newWtp4
// has no
// associated
// epmdoc
// same
// number
try {
newWtp4 = (WTPart) setCheckoutInfo(newWtp4, WorkInProgressState.WORKING);
EPMBuildRule epmbuildrule = null;
epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, newWtp4);
epmbuildrule = (EPMBuildRule) PersistenceHelper.manager.save(epmbuildrule);


System.out.println("\tCreated Association between WTPart Number: " + newWtp4.getNumber() + " & EPMDoc Number: " + epmIN.getNumber() + "\n");
} catch (WTException wtexception) {
System.out.println("\tFAILED Link association between WTPart Number: " + newWtp4.getNumber() + " & EPMDoc Number: " + epmIN.getNumber() + "\n");


WTPart wtpList5[] = ObjectDependencyUtility.getAssociated((EPMDocument) epmIN);


if (wtpList5 != null) {
System.out.println("\tAssociated EPMDoc length (wtpList5.length): " + wtpList5.length + "\n");


for (int y = 0; y < wtpList5.length; y++) {
WTPart wtpAssoc5 = null;
wtpAssoc5 = (WTPart) wtpList5[y];
System.out.println("\tBut Did Find Existing WTPart Number Association to (" + y + "): " + wtpAssoc5.getNumber());
}
}


EPMDocument epmList5[] = ObjectDependencyUtility.getAssociated((WTPart) newWtp4);


if (epmList5 != null) {
System.out.println("\tAssociated EPMDoc length: " + epmList5.length + "\n");


for (int y = 0; y < epmList5.length; y++) {
EPMDocument epmTop5 = null;
epmTop5 = (EPMDocument) epmList5[y];
System.out.println("\tBut Did Find Existing EPMDoc Number Association (" + y + "): " + epmTop5.getNumber());
}
}
System.out.println("\n");
}
}
}
}
} else { // Didnt find epmdoc associated to wtpart & == null or
// > 0
if (QueTypeIN.equals("-rw")) {


epmNoIN2 = "";
epmNmIN2 = "";


// Create and persist new wtpart
epmNoIN2 = epmIN.getNumber();
epmNmIN2 = epmIN.getName();
epmCont = epmIN.getContainer();


LMObject = (LifeCycleManaged) epmIN;
StStg = (String) LMObject.getLifeCycleState().toString();


if (epmNoIN2.indexOf(".") > 0 && epmNoIN2 != null) {
System.out.println("\tOrig EPMDoc String Number: " + epmNoIN2);
epmNoIN2 = removeExt(epmNoIN2);
System.out.println("\tFinal EPMDoc String Number: " + epmNoIN2 + "\n");
}


if (epmNmIN2.indexOf(".") > 0 && epmNmIN2 != null) {
System.out.println("\tOrig EPMDoc String Number: " + epmNmIN2);
epmNmIN2 = removeExt(epmNmIN2);
System.out.println("\tFinal EPMDoc String Number: " + epmNmIN2 + "\n");
}


WTPart newWtp2 = null;
newWtp2 = WTPart.newWTPart(epmNoIN2, epmNmIN2);
FolderHelper.assignLocation(newWtp2, epmFolderIN);


try {
newWtp2.getMaster().setSeries(epmIN.getMaster().getSeries());
VersionControlHelper.setVersionIdentifier(newWtp2, epmIN.getVersionIdentifier());
} catch (NumberFormatException numberformatexception) {
System.out.println("\tUnable to set the version id of the WTPart Number: " + newWtp2.getNumber());
}


VersionControlHelper.setIterationIdentifier(newWtp2, IterationIdentifier.newIterationIdentifier());
// newWtp2 = (WTPart)setLifeCycle(newWtp, StStg,
// epmCont);
newWtp2 = (WTPart) PersistenceHelper.manager.save(newWtp2);


System.out.println("\tCreated WTPart Number: " + newWtp2.getNumber());


wtpCont = newWtp2.getContainer();
wtpFolder = wt.folder.FolderHelper.getFolder(newWtp2);


LMObject = (LifeCycleManaged) newWtp2;
StStg = (String) LMObject.getLifeCycleState().toString();


System.out.println("\tWTPart Number: " + newWtp2.getNumber() + "| WTPart Name: " + newWtp2.getName());
System.out.println("\tWTPart Container: " + wtpCont.getName() + "| WTPart Folder: " + wtpFolder);
System.out.println("\tWTPart Version: " + newWtp2.getVersionIdentifier().getValue() + "." + newWtp2.getIterationIdentifier().getValue() + "| LC State: " + StStg + "\n");


try {
newWtp2 = (WTPart) setCheckoutInfo(newWtp2, WorkInProgressState.WORKING);
EPMBuildRule epmbuildrule = null;
epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, newWtp2);
epmbuildrule = (EPMBuildRule) PersistenceHelper.manager.save(epmbuildrule);


System.out.println("\tCreated Association between WTPart NUMBER: " + newWtp2.getNumber() + " & EPMDoc NUMBER: " + epmIN.getNumber() + "\n");
} catch (WTException wtexception) {
System.out.println("\tFAILED Association between WTPart NUMBER: " + newWtp2.getNumber() + " & EPMDoc NUMBER: " + epmIN.getNumber() + "\n");
// System.out.println(
// "\tWTPart Number Deleted: "+newWtp2.getNumber()+"\n");
// newWtp2 =
// (WTPart)PersistenceHelper.manager.delete(newWtp);
}
}
}
} catch (Exception exception) {
System.out.println("\tFAILED = Exception: " + exception.toString() + "\n");
}
}
}

你可能感兴趣的:(getWtpAssoc)