Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Source:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | package ext; import wt.pds.StatementSpec; import wt.query.QuerySpec; import wt.rule.algorithm.RuleAlgorithm; import wt.doc.WTDocument; import wt.enterprise.EnterpriseHelper; import wt.fc.PersistenceHelper; import wt.fc.QueryResult; import wt.util.WTException; import wt.inf.container.WTContainerRef; import wt.doc.*; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import java.text.*; import java.util.*; public class CustomNumberRule implements RuleAlgorithm { static int maxCount=0; public Object calculate(Object args[], WTContainerRef container) throws WTException {
int count =0; //Generate today's date. Example:20160316 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd", Locale.KOREA); Date currentDate = new Date(); String date = simpleDateFormat.format(currentDate);
//QuerySpec For wt.doc.WTDocument QuerySpec qs = new QuerySpec(wt.doc.WTDocumentMaster.class); QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs); // System.out.println("Number of WTDocument Masters: " + qr.size() + "\n\n"); //test
WTDocumentMaster master = null;
int maxNumber=0; //Count documents i.e., DOC-20160316 while (qr.hasMoreElements()) { master = (WTDocumentMaster) qr.nextElement();
if(master.getNumber().contains("DOC-"+date)) { ++count; //Number of document formatted in DOC-yyyyMMdd
//Parse document's number int number = Integer.parseInt( master.getNumber().subSequence(13, 17).toString() ); if(maxNumber < number) { maxNumber = number; } System.out.println("****Number:" + number ); System.out.println("****Max Number:" + maxNumber );
} }
System.out.println("@maxCount:" + maxCount); //test System.out.println("@count:" + count); //test
if(maxCount < maxNumber) { maxCount = maxNumber+1; }else { maxCount++; }
System.out.println("#maxCount:" + maxCount); //test System.out.println("#count:" + count); //test
String num = ""; if (args != null && args.length > 0) { num += args[0].toString(); //argument from OIR Rule of Product Document(제품문서) num += "-"; num += date; num += "-"; num += String.format("%04d", maxCount); }else { System.out.println("There are no arguments."); } System.out.println("Product Document's Number: " + num); //print
return num;
} } | cs |
Object Initialization Rule (OIR):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | <AttributeValues objType="wt.doc.WTDocument"> <!-- set the folder --> <AttrValue id="folder.id" algorithm="com.ptc.core.foundation.folder.server.impl.FolderPathAttributeAlgorithm"> <Arg>/Default</Arg> </AttrValue> <!-- set the lifecycle --> <AttrValue id="lifeCycle.id" algorithm="com.ptc.core.foundation.lifecycle.server.impl.LifeCycleTemplateAttributeAlgorithm"> <Arg> <!-- Translation of the word "Basic" must be the same as the translation done in commonLifeCycles.xml --> <?loc-begin key="BASIC_LIFECYCLE_NAME" maxlen="30" match="commonLifeCycles.xml:BASIC_LIFECYCLE_NAME"?>Basic<?loc-end?> </Arg> </AttrValue> <!-- set the team template --> <AttrValue id="teamTemplate.id" algorithm="com.ptc.core.foundation.team.server.impl.TeamTemplateAttributeAlgorithm"> <Arg>Default</Arg> </AttrValue> <!-- set the number to a generated number --> <AttrValue id="number" algorithm="ext.CustomNumberRule"><Arg>DOC</Arg><!--<Arg>{GEN:wt.enterprise.SequenceGenerator:WTDOCUMENTID_seq:4:0}</Arg>--></AttrValue><!-- set the version info to a generated version info --> <AttrValue id="MBA|versionInfo" algorithm="com.ptc.core.foundation.vc.server.impl.VersionInfoGenerator"> <Arg>wt.series.HarvardSeries</Arg> </AttrValue>
<!-- set the doc type - enumerated type, this field is no longer displayed in the UI so just default it --> <AttrValue id="docType" algorithm="wt.rule.algorithm.EnumTypeConstant"> <Arg>wt.doc.DocumentType</Arg> <Arg>$$Document</Arg> </AttrValue>
<!-- set the department type - enumerated type, this field is no longer displayed in the UI so just default it --> <AttrValue id="department" algorithm="wt.rule.algorithm.EnumTypeConstant"> <Arg>wt.doc.DepartmentList</Arg> <Arg>ENG</Arg> </AttrValue> <!-- specify AttrConstraint tag --> <AttrConstraint id="lifeCycle.id" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/> <Value algorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/> </AttrConstraint> <AttrConstraint id="lifeCycle" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/> <Value algorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/> </AttrConstraint> <AttrConstraint id="folder.id" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerPreGeneratedValue"/> </AttrConstraint> <AttrConstraint id="number" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/> <Value algorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/> </AttrConstraint> <AttrConstraint id="teamTemplate.id" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/> <Value algorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/> </AttrConstraint> <AttrConstraint id="teamTemplate" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/> <Value algorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/> </AttrConstraint> <AttrConstraint id="organization.id" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints"> <Value algorithm="com.ptc.core.rule.server.impl.GetServerPreGeneratedValue"> <Value algorithm="com.ptc.windchill.enterprise.org.server.impl.OwningOrgDefaultAlgorithm"/> </Value> </AttrConstraint> </AttributeValues>
| cs |