BIObject dossier;
String pathTempFolder = null;
JbpmContext jbpmContext = null;
InputStream procDefIS = null;
String executionMsg = null;
AuditManager auditManager = AuditManager.getInstance();
Integer auditId = null;
try {
// try {
// dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(dossierId);
RequestContainer requestContainer = this.getRequestContainer();
SessionContainer session = requestContainer.getSessionContainer();
CoreContextManager contextManager = new CoreContextManager(new SpagoBISessionContainer(session),
new LightNavigatorContextRetrieverStrategy(request));
ExecutionInstance executionInstance = contextManager.getExecutionInstance( ExecutionInstance.class.getName() );
dossier = executionInstance.getBIObject();
pathTempFolder = dossierDAO.init(dossier);
// } catch (EMFUserError e) {
// logger.error("Error while recovering dossier information: " + e);
// throw e;
// }
IEngUserProfile profile = UserProfile.createWorkFlowUserProfile();
// AUDIT
if (dossier != null) {
auditId = auditManager.insertAudit(dossier, null, profile, "", "WORKFLOW");
}
try {
procDefIS = dossierDAO.getProcessDefinitionContent(pathTempFolder);
} catch (Exception e) {
logger.error("Error while reading process definition file content from dossier template: " + e);
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
}
// parse process definition
ProcessDefinition processDefinition = null;
try{
processDefinition = ProcessDefinition.parseXmlInputStream(procDefIS);
} catch(Exception e) {
executionMsg = msgBuilder.getMessage("dossier.processDefNotCorrect", "component_dossier_messages");
logger.error("Process definition xml file not correct", e);
throw e;
}
// get name of the process
String nameProcess = processDefinition.getName();
// get jbpm context
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
jbpmContext = jbpmConfiguration.createJbpmContext();
// deploy process
try{
jbpmContext.deployProcessDefinition(processDefinition);
} catch (Exception e) {
executionMsg = msgBuilder.getMessage("dossier.workProcessStartError", "component_dossier_messages");
logger.error("Error while deploying process definition", e);
throw e;
}
// create process instance
ProcessInstance processInstance = new ProcessInstance(processDefinition);
// get context instance and set the dossier id variable
ContextInstance contextInstance = processInstance.getContextInstance();
contextInstance.createVariable(DossierConstants.DOSSIER_ID, dossier.getId().toString());
contextInstance.createVariable(DossierConstants.DOSSIER_PARAMETERS, getDossierParameters(dossier));
// adding parameters for AUDIT updating
if (auditId != null) {
contextInstance.createVariable(AuditManager.AUDIT_ID, auditId);
}
// start workflow
Token token = processInstance.getRootToken();
GraphSession graphSess = jbpmContext.getGraphSession();
try {
token.signal();
} catch (Exception e) {
if(e.getCause() instanceof OpenOfficeConnectionException ) {
executionMsg = msgBuilder.getMessage("dossier.errorConnectionOO", "component_dossier_messages");
}
throw e;
}
// save workflow data
jbpmContext.save(processInstance);
} catch (Exception e) {
if (executionMsg == null) {
executionMsg = msgBuilder.getMessage("dossier.workProcessStartError", "component_dossier_messages");
}
logger.error("Error while starting workflow", e);
// AUDIT UPDATE
auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()),
"STARTUP_FAILED", e.getMessage(), null);
} finally {
if (executionMsg == null) {
executionMsg = msgBuilder.getMessage("dossier.workProcessStartCorrectly", "component_dossier_messages");
// AUDIT UPDATE
auditManager.updateAudit(auditId, new Long(System.currentTimeMillis()), null,
"EXECUTION_STARTED", null, null);
}
if (jbpmContext != null) {
jbpmContext.close();
}