if (userLogin == null) {
userLogin = SharkContainer.getAdminUser();
}
AdminInterface admin = SharkContainer.getAdminInterface();
ExecutionAdministration exec = admin.getExecutionAdministration();
boolean beganTrans = false;
boolean hasError = false;
Transaction trans = null;
try {
beganTrans = TransactionUtil.begin();
if (!beganTrans) {
trans = TransactionUtil.suspend();
beganTrans = TransactionUtil.begin();
}
try {
// connect to admin API
try {
exec.connect(userLogin.getString("userLoginId"), userLogin.getString("currentPassword"), null, null);
} catch (BaseException e) {
throw new GenericServiceException(e);
} catch (ConnectFailed e) {
throw new GenericServiceException(e);
}
try {
// create the requester
WfRequester req = new SimpleRequester(userLogin, model, waiter);
WfProcessMgr mgr = null;
String location = this.getLocation(model);
String version = null;
// locate packageId::version
if (location.indexOf("::") != -1) {
List splitList = StringUtil.split(location, "::");
location = (String) splitList.get(0);
version = (String) splitList.get(1);
}
// obtain the process manager
try {
if (version == null) {
mgr = exec.getProcessMgr(location, model.invoke);
} else {
mgr = exec.getProcessMgr(location, version, model.invoke);
}
} catch (BaseException e) {
throw new GenericServiceException(e);
} catch (NotConnected e) {
throw new GenericServiceException(e);
}
// make sure the manager exists
if (mgr == null) {
throw new GenericServiceException("Unable to obtain Process Manager for : " + this.getLocation(model) + " / " + model.invoke);
}
// create the process instance
WfProcess proc = null;
try {
proc = mgr.create_process(req);
} catch (BaseException e) {
throw new GenericServiceException(e);
} catch (NotEnabled e) {
throw new GenericServiceException(e);
} catch (InvalidRequester e) {
throw new GenericServiceException(e);
} catch (RequesterRequired e) {
throw new GenericServiceException(e);
}
Map contextSig = null;
try {
contextSig = mgr.context_signature();
} catch (BaseException e) {
throw new GenericServiceException(e);
}
if (contextSig != null) {
Iterator sigKeys = contextSig.keySet().iterator();
Map formalParams = new HashMap();
while (sigKeys.hasNext()) {
String key = (String) sigKeys.next();
formalParams.put(key, context.get(key));
}
// set the initial WRD
try {
proc.set_process_context(formalParams);
} catch (BaseException e) {
throw new GenericServiceException(e);
} catch (InvalidData e) {
throw new GenericServiceException(e);
} catch (UpdateNotAllowed e) {
throw new GenericServiceException(e);
}
}
// start the process
try {
proc.start();
} catch (BaseException e) {
throw new GenericServiceException(e);
} catch (CannotStart e) {
throw new GenericServiceException(e);
} catch (AlreadyRunning e) {
throw new GenericServiceException(e);
}
} catch (GenericServiceException e) {
throw e;
} finally {
// disconnect from admin API
try {
exec.disconnect();
} catch (NotConnected e) {
throw new GenericServiceException(e);
} catch (BaseException e) {
throw new GenericServiceException(e);
}