use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class CaseServiceImpl method setIdentityProvider.
public void setIdentityProvider(IdentityProvider identityProvider) {
this.identityProvider = identityProvider;
this.emptyCaseEventSupport = new CaseEventSupport(identityProvider, Collections.emptyList());
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class AddDataCaseFileInstanceCommand 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, parameters.keySet());
FactHandle factHandle = ksession.getFactHandle(caseFile);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeCaseDataAdded(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), parameters);
caseFile.addAll(parameters);
// setup data restriction if any are given
for (String name : parameters.keySet()) {
if (accessRestriction != null) {
((CaseFileInstanceImpl) caseFile).addDataAccessRestriction(name, accessRestriction);
} else {
((CaseFileInstanceImpl) caseFile).removeDataAccessRestriction(name);
}
}
ksession.update(factHandle, caseFile);
triggerRules(ksession);
caseEventSupport.fireAfterCaseDataAdded(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), parameters);
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class AddDynamicTaskToStageCommand method execute.
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(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);
}
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeDynamicTaskAdded(caseId, caseFile, processInstanceId, nodeType, parameters);
DynamicUtils.addDynamicWorkItem(dynamicContext, 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 CancelCaseCommand 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");
}
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.fireBeforeCaseCancelled(caseId, caseFile, processInstanceIds);
logger.debug("Case {} consists of following process instances (ids) {}", caseId, processInstanceIds);
processService.abortProcessInstances(processInstanceIds);
caseEventSupport.fireAfterCaseCancelled(caseId, caseFile, processInstanceIds);
if (destroy) {
RuntimeManager runtimeManager = getRuntimeManager(context);
if (runtimeManager instanceof PerCaseRuntimeManager) {
caseEventSupport.fireBeforeCaseDestroyed(caseId, caseFile, processInstanceIds);
logger.debug("Case {} aborted, destroying case data including per case runtime engine (including working memory)", caseId);
((PerCaseRuntimeManager) runtimeManager).destroyCase(CaseContext.get(caseId));
caseEventSupport.fireAfterCaseDestroyed(caseId, caseFile, processInstanceIds);
}
}
return null;
}
use of org.jbpm.casemgmt.impl.event.CaseEventSupport in project jbpm by kiegroup.
the class CaseCommentCommand method execute.
@Override
public String 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);
String commentIdentifier = null;
if (add) {
CommentInstance commentInstance = new CommentInstanceImpl(author, comment, restrictedTo);
caseEventSupport.fireBeforeCaseCommentAdded(caseFile.getCaseId(), caseFile, commentInstance);
((CaseFileInstanceImpl) caseFile).addComment(commentInstance);
commentIdentifier = commentInstance.getId();
caseEventSupport.fireAfterCaseCommentAdded(caseFile.getCaseId(), caseFile, commentInstance);
} else if (update) {
CommentInstance toUpdate = ((CaseFileInstanceImpl) caseFile).getComments().stream().filter(c -> c.getId().equals(commentId)).findFirst().orElseThrow(() -> new CaseCommentNotFoundException("Cannot find comment with id " + commentId));
if (!this.author.equals(toUpdate.getAuthor())) {
throw new IllegalStateException("Only original author can update comment");
}
// apply authorization
authorizationManager.checkCommentAuthorization(caseFile.getCaseId(), caseFile, toUpdate);
caseEventSupport.fireBeforeCaseCommentUpdated(caseFile.getCaseId(), caseFile, toUpdate);
((CommentInstanceImpl) toUpdate).setComment(updatedText);
if (restrictedTo != null) {
((CommentInstanceImpl) toUpdate).setRestrictedTo(restrictedTo);
}
commentIdentifier = toUpdate.getId();
caseEventSupport.fireAfterCaseCommentUpdated(caseFile.getCaseId(), caseFile, toUpdate);
} else if (remove) {
CommentInstance toRemove = ((CaseFileInstanceImpl) caseFile).getComments().stream().filter(c -> c.getId().equals(commentId)).findFirst().orElseThrow(() -> new CaseCommentNotFoundException("Cannot find comment with id " + commentId));
// apply authorization
authorizationManager.checkCommentAuthorization(caseFile.getCaseId(), caseFile, toRemove);
caseEventSupport.fireBeforeCaseCommentRemoved(caseFile.getCaseId(), caseFile, toRemove);
((CaseFileInstanceImpl) caseFile).removeComment(toRemove);
commentIdentifier = toRemove.getId();
caseEventSupport.fireAfterCaseCommentRemoved(caseFile.getCaseId(), caseFile, toRemove);
}
ksession.update(factHandle, caseFile);
triggerRules(ksession);
return commentIdentifier;
}
Aggregations