(HttpSession session, String packageID, String processID,
ProcessData initData, String dataItemName, String dataItemValue)
throws ProcessingException {
while (true) {
try {
WorkflowService wfs = getWorkflowService();
if (wfs == null) {
throw new ProcessingException
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Unable to retrieve workflow service");
}
ProcessLookup pl = new ProcessLookup();
ProcessDefinitionDirectory procDefDir
= wfs.processDefinitionDirectory();
if ( packageID != null && processID != null ) {
ProcessMgr mgr = null;
try {
mgr = procDefDir.processMgr(packageID, processID);
} catch (InvalidKeyException e) {
throw new ProcessingException
(HttpServletResponse.SC_BAD_REQUEST,
e.getMessage());
}
String mgrName = mgr.name();
if (dataItemName != null && dataItemValue != null) {
// Try to connect to existing process
Collection procs = mgr
.findByDataItem(dataItemName, dataItemValue);
if (procs.size() == 1) {
pl.process = (WfProcess)procs.iterator().next();
pl.procKey = pl.process.key();
pl.packageId = packageID;
pl.processId = processID;
if ( session != null) {
session.setAttribute("WfM_mgrName", mgr.name());
session.setAttribute("WfM_procKey", pl.procKey);
}
return pl;
}
if (procs.size() > 1) {
logger.error
("More than one process found for " + mgr.name()
+ ", data item: " + dataItemName + " = "
+ dataItemValue);
throw new ProcessingException
(HttpServletResponse.SC_CONFLICT,
"More than one matching process found");
}
// add to init data for creation
initData.put(dataItemName, dataItemValue);
}
// Not found, create new process
MethodInvocationBatch mib = new MethodInvocationBatch();
mib.addInvocation
(mgr, "createProcess", new String[]
{"de.danet.an.workflow.omgcore.WfRequester"},
new Object[]{new DefaultRequester(wfs)});
mib.addInvocation
(-1, "setProcessContext", new String[]
{"de.danet.an.workflow.omgcore.ProcessData"},
new Object[]{initData}, false);
mib.addInvocation(-2, "key", null, null, false);
MethodInvocationBatch.Result mir
= (MethodInvocationBatch.Result)wfs.executeBatch(mib);
if (mir.hasExceptions ()) {
Exception e = mir.firstException ();
logger.error ("Problem executing batch: "
+ e.getMessage(), e);
throw new ProcessingException
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
mir.firstException ().getMessage());
}
pl.process = (WfProcess)mir.result(0);
pl.procKey = mir.resultAsString(2);
pl.packageId = packageID;
pl.processId = processID;
pl.created = true;
if ( session != null) {
session.setAttribute("WfM_mgrName", mgrName);
session.setAttribute("WfM_procKey", pl.procKey);
}
return pl;
}
if (session != null) {
// Retrieve process key from session context
String mgrName
= (String)session.getAttribute("WfM_mgrName");
String procKey
= (String)session.getAttribute("WfM_procKey");
if (mgrName == null || procKey == null) {
throw new ProcessingException
(HttpServletResponse.SC_BAD_REQUEST,
"No process information available");
}
ProcessDirectory procDir = wfs.processDirectory();
try {
pl.process
= procDir.lookupProcess(mgrName, procKey);
pl.procKey = pl.process.key();
} catch (InvalidKeyException e) {