Example Code - EnterWorks_Process_Exchange_(EPX) - 10.6

EnterWorks EPX Process Modeling

Product type
Software
Portfolio
Verify
Product family
EnterWorks
Product
Precisely EnterWorks > EnterWorks Process Exchange (EPX)
Version
10.6
Language
English
Product name
Precisely EnterWorks
Title
EnterWorks EPX Process Modeling
First publish date
2007
Last updated
2023-07-28
Published on
2023-09-20T04:05:11.973084
Class

examples.custom.SampleCustomSendAction

Description

The SampleCustomSendAction class is created to customize the work item’s "send" process. This class shows what actions to take before and after sending a work item that are defined in the preSendAction( ) and preReceiveAction( ) methods.

The preSendAction will be called just before the send is attempted while the preReceiveAction will be called when the work item arrives at the activity. In the preSendAction method, there is a customPropertyList argument that is for output only that would contain any passing work item properties that the custom code would want to introduce to the Send operation.

Creating more properties in the Custom Action tab makes those properties become additional part of custom send action handler. The code in the custom send action handler calls the APIs on the ActivityVO::getActivityPropertyOfActivityList( ) in the activity object passed to the preSendAction method to retrieve the additional properties which will then become a part of the custom send action handler.

This sample code defines an action to be performed on pre-sending a work item. It checks out the wait time if it is set as an activity property with a key relative_send_time and sets the wait date time on the send work item version. This activity property can be added using the activity editor's Custom Action tab. Also, it sets transient work item properties that can be used in a DPA. If the value of the property key is not a valid integer, the preSendAction will fail with an exception.

Before receiving the work item, this code defines another action to be performed. It checks out the expiration time if it is set as an activity property with a key expiration_time and sets the wait date time on the send work item version. Similarly, this activity property can be added using the activity editor's Custom Action tab. The user can also overwrite the wait time, optionally. If the value of the property key is not a valid integer, this method will fail with an exception.

Note: For more details on custom send action class, refer to the BaseSendAction class and CustomSendAction interface on EPX Javadoc HTML Pages.

public class SampleCustomSendAction extends BaseSendAction

{

/** default constructor */

public SampleCustomSendAction()

{

super();

}

public String getAuditComponent()

{

return "custom.SampleCustomSendAction";

}

// Defines an action to be done before sending a workitem

public void preSendAction(

JdbcConnection con, ActivityVO sendActivity, WorkItemVersionVO sendVersion,

ArrayList customPropertyList) throws Exception

{

try

{

EnvironmentManager em =

EnvironmentManager.getInstance();

PropertyFile propertyFile = new PropertyFile();

String configFile =

em.getConfig("examplesCustomDirectory") +

"/custom.properties";

log ("SampleCustomSendAction: preSendAction

property file:"+configFile);

propertyFile.load(configFile);

boolean setDate = true;

boolean firstTime = true;

String firstTimeKey = sendVersion.getWorkVersionId()

+ ".firstSend";

log ("SampleCustomSendAction: preSendAction:");

log (" getSendDate:

"+propertyFile.getValue("getSendDate"));

log (" " + firstTimeKey + ": " +

propertyFile.getValue(firstTimeKey));

if ("false".equals(propertyFile.getValue("getSendDate")))

{

setDate = false;

}

if ("false".equals(propertyFile.getValue(firstTimeKey)))

{

firstTime = false;

}

else

{

propertyFile.putLine(firstTimeKey, "false");

}

log ("firstTime: " + firstTime + " setDate: "

+ setDate);

/** Overwrite the wait time here if the user wants to. */

// Check if the wait time is set as an activity property

// with a key 'relative_send_time'. This activity property

// would be added using the Activity editor's Custom Action

// tab. If the value of the property key is not a valid

// integer the preSendAction will fail with an exception

Integer relativeWaitTime = null;

Collection actProps =

sendActivity.getActivityPropertyOfActivityList();

Iterator iter = actProps.iterator();

while ( iter.hasNext() )

{

ActivityPropertyVO prop =

(ActivityPropertyVO) iter.next();

if ("relative_send_time".equals(

prop.getPropertyKey())&& prop.getPropertyValue() != null)

{

relativeWaitTime =

new Integer(prop.getPropertyValue());

break;

}

}

// Set the wait date time once for this work

// item version

if ( firstTime || sendVersion.getWaitDatetime() ==

null )

{

Calendar rightNow = null;

if (relativeWaitTime!=null &&

relativeWaitTime.intValue()>0 )

{

rightNow = Calendar.getInstance();

rightNow.add(Calendar.MINUTE,

relativeWaitTime.intValue());

// set the wait date time on the send work

// item version

sendVersion.setWaitDatetime(

rightNow.getTime(), false);

}

else if ( setDate )

{

rightNow = Calendar.getInstance();

rightNow.add(Calendar.MINUTE,

Integer.parseInt(

propertyFile.getValue("sendWaitPeriod")

== null ? "5" :

propertyFile.getValue("sendWaitPeriod")

));

sendVersion.setWaitDatetime(

rightNow.getTime(), false);

}

else

{

sendVersion.setWaitDatetime(null, false);

}

}

else

{

// could throw an exception if send date is set to

// false in the property file throw new

// Exception("getSendDate is not enabled");

sendVersion.setWaitDatetime(null, false);

}

//Set transient workitem properties that can be

//used in a DPA

WorkItemPropertyVO property = new

WorkItemPropertyVO();

property.setPropertyKey("external_property", false);

property.setPropertyValue("yes", false);

customPropertyList.add(property);

propertyFile.save(configFile);

}

catch (Throwable ex)

{

ex.printStackTrace();

throw new Exception(

"Error setting delayed send datetime:"

+ex.getMessage());

}

}

/**Defines an Action that will be taken after send a workitem. */

public void preReceiveAction (

JdbcConnection con, ActivityVO receiveActivity,

WorkItemVersionVO receiveVersion) throws Exception

{

log( "SampleCustomSendAction: preReceiveAction

on version:"+receiveVersion.getWorkVersionId());

try

{

EnvironmentManager em =

EnvironmentManager.getInstance();

PropertyFile propertyFile = new PropertyFile();

String configFile =

em.getConfig("examplesCustomDirectory")

+"/custom.properties";

propertyFile.load(configFile);

boolean setDate = true;

boolean firstTime = true;

String firstTimeKey =

receiveVersion.getWorkVersionId()

+ ".firstReceive";

if ("false".equals(propertyFile.getValue(

"getExpireDate")))

{

setDate = false;

}

if ( "false".equals(propertyFile.getValue(

firstTimeKey) ) )

{

firstTime = false;

}

else

{

propertyFile.putLine(firstTimeKey, "false");

}

// Overwrite the wait time here if the user wants to.

// First check if the expiration time is set as a activity

// property with a key 'expiration_time'. This activity

// property would be added using the Activity editor's Custom

// Action tab. If the value of the property key is not a

// valid integer this method will fail with an exception

Integer relativeExpirationTime = null;

Collection actProps =

receiveActivity.getActivityPropertyOfActivityList

();

Iterator iter = actProps.iterator();

while ( iter.hasNext() )

{

ActivityPropertyVO prop = (

ActivityPropertyVO) iter.next();

if ( "expiration_time".equals(

prop.getPropertyKey()) &&

prop.getPropertyValue() != null )

{

relativeExpirationTime=newInteger(

prop.getPropertyValue());

break;

}

}

if ( firstTime )

{

Calendar rightNow = null;

if ( relativeExpirationTime != null &&

relativeExpirationTime.intValue() > 0)

{

rightNow = Calendar.getInstance();

rightNow.add(

Calendar.MINUTE,

relativeExpirationTime.intValue());

// Set the wait date time on the send work

// item version

receiveVersion.setExpirationDatetime(

rightNow.getTime(), false );

}

else if ( setDate )

{

rightNow = Calendar.getInstance();

rightNow.add(

Calendar.MINUTE, Integer.parseInt (

propertyFile.getValue(

"expireWaitPeriod") == null ?

"5":propertyFile.getValue (

"expireWaitPeriod") ) );

receiveVersion.setExpirationDatetime(

rightNow.getTime(), false );

}

else

{

receiveVersion.setExpirationDatetime(

null, false);

}

}

propertyFile.save (configFile);

}

catch (Throwable ex)

{

ex.printStackTrace();

throw new Exception(

"Error setting expiration datetime: "

+ex.getMessage());

}

}

}