package ext; import java.util.*; import wt.util.*; import wt.fc.*; import wt.vc.*; import wt.query.*; import wt.part.*; import wt.epm.*; import wt.httpgw.GatewayAuthenticator; import wt.method.RemoteMethodServer; public class ObjMan_07 { public static Enumeration FindEpmNumbered( String ObjType, String number ) throws WTException, WTPropertyVetoException { QuerySpec qs = new QuerySpec(EPMDocumentMaster.class); qs.appendSearchCondition(new SearchCondition(EPMDocumentMaster.class,EPMDocumentMaster.NUMBER,SearchCondition.LIKE,number) ); final QueryResult qr = PersistenceHelper.manager.find(qs); while (qr.hasMoreElements()) { EPMDocumentMaster epmm = (EPMDocumentMaster)qr.nextElement(); System.out.println( "EPMDoc - Number: " + epmm.getNumber() + " - Name: " + epmm.getName()+ " - CadName: " + epmm.getCADName() ); if (ObjType.equals("-re")||ObjType.equals("-rb")||ObjType.equals("-rpe") ||ObjType.equals("-rpb")||ObjType.equals("-rae")||ObjType.equals("-rab")) { String newNo=epmm.getNumber().substring(0, epmm.getNumber().lastIndexOf(".")); if ( number.endsWith(".DRW") ) { newNo = newNo+".D"; } if ( ObjType.equals("-rpe")||ObjType.equals("-rpb") ) { if ( number.endsWith(".PRT") ) { newNo = newNo+".P"; } } if ( ObjType.equals("-rae")||ObjType.equals("-rab") ) { if ( number.endsWith(".ASM") ) { newNo = newNo+".A"; } } IdentificationObject identificationobject = ((Identified)epmm).getIdentificationObject(); EPMDocumentMasterIdentity identity=(EPMDocumentMasterIdentity)identificationobject; identity.setNumber(newNo); IdentityHelper.service.changeIdentity((Identified)epmm,identity); renCnt++; } queCnt++; } return new Enumeration() { public boolean hasMoreElements() { return qr.hasMoreElements(); } public Object nextElement() throws NoSuchElementException { return ((Persistable[])qr.nextElement()); } }; } public static Enumeration FindWtpNumbered( String ObjType, String number ) throws WTException, WTPropertyVetoException { QuerySpec qs = new QuerySpec(WTPartMaster.class); qs.appendSearchCondition(new SearchCondition(WTPartMaster.class,WTPartMaster.NUMBER,SearchCondition.LIKE,number) ); final QueryResult qr = PersistenceHelper.manager.find(qs); while (qr.hasMoreElements()) { WTPartMaster wtpm = (WTPartMaster)qr.nextElement(); System.out.println( "WtPart - Number: " + wtpm.getNumber() + " - Name: " + wtpm.getName() ); //System.out.println( " WtPart - OrgName: " + wtpm.getOrganizationName() ); if (ObjType.equals("-rw")||ObjType.equals("-rb")||ObjType.equals("-rpw") ||ObjType.equals("-rpb")||ObjType.equals("-raw")||ObjType.equals("-rab")) { String newNo=wtpm.getNumber().substring(0, wtpm.getNumber().lastIndexOf(".")); if ( number.endsWith(".DRW") ) { newNo = newNo+".D"; } if ( ObjType.equals("-rpw")||ObjType.equals("-rpb") ) { if ( number.endsWith(".PRT") ) { newNo = newNo+".P"; } } if ( ObjType.equals("-raw")||ObjType.equals("-rab") ) { if ( number.endsWith(".ASM") ) { newNo = newNo+".A"; } } IdentificationObject identificationobject = ((Identified)wtpm).getIdentificationObject(); WTPartMasterIdentity identity=(WTPartMasterIdentity)identificationobject; identity.setNumber(newNo); IdentityHelper.service.changeIdentity((Identified)wtpm,identity); renCnt++; } queCnt++; } return new Enumeration() { public boolean hasMoreElements() { return qr.hasMoreElements(); } public Object nextElement() throws NoSuchElementException { return ((Persistable[])qr.nextElement()); } }; } 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 || args.length > 2 ) { System.out.println(Usage); System.exit(0); } else { OT = args[0]; QueStg = args[1].toUpperCase(); if ( OT.equals("-qe")||OT.equals("-re")||OT.equals("-rae")||OT.equals("-rpe")) { Enumeration e = FindEpmNumbered(OT,QueStg); while (e.hasMoreElements()) { System.out.println(((EPMDocument)e.nextElement()).getIdentity()); } } else if ( OT.equals("-qw")||OT.equals("-rw")||OT.equals("-raw")||OT.equals("-rpw") ) { Enumeration w = FindWtpNumbered(OT,QueStg); while (w.hasMoreElements()) { System.out.println(((WTPart)w.nextElement()).getIdentity()); } } else if ( OT.equals("-qb")||OT.equals("-rb")||OT.equals("-rab")||OT.equals("-rpb") ) { Enumeration e = FindEpmNumbered(OT,QueStg); while (e.hasMoreElements()) { System.out.println(((EPMDocument)e.nextElement()).getIdentity()); } Enumeration w = FindWtpNumbered(OT,QueStg); while (w.hasMoreElements()) { System.out.println(((WTPart)w.nextElement()).getIdentity()); } } else { System.out.println(Usage); System.exit(0); } System.out.println(queCnt+" Objects Queried."); System.out.println(renCnt+" Objects Renamed."); } } catch (WTException wtee) { wtee.printStackTrace(); } catch (WTPropertyVetoException wtpe) { wtpe.printStackTrace(); } finally { System.exit(0); } } static String OT; static String QueStg; static int renCnt=0; static int queCnt=0; public static String Usage = "\nUsage:\n\njava/windchill [-mx1024m] "+ "lj_cust.ObjMan - %.\n\n"+ "1st Argument = :\n\n-qw = query wtparts only\n-qe = query epmdocs only\n"+ "-qb = query both (wtparts & epmdocs)\n\n-rw = rename wtparts only (query 1st)\n"+ "-re = rename epmdocs only (query 1st)\n-rb = rename both (wtparts & epmdocs) (query 1st)\n\n"+ "-rpw = rename .PRT to .P - wtparts only (query 1st)\n"+ "-rpe = rename .PRT to .P - epmdocs only (query 1st)\n"+ "-rpb = rename .PRT to .P - both (wtparts & epmdocs) (query 1st)\n\n"+ "-raw = rename .ASM to .A - wtparts only (query 1st)\n"+ "-rae = rename .ASM to .A - epmdocs only (query 1st)\n"+ "-rab = rename .ASM to .A - both (wtparts & epmdocs) (query 1st)\n\n"+ "1st Argument should be lower case.\n\n2nd Argument = %\n\n"+ "Should include % & . where % = * = wild card.\nTypical = %.PRT or %.ASM\n"; }