use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class EscalateToAdminSLAViolationListener method getCaseFile.
protected CaseFileInstance getCaseFile(KieSession ksession) {
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
if (caseFiles.size() == 0) {
return null;
}
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
return caseFile;
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class NotifyOwnerSLAViolationListener method getCaseFile.
protected CaseFileInstance getCaseFile(KieSession ksession) {
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
if (caseFiles.size() == 0) {
return null;
}
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
return caseFile;
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class NotifyOwnerSLAViolationListener method afterSLAViolated.
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
if (caseFile != null) {
String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
if (caseFile.getCaseId().equals(caseId)) {
try {
Collection<OrganizationalEntity> adminAssignments = ((CaseAssignment) caseFile).getAssignments("owner");
String recipients = adminAssignments.stream().map(oe -> userInfo.getEmailForEntity(oe)).collect(Collectors.joining(";"));
logger.debug("Case instance {} has SLA violation, notifying owner", caseId);
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
Map<String, Object> parameters = buildEmailParameters(recipients, caseId, event);
TaskSpecification taskSpec = caseService.newTaskSpec("Email", "SLA Violation for case " + caseId, parameters);
caseService.addDynamicTask(caseId, taskSpec);
} catch (IllegalArgumentException e) {
logger.debug("There is no owner role defined in case instance {}, unable to notify SLA violation", caseId);
}
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class NotifyParentCaseEventListener method afterProcessCompleted.
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
if (caseFile != null) {
String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
if (caseFile.getCaseId().equals(caseId)) {
logger.debug("Process instance {} that represents main case instance {} has completed/was aborted, notify parent if exists", event.getProcessInstance().getId(), caseId);
CaseEvent caseEvent = null;
if (event.getProcessInstance().getState() == ProcessInstance.STATE_COMPLETED) {
caseEvent = new CaseCloseEvent(identityProvider.getName(), caseId, caseFile, "");
} else {
caseEvent = new CaseCancelEvent(identityProvider.getName(), caseId, caseFile, Arrays.asList(event.getProcessInstance().getId()));
}
notifyParentOnCompletion(caseEvent);
}
}
}
Aggregations