Search in sources :

Example 1 with CaseRoleInstance

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;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 2 with CaseRoleInstance

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()));
}
Also used : CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) PersistObjectCommand(org.jbpm.shared.services.impl.commands.PersistObjectCommand) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 3 with CaseRoleInstance

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;
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 4 with CaseRoleInstance

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);
}
Also used : CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 5 with CaseRoleInstance

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;
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Aggregations

CaseRoleInstance (org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)7 ArrayList (java.util.ArrayList)4 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)2 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 CaseMilestoneInstance (org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance)1 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)1 CommentInstance (org.jbpm.casemgmt.api.model.instance.CommentInstance)1 CaseInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl)1 PersistObjectCommand (org.jbpm.shared.services.impl.commands.PersistObjectCommand)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 User (org.kie.api.task.model.User)1