Search in sources :

Example 1 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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();
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc)

Example 2 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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 3 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImpl method getCaseComments.

/*
     * Case comments methods
     */
@Override
public Collection<CommentInstance> getCaseComments(String caseId, QueryContext queryContext) throws CaseNotFoundException {
    authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.MODIFY_COMMENT);
    ProcessInstanceDesc pi = verifyCaseIdExists(caseId);
    CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, pi.getDeploymentId());
    List<CommentInstance> caseComments = new ArrayList<>(((CaseFileInstanceImpl) caseFile).getComments());
    // apply authorization
    caseComments = authorizationManager.filterByCommentAuthorization(caseId, caseFile, caseComments);
    int caseCommentsSize = caseComments.size();
    int offset = queryContext.getOffset();
    int pageSize = queryContext.getCount();
    int pageIndex = (caseCommentsSize + pageSize - 1) / pageSize;
    if (caseCommentsSize < pageSize) {
        return caseComments;
    } else if (pageIndex == (offset / pageSize) + 1) {
        return caseComments.subList(offset, caseCommentsSize);
    } else {
        return caseComments.subList(offset, offset + pageSize);
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc)

Example 4 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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 5 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) ClassObjectFilter(org.drools.core.ClassObjectFilter) FactHandle(org.kie.api.runtime.rule.FactHandle) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Aggregations

CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)121 HashMap (java.util.HashMap)95 Test (org.junit.Test)86 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)81 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)66 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)61 UserImpl (org.jbpm.services.task.impl.model.UserImpl)54 QueryContext (org.kie.api.runtime.query.QueryContext)46 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)44 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)42 TaskSummary (org.kie.api.task.model.TaskSummary)40 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)39 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)39 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)39 QueryFilter (org.kie.internal.query.QueryFilter)26 ArrayList (java.util.ArrayList)21 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)20 Collection (java.util.Collection)17 List (java.util.List)17 Map (java.util.Map)16