cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Custom OIR Rule Algorithm

pwilliams-3
11-Garnet

Custom OIR Rule Algorithm

Has anyone implemented a custom OIR rule algorithm that implements the RuleAlgorithm interface? If so then is it possible to pass a handle to the object being created to the RuleAlgorithm.calculate() method? For example pass a handle to an EPMDocument in the Object[] array?

public Object calculate(Object[] paramArrayOfObject, WTContainerRef paramWTContainerRef)

Patrick Williams | Engineering Systems | c: 616.947.2110
[cid:image001.jpg@01CD807F.0A867BC0]

2 REPLIES 2

Patrick,



As the object is not persisted yet, it would not be for any current
document/object, you could pass in some type of metadata in the XML that
allows the algorithm to query for something? Typically paramArrayOfObject[0]
is actually a String. The array is formed from the <arg></arg> tags defined
in the XML file for that algorithm.





Regards,

David DeMay






Cat
5-Regular Member
5-Regular Member
(To:pwilliams-3)

  1. 1.     Implement Java code of custom RuleAlgorithm by implementing interface wt.rule.algorithm.RuleAlgorithm
  • Create java code, see below for sample:

For Scenario 1A:

package ext.mytest;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: </p>
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import wt.rule.algorithm.RuleAlgorithm;
import wt.enterprise.EnterpriseHelper;
import wt.util.WTException;
import wt.inf.container.WTContainerRef;
import java.util.TimeZone;
import java.text.*;
import java.util.*;

public class customNumberRule implements RuleAlgorithm {

public Object calculate(Object args[], WTContainerRef container) throws //
WTException {

// Add current date to the end of the generated number
String num = EnterpriseHelper.getNumber(args);  //This is OOTB
Calendar gmtlocal = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
sf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
num =  sf.format(gmtlocal.getTime())+"-" + num;

return num;


}

}

For Scenario 1B:

  1. 1. Need to handle Date type attribute(IBA) by removing time and only keep date:

public class customNumberRule implements RuleAlgorithm {

public Object calculate(Object args[], WTContainerRef container) throws WTException {

String num= "";
if (args!=null && args.length>0) {
for (int i=0; i<args.length; i++) {
if (args[i] instanceof java.sql.Timestamp) {
  Date date = new Date(((java.sql.Timestamp)args[i]).getTime());
 
num += wt.util.WTStandardDateFormat.format(date, "yyyyMMdd");
}
  else
 
num += args[i].toString();
}
}

         return num;
}


  1. 2. Create the file in $WT_HOME/src/ext/VariableCNNumberPrefix.java, and then compile it into $WT_HOME/codebase/ext/ and update the OIR

package ext;

import wt.enterprise.EnterpriseHelper;
import wt.inf.container.WTContainerRef;
import wt.rule.algorithm.RuleAlgorithm;
import wt.util.WTException;
import wt.util.WTProperties;

public class VariableCNNumberPrefix implements RuleAlgorithm {

public Object calculate(Object args[], WTContainerRef container) throws WTException {

// Determine the server hostname
String serverHostName = "";
try {

serverHostName = WTProperties.getLocalProperties().getProperty("wt.rmi.server.hostname");

} catch (Throwable t) {

  1. t.printStackTrace();

}
// OOTB code to get the next number in the sequence
String num = EnterpriseHelper.getNumber(args);

// Set the default prefix, and change it if we're on a different server
String prefix = "ECN";

if (serverHostName.equals("<enter_test_server_name_here>")) {

prefix = "TST";

}
// Concantentate the prefix with the number from the ECO number.

num = prefix + num;
return num;

}

}

  1. 2.     Update OIR file by changing the algorithm used from

         <AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
</AttrValue>


To (scenario 1A):

         <AttrValue id="number" algorithm="ext.mytest.customNumberRule">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
</AttrValue>


OR (scenario 1B):

         <AttrValue id="number" algorithm="ext.mytest.customNumberRule">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
<Attr id="<dateTypeAttribute>"/>

</AttrValue>

Top Tags