This section describes how a process run definition can be implemented.
What does this section cover?
In order to implement a process run definition, you need to:
- Create a new data object class extending com.crm.dataobject.ViewObject class.
- Create five new summary pages.
- Create a new data entry page.
- Create a new user interface class extending com.crm.process.processrun.CRMUIProcessRunDefinitionBean class.
- Create a new class extending com.crm.businessobject.processrun.ProcessRunDefinitionXMLUtilBean class, to save and load any criteria, action inputs and/or scheduling settings.
- Define the process in modules metadata file.
Create Data Object Class
The new data object class must extend com.crm.dataobject.ViewObject class and must implement both getViewMandatoryFields() and getAssociatedObjects() methods. The associated objects will be used by setMandatoryFields() method of com.crm.dataobject.ViewObject for mandatory field calculation. This method calculates the associated objects' mandatory fields and along with the ones defined in getViewMandatoryFields() method it constructs the new data object's defaultMandatoryFields linked hash map.
A com.crm.process.utilities.SchedulerTask object must be defined as well, in order for the process run definition to be handled by the scheduler mechanism.
public class RewardSettlementRunDefinition extends ViewObject {
/**
*
*/
private static final long serialVersionUID = 1L;
private CRMDOProcessRunDefinition processRunDefinition;
private SchedulerTask schedulerTask;
//input settings
private RewardSettlementType rewardSettlementType;
//criteria
private Set<RewardSchemeCriterion> schemeCriteria;
private Integer daysAgo;
public CRMDOProcessRunDefinition getProcessRunDefinition() {
return processRunDefinition;
}
public void setProcessRunDefinition(CRMDOProcessRunDefinition processRunDefinition) {
this.processRunDefinition = processRunDefinition;
}
public SchedulerTask getSchedulerTask() {
return schedulerTask;
}
public void setSchedulerTask(SchedulerTask schedulerTask) {
this.schedulerTask = schedulerTask;
}
public RewardSettlementType getRewardSettlementType() {
return rewardSettlementType;
}
public void setRewardSettlementType(RewardSettlementType rewardSettlementType) {
this.rewardSettlementType = rewardSettlementType;
}
public Set<RewardSchemeCriterion> getSchemeCriteria() {
return schemeCriteria;
}
public void setSchemeCriteria(Set<RewardSchemeCriterion> schemeCriteria) {
this.schemeCriteria = schemeCriteria;
}
public Integer getDaysAgo() {
return daysAgo;
}
public void setDaysAgo(Integer daysAgo) {
this.daysAgo = daysAgo;
}
@Override
protected LinkedHashMap<String, CRMDO> getAssociatedDataObjects() {
LinkedHashMap<String, CRMDO> dataObjects=new LinkedHashMap<String, CRMDO>();
dataObjects.put("processRunDefinition", getProcessRunDefinition());
return dataObjects;
}
@Override
public LinkedHashMap<String, String> getViewMandatoryFields() {
LinkedHashMap<String, String> viewMandatoryFields = new LinkedHashMap<String, String>();
viewMandatoryFields.put( "rewardSettlementType", "key_reward_settlement_type");
return viewMandatoryFields;
}
Create Summary Pages
Five new summary pages need to be implemented in order to give the user all the necessary information about the process run definition, its runs, and their results.
Process Run Definition Summary Page
The first summary page to create is the process run definition summary page, which is the main summary page that will display all the process run definition records.
As you can see, two drill-down summary pages must be created and included in the main summary page: process runs and previous version pages.
Process Runs Drilldown Summary Page
Process runs summary page shows all the process runs created by a specific process run definition.
As you can see, two drill-down summary pages must be created and included in process runs summary page: processed successfully and processed with errors pages.
Processed Successfully Summary Page
Processed successfully summary page shows all the entities that were processed successfully by a specific process run.
Processed with errors summary page shows all the entities that their processing, by a specific process run, failed.
Previous Version Summary Page
Previous version summary page shows the previous version of a specific process run.
Create Data Entry Page
In this case, a UI class have to implement as well, extending the CRMUIProcessRunDefinitionBean. Also, module id and process id, must be defined in the UI as they declared in the module.xml file. To implement the basic functionality, we will need to create the following methods: createButton, loadForm, editButton, saveButton, submitButton, deleteButton and amendButton, as demonstrated below:
/**
* Session Bean implementation class CRMUISmsMessageRunDefinition
*/
@Stateless(mappedName = "ejb/CRMUISmsMessageRunDefinition")
@LocalBean
public class CRMUISmsMessageRunDefinitionBean extends CRMUIProcessRunDefinitionBean {
private static final long serialVersionUID = 1L;
private static final String PROCESS_RUN_LOG_ENTRIES_EXIST = "PROCESS_RUN_LOG_ENTRIES_EXIST";
private static final String IS_PROCESS_RUN_DEF_LATEST_VERSION = "IS_PROCESS_RUN_DEF_LATEST_VERSION";
//Declare module and process id as defined in metadata
private static final String MODULE_ID = "SMS_SERVICES";
private static final String PROCESS_ID = "SMS_MESSAGE_PROCESS";
@EJB private CRMBOProcessRunDefinitionBean processRunDefinitionBean;
@EJB private CRMBOProcessRunLogBean processRunLogBean;
@EJB private smsInfocasMessageRunDefinitionXMLUtilBean smsInfocasMessageRunDefinitionXMLUtilBean;
/**
* Default constructor.
*/
public CRMUISmsMessageRunDefinitionBean() {
// TODO Auto-generated constructor stub
}
public smsMessageRunDefintion createButton() throws Exception {
smsMessageRunDefintion definition = new smsMessageRunDefintion();
CRMDOProcessRunDefinition processRunDefinition = (CRMDOProcessRunDefinition)processRunDefinitionBean.construct();
processRunDefinition.setModule(MODULE_ID);
processRunDefinition.setProcess(PROCESS_ID);
definition.setProcessRunDefinition(processRunDefinition);
definition.setSchedulerTask(new SchedulerTask());
definition.setMandatoryFields();
return definition;
}
public smsMessageRunDefintion loadForm(String id) throws Exception {
CRMDOProcessRunDefinition processRunDefinition = (CRMDOProcessRunDefinition)processRunDefinitionBean.load(id);
smsMessageRunDefintion definition = new smsMessageRunDefintion();
definition.setProcessRunDefinition(processRunDefinition);
definition = smsMessageRunDefinitionXMLUtilBean.loadProcessingRunDefinition(definition);
ArrayList<CRMDO> provisioningRequestProcessingRuns = processRunLogBean.load(definition.getProcessRunDefinition());
if (provisioningRequestProcessingRuns!=null && provisioningRequestProcessingRuns.size() > 0)
{
definition.setAlias(PROCESS_RUN_LOG_ENTRIES_EXIST, "1");
}
else
{
definition.setAlias(PROCESS_RUN_LOG_ENTRIES_EXIST, "0");
}
Boolean isLatestVersion = isLatestVersion(processRunDefinition);
if (isLatestVersion)
{
definition.setAlias(IS_PROCESS_RUN_DEF_LATEST_VERSION, "1");
}
else
{
definition.setAlias(IS_PROCESS_RUN_DEF_LATEST_VERSION, "0");
}
definition.setMandatoryFields();
return definition;
}
public smsMessageRunDefintion editButton(smsMessageRunDefintion definition) throws Exception {
CRMDOProcessRunDefinition processRundefinition = (CRMDOProcessRunDefinition)processRunDefinitionBean.load(definition.getProcessRunDefinition().getId());
if (processRundefinition==null)
{
processRundefinition = processRunDefinitionBean.loadLatest(definition.getProcessRunDefinition().getCode());
}
definition = loadForm(processRundefinition.getId());
if (definition.getAlias(PROCESS_RUN_LOG_ENTRIES_EXIST).equals("1"))
{
definition = amendMessageRunDefinition(definition);
}
return definition;
}
public smsMessageRunDefintion saveButton(smsMessageRunDefintion definition) throws Exception, MandatoryFieldException {
definition.setMandatoryFields();
validateMandatoryFields(definition);
definition = smsMessageRunDefinitionXMLUtilBean.setMessageRunDefinitionXML(definition);
CRMDOProcessRunDefinition processRunDefinition = definition.getProcessRunDefinition();
if (processRunDefinition.getCode()==null)
{
processRunDefinition.setCode(processRunDefinitionBean.getNextSequenceNumber(SequenceNumber.PROCESSRUNDEFINITIONCODES));
}
processRunDefinitionBean.validateAndSave(definition.getProcessRunDefinition());
if (definition.getBroadcastPeriod()==null)
{
throw new MandatoryFieldException(getCRMSession(), "key_broadcast_period");
}
if (definition.getBroadcastInterval()==null)
{
throw new MandatoryFieldException(getCRMSession(), "key_broadcast_interval");
}
ArrayList<CRMDO> provisioningRequestProcessingRuns = processRunLogBean.load(definition.getProcessRunDefinition());
if (provisioningRequestProcessingRuns!=null && provisioningRequestProcessingRuns.size() > 0)
{
definition.setAlias(PROCESS_RUN_LOG_ENTRIES_EXIST, "1");
}
else
{
definition.setAlias(PROCESS_RUN_LOG_ENTRIES_EXIST, "0");
}
Boolean isLatestVersion = isLatestVersion(processRunDefinition);
if (isLatestVersion)
{
definition.setAlias(IS_PROCESS_RUN_DEF_LATEST_VERSION, "1");
}
else
{
definition.setAlias(IS_PROCESS_RUN_DEF_LATEST_VERSION, "0");
}
return definition;
}
public smsMessageRunDefintion submitButton(smsMessageRunDefintion definition) throws Exception {
CRMDOProcessRunLog processRunLog = (CRMDOProcessRunLog)processRunLogBean.construct(definition.getProcessRunDefinition());
submit(processRunLog);
return loadForm(definition.getProcessRunDefinition().getId());
}
public smsMessageRunDefintion deleteButton(smsMessageRunDefintion definition) throws Exception {
processRunDefinitionBean.validateAndDelete(definition.getProcessRunDefinition());
return definition;
}
public smsMessageRunDefintion amendMessageRunDefinition(smsMessageRunDefintion definition) throws Exception {
CRMDOProcessRunDefinition processRunDefinition = definition.getProcessRunDefinition();
CRMDOProcessRunDefinition newProcessRunDefinition = (CRMDOProcessRunDefinition)processRunDefinition.clone();
newProcessRunDefinition.setVersion(new Integer(processRunDefinition.getVersion().intValue()+1));
newProcessRunDefinition.setProperty("name", new FieldAttribute("1"));
newProcessRunDefinition.setProperty("altCode", new FieldAttribute("1"));
definition.setProcessRunDefinition(newProcessRunDefinition);
definition.setAlias(PROCESS_RUN_LOG_ENTRIES_EXIST, "0");
definition.setAlias(IS_PROCESS_RUN_DEF_LATEST_VERSION, "1");
return definition;
}
}
Later on, data entry page must be implemented by giving the ability to the user create, view, modify, delete or apply other operations on a process run record. Below, we can see the detail page of the process run definition and specifically the process runs tab, showing the successful whilst failed runs.
In addition, an XMLUtilBean need to be implemented, in order to save action inputs, criteria and schedule settings in the xml. Also this, messageRunDefinitionXMLUtilBean extends ProcessRunDefinitionXMLUtilBean.
On the last step, the CRMProcessRunBean mentioned in the module.xml as additional process need to be implemented whilst the method executeMessageProcess which executes the process runs via threats mechanism like in Implement a Multithreaded Process section. Firstly, process run method saves the action inputs. Then each process run request processed from a thread and if procedure works correctly, the next process run prepares to been processed and the current one saved as completed. On the other hand, if something goes wrong, the current process run is saved as failed and moves to process the next request. This procedure continues until all the process run requests pass from the multi-threading mechanism. As a result, all the successful and failed process runs are illustrated in the summary page image above. Also, below is illustrated the example of the multi-threaded method implemented:
public class CRMProcessSmsRunBean extends CRMProcessRunBean {
@EJB private smsMessageRunDefinitionXMLUtilBean messageRunDefinitionXMLUtilBean;
...
public void executeMessageProcess(CRMDOProcessRunLog processRun) throws Exception {
CRMDOProcessRunDefinition processRunDefinition = processRun.getProcessRunDefinition();
smsMessageRunDefintion messageRunDefinition= new smsMessageRunDefintion();
messageRunDefinition.setProcessRunDefinition(processRunDefinition);
messageRunDefinition = messageRunDefinitionXMLUtilBean.loadProcessingRunDefinition(messageRunDefinition);
CRMDOProvProvider provProvider = exsetProviderBean.loadEffective();
provProvider = exsetProviderBean.setObjectsFromXML(provProvider);
processRun.setStatus(ProcessRunLogStatus.IN_PROGRESS);
processRun.setStartDate(getCurrentDate());
processRunLogBean.save(processRun);
Boolean processComplete = new Boolean(false);
JDBCConnection connection= null;
try
{
//At this point is implemented the threats mechanism like in Implement a Multithreaded Process section
catch (Exception e)
{
saveEntityLogRecord(
processRun,
"",
"",
ProcessRunLogEntityStatus.FAILED,
e.getClass().getSimpleName(),
ExceptionUtil.getStackTrace(e));
processRun.setEndDate(getCurrentDate());
processRun.setStatus(ProcessRunLogStatus.FAILED);
processRunLogBean.save(processRun);
processRun = saveNextProcessRun(processRun);
if(connection!=null)
connection.close();
}
if (processComplete)
{
processRun.setStatus(ProcessRunLogStatus.COMPLETED);
processRun.setEndDate(getCurrentDate());
processRun = saveNextProcessRun(processRun);
processRunLogBean.save(processRun);
}
}
...
}
CRMProcessSmsRunBean must be also bind to the server by specifying the EJB in the ibm-ejb-jar-bnd.xml binding file.This xml found in CRMEJB > ejbModule > METADATA-INF
<ejb-jar-bnd>
...
<session name="CRMProcessProcessSmsRun" simple-binding-name="ejb/CRMProcessProcessSmsRun" />
...
</ejb-jar-bnd>
The process must also be added in the CrmEJB/ejbModule/META-INF/ibm-ejb-jar-ext.xml to define how much time the process could been executing on WebSphere server as follows:
...
<session name="CRMProcessProcessSmsRun">
<global-transaction transaction-time-out="86400" />
<time-out value="86400" />
</session>
...
Then the process, should be mentioned in CrmEJB/ejbModule/META-INF/jboss-ejb3.xml file where we declare in enterprise beans, the process and in assembly descriptor we mention the timeout of the execution on WildFly server as follows:
...
<session>
<ejb-name>CRMProcessProcessSmsRunBean</ejb-name>
<ejb-class>com.crm.process.provisioning.sms.CRMProcessProcessSmsRunBean</ejb-class>
<session-type>Stateless</session-type>
</session>
...
<container-transaction>
<method>
<ejb-name>CRMProcessProcessSmsRunBean</ejb-name>
<method-name>*</method-name>
<method-intf>Local</method-intf>
</method>
<tx:trans-timeout>
<tx:timeout>86400</tx:timeout>
<tx:unit>Seconds</tx:unit>
</tx:trans-timeout>
</container-transaction>
...