use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImpl method getCaseRoleAssignments.
@Override
public Collection<CaseRoleInstance> getCaseRoleAssignments(String caseId) throws CaseNotFoundException {
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.MODIFY_ROLE_ASSIGNMENT);
ProcessInstanceDesc pi = verifyCaseIdExists(caseId);
CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, pi.getDeploymentId());
return ((CaseFileInstanceImpl) caseFile).getAssignments();
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImpl method newCaseFileInstance.
/*
* new instances methods
*/
@Override
public CaseFileInstance newCaseFileInstance(String deploymentId, String caseDefinition, Map<String, Object> data) {
CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
if (def == null) {
throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
}
CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
caseFile.setupRoles(def.getCaseRoles());
caseFile.setAccessRestrictions(def.getDataAccessRestrictions());
return caseFile;
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.
the class CaseInstanceAuditEventListener method afterCaseStarted.
@Override
public void afterCaseStarted(CaseStartEvent event) {
CaseFileInstance caseFile = event.getCaseFile();
if (caseFile == null) {
return;
}
Collection<CaseRoleInstance> caseRoleAssignments = ((CaseFileInstanceImpl) caseFile).getAssignments();
if (caseRoleAssignments != null && !caseRoleAssignments.isEmpty()) {
for (CaseRoleInstance roleAssignment : caseRoleAssignments) {
logger.debug("Role {} has following assignments {}", roleAssignment.getRoleName(), roleAssignment.getRoleAssignments());
if (roleAssignment.getRoleAssignments() != null && !roleAssignment.getRoleAssignments().isEmpty()) {
List<CaseRoleAssignmentLog> objects = new ArrayList<>();
roleAssignment.getRoleAssignments().forEach(entity -> {
CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(event.getProcessInstanceId(), event.getCaseId(), roleAssignment.getRoleName(), entity);
objects.add(assignmentLog);
});
commandService.execute(new PersistObjectCommand(objects.toArray()));
}
}
} else {
// add public role so it can be found by queries that take assignments into consideration
CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(event.getProcessInstanceId(), event.getCaseId(), "*", TaskModelProvider.getFactory().newGroup(AuthorizationManager.PUBLIC_GROUP));
commandService.execute(new PersistObjectCommand(assignmentLog));
}
Map<String, Object> initialData = caseFile.getData();
if (initialData.isEmpty()) {
return;
}
List<CaseFileDataLog> insert = new ArrayList<>();
initialData.forEach((name, value) -> {
if (value != null) {
CaseFileDataLog caseFileDataLog = new CaseFileDataLog(event.getCaseId(), caseFile.getDefinitionId(), name);
insert.add(caseFileDataLog);
caseFileDataLog.setItemType(value.getClass().getName());
caseFileDataLog.setItemValue(value.toString());
caseFileDataLog.setLastModified(new Date());
caseFileDataLog.setLastModifiedBy(event.getUser());
}
});
commandService.execute(new PersistObjectCommand(insert.toArray()));
}
use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl 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.model.instance.CaseFileInstanceImpl 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