use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class ReopenCaseCommand method execute.
@Override
public Void execute(Context context) {
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
caseEventSupport.fireBeforeCaseReopened(caseId, caseFile, deploymentId, caseDefinitionId, data);
logger.debug("Updating case file in working memory");
FactHandle factHandle = ksession.getFactHandle(caseFile);
((CaseFileInstanceImpl) caseFile).setCaseReopenDate(new Date());
if (data != null && !data.isEmpty()) {
caseFile.addAll(data);
}
ksession.update(factHandle, caseFile);
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);
long processInstanceId = processService.startProcess(deploymentId, caseDefinitionId, correlationKey, params);
logger.debug("Case {} successfully reopened (process instance id {})", caseId, processInstanceId);
caseEventSupport.fireAfterCaseReopened(caseId, caseFile, deploymentId, caseDefinitionId, data, processInstanceId);
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class AddDynamicTaskCommand method execute.
@Override
public Void 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);
}
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeDynamicTaskAdded(caseId, caseFile, processInstanceId, nodeType, parameters);
DynamicUtils.addDynamicWorkItem(processInstance, ksession, nodeType, parameters);
caseEventSupport.fireAfterDynamicTaskAdded(caseId, caseFile, processInstanceId, nodeType, parameters);
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class CloseCaseCommand method execute.
@Override
public Void execute(Context context) {
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
Collection<ProcessInstanceDesc> caseProcesses = runtimeDataService.getProcessInstancesByCorrelationKey(correlationKey, new QueryContext(0, 1000));
if (caseProcesses.isEmpty()) {
throw new CaseNotFoundException("Case with id " + caseId + " was not found");
}
final List<Long> processInstanceIds = caseProcesses.stream().filter(pi -> pi.getState().equals(ProcessInstance.STATE_ACTIVE)).sorted((ProcessInstanceDesc o1, ProcessInstanceDesc o2) -> {
return Long.valueOf(o2.getParentId()).compareTo(Long.valueOf(o1.getParentId()));
}).map(pi -> pi.getId()).collect(toList());
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
caseEventSupport.fireBeforeCaseClosed(caseId, caseFile, comment);
logger.debug("Process instances {} that will be completed as part of the close of the case {}", processInstanceIds, caseId);
processService.execute(deploymentId, CaseContext.get(caseId), new ExecutableCommand<Void>() {
private static final long serialVersionUID = 1L;
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
for (Long processInstanceId : processInstanceIds) {
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId);
processInstance.setState(ProcessInstance.STATE_COMPLETED, comment);
logger.debug("Process instance {} set to state completed", processInstanceId);
}
return null;
}
});
caseEventSupport.fireAfterCaseClosed(caseId, caseFile, comment);
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class ModifyRoleAssignmentCommand method execute.
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
if (caseFiles.size() != 1) {
throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size());
}
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
FactHandle factHandle = ksession.getFactHandle(caseFile);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
if (add) {
caseEventSupport.fireBeforeCaseRoleAssignmentAdded(caseFile.getCaseId(), caseFile, roleName, entity);
((CaseAssignment) caseFile).assign(roleName, entity);
caseEventSupport.fireAfterCaseRoleAssignmentAdded(caseFile.getCaseId(), caseFile, roleName, entity);
} else {
caseEventSupport.fireBeforeCaseRoleAssignmentRemoved(caseFile.getCaseId(), caseFile, roleName, entity);
((CaseAssignment) caseFile).remove(roleName, entity);
caseEventSupport.fireAfterCaseRoleAssignmentRemoved(caseFile.getCaseId(), caseFile, roleName, entity);
}
ksession.update(factHandle, caseFile);
triggerRules(ksession);
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class RemoveDataCaseFileInstanceCommand method execute.
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
if (caseFiles.size() != 1) {
throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size());
}
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
// apply authorization
authorizationManager.checkDataAuthorization(caseFile.getCaseId(), caseFile, variableNames);
FactHandle factHandle = ksession.getFactHandle(caseFile);
Map<String, Object> remove = new HashMap<>();
variableNames.forEach(p -> remove.put(p, caseFile.getData(p)));
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeCaseDataRemoved(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), remove);
variableNames.forEach(p -> caseFile.remove(p));
ksession.update(factHandle, caseFile);
triggerRules(ksession);
caseEventSupport.fireAfterCaseDataRemoved(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), remove);
return null;
}
Aggregations