- Print
- DarkLight
Start a Process
To start a process via a rule you have to do two primary things:
- You have to send an event to Comflow that indicates start of the process.
- You have to add information to the process instance about key and description, mapdata and keymap via a callback method.
Do it this way:
- Extend AsynchRule and implement AsynchConnectServiceCalling
- In the execute method implement the start of the process. In this example it is the "TestProcess" and the event parameter is "start", retrieved via transition event.
- Implement the postReceive method an there get the related data via mapdata for presentation key, presentation title and mapkey and store them on the process instance
- Store the current mapdata to the process instance.
public class TestServiceEvent extends AsynchRule implements AsynchConnectServiceCalling {
private static final String PROCESS = "TestProcess";
private static final String MD_virtual = "virtual";
private static final String TE_START = "start";
private static final String TE_CONTINUE = "continue";
private static final String VAR_KEY1 = "Key1";
private static final String VAR_REF1 = "Ref1";
public boolean execute(String point) {
try {
String transitionEvent = processData.getSessionMessage().getTransitionEvent();
int pid = -1; // for start (-1 = undefined, i.e. please create a new one)
if (transitionEvent.equals(TE_CONTINUE) && getProcessInstance() != null) {
pid = getProcessInstanceId(); // Current instance
}
// Parameter setup
String ent = InternalAsynchUtil.getDefaultEnterprise(); // Default enterprise (from sitedef)
String processId = PROCESS; // Which Process?
String parameter = transitionEvent; // parameter to the process so it can differentiate on several events from same rule in same wait point (in this demo we use only one though)
Object callingRule = this; // Just precaution so that not any rule in the system can use this event, of some other rule makes the same call, nothing will happen
// Send a service event to the process instance
ServiceConnector.handleEventSynch(ent, processId, pid, callingRule, parameter, dialogWorkspace);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
// This method is called from the process framework after the event has been been executed
public void postReceiveEvent(AsynchControl processInstance, String eventId) throws Exception {
String transitionEvent = processData.getSessionMessage().getTransitionEvent();
//Savé current MapData on the process instance
String ent = InternalAsynchUtil.getEnterprise(dialogWorkspace);
String key1 = mapData.getVariable("Key");
String ref1 = mapData.getData(MD_virtual, "WorkItemDescriptionAWF");
String ref2 = "";
String ref = ref1;
if (StringUtil.isBlankOrNull(ref)) {
ref1 = mapData.getData(MD_virtual, "Info");
ref2 = mapData.getData(MD_virtual, "Number");
ref = ref1;
}
//Set variables on process instance (for sub process to use)
processInstance.setVariable(VAR_KEY1, key1);
processInstance.setVariable(VAR_REF1, ref1);
// If not a start of a process, return
if (!transitionEvent.equals(TE_START)){
return;
}
// Set Visual Presentation
processInstance.updatePresentationKey(key1);
processInstance.updatePresentationTitle(ref);
// Save MapData for the Process Instance. First create a key value for MD
long mapDataId = System.currentTimeMillis();
// Typically the keys that you want to be reconstructed when clicking on next work item (see TestDefault.cml)
//String keyColumns = "Key,Number,Info"; // Just guess from your detail portlet, assuming these are in mapData
String keyColumns = null; // Alternative to the line above: This one save ALL mapData (can have negative impact on performance)
// Store MapData (service event does not explicitly store map data as workspace event does)
AsynchConnectWorkspace.saveMapData(mapDataId, eventId, processInstance.getProcessInstId(), mapData, dialogWorkspace, keyColumns);
processInstance.storeMapDataId(mapDataId, eventId);
// Mapping between data keys and process instance
String mapKey = key1;
AsynchUtil.mapProcessInstID(ent, processInstance.getProcessId(), mapKey, processInstance.getProcessInstId());
}
}