Search in sources :

Example 61 with CaseFileInstance

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

the class NotifyParentCaseEventListener method getCaseFile.

protected CaseFileInstance getCaseFile(KieSession ksession) {
    Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
    if (caseFiles.size() == 0) {
        return null;
    }
    CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
    return caseFile;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) ClassObjectFilter(org.drools.core.ClassObjectFilter)

Example 62 with CaseFileInstance

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

the class AuthorizationManagerImpl method checkCommentAuthorization.

@Override
public void checkCommentAuthorization(String caseId, CaseFileInstance caseFileInstance, CommentInstance commentInstance) {
    CommentInstanceImpl comment = ((CommentInstanceImpl) commentInstance);
    if (comment.getRestrictedTo() == null || comment.getRestrictedTo().isEmpty()) {
        return;
    }
    List<String> callerAuthorization = collectUserAuthInfo();
    logger.debug("Caller {} authorization set is {}", identityProvider.getName(), callerAuthorization);
    List<String> callerCaseRoles = getCallerRoles(caseFileInstance, callerAuthorization);
    logger.debug("Caller {} case role set is {}", identityProvider.getName(), callerCaseRoles);
    List<String> requiredRoles = comment.getRestrictedTo();
    if (requiredRoles.isEmpty() || requiredRoles.stream().anyMatch(role -> callerCaseRoles.contains(role))) {
        logger.debug("Caller has access to comment {}", comment.getId());
        return;
    }
    logger.warn("User {} does not have access to comment {} in case {}, required roles are {} and user has {}", identityProvider.getName(), comment.getId(), caseId, requiredRoles, callerCaseRoles);
    throw new SecurityException(MessageFormat.format(NO_AUTH_TO_COMMENT, identityProvider.getName(), comment.getId(), caseId));
}
Also used : IdentityProvider(org.kie.internal.identity.IdentityProvider) Arrays(java.util.Arrays) Properties(java.util.Properties) Logger(org.slf4j.Logger) Collection(java.util.Collection) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) HashMap(java.util.HashMap) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) List(java.util.List) Stream(java.util.stream.Stream) Map(java.util.Map) Entry(java.util.Map.Entry) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) InputStream(java.io.InputStream) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl)

Example 63 with CaseFileInstance

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

the class AuthorizationManagerImpl method filterByCommentAuthorization.

@Override
public List<CommentInstance> filterByCommentAuthorization(String caseId, CaseFileInstance caseFileInstance, List<CommentInstance> comments) {
    if (comments == null || comments.isEmpty()) {
        logger.debug("No comments to be filtered");
        return comments;
    }
    List<String> callerAuthorization = collectUserAuthInfo();
    logger.debug("Caller {} authorization set is {}", identityProvider.getName(), callerAuthorization);
    List<String> callerCaseRoles = getCallerRoles(caseFileInstance, callerAuthorization);
    logger.debug("Caller {} case role set is {}", identityProvider.getName(), callerCaseRoles);
    List<CommentInstance> filteredComments = new ArrayList<>(comments);
    for (CommentInstance commentInstance : comments) {
        CommentInstanceImpl comment = ((CommentInstanceImpl) commentInstance);
        List<String> requiredRoles = comment.getRestrictedTo();
        if (requiredRoles == null || requiredRoles.isEmpty()) {
            continue;
        }
        if (requiredRoles.isEmpty() || requiredRoles.stream().anyMatch(role -> callerCaseRoles.contains(role))) {
            logger.debug("Caller {} has access to comment {}", identityProvider.getName(), comment.getId());
            continue;
        }
        logger.debug("Caller {} does not have access to comment {}", identityProvider.getName(), comment.getId());
        filteredComments.remove(comment);
    }
    return filteredComments;
}
Also used : IdentityProvider(org.kie.internal.identity.IdentityProvider) Arrays(java.util.Arrays) Properties(java.util.Properties) Logger(org.slf4j.Logger) Collection(java.util.Collection) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) HashMap(java.util.HashMap) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) List(java.util.List) Stream(java.util.stream.Stream) Map(java.util.Map) Entry(java.util.Map.Entry) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) InputStream(java.io.InputStream) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) ArrayList(java.util.ArrayList)

Example 64 with CaseFileInstance

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

the class CaseRuntimeDataServiceImplTest method testAddSubprocessToEmptyCaseCheckCaseNodes.

@Test
public void testAddSubprocessToEmptyCaseCheckCaseNodes() {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        Collection<NodeInstanceDesc> completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(0, completedNodes.size());
        Map<String, Object> parameters = new HashMap<>();
        caseService.addDynamicSubprocess(caseId, "UserTask", parameters);
        Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(2, caseProcessInstances.size());
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(2, activeNodes.size());
        Map<String, NodeInstanceDesc> mappedNodes = mapNodeInstances(activeNodes);
        assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
        assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
        completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(0, completedNodes.size());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(2, completedNodes.size());
        assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
        assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSummary(org.kie.api.task.model.TaskSummary) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 65 with CaseFileInstance

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

the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCaseWithActiveElements.

@Test
public void testTransitionBetweenStagesInCaseWithActiveElements() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    try {
        Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        CaseStageInstance stageInstance = stage.iterator().next();
        assertEquals("Stage One", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        caseService.triggerAdHocFragment(caseId, "Task 1", data);
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        stageInstance = stage.iterator().next();
        assertEquals("Stage One", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        assertEquals("Task 1", activeNodes.iterator().next().getName());
        caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        assertEquals("Stage Two", stage.iterator().next().getName());
        assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        stageInstance = stage.iterator().next();
        assertEquals("Stage Two", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        caseService.triggerAdHocFragment(caseId, "Task 2", data);
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        stageInstance = stage.iterator().next();
        assertEquals("Stage Two", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        assertEquals("Task 2", activeNodes.iterator().next().getName());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

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