Search in sources :

Example 1 with CaseRole

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

the class CaseRuntimeDataServiceImpl method onDeploy.

/*
     * Deploy and undeploy handling
     */
@Override
public void onDeploy(DeploymentEvent event) {
    AbstractRuntimeManager runtimeManager = (AbstractRuntimeManager) event.getDeployedUnit().getRuntimeManager();
    KieBase kieBase = runtimeManager.getEnvironment().getKieBase();
    Collection<Process> processes = kieBase.getProcesses();
    Map<String, DeployedAsset> mapProcessById = event.getDeployedUnit().getDeployedAssets().stream().collect(toMap(DeployedAsset::getId, asset -> asset));
    for (Process process : processes) {
        if (((WorkflowProcess) process).isDynamic()) {
            String caseIdPrefix = collectCaseIdPrefix(process);
            Collection<CaseMilestone> caseMilestones = collectMilestoness(process);
            Collection<CaseStage> caseStages = collectCaseStages(event.getDeploymentId(), process.getId(), ((WorkflowProcess) process));
            Collection<CaseRole> caseRoles = collectCaseRoles(process);
            Collection<AdHocFragment> adHocFragments = collectAdHocFragments((WorkflowProcess) process);
            Map<String, List<String>> dataAccessRestrictions = collectDataAccessRestrictions(process);
            CaseDefinitionImpl caseDef = new CaseDefinitionImpl((ProcessAssetDesc) mapProcessById.get(process.getId()), caseIdPrefix, caseStages, caseMilestones, caseRoles, adHocFragments, dataAccessRestrictions);
            availableCases.add(caseDef);
            caseIdGenerator.register(caseIdPrefix);
        }
    }
    // collect role information
    Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
    List<String> roles = null;
    for (DeployedAsset asset : assets) {
        if (asset instanceof ProcessAssetDesc) {
            // if it's not dynamic it's considered as not case definition
            if (!((ProcessAssetDesc) asset).isDynamic()) {
                availableProcesses.add((ProcessAssetDesc) asset);
            }
            if (roles == null) {
                roles = ((ProcessAssetDesc) asset).getRoles();
            }
        }
    }
    if (roles == null) {
        roles = Collections.emptyList();
    }
    deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CaseDefinitionComparator(org.jbpm.casemgmt.impl.model.CaseDefinitionComparator) Collectors.toMap(java.util.stream.Collectors.toMap) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) FILTER(org.kie.internal.query.QueryParameterIdentifiers.FILTER) Set(java.util.Set) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) NodeContainer(org.kie.api.definition.process.NodeContainer) AdHocFragmentImpl(org.jbpm.casemgmt.impl.model.AdHocFragmentImpl) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ArrayList(java.util.ArrayList) ProcessDefinitionComparator(org.jbpm.casemgmt.impl.model.ProcessDefinitionComparator) HashSet(java.util.HashSet) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) KieBase(org.kie.api.KieBase) IdentityProvider(org.kie.internal.identity.IdentityProvider) QueryManager(org.jbpm.shared.services.impl.QueryManager) CorrelationKey(org.kie.internal.process.CorrelationKey) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) CaseIdGenerator(org.jbpm.casemgmt.api.generator.CaseIdGenerator) Collectors.toList(java.util.stream.Collectors.toList) Node(org.kie.api.definition.process.Node) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) CaseMilestoneImpl(org.jbpm.casemgmt.impl.model.CaseMilestoneImpl) CommonUtils.getAuthenticatedUserRoles(org.jbpm.kie.services.impl.CommonUtils.getAuthenticatedUserRoles) Collections(java.util.Collections) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) Process(org.kie.api.definition.process.Process) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) KieBase(org.kie.api.KieBase) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess)

Example 2 with CaseRole

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

the class CaseRuntimeDataServiceImpl method collectCaseRoles.

private Collection<CaseRole> collectCaseRoles(Process process) {
    String roles = (String) process.getMetaData().get("customCaseRoles");
    if (roles == null) {
        return Collections.emptyList();
    }
    List<CaseRole> result = new ArrayList<CaseRole>();
    String[] roleStrings = roles.split(",");
    for (String roleString : roleStrings) {
        String[] elements = roleString.split(":");
        CaseRoleImpl role = new CaseRoleImpl(elements[0]);
        result.add(role);
        if (elements.length > 1) {
            role.setCardinality(Integer.parseInt(elements[1]));
        }
    }
    return result;
}
Also used : CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) ArrayList(java.util.ArrayList)

Example 3 with CaseRole

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

the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionByIdWithBoundaryEvent.

@Test
public void testGetCaseDefinitionByIdWithBoundaryEvent() {
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskCaseBoundary");
    // UserTaskWithStageCase asserts
    assertNotNull(caseDef);
    assertEquals("UserTaskCaseBoundary", caseDef.getId());
    assertEquals("Simple Case with User Tasks and Boundary", caseDef.getName());
    assertEquals("1.0", caseDef.getVersion());
    assertEquals("HR", caseDef.getIdentifierPrefix());
    assertEquals(2, caseDef.getCaseMilestones().size());
    assertEquals(0, caseDef.getCaseStages().size());
    assertEquals(3, caseDef.getAdHocFragments().size());
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    Map<String, CaseMilestone> mappedMilestones = mapMilestones(caseDef.getCaseMilestones());
    assertTrue(mappedMilestones.containsKey("Milestone1"));
    assertTrue(mappedMilestones.containsKey("Milestone2"));
    Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseDef.getAdHocFragments());
    assertTrue(mappedFragments.containsKey("Hello2"));
    assertEquals("HumanTaskNode", mappedFragments.get("Hello2").getType());
    assertTrue(mappedFragments.containsKey("Milestone1"));
    assertEquals("MilestoneNode", mappedFragments.get("Milestone1").getType());
    assertTrue(mappedFragments.containsKey("Milestone2"));
    assertEquals("MilestoneNode", mappedFragments.get("Milestone2").getType());
    assertNotNull(caseDef.getCaseRoles());
    assertEquals(3, caseDef.getCaseRoles().size());
    Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
    assertTrue(mappedRoles.containsKey("owner"));
    assertTrue(mappedRoles.containsKey("contact"));
    assertTrue(mappedRoles.containsKey("participant"));
    assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
    assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
    assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
Also used : CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 4 with CaseRole

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

the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitions.

@Test
public void testGetCaseDefinitions() {
    Collection<CaseDefinition> cases = caseRuntimeDataService.getCases(new QueryContext());
    assertNotNull(cases);
    assertEquals(5, cases.size());
    Map<String, CaseDefinition> mappedCases = mapCases(cases);
    assertTrue(mappedCases.containsKey("EmptyCase"));
    assertTrue(mappedCases.containsKey("UserTaskCase"));
    assertTrue(mappedCases.containsKey("UserTaskCaseBoundary"));
    assertTrue(mappedCases.containsKey("UserTaskWithStageCase"));
    // EmptyCase asserts
    CaseDefinition caseDef = mappedCases.get("EmptyCase");
    assertNotNull(caseDef);
    assertEquals("EmptyCase", caseDef.getId());
    assertEquals("New Case", caseDef.getName());
    assertEquals("", caseDef.getVersion());
    assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
    assertNotNull(caseDef.getCaseMilestones());
    assertTrue(caseDef.getCaseMilestones().isEmpty());
    assertNotNull(caseDef.getCaseStages());
    assertTrue(caseDef.getCaseStages().isEmpty());
    assertNotNull(caseDef.getCaseRoles());
    assertTrue(caseDef.getCaseRoles().isEmpty());
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    // UserTaskCase asserts
    caseDef = mappedCases.get("UserTaskCase");
    assertNotNull(caseDef);
    assertEquals("UserTaskCase", caseDef.getId());
    assertEquals("Simple Case with User Tasks", caseDef.getName());
    assertEquals("1.0", caseDef.getVersion());
    assertEquals("HR", caseDef.getIdentifierPrefix());
    assertNotNull(caseDef.getCaseMilestones());
    assertEquals(2, caseDef.getCaseMilestones().size());
    Map<String, CaseMilestone> mappedMilestones = mapMilestones(caseDef.getCaseMilestones());
    assertTrue(mappedMilestones.containsKey("Milestone1"));
    assertTrue(mappedMilestones.containsKey("Milestone2"));
    CaseMilestone milestone = mappedMilestones.get("Milestone1");
    assertEquals("_SomeID4", milestone.getId());
    assertEquals("Milestone1", milestone.getName());
    assertEquals("", milestone.getAchievementCondition());
    assertEquals(false, milestone.isMandatory());
    milestone = mappedMilestones.get("Milestone2");
    assertEquals("_5", milestone.getId());
    assertEquals("Milestone2", milestone.getName());
    assertEquals("org.kie.api.runtime.process.CaseData(data.get(\"dataComplete\") == true)", milestone.getAchievementCondition());
    assertEquals(false, milestone.isMandatory());
    assertNotNull(caseDef.getCaseStages());
    assertEquals(0, caseDef.getCaseStages().size());
    assertNotNull(caseDef.getCaseRoles());
    assertEquals(3, caseDef.getCaseRoles().size());
    Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
    assertTrue(mappedRoles.containsKey("owner"));
    assertTrue(mappedRoles.containsKey("contact"));
    assertTrue(mappedRoles.containsKey("participant"));
    assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
    assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
    assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
    // UserTaskWithStageCase asserts
    caseDef = mappedCases.get("UserTaskWithStageCase");
    assertNotNull(caseDef);
    assertEquals("UserTaskWithStageCase", caseDef.getId());
    assertEquals("UserTaskWithStageCase", caseDef.getName());
    assertEquals("1.0", caseDef.getVersion());
    assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
    assertNotNull(caseDef.getCaseMilestones());
    assertEquals(0, caseDef.getCaseMilestones().size());
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    assertNotNull(caseDef.getCaseStages());
    assertEquals(1, caseDef.getCaseStages().size());
    Map<String, CaseStage> mappedStages = mapStages(caseDef.getCaseStages());
    assertTrue(mappedStages.containsKey("Collect input"));
    CaseStage caseStage = mappedStages.get("Collect input");
    assertNotNull(caseStage);
    assertEquals("Collect input", caseStage.getName());
    assertEquals(2, caseStage.getAdHocFragments().size());
    Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseStage.getAdHocFragments());
    assertTrue(mappedFragments.containsKey("Missing data"));
    assertEquals("HumanTaskNode", mappedFragments.get("Missing data").getType());
    assertTrue(mappedFragments.containsKey("Verification of data"));
    assertEquals("SubProcessNode", mappedFragments.get("Verification of data").getType());
    assertNotNull(caseDef.getCaseRoles());
    assertEquals(3, caseDef.getCaseRoles().size());
    mappedRoles = mapRoles(caseDef.getCaseRoles());
    assertTrue(mappedRoles.containsKey("owner"));
    assertTrue(mappedRoles.containsKey("contact"));
    assertTrue(mappedRoles.containsKey("participant"));
    assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
    assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
    assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
Also used : CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 5 with CaseRole

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

the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionById.

@Test
public void testGetCaseDefinitionById() {
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskWithStageCase");
    // UserTaskWithStageCase asserts
    assertNotNull(caseDef);
    assertEquals("UserTaskWithStageCase", caseDef.getId());
    assertEquals("UserTaskWithStageCase", caseDef.getName());
    assertEquals("1.0", caseDef.getVersion());
    assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
    assertNotNull(caseDef.getCaseMilestones());
    assertEquals(0, caseDef.getCaseMilestones().size());
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    assertNotNull(caseDef.getCaseStages());
    assertEquals(1, caseDef.getCaseStages().size());
    Map<String, CaseStage> mappedStages = mapStages(caseDef.getCaseStages());
    assertTrue(mappedStages.containsKey("Collect input"));
    CaseStage caseStage = mappedStages.get("Collect input");
    assertNotNull(caseStage);
    assertEquals("Collect input", caseStage.getName());
    assertEquals(2, caseStage.getAdHocFragments().size());
    Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseStage.getAdHocFragments());
    assertTrue(mappedFragments.containsKey("Missing data"));
    assertEquals("HumanTaskNode", mappedFragments.get("Missing data").getType());
    assertTrue(mappedFragments.containsKey("Verification of data"));
    assertEquals("SubProcessNode", mappedFragments.get("Verification of data").getType());
    assertNotNull(caseDef.getCaseRoles());
    assertEquals(3, caseDef.getCaseRoles().size());
    Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
    assertTrue(mappedRoles.containsKey("owner"));
    assertTrue(mappedRoles.containsKey("contact"));
    assertTrue(mappedRoles.containsKey("participant"));
    assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
    assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
    assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
Also used : CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseRole (org.jbpm.casemgmt.api.model.CaseRole)6 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)4 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 CaseMilestone (org.jbpm.casemgmt.api.model.CaseMilestone)3 CaseStage (org.jbpm.casemgmt.api.model.CaseStage)3 CaseRoleImpl (org.jbpm.casemgmt.impl.model.CaseRoleImpl)3 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 QueryContext (org.kie.api.runtime.query.QueryContext)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Predicate (java.util.function.Predicate)1