package ext; import java.util.*; import java.rmi.RemoteException; import java.io.*; import wt.util.*; import wt.fc.*; import wt.vc.*; import wt.vc.wip.*; import wt.vc.config.*; import wt.vc.struct.StructHelper; import wt.vc.struct.StructService; import wt.query.*; import wt.epm.*; import wt.epm.build.*; import wt.epm.structure.*; import wt.enterprise.RevisionControlled; import wt.part.*; import wt.pom.*; import wt.folder.*; import wt.lifecycle.*; import wt.lifecycle.State; import wt.inf.container.*; import wt.ownership.OwnershipHelper; import wt.httpgw.GatewayAuthenticator; import wt.method.RemoteMethodServer; import com.ptc.windchill.cadx.common.util.AssociateUtilities; import com.ptc.windchill.cadx.common.util.GenericUtilities; import com.ptc.windchill.cadx.common.util.ObjectDependencyUtility; public class ObjUtil_21 { public static void findEpmNo(String QueType, String objNo) throws WTException, WTPropertyVetoException { configSpec = new LatestConfigSpec(); QuerySpec qs = new QuerySpec(EPMDocument.class); qs.appendWhere(new SearchCondition(EPMDocument.class,EPMDocument.NUMBER,SearchCondition.LIKE,objNo)); qs.appendAnd(); qs.appendWhere(new SearchCondition(EPMDocument.class, "iterationInfo.latest", "TRUE")); qs = configSpec.appendSearchCriteria(qs); qr = PersistenceHelper.manager.find(qs); qr = configSpec.process(qr); //System.out.println( "\nSQL (findEpmNo): \n"+qs.toString()+"\n"); while (qr.hasMoreElements()) { epm = null; epm = (EPMDocument)qr.nextElement(); epmm = (EPMDocumentMaster)epm.getMaster(); epmNo = epm.getNumber(); epmCont = epm.getContainer(); epmFolder = wt.folder.FolderHelper.getFolder(epm); //System.out.println( "epm.getContainer().getName(): "+epm.getContainer().getName()+"\n"); LMObject = (LifeCycleManaged)epm; StStg = (String)LMObject.getLifeCycleState().toString(); System.out.println( "Running Tree For EPMDocument Number: "+epmNo+"\n"); epmTree(QueType,epm); } System.out.println( "Running Array Print Before runUsage()\n"); arrayPrint(); //removeDuplicate(arraylistWtpLink); //System.out.println( "Running Array Print After Clean()\n"); //arrayPrint(); runUsage(); System.out.println( "Running Array Print After runUsage()\n"); arrayPrint(); } public static void runUsage() throws WTException { if ( arraylistWtpLink.size() > 0 ) { System.out.println( "\n=====================\n0) arraylistWtpLink.size(): "+ arraylistWtpLink.size()); }; for (int z = 0; z < arraylistWtpLink.size(); z++ ) { // linkWtpStg(0): XYZ567|wt.part.WTPart:234322|ASSOC|XYZ567.ASM|wt.epm.EPMDocument:201051 linkWtpStg = (String)arraylistWtpLink.get(z); System.out.println( "\n=====================\n0) linkWtpStg("+z+"): "+ linkWtpStg); attrWtpStgArr = null; attrWtpStgArr = linkWtpStg.split("\\|"); tmpWtpNoStg = null; tmpWtpIdStg = null; assEpmNoStg = null; assEpmIdStg = null; if ( attrWtpStgArr.length > 0 ) { // WTPART STRING ASSOC ARRAY tmpWtpNoStg = attrWtpStgArr[0]; // XYZ567 - WTPART NO tmpWtpIdStg = attrWtpStgArr[1]; // wt.part.WTPart:234322 - WTPART ID assEpmNoStg = attrWtpStgArr[3]; // XYZ567.ASM - EPMDOC NO assEpmIdStg = attrWtpStgArr[4]; // wt.epm.EPMDocument:201051 - EPMDOC ID } System.out.println( "\n\t0) WTPART NO - tmpWtpNoStg: "+ tmpWtpNoStg+ " + ID - tmpWtpIdStg: " +tmpWtpIdStg); System.out.println( "\t0) ASM EPMDOC NO - assEpmNoStg: "+ assEpmNoStg+ " + ID - assEpmIdStg: " +assEpmIdStg); if ( arraylistEpmLink.size() > 0 ) { System.out.println( "\n=====================\n0) arraylistEpmLink.size(): "+ arraylistEpmLink.size()); }; for (int x = 0; x < arraylistEpmLink.size(); x++ ) { // linkEpmStg(0): XYZ567.PRT|wt.epm.EPMDocument:201050|PARENT|XYZ567.ASM|wt.epm.EPMDocument:201051|ASSOC|X-Y-Z567|wt.part.WTPart:234322 linkEpmStg = (String)arraylistEpmLink.get(x); System.out.println( "\n\t\t1) linkEpmStg("+x+"): "+ linkEpmStg); attrEpmStgArr = null; attrEpmStgArr = linkEpmStg.split("\\|"); tmpEpmNoStg = null; tmpEpmIdStg = null; parEpmNoStg = null; parEpmIdStg = null; tmpWtpNoStg2 = null; tmpWtpIdStg2 = null; if ( attrEpmStgArr.length > 0 ) { // EPMDOC STRING PARENT/CHILD ARRAY tmpEpmNoStg = attrEpmStgArr[0]; // XYZ567.PRT - CHILD EPMDOC NO tmpEpmIdStg = attrEpmStgArr[1]; // wt.epm.EPMDocument:201050 - CHILD EPMDOC ID parEpmNoStg = attrEpmStgArr[3]; // XYZ567.ASM - PARENT EPMDOC NO parEpmIdStg = attrEpmStgArr[4]; // wt.epm.EPMDocument:201051 - PARENT EPMDOC ID System.out.println( "\n\t\t\t1) CHILD EPMDOC NO - tmpEpmNoStg: "+ tmpEpmNoStg+ " + ID tmpEpmIdStg: " +tmpEpmIdStg); System.out.println( "\t\t\t1) PARENT EPMDOC NO - parEpmNoStg: "+ parEpmNoStg+ " + ID parEpmIdStg: " +parEpmIdStg); if ( attrEpmStgArr.length > 4 ) { // WTPART STRING ASSOC ARRAY tmpWtpNoStg2 = attrEpmStgArr[6]; // XYZ567 - WTPART NO ASSOC TO EPMDOC PARENT tmpWtpIdStg2 = attrEpmStgArr[7]; // wt.part.WTPart:234322 - WTPART ID ASSOC TO EPMDOC PARENT System.out.println( "\t\t\t1) WTPART NO ASSOC TO EPMDOC PARENT - tmpWtpNoStg2: " + tmpWtpNoStg2+" + ID tmpWtpIdStg2: " +tmpWtpIdStg2); } } if ( tmpEpmNoStg.equalsIgnoreCase(assEpmNoStg) && tmpEpmIdStg.equalsIgnoreCase(assEpmIdStg) ) { System.out.println("\n\t\t\tMATCH FOUND:"); System.out.println( "\n\t\t\t1) CHILD EPMDOC NO - tmpEpmNoStg: "+ tmpEpmNoStg+ " = ASM EPMDOC NO - assEpmNoStg: "+assEpmNoStg); System.out.println("\t\t\t1) & CHILD EPMDOC ID - tmpEpmIdStg: "+ tmpEpmIdStg + " = ASM EPMDOC ID - assEpmIdStg: "+assEpmIdStg); System.out.println("\n\t\t\t1) WTPART NO ASSOC TO EPMDOC CHILD - tmpWtpNoStg: "+tmpWtpNoStg+ " = WTPART ID - tmpWtpIdStg: "+ tmpWtpIdStg); System.out.println("\t\t\t1) Should be linked to: "); System.out.println("\t\t\t1) WTPART NO ASSOC TO EPMDOC PARENT - tmpWtpNoStg2: "+tmpWtpNoStg2+ " = WTPART ID ASSOC TO EPMDOC PARENT - tmpWtpIdStg2: "+ tmpWtpIdStg2); try { wtpObjPar = null; wtpObjCh = null; wtpObjPar = findWtpNoEQ(tmpWtpNoStg2); // WTPART OBJECT = WTPART NO ASSOC TO EPMDOC PARENT wtpObjCh = findWtpNoEQ(tmpWtpNoStg); // WTPART OBJECT = WTPART NO ASSOC TO EPMDOC CHILD } catch(Exception exception) { System.out.println( "\tFAILED (runUsage()) = Exception: "+exception.toString()+"\n"); } wtpObjParNo = wtpObjPar.getNumber(); System.out.println( "\n1TST) WTPART OBJECT = WTPART NO ASSOC TO EPMDOC PARENT - wtpObjParNo (wtpObjPar.getNumber()): "+ wtpObjParNo); System.out.println( "\nX-Y-Z"+ wtpObjParNo); wtpObjParOid = wtpObjPar.getPersistInfo().getObjectIdentifier().toString(); System.out.println( "1TST) ID - wtpObjParOid: "+ wtpObjParOid); System.out.println( "X-Y-Z"+ wtpObjParOid); wtpObjChNo = wtpObjCh.getNumber(); System.out.println( "\n1TST) WTPART OBJECT = WTPART NO ASSOC TO EPMDOC CHILD - wtpObjChNo (wtpObjCh.getNumber()): "+ wtpObjChNo); System.out.println( "X-Y-Z"+ wtpObjChNo); wtpObjChOid = wtpObjCh.getPersistInfo().getObjectIdentifier().toString(); System.out.println( "1TST) ID - wtpObjChOid: "+ wtpObjChOid); System.out.println( "X-Y-Z"+ wtpObjChOid); try { // CHILD WTPART ID = CHILD WTPART ID && PARENT WTPART ID = PARENT WTPART ID if ( tmpWtpIdStg.equalsIgnoreCase(wtpObjChOid) && tmpWtpIdStg2.equalsIgnoreCase(wtpObjParOid) ) { // QUERY PARENT WTPART OBJECT FOR CHILDREN QueryResult qrUses3 = null; qrUses3 = WTPartHelper.service.getUsesWTParts(wtpObjPar, configSpec); System.out.println("\n\t2TSTgetUsesWTParts(wtpObjPar: "+wtpObjPar.getNumber()+",PARENT) (qrUses3.size()): "+qrUses3.size()); System.out.println("\t2TST) WTPART NO ASSOC TO EPMDOC PARENT ID - wtpObjParOid: "+ wtpObjParOid); System.out.println("\nsize:"+qrUses3.size()); System.out.println("X-Y-Z"+wtpObjPar.getNumber()); System.out.println("X-Y-Z"+ wtpObjParOid); boolean linkCheck = false; int j = 0; if(qrUses3 != null) do { if(!qrUses3.hasMoreElements()) break; Object obj1 = qrUses3.nextElement(); System.out.println("\tX-Y-Zj:"+j); if(obj1 instanceof wt.fc.Persistable[]) { wt.fc.Persistable apersistable1[] = (wt.fc.Persistable[])(wt.fc.Persistable[])obj1; if(apersistable1[1] instanceof WTPart) { WTPart wtpUsesChk = (WTPart)apersistable1[1]; wtpUsesChkNo = wtpUsesChk.getNumber(); System.out.println("\n\t2TST) CHILD WTPART NO - wtpUsesChkNo (wtpUsesChk.getNumber()): "+ wtpUsesChkNo); System.out.println("\nX-Y-Z"+ wtpUsesChkNo); wtpUsesChkOid = wtpUsesChk.getPersistInfo().getObjectIdentifier().toString(); System.out.println("X-Y-Z"+ wtpUsesChkOid); if ( wtpUsesChkOid.equalsIgnoreCase(wtpObjParOid) ) { System.out.println("\t2TST) MATCH FOUND FOR CHILD WTPART NO - wtpUsesChkNo: " +wtpUsesChkNo+ " & CHILD WTPART ID - wtpUsesChkOid: "+wtpUsesChkOid + " & PARENT WTPART ID - wtpObjParOid: "+ wtpObjParOid); System.out.println("\tGO:NO:X-Y-Z"+wtpUsesChkNo+"CH:X-Y-Z"+wtpUsesChkOid+"=PAR:X-Y-Z"+ wtpObjParOid); linkCheck = true; break; } else { System.out.println("\t2TST) NO MATCH FOUND FOR CHILD WTPART NO - wtpUsesChkNo: " +wtpUsesChkNo+ " & CHILD WTPART ID - wtpUsesChkOid: "+wtpUsesChkOid + " & PARENT WTPART ID - wtpObjParOid: "+ wtpObjParOid); System.out.println("\tNOGO:NO:X-Y-Z"+wtpUsesChkNo+"CH:X-Y-Z"+wtpUsesChkOid+"=PAR:X-Y-Z"+ wtpObjParOid); } } } } while(true); System.out.println("\n\t3TST) BOOLEAN CHECK: linkCheck: "+ linkCheck); if (!linkCheck) { System.out.println("\n\t3TST) BOOLEAN CHECK: NO MATCH FOUND FOR wtpObjParOid: " + wtpObjParOid + " & wtpUsesChkOid: "+wtpUsesChkOid); //wtpObjCh = (WTPart)setCheckoutInfo(wtpObjCh, WorkInProgressState.WORKING); //wtpObjPar = (WTPart)setCheckoutInfo(wtpObjPar, WorkInProgressState.WORKING); wtpObjPar = checkOutPart(wtpObjPar); wtpObjCh = checkOutPart(wtpObjCh); System.out.println("\nWTPart: wtpObjPar.getNumber(): "+wtpObjPar.getNumber() +" = Is Now Linked to WTPart: wtpObjCh.getNumber(): "+wtpObjCh.getNumber()); System.out.println("3)X-Y-ZLink:PAR:"+wtpObjPar.getNumber()+"=CH:"+wtpObjCh.getNumber()); createUsageLink(wtpObjPar,wtpObjCh); wtpObjCh = checkInPart(wtpObjCh); wtpObjPar = checkInPart(wtpObjPar); } else { System.out.println("\n\t3TST) BOOLEAN CHECK: MATCH FOUND FOR wtpObjParOid: "+ wtpObjParOid + " & wtpUsesChkOid: "+wtpUsesChkOid); System.out.println("3)X-Y-ZNoLink:PAR:"+wtpObjPar.getNumber()+"=CH:"+wtpObjCh.getNumber()); } } } catch(Exception exception) { System.out.println( "\tFAILED (createUsageLink) = Exception: "+exception.toString()+"\n"); } } } } } public static void epmTree(String QueTypeIN, EPMDocument epmDoc) throws WTException { try { arraylistTopEPM = new ArrayList(); arraylistTopWTP = new ArrayList(); arraylistEpmLink = new ArrayList(); arraylistWtpLink = new ArrayList(); arraylist1 = new ArrayList(); configSpec = new LatestConfigSpec(); qrChildChecker = EPMStructureHelper.service.navigateUsesToIteration(epmDoc, null, false, configSpec); if ( qrChildChecker.size() > 0) { arraylistTopEPM.add(epmDoc); arraylist1 = new ArrayList(); arraylist1 = listSortedChildrenInfo(epmDoc, configSpec); System.out.println( "EPMDoc Tree "+epmDoc.getNumber()+" Children/Size (arraylistTopEPM.size()): "+arraylistTopEPM.size()+"\n"); for (int x = 0; x < arraylistTopEPM.size(); x++ ) { EPMDocument epmTop = null; epmTop = (EPMDocument)arraylistTopEPM.get(x); epmCont = epmTop.getContainer(); epmFolder = wt.folder.FolderHelper.getFolder(epmTop); LMObject = (LifeCycleManaged)epmTop; StStg = (String)LMObject.getLifeCycleState().toString(); String oid = epmTop.getPersistInfo().getObjectIdentifier().toString(); //System.out.println( "\nEPMDoc (epmTop) ID: "+ oid); System.out.println( "EPMDoc Number: "+ epmTop.getNumber() + "| EPMDoc Name: " + epmTop.getName()); System.out.println( "EPMDoc CADName: "+ epmTop.getCADName() + "| EPMDoc DocType: " + epmTop.getDocType()); System.out.println( "EPMDoc Container: "+ epmCont.getName() + "| EPMDoc Folder: " + epmFolder); System.out.println( "EPMDoc Version: " + epmTop.getVersionIdentifier().getValue() + "."+epmTop.getIterationIdentifier().getValue()+"| LC State: "+StStg+"\n"); getWtpAssoc(QueTypeIN,epmTop,epmFolder); QueryResult qrNav = EPMStructureHelper.service.navigateUsesToIteration(epmTop, null, false, configSpec); System.out.println( "\n=================================================="); System.out.println( "Number: "+ epmTop.getNumber()+" = navigateUsesToIteration (qrNav.size()): "+qrNav.size()+"\n"); while (qrNav.hasMoreElements()) { Persistable apersistable1[] = (Persistable[])(Persistable[])qrNav.nextElement(); if(apersistable1[1] instanceof EPMDocument) { EPMDependencyLink epmLink = (EPMDependencyLink)apersistable1[0]; EPMDocument epm1 = (EPMDocument)apersistable1[1]; System.out.println( "EPMDoc Number (epm1): "+ epm1.getNumber() + "| EPMDoc Name: " + epm1.getName()); System.out.println( "EPMDoc Version (epm1): " + epm1.getVersionIdentifier().getValue() + "."+epm1.getIterationIdentifier().getValue()+"\n"); getLinkEpmStg(epm1, epmTop); } } } } } catch(Exception exception) { System.out.println( "\tFAILED (epmTree) = Exception: "+exception.toString()+"\n"); } } public static void getLinkEpmStg(EPMDocument epmCh, EPMDocument epmPar ) throws WTException { oidCh = epmCh.getPersistInfo().getObjectIdentifier().toString(); oidPar = epmPar.getPersistInfo().getObjectIdentifier().toString(); WTPart wtpList5[] = ObjectDependencyUtility.getAssociated((EPMDocument)epmPar); if( wtpList5 != null ) { System.out.println( "\t###Associated EPMDoc length (wtpList5.length): " + wtpList5.length+"\n"); for (int y = 0; y < wtpList5.length; y++ ) { WTPart wtpAssoc5 = null; wtpAssoc5 = (WTPart)wtpList5[y]; oidWtp = wtpAssoc5.getPersistInfo().getObjectIdentifier().toString(); System.out.println( "\t###But Did Find Existing WTPart Number Association to (y:"+y+"): "+wtpAssoc5.getNumber()+" with ID: "+oidWtp+"\n"); linkEpmStg = epmCh.getNumber() + "|" + oidCh+ "|PARENT|" + epmPar.getNumber() + "|" + oidPar + "|ASSOC|"+wtpAssoc5.getNumber()+ "|" + oidWtp; System.out.println( "\t###linkEpmStg: " + linkEpmStg+"\n"); arraylistEpmLink.add(linkEpmStg); } } else { linkEpmStg = epmCh.getNumber() + "|" + oidCh+ "|PARENT|" + epmPar.getNumber() + "|" + oidPar; System.out.println( "\t###linkEpmStg: " + linkEpmStg+"\n"); arraylistEpmLink.add(linkEpmStg); } } public static void getWtpAssoc(String QueTypeIN, EPMDocument epmIN, Folder epmFolderIN) throws WTException { epmNoLg = ""; epmNoSh = ""; epmNoLg = epmIN.getNumber(); epmNmIn = epmIN.getName(); epmNoSh = epmIN.getNumber(); wtpSh = null; wtpLg = null; WTPartMaster wtpMaster; String wtpNoFinal; if (epmNoLg.indexOf(".") > 0 && epmNoLg != null ) { // create epmdoc short number, remove epmdoc number extension //System.out.println( "\tLong EPMDoc Number: "+epmNoLg); epmNoSh = removeExt(epmNoLg); //System.out.println( "\tShort EPMDoc Number: "+epmNoSh+"\n"); } try { wtpSh = findWtpNoEQ(epmNoSh); // check if wtpart exists with same number as epmdoc short number wtpLg = findWtpNoEQ(epmNoLg); // check if wtpart exists with same number as epmdoc long number } catch(WTException wte) { System.out.println( "\tQueryfor wtpLg ( "+wtpLg+") or wtpSh ( "+wtpSh+") FAILED.\n"); } catch(WTPropertyVetoException wtp) { System.out.println( "\tQuery for wtpLg ( "+wtpLg+") or wtpSh ( "+wtpSh+") FAILED:\n"); } WTPart wtpList[] = ObjectDependencyUtility.getAssociated((EPMDocument)epmIN); // find list of associated wtparts //wtpListTest(epmIN); // run method to print several separate active & passive associations if( wtpList != null ) { // Found wtpart associated to current epmdoc array element //System.out.println( "\tAssociated (.getAssociated) WTPart (wtpList.length): " + wtpList.length+"\n"); for (int y = 0; y < wtpList.length; y++ ) { // Loop through epmdoc (epmIN) associated wtpart array wtpAssoc = null; wtpNo = ""; wtpCont = null; wtpFolder = null; wtpNoFinal = ""; wtpAssoc = (WTPart)wtpList[y]; wtpNo = wtpAssoc.getNumber(); wtpCont = wtpAssoc.getContainer(); wtpFolder = wt.folder.FolderHelper.getFolder(wtpAssoc); LMObject = (LifeCycleManaged)wtpAssoc; StStg = (String)LMObject.getLifeCycleState().toString(); System.out.println( "\tAssociated WTPart Info: ("+y+")"); oid = wtpAssoc.getPersistInfo().getObjectIdentifier().toString(); //System.out.println( "\tWTPart (wtpAssoc) ID: "+ oid); 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"); wtpMaster = null; wtpMaster = (WTPartMaster)wtpAssoc.getMaster(); wt.fc.IdentificationObject idObj = wtpMaster.getIdentificationObject(); WTPartMasterIdentity wtpmID = (WTPartMasterIdentity)idObj; /* // create (wtp no|ID|ASSOC|epm no|ID) String linkWtpStg = wtpAssoc.getNumber() + "|" + wtpAssoc.getPersistInfo().getObjectIdentifier().toString() + "|ASSOC|"+epmIN.getNumber()+ "|" + epmIN.getPersistInfo().getObjectIdentifier().toString(); System.out.println( "\t###linkWtpStg(getWtpAssoc:wtpList["+y+"]): " + linkWtpStg+"\n"); arraylistWtpLink.add(linkWtpStg); //System.out.println("\tarraylistWtpLink.size(): "+arraylistWtpLink.size()+ "\n"); */ if (wtpNo.equals(epmNoSh)) { // epmdoc short number & wtpart long number are same number System.out.println("\tEPMDoc (Short Number): "+epmNoSh+" & WTPart: "+wtpNo+ " NUMBERS MATCH: \n"); } else { // epmdoc short number & wtpart number are NOT same if (wtpSh != null) { // wtpLg exists if ( wtpLg != null ) { break; } else { if (QueTypeIN.equals("-rw")||QueTypeIN.equals("-ro")) { try { //System.out.println("\tFound WTPart Master of "+wtpMaster.getNumber()+"\n"); wtpmID.setNumber(epmNoLg); IdentityHelper.service.changeIdentity(wtpMaster, wtpmID); System.out.println("\tIdentity Changed to: "+epmNoLg+"\n"); } catch(WTException wte) { System.out.println( "\tWTPart Number ( "+epmNoLg+") Change FAILED:\n"); } catch(WTPropertyVetoException wtp) { System.out.println( "\tWTPart Number ( "+epmNoLg+") Change FAILED:\n"); } } } } else { if (QueTypeIN.equals("-rw")||QueTypeIN.equals("-ro")) { try { //System.out.println("\tFound WTPart Master of "+wtpMaster.getNumber()+"\n"); wtpmID.setNumber(epmNoSh); IdentityHelper.service.changeIdentity(wtpMaster, wtpmID); System.out.println("\tIdentity Changed to: "+epmNoLg+"\n"); } catch(WTException wte) { System.out.println( "\tWTPart Number ( "+epmNoSh+") Change FAILED:\n"); } catch(WTPropertyVetoException wtp) { System.out.println( "\tWTPart Number ( "+epmNoSh+") Change FAILED:\n"); } } } } } } else { System.out.println( "\tFOUND NO Associated (.getAssociated) WTParts: 0\n"); epmSh = ObjectDependencyUtility.getAssociated((WTPart)wtpSh); // = ABC123 epmLg = ObjectDependencyUtility.getAssociated((WTPart)wtpLg); // = ABC123.PRT try { // 1) Does wtpSh exist? ( wtpart with short number [ABC123] ) if (wtpSh != null) { // A) YES - wtpSh exists ( wtpart with short number [ABC123] ) //System.out.println( "\tFound Non Associated WTPart NO: "+wtpSh.getNumber() +"\n\twith same Number as EPMDoc: "+epmNoLg+"\n"); // Is wtpSh assoc to any epmdoc? if( epmSh != null && epmSh.length > 0 ) { // YES ( Go wtpLg route = [ wtpart with epmdoc long number [ABC123.PRT] ] ) //System.out.println( "\tFound Associated EPMDoc length (epmSh.length): " + epmSh.length+"\n"); // Does wtpLg exist? if (wtpLg != null) { // Yes wtpLg exists //System.out.println( "\tFound Non Associated WTPart NO: "+wtpLg.getNumber() +"\n\twith same Number as EPMDoc: "+epmNoIn+"\n"); // Is wtpLg associated to any epmdoc (epmLg)? if( epmLg != null && epmLg.length > 0 ) { // Yes, wtpLg is associated to a epmdoc (epmLg)? //System.out.println( "\tYes, wtpLg "+wtpLg.getNumber()+" is associated to a epmdoc (epmLg)?"); } else { // wtpLg is not associated to any epmdoc? //System.out.println( "\tNO, wtpLg is not associated to a epmdoc (epmLg)?"); //System.out.println( "\tAssoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT]"); // Assoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT] ) if (QueTypeIN.equals("-rw")) { try { //wtpLg = (WTPart)setCheckoutInfo(wtpLg, WorkInProgressState.WORKING); wtpLg = checkOutPart(wtpLg); EPMBuildRule epmbuildrule = null; epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, wtpLg); epmbuildrule = (EPMBuildRule)PersistenceHelper.manager.save(epmbuildrule); System.out.println( "\tCreated Association between WTPart Number: "+wtpLg.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+"\n"); wtpLg = checkInPart(wtpLg); } catch(WTException wtexception) { System.out.println( "\tFAILED Link association between WTPart Number: "+wtpLg.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)wtpLg); 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"); } //assocObjs( wtpLg, epmIN ); } } } else { // NO, wtpLg does not exist //System.out.println( "\tFound Associated EPMDoc length (epmSh.length): " + epmSh.length+"\n"); if (QueTypeIN.equals("-rw")) { //System.out.println( "\tCreate wtpLg (wtpart with epmdoc long number [ABC123.PRT] )\n"); // Create wtpLg (wtpart with epmdoc long number [ABC123.PRT] ) WTPart wtpLg = createWtp(epmNoLg, epmNmIn, epmFolderIN, epmIN ); String tmpWtpNo = wtpLg.getNumber(); System.out.println( "\n1) tmpWtpNo (wtpLg.getNumber()): "+ tmpWtpNo); //System.out.println( "\tAssoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT] )\n"); // Assoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT] ) try { //wtpLg = (WTPart)setCheckoutInfo(wtpLg, WorkInProgressState.WORKING); wtpLg = checkOutPart(wtpLg); EPMBuildRule epmbuildrule = null; epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, wtpLg); epmbuildrule = (EPMBuildRule)PersistenceHelper.manager.save(epmbuildrule); System.out.println( "\tCreated Association between WTPart Number: "+wtpLg.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+"\n"); wtpLg = checkInPart(wtpLg); } catch(WTException wtexception) { System.out.println( "\tFAILED Link association between WTPart Number: "+wtpLg.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)wtpLg); 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"); } //assocObjs( wtpLgNew, epmIN ); } } } else { // NO, wtpSh is NOT assoc to any epmdoc // Assoc wtpSh (wtpart with epmdoc short number [ABC123]) to epmIN (epmdoc) System.out.println( "\tAssoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT] )"); if (QueTypeIN.equals("-rw")) { try { //wtpSh = (WTPart)setCheckoutInfo(wtpSh, WorkInProgressState.WORKING); wtpSh = checkOutPart(wtpSh); EPMBuildRule epmbuildrule = null; epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, wtpSh); epmbuildrule = (EPMBuildRule)PersistenceHelper.manager.save(epmbuildrule); System.out.println( "\tCreated Association between WTPart Number: "+wtpSh.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+"\n"); wtpSh = checkInPart(wtpSh); } catch(WTException wtexception) { System.out.println( "\tFAILED Link association between WTPart Number: "+wtpSh.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)wtpSh); 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"); } //assocObjs( wtpSh, epmIN ); } } } else { // NO - wtpart with short number (abc123) does not exist // Didnt find epmdoc associated to wtpart short & == null or > 0 //System.out.println( "\tNO - wtpart with short number (abc123) does not exist"); //System.out.println( "\tDidnt find epmdoc associated to wtpart short & == null or > 0"); if (QueTypeIN.equals("-rw")) { //System.out.println( "\tCreate wtpSh (wtpart with epmdoc short number [ABC123] )"); // Create wtpSh (wtpart with epmdoc short number [ABC123] ) wtpSh = createWtp( epmNoSh, epmNmIn, epmFolderIN, epmIN ); String tmpWtpNo = wtpSh.getNumber(); System.out.println( "\n1) tmpWtpNo (wtpSh.getNumber()): "+ tmpWtpNo); // Assoc wtpSh to epmIN (wtpart with epmdoc short number [ABC123] ) // System.out.println( "\tAssoc wtpSh to epmIN (wtpart with epmdoc short number [ABC123] )"); try { //wtpSh = (WTPart)setCheckoutInfo(wtpSh, WorkInProgressState.WORKING); wtpSh = checkOutPart(wtpSh); EPMBuildRule epmbuildrule = null; epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, wtpSh); epmbuildrule = (EPMBuildRule)PersistenceHelper.manager.save(epmbuildrule); System.out.println( "\tCreated Association between WTPart Number: "+wtpSh.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+"\n"); wtpSh = checkInPart(wtpSh); } catch(WTException wtexception) { System.out.println( "\tFAILED Link association between WTPart Number: "+wtpSh.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)wtpSh); 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"); } //assocObjs( wtpSh, epmIN ); } } } catch(Exception exception) { System.out.println( "\tFAILED = Exception: "+exception.toString()+"\n"); } } } public static void wtpTree(WTPart wtp) throws WTException { try{ arraylistTopWTP = new ArrayList(); arraylist1 = new ArrayList(); configSpec = new LatestConfigSpec(); qrChildChecker = WTPartHelper.service.getUsesWTParts(wtp, configSpec); if ( qrChildChecker.size() > 0) { arraylistTopWTP.add(wtp); arraylist1 = new ArrayList(); arraylist1 = listSortedChildrenInfo(wtp, configSpec); System.out.println( "WTPart Tree "+wtp.getNumber()+" Children/Size (arraylistTopWTP.size()): "+arraylistTopWTP.size()+"\n"); for (int x = 0; x < arraylistTopWTP.size(); x++ ) { WTPart wtpTop = null; wtpTop = (WTPart)arraylistTopWTP.get(x); wtpCont = wtpTop.getContainer(); wtpFolder = wt.folder.FolderHelper.getFolder(wtpTop); LMObject = (LifeCycleManaged)wtpTop; StStg = (String)LMObject.getLifeCycleState().toString(); System.out.println( "WTPart Number: "+ wtpTop.getNumber() + "| WTPart Name: " + wtpTop.getName()); System.out.println( "WTPart Container: "+ wtpCont.getName() + "| WTPart Folder: " + wtpFolder); System.out.println( "WTPart Version: " + wtpTop.getVersionIdentifier().getValue() + "."+wtpTop.getIterationIdentifier().getValue()+"| LC State: "+StStg+"\n"); EPMDocument epmList[] = ObjectDependencyUtility.getAssociated((WTPart)wtpTop); if( epmList != null ) { //System.out.println( "\tAssociated EPMDoc (epmList.length): " + epmList.length+"\n"); for (int y = 0; y < epmList.length; y++ ) { EPMDocument epmTop = null; epmTop = (EPMDocument)epmList[y]; epmCont = epmTop.getContainer(); epmFolder = wt.folder.FolderHelper.getFolder(epmTop); LMObject = (LifeCycleManaged)epmTop; StStg = (String)LMObject.getLifeCycleState().toString(); System.out.println( "\tAssociated EPMDoc Info ("+y+"): "); System.out.println( "\tEPMDoc Number: "+ epmTop.getNumber() + "| EPMDoc Name: " + epmTop.getName()); System.out.println( "\tEPMDoc CADName: "+ epmTop.getCADName() + "| EPMDoc DocType: " + epmTop.getDocType()); System.out.println( "\tEPMDoc Container: "+ epmCont.getName() + "| EPMDoc Folder: " + epmFolder); System.out.println( "\tEPMDoc Version: " + epmTop.getVersionIdentifier().getValue() + "."+epmTop.getIterationIdentifier().getValue()+"| LC State: "+StStg+"\n"); } } } } } catch(Exception exception) { System.out.println( "\tFAILED = Exception: "+exception.toString()+"\n"); } } public static WTPart createWtp( String epmNum, String epmName, Folder foldLoc, EPMDocument epmInTA ) throws WTException, WTPropertyVetoException { WTPart wtpNew = null; wtpNew = WTPart.newWTPart(epmNum,epmName); FolderHelper.assignLocation(wtpNew,foldLoc); try { wtpNew.getMaster().setSeries(epmInTA.getMaster().getSeries()); VersionControlHelper.setVersionIdentifier(wtpNew, epmInTA.getVersionIdentifier()); } catch(NumberFormatException numberformatexception) { System.out.println( "\tUnable to set the version id of the WTPart Number: "+wtpNew.getNumber()); } VersionControlHelper.setIterationIdentifier(wtpNew, IterationIdentifier.newIterationIdentifier()); wtpNew.setSource(Source.MAKE); wtpNew.setDefaultUnit(QuantityUnit.EA); wtpNew.setPartType(PartType.SEPARABLE); //wtpNew.setView(View.DESIGN); wtpNew=(WTPart)PersistenceHelper.manager.save(wtpNew); System.out.println( "\tCreated WTPart Number: "+wtpNew.getNumber()); wtpCont = wtpNew.getContainer(); LMObject = (LifeCycleManaged)wtpNew; StStg = (String)LMObject.getLifeCycleState().toString(); oid = wtpNew.getPersistInfo().getObjectIdentifier().toString(); //System.out.println( "\tWTPart (wtpNew) ID: "+ oid); System.out.println( "\tWTPart Number: "+ wtpNew.getNumber() + "| WTPart Name: "+ wtpNew.getName()); System.out.println( "\tWTPart Container: "+ wtpCont.getName() + "| WTPart Folder: "+ foldLoc); System.out.println( "\tWTPart Version: " + wtpNew.getVersionIdentifier().getValue() + "."+wtpNew.getIterationIdentifier().getValue()+"| LC State: "+StStg+"\n"); // create (wtp no|ID|ASSOC|epm no|ID) String linkWtpStg = wtpNew.getNumber() + "|" + wtpNew.getPersistInfo().getObjectIdentifier().toString() + "|ASSOC|"+epmInTA.getNumber()+ "|" + epmInTA.getPersistInfo().getObjectIdentifier().toString(); System.out.println( "\t###linkWtpStg (createWtp): " + linkWtpStg+"\n"); arraylistWtpLink.add(linkWtpStg); return wtpNew; } public static void assocObjs( WTPart wtpTA, EPMDocument epmInTA ) throws WTException { try { //wtpTA = (WTPart)setCheckoutInfo(wtpTA, WorkInProgressState.WORKING); wtpTA = checkOutPart(wtpTA); EPMBuildRule epmbuildrule = null; epmbuildrule = EPMBuildRule.newEPMBuildRule(epmIN, wtpTA); epmbuildrule = (EPMBuildRule)PersistenceHelper.manager.save(epmbuildrule); System.out.println( "\tCreated Association between WTPart Number: "+wtpTA.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+"\n"); wtpTA = checkInPart(wtpTA); } catch(WTException wtexception) { System.out.println( "\tFAILED Link association between WTPart Number: "+wtpTA.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+" Exception: "+wtexception+"\n"); WTPart wtpListTmp[] = ObjectDependencyUtility.getAssociated((EPMDocument)epmIN); if( wtpListTmp != null ) { //System.out.println( "\tAssociated EPMDoc length (wtpListTmp.length): " + wtpListTmp.length+"\n"); for (int y = 0; y < wtpListTmp.length; y++ ) { WTPart wtpAssocTmp = null; wtpAssocTmp = (WTPart)wtpListTmp[y]; System.out.println( "\tBut Did Find Existing WTPart Number Association to ("+y+"): "+wtpAssocTmp.getNumber()); } } if( epmLg != null ) { //System.out.println( "\tAssociated EPMDoc length: " + epmLg.length+"\n"); for (int y = 0; y < epmLg.length; y++ ) { EPMDocument epmTopLg = null; epmTopLg = (EPMDocument)epmLg[y]; System.out.println( "\tBut Did Find Existing EPMDoc Number Association ("+y+"): "+epmTopLg.getNumber()); } } System.out.println( "\n"); } catch(WTPropertyVetoException wtVeto) { System.out.println( "\tFAILED Link association between WTPart Number: "+wtpTA.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+" Exception: "+wtVeto+"\n"); } } public static WTPart findWtpNoEQ(String objNo) throws WTException, WTPropertyVetoException { configSpec = new LatestConfigSpec(); QuerySpec qs = new QuerySpec(WTPart.class); qs.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.EQUAL,objNo)); qs.appendAnd(); qs.appendWhere(new SearchCondition(WTPart.class, "iterationInfo.latest", "TRUE")); qs = configSpec.appendSearchCriteria(qs); qr = PersistenceHelper.manager.find(qs); qr = configSpec.process(qr); //System.out.println( "\nSQL (findWtpNoEQ): \n"+qs.toString()+"\n"); if(qr.size() == 1) { WTPart wtpEQ = (WTPart)qr.nextElement(); //System.out.println( "\tFound EQUAL WTPart for : "+wtpEQ.getNumber()+" qr.size(): "+qr.size()+"\n"); return wtpEQ; } else { //qr.size() == 0 //System.out.println( "\tFound Other than 1 EQUAL WTPart for qr.size() : "+qr.size()+"\n"); return null; } } public static void findWtpNo(String QueType, String objNo) throws WTException, WTPropertyVetoException { configSpec = new LatestConfigSpec(); QuerySpec qs = new QuerySpec(WTPart.class); qs.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.LIKE,objNo)); qs.appendAnd(); qs.appendWhere(new SearchCondition(WTPart.class, "iterationInfo.latest", "TRUE")); qs = configSpec.appendSearchCriteria(qs); qr = PersistenceHelper.manager.find(qs); qr = configSpec.process(qr); while (qr.hasMoreElements()) { wtpOrig = null; wtpOrig = (WTPart)qr.nextElement(); System.out.println( "Running Original WTPart Tree for : "+wtpOrig.getNumber()+"\n"); wtpTree(wtpOrig); QueryResult qrUses = WTPartHelper.service.getUsesWTParts(wtpOrig, configSpec); if(qrUses != null) do { if(!qrUses.hasMoreElements()) break; Object obj1 = qrUses.nextElement(); if(obj1 instanceof wt.fc.Persistable[]) { wt.fc.Persistable apersistable1[] = (wt.fc.Persistable[])(wt.fc.Persistable[])obj1; if(apersistable1[1] instanceof WTPart) { WTPart wtpm2 = (WTPart)apersistable1[1]; LMObject = (LifeCycleManaged)wtpm2; StStg = (String)LMObject.getLifeCycleState().toString(); wtpCont = wtpm2.getContainer(); wtpFolder = wt.folder.FolderHelper.getFolder(wtpm2); } } } while(true); } } private static void createUsageLink(WTPart wtpart, WTPart wtpart1) throws Exception { WTPartUsageLink wtpartusagelink = WTPartUsageLink.newWTPartUsageLink(wtpart, (WTPartMaster)wtpart1.getMaster()); Quantity quantity = Quantity.newQuantity(); quantity.setUnit(QuantityUnit.EA); quantity.setAmount(1.0D); wtpartusagelink.setQuantity(quantity); wtpartusagelink = (WTPartUsageLink)PersistenceHelper.manager.save(wtpartusagelink); } public static void wtpListTest(EPMDocument epmDocIn) throws WTException { WTPart wtpListPA[] = ObjectDependencyUtility.getPassiveAssociated(epmDocIn); 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(epmDocIn); 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"); QueryResult qrAct = null; QueryResult qrPas = null; try { if(VersionControlHelper.isLatestIteration(epmDocIn)) qrAct = PersistenceHelper.manager.navigate(epmDocIn, "buildTarget", wt.epm.build.EPMBuildRule.class); else qrAct = PersistenceHelper.manager.navigate(epmDocIn, "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"); } try { qrPas = StructHelper.service.navigateDescribes(epmDocIn, 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"); } } public static Persistable[][] my_getUsesWTParts(WTPart wtpart, ConfigSpec configSpec) throws WTException { ArrayList arraylist2 = new ArrayList(); QueryResult qrMY = WTPartHelper.service.getUsesWTParts(wtpart, configSpec); do { if(!qrMY.hasMoreElements()) break; Persistable apersistable[] = (Persistable[])(Persistable[])qrMY.nextElement(); if(apersistable[1] instanceof WTPart) { WTPartUsageLink wtpartusagelink = (WTPartUsageLink)apersistable[0]; if(!wtpartusagelink.dissatisfiesFilterCriteria()) arraylist2.add(apersistable); WTPart wtChild3 = ((WTPart) apersistable[1] ); arraylistTopWTP.add(wtChild3); } } while(true); return (Persistable[][])(Persistable[][])arraylist2.toArray(new Persistable[arraylist2.size()][]); } public static Persistable[][] my_getUsesEPMDocs(EPMDocument epmDoc, ConfigSpec configSpec) throws WTException { ArrayList arraylist2 = new ArrayList(); QueryResult qrMY = EPMStructureHelper.service.navigateUsesToIteration(epmDoc, null, false, configSpec); do { if(!qrMY.hasMoreElements()) break; Persistable apersistable[] = (Persistable[])(Persistable[])qrMY.nextElement(); Persistable persistable = apersistable[0]; Persistable persistable1 = apersistable[1]; if((persistable instanceof EPMDependencyLink) && (persistable1 instanceof EPMDocument)) { EPMDependencyLink epmdependencylink = (EPMDependencyLink)persistable; epm1 = (EPMDocument)persistable1; epmCont = epm1.getContainer(); epmFolder = wt.folder.FolderHelper.getFolder(epm1); epmNo = epm1.getNumber(); arraylist2.add(apersistable); arraylistTopEPM.add(epm1); LMObject = (LifeCycleManaged)epm1; StStg = (String)LMObject.getLifeCycleState().toString(); } } while(true); return (Persistable[][])(Persistable[][])arraylist2.toArray(new Persistable[arraylist2.size()][]); } public static ArrayList listSortedChildrenInfo(WTPart wtpart, ConfigSpec configSpec) throws WTPropertyVetoException, WTException { ArrayList arraylist = new ArrayList(); Persistable apersistable[][] = my_getUsesWTParts(wtpart, configSpec); if(apersistable.length > 0) { for(int j = 0; j < apersistable.length; j++) { WTPart wtChild2 = (WTPart)apersistable[j][1]; System.out.println( "%%% - WTPart: (wtChild2): "+wtChild2.getNumber()+" & ID: "+wtChild2.getPersistInfo().getObjectIdentifier().toString()+"\n"); ArrayList arraylist1 = listSortedChildrenInfo(wtChild2, configSpec); arraylist.add(arraylist1); } } return arraylist; } public static ArrayList listSortedChildrenInfo(EPMDocument epmDoc, ConfigSpec configSpec) throws WTPropertyVetoException, WTException { ArrayList arraylist = new ArrayList(); Persistable apersistable[][] = my_getUsesEPMDocs(epmDoc, configSpec); if(apersistable.length > 0) { for(int j = 0; j < apersistable.length; j++) { EPMDocument epmDoc2 = (EPMDocument)apersistable[j][1]; ArrayList arraylist1 = listSortedChildrenInfo(epmDoc2, configSpec); arraylist.add(arraylist1); } } return arraylist; } public static String removeExt(String tmpStg) { if ( tmpStg.endsWith(".PRT") || tmpStg.endsWith(".prt") ) { tmpStg = tmpStg.substring(0, tmpStg.length() - 4); } if ( tmpStg.endsWith(".DRW") || tmpStg.endsWith(".drw") ) { tmpStg = tmpStg.substring(0, tmpStg.length() - 4); } if ( tmpStg.endsWith(".ASM") || tmpStg.endsWith(".asm") ) { tmpStg = tmpStg.substring(0, tmpStg.length() - 4); } return tmpStg; } private static WTPart checkOutPart(WTPart wtpart) throws WTException, WorkInProgressException, NonLatestCheckoutException, WTPropertyVetoException, PersistenceException { boolean flag = WorkInProgressHelper.isCheckedOut(wtpart); if(flag) { return wtpart; } else { wt.folder.Folder folder = WorkInProgressHelper.service.getCheckoutFolder(); CheckoutLink checkoutlink = WorkInProgressHelper.service.checkout(wtpart, folder, null); wtpart = (WTPart)checkoutlink.getRoleBObject(); return wtpart; } } private static WTPart checkInPart(WTPart wtpart) throws WTException, WorkInProgressException, WTPropertyVetoException, PersistenceException { wt.vc.wip.Workable workable = WorkInProgressHelper.service.checkin(wtpart, ""); return (WTPart)workable; } protected static RevisionControlled setCheckoutInfo(RevisionControlled revCon, WorkInProgressState wipState) throws WTException { try { CheckoutInfo checkoutinfo = CheckoutInfo.newCheckoutInfo(); checkoutinfo.setState(wipState); revCon.setCheckoutInfo(checkoutinfo); } catch(WTPropertyVetoException wtp) { System.out.println( "\tFAILED = WTPropertyVetoException: "+wtp.toString()+"\n"); } catch(WTException wte) { System.out.println( "\tFAILED = WTException: "+wte.toString()+"\n"); } return revCon; } public static void arrayPrint() throws WTException { System.out.println( "\narraylistTopEPM.size(): "+arraylistTopEPM.size()+"\n==================================================\n"); for (int x = 0; x < arraylistTopEPM.size(); x++ ) { epmRun = (EPMDocument)arraylistTopEPM.get(x); System.out.println( "\nRUN("+x+"): EPMDoc Number: "+ epmRun.getNumber() +"| ID: "+epmRun.getPersistInfo().getObjectIdentifier().toString() + "| EPMDoc Name: " + epmRun.getName()); WTPart wtpListM[] = ObjectDependencyUtility.getAssociated((EPMDocument)epmRun); if( wtpListM != null ) { System.out.println( "\tAssociated WTPart (wtpListM.length): " + wtpListM.length); for (int y = 0; y < wtpListM.length; y++ ) { wtpRun2 = (WTPart)wtpListM[y]; System.out.println( "\t\tAssociated WTPart Info: ("+y+"): WTPart Number: "+ wtpRun2.getNumber() +"| ID: "+wtpRun2.getPersistInfo().getObjectIdentifier().toString() + "| WTPart Name: " + wtpRun2.getName()); } } } System.out.println( "\narraylistTopWTP.size(): "+arraylistTopWTP.size()+"\n==================================================\n"); for (int x = 0; x < arraylistTopWTP.size(); x++ ) { wtpRun = (WTPart)arraylistTopWTP.get(x); System.out.println( "\nRUN("+x+"): WTPart Number: "+ wtpRun.getNumber() +"| ID: "+wtpRun.getPersistInfo().getObjectIdentifier().toString() + "| WTPart Name: " + wtpRun.getName()); EPMDocument epmListM[] = ObjectDependencyUtility.getAssociated((WTPart)wtpRun); if( epmListM != null ) { System.out.println( "\tAssociated EPMDoc (epmListM.length): " + epmListM.length); for (int y = 0; y < epmListM.length; y++ ) { epmRun2 = (EPMDocument)epmListM[y]; System.out.println( "\t\tAssociated EPMDoc Info ("+y+"): EPMDoc Number: "+ epmRun2.getNumber() +"| ID: "+epmRun2.getPersistInfo().getObjectIdentifier().toString() + "| EPMDoc Name: " + epmRun2.getName()); } } } System.out.println( "\narraylistEpmLink.size(): "+arraylistEpmLink.size()+"\n==================================================\n"); for (int x = 0; x < arraylistEpmLink.size(); x++ ) { linkEpmStg = (String)arraylistEpmLink.get(x); System.out.println( "\nlinkEpmStg("+x+"): "+ linkEpmStg); } System.out.println( "\n==================================================\n"); System.out.println( "\narraylistWtpLink.size(): "+arraylistWtpLink.size()+"\n==================================================\n"); for (int x = 0; x < arraylistWtpLink.size(); x++ ) { linkWtpStg = (String)arraylistWtpLink.get(x); System.out.println( "\nlinkWtpStg("+x+"): "+ linkWtpStg); } System.out.println( "\n==================================================\n"); } public static void removeDuplicate(ArrayList arlList) { HashSet h = new HashSet(arlList); arlList.clear(); arlList.addAll(h); } public static void main(String[] args) { RemoteMethodServer rms = RemoteMethodServer.getDefault(); GatewayAuthenticator auth = new GatewayAuthenticator(); auth.setRemoteUser("wcadmin"); rms.setAuthenticator(auth); try { if(args.length < 2) { System.out.println(Usage); System.exit(0); } else { OT = args[0]; QueStg = args[1].toUpperCase(); if ( OT.equals("-qe") ) { findEpmNo(OT,QueStg); } else if ( OT.equals("-qw") ) { findWtpNo(OT,QueStg); } else if ( OT.equals("-qb")||OT.equals("-rw")||OT.equals("-ro") ) { System.out.println( "\nfindEpmNo==================================================\n"); findEpmNo(OT,QueStg); //System.out.println( "\nfindWtpNo==================================================\n"); //findWtpNo(OT,QueStg); arrayPrint(); } else { System.out.println(Usage); } System.exit(0); } } catch(WTException wtee) { System.out.println( "\tFAILED = WTException: "+wtee.toString()+"\n"); } catch(WTPropertyVetoException wtpe) { System.out.println( "\tFAILED = WTPropertyVetoException: "+wtpe.toString()+"\n"); } finally { System.exit(0); } } public static String Usage = "\nUsage:\n\njava/windchill [-mx1024m] "+ "ext.epmList - %%\n\n"+ "1st Argument = :\n\n-qe = query epmdocs only\n-qw = query wtparts only\n"+ "-rw = query epmdocs & rename wtparts (query 1st)\n\n"+ "1st Argument should be lower case.\n\n2nd Argument = %%\n\n"+ "Should include % where % = * = wild card.\n"; static String OT, QueStg, StStg, epmNo, wtpNo, epmNmIn, epmNoIn, epmNoLg, epmNoSh; static String oid, oidEpm, oidWtp, linkEpmStg, linkWtpStg, oidCh, oidPar, wtpUsesChkNo, wtpUsesChkOid; static String tmpWtpNoStg, tmpWtpIdStg, assEpmNoStg, assEpmIdStg; static String tmpEpmNoStg, tmpEpmIdStg, parEpmNoStg, parEpmIdStg, tmpWtpNoStg2, tmpWtpIdStg2; static String wtpObjChNo,wtpObjChOid,wtpObjParNo,wtpObjParOid; static String[] attrWtpStgArr, attrEpmStgArr; static WTContainer wtpCont, epmCont; static Folder wtpFolder, epmFolder; static EPMDocumentMaster epmm; static EPMDocument epmLg[], epmSh[]; static EPMDocument epm, epm1, epmIN, epmOrig, epmRun, epmRun2; static WTPart wtpAssoc, wtpOrig, wtpRun, wtpRun2, wtpNew, wtpLg, wtpSh, wtpObjCh, wtpObjPar; static LifeCycleTemplate lifecycletemplate; static LifeCycleManaged LMObject; static QueryResult qrUses, qrChildChecker, qr; static ArrayList arraylist1, arraylistTopWTP, arraylistTopEPM, arraylistEpmLink, arraylistWtpLink; static ConfigSpec configSpec; }