use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class StartCaseCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context context) {
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeCaseStarted(caseId, deploymentId, caseDefinitionId, caseFile);
logger.debug("Inserting case file into working memory");
List<Command<?>> commands = new ArrayList<>();
commands.add(commandsFactory.newInsert(caseFile));
commands.add(commandsFactory.newFireAllRules());
BatchExecutionCommand batch = commandsFactory.newBatchExecution(commands);
processService.execute(deploymentId, CaseContext.get(caseId), batch);
logger.debug("Starting process instance for case {} and case definition {}", caseId, caseDefinitionId);
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
Map<String, Object> params = new HashMap<>();
// set case id to allow it to use CaseContext when creating runtime engine
params.put(EnvironmentName.CASE_ID, caseId);
final long processInstanceId = processService.startProcess(deploymentId, caseDefinitionId, correlationKey, params);
logger.debug("Case {} successfully started (process instance id {})", caseId, processInstanceId);
final Map<String, Object> caseData = caseFile.getData();
if (caseData != null && !caseData.isEmpty()) {
processService.execute(deploymentId, CaseContext.get(caseId), new ExecutableCommand<Void>() {
private static final long serialVersionUID = -7093369406457484236L;
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance pi = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
if (pi != null) {
ProcessEventSupport processEventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport();
for (Entry<String, Object> entry : caseData.entrySet()) {
String name = "caseFile_" + entry.getKey();
processEventSupport.fireAfterVariableChanged(name, name, null, entry.getValue(), pi, (KieRuntime) ksession);
}
}
return null;
}
});
}
caseEventSupport.fireAfterCaseStarted(caseId, deploymentId, caseDefinitionId, caseFile, processInstanceId);
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class AddDynamicProcessCommand method execute.
@Override
public Long execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance == null) {
throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId);
}
try {
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
FactHandle factHandle = ksession.getFactHandle(caseFile);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters);
long subProcessInstanceId = DynamicUtils.addDynamicSubProcess(processInstance, ksession, processId, parameters);
ksession.update(factHandle, caseFile);
triggerRules(ksession);
caseEventSupport.fireAfterDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters, subProcessInstanceId);
return subProcessInstanceId;
} catch (IllegalArgumentException e) {
throw new ProcessDefinitionNotFoundException(e.getMessage());
}
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class AddDynamicProcessToStageCommand method execute.
@Override
public Long execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance == null) {
throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId);
}
DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances(true).stream().filter(ni -> (ni instanceof DynamicNodeInstance) && stageId.equals(ni.getNode().getMetaData().get("UniqueId"))).findFirst().orElse(null);
if (dynamicContext == null) {
throw new StageNotFoundException("No stage found with id " + stageId);
}
try {
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters);
long subProcessInstanceId = DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, processId, parameters);
if (subProcessInstanceId < 0) {
throw new ProcessDefinitionNotFoundException("No process definition found with id: " + processId);
}
caseEventSupport.fireAfterDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters, subProcessInstanceId);
return subProcessInstanceId;
} catch (IllegalArgumentException e) {
throw new ProcessDefinitionNotFoundException(e.getMessage());
}
}
Aggregations