Class | examples.custom.CustomExpiredWorkHandler |
---|---|
Description | The custom expired work handler is a class that handles the tasks required for identifying and processing expired work items. For any expired work items found, the doExpirationAction( ) method is called. The doExpirationAction( ) method performs specific tasks when a work item has expired. For example, you created additional properties in the custom action tab, those additional properties will become a part of custom expired work handler. The code in the custom expired work handler calls the getActivityProperties method to retrieve the additional properties which will then become a part of the custom expired work handler. Another example would be if a work item expired in an activity, the method marks the work item as expired and then performs the action defined in it. In this example, it will reassign the work item to another user. |
Note: For more details on custom send action class, refer to the ExpiredWorkHandler class and CustomExpiredWorkHandler interface on EPX Javadoc HTML Pages.
public class CustomExpiredWorkHandler extends ExpiredWorkHandler
{
// default constructor that creates the expired
// work item handler
public CustomExpiredWorkHandler()
{
super();
}
protected void doExpirationAction(
WorkItemExpiredVOexpiredWorkItem) throws Exception
{
try
{
EnvironmentManager em = EnvironmentManager.getInstance();
PropertyFile propertyFile = new PropertyFile();
String configFile = em.getConfig(
"examplesCustomDirectory") + "/custom.properties";
log("CustomExpiredWorkHandler: doExpirationAction property
file:"+configFile);
propertyFile.load(configFile);
log("CustomExpiredWorkHandler: after load");
String firstTimeKey = expiredWorkItem.getWorkVersionId() +
".firstExpire";
log("CustomExpiredWorkHandler: first time key " +
firstTimeKey);
boolean firstTime = true;
log("CustomExpiredWorkHandler: firstTimeKey value: " +
propertyFile.getValue(firstTimeKey));
if ( "false".equals(propertyFile.getValue(firstTimeKey) ) )
{
log("CustomExpiredWorkHandler: not firstTime");
firstTime = false;
}
else
{
log("CustomExpiredWorkHandler: set the key in the file
because this is the first time");
propertyFile.putLine(firstTimeKey, "false");
propertyFile.save(
em.getConfig ("examplesCustomDirectory" ) +
"/custom.properties");
}
log("CustomExpiredWorkHandler: work item name: " +
expiredWorkItem.getWorkItemName());
log("CustomExpiredWorkHandler: activity name:" +
expiredWorkItem.getActivityName());
// do custom actions here.
Collection ActPropertyList =
getActivityProperties(expiredWorkItem.getActivityId());
String newUserLogin = null;
String emailUserLogin = null;
String emailBody = null;
String emailSubject = null;
if (ActPropertyList != null)
{
Iterator propIter = ActPropertyList.iterator();
while (propIter.hasNext())
{
ActivityPropertyVO actProperty =
(ActivityPropertyVO)propIter.next();
log("CustomExpiredWorkHandler: actProperty = " +
actProperty.getPropertyKey());
if(actProperty.getPropertyKey().equals(
"newUserLogin"))
{
newUserLogin =
actProperty.getPropertyValue();
}
else
if (actProperty.getPropertyKey().equals(
"email_user"))
{
emailUserLogin =
actProperty.getPropertyValue();
}
else
if (actProperty.getPropertyKey().equals(
"email_message"))
{
emailBody =
actProperty.getPropertyValue();
}
else
if (actProperty.getPropertyKey().equals(
"email_subject"))
{
emailSubject =
actProperty.getPropertyValue();
}
}
}
if (firstTime)
{
Calendar rightNow = Calendar.getInstance();
rightNow.add(Calendar.MINUTE,
Integer.parseInt(propertyFile.getValue(
"expireWaitPeriod") == null ? "5" :
propertyFile.getValue("expireWaitPeriod")));
log("CustomExpiredWorkHandler: firstTime - new date "
+ rightNow.getTime());
this.getWorkItemFacade()
.setWorkItemVersionExpirationDate(
getSessionProfile(),
expiredWorkItem.getWorkVersionId(), rightNow.getTime());
if (newUserLogin != null)
{
log("CustomExpiredWorkHandler:
firstTime - new user " + newUserLogin);
ArrayList workItemVersionIDs = new ArrayList();
workItemVersionIDs.add(
expiredWorkItem.getWorkVersionId());
this.getWorkItemFacade()
.reassignWorkItemVersionList(
getSessionProfile(),
newUserLogin,
workItemVersionIDs);
}
if (emailUserLogin != null &&
emailSubject != null && emailBody != null)
{
log("CustomExpiredWorkHandler:
firstTime - email user " + emailUserLogin);
ArrayList loginList = new ArrayList();
loginList.add(emailUserLogin);
this.sendEmailMessageToUserLogins(
loginList, emailSubject, emailBody);
}
else
{
log("CustomExpiredWorkHandler: send the work
item");
super.doExpirationAction(expiredWorkItem);
}
}
}
catch (Exception ex)
{
log("CustomExpiredWorkHandler:
Error in work item expiration");
log("CustomExpiredWorkHandler Error:" + ex.getMessage());
}
}
}