Quantcast
Channel: PTC Community : Document List - All Communities
Viewing all articles
Browse latest Browse all 1247

How to make a Custom Number Rule (Rule Algorithm) e.g., DOC-20160316-0012

$
0
0

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.*;

 

publicclass CustomNumberRule implements RuleAlgorithm {

 

     staticint 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;

      

     }

 

}

Colored by Color Scripter

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

 

            <AttributeValuesobjType="wt.doc.WTDocument">

 

 

               <!-- set the folder -->

               <AttrValueid="folder.id"algorithm="com.ptc.core.foundation.folder.server.impl.FolderPathAttributeAlgorithm">

                  <Arg>/Default</Arg>

               </AttrValue>

 

               <!-- set the lifecycle -->

               <AttrValueid="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-beginkey="BASIC_LIFECYCLE_NAME"maxlen="30"match="commonLifeCycles.xml:BASIC_LIFECYCLE_NAME"?>Basic<?loc-end?>

                  </Arg>

               </AttrValue>

 

               <!-- set the team template -->

               <AttrValueid="teamTemplate.id"algorithm="com.ptc.core.foundation.team.server.impl.TeamTemplateAttributeAlgorithm">

                  <Arg>Default</Arg>

               </AttrValue>

 

               <!-- set the number to a generated number -->

               <AttrValueid="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 -->

               <AttrValueid="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 -->

               <AttrValueid="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 -->

               <AttrValueid="department"algorithm="wt.rule.algorithm.EnumTypeConstant">

                  <Arg>wt.doc.DepartmentList</Arg>

                  <Arg>ENG</Arg>

               </AttrValue>

 

               <!-- specify AttrConstraint tag -->

               <AttrConstraintid="lifeCycle.id"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">            

                  <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/>

                  <Valuealgorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/>

           </AttrConstraint>

           <AttrConstraintid="lifeCycle"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">

                  <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/>   

                  <Valuealgorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/>

           </AttrConstraint>

           <AttrConstraintid="folder.id"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerPreGeneratedValue"/>       

           </AttrConstraint>       

           <AttrConstraintid="number"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/>

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/>

           </AttrConstraint>            

           <AttrConstraintid="teamTemplate.id"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">            

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/>                      

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/>

           </AttrConstraint>

           <AttrConstraintid="teamTemplate"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/>   

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetImmutableConstraint"/>

           </AttrConstraint>

           <AttrConstraintid="organization.id"algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">

                   <Valuealgorithm="com.ptc.core.rule.server.impl.GetServerPreGeneratedValue">

                      <Valuealgorithm="com.ptc.windchill.enterprise.org.server.impl.OwningOrgDefaultAlgorithm"/>

                   </Value>

           </AttrConstraint>

            </AttributeValues>

 

            

Colored by Color Scripter

cs

Viewing all articles
Browse latest Browse all 1247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>