use of org.jbpm.casemgmt.api.model.instance.CaseRoleInstance in project jbpm by kiegroup.
the class CaseServiceImpl method getCaseInstance.
@Override
public CaseInstance getCaseInstance(String caseId, boolean withData, boolean withRoles, boolean withMilestones, boolean withStages) throws CaseNotFoundException {
authorizationManager.checkAuthorization(caseId);
CaseInstanceImpl caseInstance = (CaseInstanceImpl) caseRuntimeDataService.getCaseInstanceById(caseId);
if (caseInstance.getStatus().equals(ProcessInstance.STATE_ACTIVE)) {
if (withData) {
CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, caseInstance.getDeploymentId());
caseInstance.setCaseFile(caseFile);
}
if (withMilestones) {
Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(caseId, false, new org.kie.internal.query.QueryContext(0, 100));
caseInstance.setCaseMilestones(milestones);
}
if (withRoles) {
Collection<CaseRoleInstance> roles = getCaseRoleAssignments(caseId);
caseInstance.setCaseRoles(roles);
}
if (withStages) {
Collection<CaseStageInstance> stages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new org.kie.internal.query.QueryContext(0, 100));
caseInstance.setCaseStages(stages);
}
}
return caseInstance;
}
use of org.jbpm.casemgmt.api.model.instance.CaseRoleInstance 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.api.model.instance.CaseRoleInstance in project jbpm by kiegroup.
the class CaseFileInstanceImpl method getAssignments.
@Override
public Collection<OrganizationalEntity> getAssignments(String roleName) {
String[] roleNames = roleName.split(separator);
Collection<OrganizationalEntity> foundAssignments = new ArrayList<>();
for (String role : roleNames) {
CaseRoleInstance caseRoleInstance = this.roles.get(role);
if (caseRoleInstance == null) {
throw new IllegalArgumentException("No role with name " + role + " was found");
}
foundAssignments.addAll(caseRoleInstance.getRoleAssignments());
}
return foundAssignments;
}
use of org.jbpm.casemgmt.api.model.instance.CaseRoleInstance in project jbpm by kiegroup.
the class CaseFileInstanceImpl method assignOwner.
public void assignOwner(User actualOwner) {
CaseRoleInstance caseRoleInstance = this.roles.get(AuthorizationManager.OWNER_ROLE);
if (caseRoleInstance == null) {
caseRoleInstance = new CaseRoleInstanceImpl(AuthorizationManager.OWNER_ROLE, 1);
this.roles.put(AuthorizationManager.OWNER_ROLE, caseRoleInstance);
}
((CaseRoleInstanceImpl) caseRoleInstance).addRoleAssignment(actualOwner);
}
use of org.jbpm.casemgmt.api.model.instance.CaseRoleInstance in project jbpm by kiegroup.
the class CaseFileInstanceImpl method getRolesForOrgEntities.
public List<String> getRolesForOrgEntities(List<String> orgEntities) {
List<String> collected = new ArrayList<>();
if (roles == null || roles.isEmpty()) {
return collected;
}
List<CaseRoleInstance> roleInstances = new ArrayList<>();
for (Entry<String, CaseRoleInstance> entry : roles.entrySet()) {
roleInstances.add(entry.getValue());
}
for (CaseRoleInstance cri : roleInstances) {
if (cri.getRoleAssignments() == null || cri.getRoleAssignments().isEmpty()) {
continue;
}
for (OrganizationalEntity assignee : cri.getRoleAssignments()) {
if (orgEntities.contains(assignee.getId())) {
collected.add(cri.getRoleName());
}
}
}
return collected;
}
Aggregations