
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.folder.*;
import wt.lifecycle.*;
import wt.lifecycle.State;
import wt.inf.container.*;

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 epmList_66 {

	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);

			LMObject = (LifeCycleManaged)epm;
			StStg = (String)LMObject.getLifeCycleState().toString();

			System.out.println( "Running Tree For EPMDocument Number: "+epmNo+"\n");
			epmTree(QueType,epm);
		}
	}

	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);

					oidEpm = epmTop.getPersistInfo().getObjectIdentifier().toString();

					QueryResult qrRef = EPMStructureHelper.service.navigateReferencedBy((EPMDocumentMaster)epmTop.getMaster(), null, false);
					System.out.println( "\n**************************************************");

					System.out.println( "Number: "+ epmTop.getNumber()+" = navigateReferencedBy (qrRef.size()): "+qrRef.size()+"\n");

					while (qrRef.hasMoreElements()) {
						EPMReferenceLink epmRefLink;
						epmRefLink = (EPMReferenceLink)qrRef.nextElement();
						EPMDocument epmRef = epmRefLink.getReferencedBy();

						oid = epmRef.getPersistInfo().getObjectIdentifier().toString();
						System.out.println( "\nEPMDoc (epmRef) ID: "+ oid);

						System.out.println( "EPMDoc Ref Number: "+ epmRef.getNumber() + "| EPMDoc Ref Name: " + epmRef.getName());
						System.out.println( "EPMDoc Ref Version: " + epmRef.getVersionIdentifier().getValue() + "."+epmRef.getIterationIdentifier().getValue()+"\n");
					}

					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);
						}
					}

					QueryResult qrUses = EPMStructureHelper.service.navigateUses(epmTop, null, false);
					System.out.println( "\n==================================================");
					System.out.println( "Number: "+ epmTop.getNumber()+" = navigateUses (qrUses.size()): "+qrUses.size()+"\n");

					while (qrUses.hasMoreElements()) {
						EPMMemberLink epmmemberlink = (EPMMemberLink)qrUses.nextElement();

						QueryResult qrML = ConfigHelper.service.filteredIterationsOf(epmmemberlink.getUses(), configSpec);
						while(qrML.hasMoreElements())
						{
							EPMDocument epmML = (EPMDocument)qrML.nextElement();
							oid = epmML.getPersistInfo().getObjectIdentifier().toString();
							System.out.println( "\nEPMDoc (epmML) ID: "+ oid);

							System.out.println( "EPMDoc Number (epmML): "+ epmML.getNumber() + "| EPMDoc Name: " + epmML.getName());
							System.out.println( "EPMDoc Version (epmML): " + epmML.getVersionIdentifier().getValue() + "."+epmML.getIterationIdentifier().getValue()+"\n");
						}
					}

					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);
				}
			}
			arrayPrint();
		}
		catch(Exception exception) { exception.printStackTrace(); }
	}

	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

		System.out.println( "\n1) arraylistEpmLink.size(): "+arraylistEpmLink.size()+"\n==================================================\n");
		for (int x = 0; x < arraylistEpmLink.size(); x++ ) {
			linkEpmStg = (String)arraylistEpmLink.get(x);
			System.out.println( "\nlinkEpmStg("+x+"): "+ linkEpmStg);

			if ( linkEpmStg.toLowerCase().contains(epmNoSh.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoSh: "+epmNoSh); }
			else if ( linkEpmStg.toLowerCase().contains(epmNoLg.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoLg: "+ epmNoLg); }
			//else { System.out.println( "linkEpmStg: "+ linkEpmStg + " Does NOT Match epmNoLg: "+ epmNoLg + " or epmNoSh: "+epmNoSh); }
		}
		System.out.println( "\n==================================================\n");

		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+")");
				System.out.println( "\tWTPart (wtpAssoc) ID: "+ wtpAssoc.getPersistInfo().getObjectIdentifier().toString());
				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")) {
								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")) {
							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

			System.out.println( "\n2) arraylistEpmLink.size(): "+arraylistEpmLink.size()+"\n==================================================\n");
			for (int x = 0; x < arraylistEpmLink.size(); x++ ) {
				String linkEpmStg = (String)arraylistEpmLink.get(x);
				System.out.println( "\nlinkEpmStg("+x+"): "+ linkEpmStg);

				if ( linkEpmStg.toLowerCase().contains(epmNoSh.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoSh: "+epmNoSh); }
				else if ( linkEpmStg.toLowerCase().contains(epmNoLg.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoLg: "+ epmNoLg); }
				//else { System.out.println( "linkEpmStg: "+ linkEpmStg + " Does NOT Match epmNoLg: "+ epmNoLg + " or epmNoSh: "+epmNoSh); }
			}
			System.out.println( "\n==================================================\n");

			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);
										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");
									}
									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");

							for (int x = 0; x < arraylistEpmLink.size(); x++ ) {
								String linkEpmStg = (String)arraylistEpmLink.get(x);
								System.out.println( "\n4) linkEpmStg("+x+"): "+ linkEpmStg);
								System.out.println( "\n4) epmNoLg: "+ epmNoLg);

								if ( linkEpmStg.toLowerCase().contains(epmNoSh.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoSh: "+epmNoSh); }
								else if ( linkEpmStg.toLowerCase().contains(epmNoLg.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoLg: "+ epmNoLg); }
								//else { System.out.println( "linkEpmStg: "+ linkEpmStg + " Does NOT Match epmNoLg: "+ epmNoLg + " or epmNoSh: "+epmNoSh); }
							}

							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( "\n3) tmpWtpNo (wtpLg.getNumber()): "+ tmpWtpNo);

								// Assoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT] )

								System.out.println( "\tAssoc wtpLg to epmIN (wtpart with epmdoc long number [ABC123.PRT] )\n");

								try {
									wtpLg = (WTPart)setCheckoutInfo(wtpLg, WorkInProgressState.WORKING);
									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");
								}
								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);
								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");
							}
							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");

					for (int x = 0; x < arraylistEpmLink.size(); x++ ) {
						String linkEpmStg = (String)arraylistEpmLink.get(x);
						System.out.println( "\n3) linkEpmStg("+x+"): "+ linkEpmStg);
						System.out.println( "\n3) epmNoSh: "+ epmNoSh);

						if ( linkEpmStg.toLowerCase().contains(epmNoSh.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoSh: "+epmNoSh); }
						else if ( linkEpmStg.toLowerCase().contains(epmNoLg.toLowerCase()) ) { System.out.println( "linkEpmStg: "+ linkEpmStg + " Matches epmNoLg: "+ epmNoLg); }
						//else { System.out.println( "linkEpmStg: "+ linkEpmStg + " Does NOT Match epmNoLg: "+ epmNoLg + " or epmNoSh: "+epmNoSh); }
					}

					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( "\n3) 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);
							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");
						}
						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"); }
			//catch(wt.pom.UniquenessException Uexc) { System.out.println( "\tFAILED = UniquenessException: "+Uexc.toString()+"\n"); }
		}
	}

	public static void wtpTree(WTPart wtp)
		throws WTException
	{
		try{
			arraylistTopWTP = new ArrayList();
			arraylist1 = new ArrayList();
			arraylistWtpLink = 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");

							// create (wtp no|ID|ASSOC|epm no|ID) String

							linkWtpStg = wtpTop.getNumber() + "|" + wtpTop.getPersistInfo().getObjectIdentifier().toString()
							+ "|ASSOC|"+epmTop.getNumber()+ "|" + epmTop.getPersistInfo().getObjectIdentifier().toString();

							System.out.println( "\t###linkWtpStg(wtpTree:epmList["+y+"]): " + linkWtpStg+"\n");
							arraylistWtpLink.add(linkWtpStg);
						}
					}
				}
			}
		}
		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=(WTPart)PersistenceHelper.manager.save(wtpNew);

		System.out.println( "\tCreated WTPart Number: "+wtpNew.getNumber());

		wtpCont = wtpNew.getContainer();
		LMObject = (LifeCycleManaged)wtpNew;
		StStg = (String)LMObject.getLifeCycleState().toString();

		System.out.println( "\tWTPart (wtpNew) ID: "+ wtpNew.getPersistInfo().getObjectIdentifier().toString());
		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);
			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");
		}
		catch(WTException wtexception) {
			System.out.println( "\tFAILED Link association between WTPart Number: "+wtpTA.getNumber()+ " & EPMDoc Number: "+epmIN.getNumber()+"\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");
		}
	}

	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()+" with 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);

		//System.out.println( "\nSQL (findWtpNo): \n"+qs.toString()+"\n");

		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);

						System.out.println( "\n========================================\n");

						System.out.println( "\tWTPart Number: "+ wtpm2.getNumber() + "| WTPart Name: " + wtpm2.getName());
						System.out.println( "\tWTPart Container: "+ wtpCont.getName() + "| WTPart Folder: " + wtpFolder);
						System.out.println( "\tWTPart Version: " + wtpm2.getVersionIdentifier().getValue() + "."+wtpm2.getIterationIdentifier().getValue()+"| LC State: "+StStg+"\n");
					}
				}
			} while(true);
		}
	}

	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] );
				System.out.println( "%%% - WTPart: (wtChild3): "+wtChild3.getNumber()+" & ID: "+wtChild3.getPersistInfo().getObjectIdentifier().toString()+"\n");
				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;
	}

	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 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") ) {
					System.out.println( "\nfindEpmNo==================================================\n");
					findEpmNo(OT,QueStg);
					arrayPrint();
				}
				else if ( OT.equals("-qw") ) {
					System.out.println( "\nfindWtpNo==================================================\n");
					findWtpNo(OT,QueStg);
					arrayPrint();
				}
				else if ( OT.equals("-qb")||OT.equals("-rw")) {
					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 -<query/rename> %<epmdoc/wtpart number search string>%\n\n"+
	"1st Argument = <query/rename>:\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 = %<object number string>%\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;
	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;
	static LifeCycleTemplate lifecycletemplate;
	static LifeCycleManaged LMObject;
	static QueryResult qrUses, qrChildChecker, qr;
	static ArrayList arraylist1, arraylistTopWTP, arraylistTopEPM, arraylistEpmLink, arraylistWtpLink;
	static ConfigSpec configSpec;
}
