Search in sources :

Example 1 with CaseFile

use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.

the class CaseManagementServiceBase method startCase.

public String startCase(String containerId, String caseDefinitionId, String payload, String marshallingType) {
    containerId = context.getContainerId(containerId, ContainerLocatorProvider.get().getLocator());
    CaseDefinition caseDef = caseRuntimeDataService.getCase(containerId, caseDefinitionId);
    if (caseDef == null) {
        throw new CaseDefinitionNotFoundException("Unable to find case '" + caseDefinitionId + "' in container " + containerId);
    }
    logger.debug("About to unmarshal case file from payload: '{}'", payload);
    CaseFile caseFile = marshallerHelper.unmarshal(containerId, payload, marshallingType, CaseFile.class);
    String caseId;
    if (caseFile == null) {
        logger.debug("Case file not given, starting case without case file");
        caseId = caseService.startCase(containerId, caseDefinitionId);
    } else {
        logger.debug("Case file provided {}", caseFile);
        Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
        if (caseFile.getUserAssignments() != null) {
            caseFile.getUserAssignments().entrySet().stream().filter(entry -> entry.getValue() != null && !entry.getValue().isEmpty()).forEach(entry -> roleAssignments.put(entry.getKey(), taskModelFactory.newUser(entry.getValue())));
        }
        if (caseFile.getGroupAssignments() != null) {
            caseFile.getGroupAssignments().entrySet().stream().filter(entry -> entry.getValue() != null && !entry.getValue().isEmpty()).forEach(entry -> roleAssignments.put(entry.getKey(), taskModelFactory.newGroup(entry.getValue())));
        }
        Map<String, List<String>> accessRestrictions = null;
        if (caseFile.getAccessRestrictions() != null) {
            accessRestrictions = new HashMap<>();
            for (Entry<String, String[]> entry : caseFile.getAccessRestrictions().entrySet()) {
                accessRestrictions.put(entry.getKey(), Arrays.asList(entry.getValue()));
            }
        }
        CaseFileInstance caseFileInstance = caseService.newCaseFileInstanceWithRestrictions(containerId, caseDefinitionId, caseFile.getData(), roleAssignments, accessRestrictions);
        caseId = caseService.startCase(containerId, caseDefinitionId, caseFileInstance);
    }
    logger.debug("New case instance started with case id {} for case definition {}", caseId, caseDefinitionId);
    // return response
    return marshallerHelper.marshal(containerId, marshallingType, caseId);
}
Also used : Arrays(java.util.Arrays) CASE_DYNAMIC_ACTORS_PROP(org.kie.server.api.KieServerConstants.CASE_DYNAMIC_ACTORS_PROP) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CASE_DYNAMIC_DESC_PROP(org.kie.server.api.KieServerConstants.CASE_DYNAMIC_DESC_PROP) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CommentSortBy(org.jbpm.casemgmt.api.model.instance.CommentSortBy) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) KieServerConstants(org.kie.server.api.KieServerConstants) LoggerFactory(org.slf4j.LoggerFactory) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) CASE_DYNAMIC_NODE_TYPE_PROP(org.kie.server.api.KieServerConstants.CASE_DYNAMIC_NODE_TYPE_PROP) ByCaseIdContainerLocator(org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) Map(java.util.Map) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) IdentityProvider(org.kie.internal.identity.IdentityProvider) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) CaseDefinitionNotFoundException(org.jbpm.casemgmt.api.CaseDefinitionNotFoundException) Logger(org.slf4j.Logger) CASE_DYNAMIC_NAME_PROP(org.kie.server.api.KieServerConstants.CASE_DYNAMIC_NAME_PROP) Collection(java.util.Collection) CaseService(org.jbpm.casemgmt.api.CaseService) TaskModelProvider(org.kie.internal.task.api.TaskModelProvider) CaseComment(org.kie.server.api.model.cases.CaseComment) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) List(java.util.List) CASE_DYNAMIC_DATA_PROP(org.kie.server.api.KieServerConstants.CASE_DYNAMIC_DATA_PROP) CaseCommentList(org.kie.server.api.model.cases.CaseCommentList) CASE_DYNAMIC_GROUPS_PROP(org.kie.server.api.KieServerConstants.CASE_DYNAMIC_GROUPS_PROP) Entry(java.util.Map.Entry) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) CaseRoleAssignmentList(org.kie.server.api.model.cases.CaseRoleAssignmentList) ContainerLocatorProvider(org.kie.server.services.impl.locator.ContainerLocatorProvider) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseDefinitionNotFoundException(org.jbpm.casemgmt.api.CaseDefinitionNotFoundException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseFile(org.kie.server.api.model.cases.CaseFile) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) List(java.util.List) CaseCommentList(org.kie.server.api.model.cases.CaseCommentList) CaseRoleAssignmentList(org.kie.server.api.model.cases.CaseRoleAssignmentList)

Example 2 with CaseFile

use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testFindCaseTasksAssignedAsBusinessAdminByPassAuth.

@Test
public void testFindCaseTasksAssignedAsBusinessAdminByPassAuth() throws Exception {
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_OWNER_ROLE, USER_YODA).addUserAssignments(CASE_CONTACT_ROLE, USER_JOHN).addGroupAssignments(CASE_PARTICIPANT_ROLE, CASE_ADMIN_GROUP).build();
    String caseId = startUserTaskCase(caseFile);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    assertTaskListAsBusinessAdmin(caseId, USER_YODA, USER_YODA);
    caseClient.destroyCaseInstance(CONTAINER_ID, caseId);
    caseId = startUserTaskCase(caseFile);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    assertTaskListAsBusinessAdmin(caseId, USER_YODA, USER_ADMINISTRATOR);
    changeUser(USER_YODA);
    caseClient.destroyCaseInstance(CONTAINER_ID, caseId);
}
Also used : CaseFile(org.kie.server.api.model.cases.CaseFile) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 3 with CaseFile

use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testAddDynamicProcessToCaseNotExistingProcessDefinition.

@Test
public void testAddDynamicProcessToCaseNotExistingProcessDefinition() {
    String invalidProcessId = "not-existing-process-id";
    Map<String, Object> data = new HashMap<>();
    data.put("s", "first case started");
    CaseFile caseFile = CaseFile.builder().data(data).addUserAssignments(CASE_INSURED_ROLE, USER_YODA).addUserAssignments(CASE_INS_REP_ROLE, USER_JOHN).build();
    String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
    assertNotNull(caseId);
    assertClientException(() -> caseClient.addDynamicSubProcess(CONTAINER_ID, caseId, invalidProcessId, null), 404, "Could not find process definition \"" + invalidProcessId + "\" in container \"" + CONTAINER_ID + "\"", "No process definition found with id: " + invalidProcessId);
}
Also used : HashMap(java.util.HashMap) CaseFile(org.kie.server.api.model.cases.CaseFile) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 4 with CaseFile

use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.

the class CaseSLAComplianceIntegrationTest method testStartCaseWithSLAEscalation.

@Test
public void testStartCaseWithSLAEscalation() throws Exception {
    Map<String, Object> data = new HashMap<>();
    data.put("s", "with SLA");
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_SLA_OWNER_ROLE, USER_JOHN).addUserAssignments(CASE_SLA_ADMIN_ROLE, USER_MARY).data(data).build();
    changeUser(USER_JOHN);
    String caseId = caseClient.startCase(CONTAINER_ID, SLA_CASE_DEF_ID, caseFile);
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    List<org.kie.server.api.model.instance.ProcessInstance> instances = caseClient.getActiveProcessInstances(CONTAINER_ID, caseId, 0, 10);
    assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
    assertThat(caseInstance.getCaseDefinitionId()).isEqualTo(SLA_CASE_DEF_ID);
    assertThat(caseInstance.getContainerId()).isEqualTo(CONTAINER_ID);
    assertThat(caseInstance.getCaseDescription()).isEqualTo("Case with SLA");
    assertThat(caseInstance.getSlaCompliance()).isEqualTo(ProcessInstance.SLA_PENDING);
    assertThat(caseInstance.getSlaDueDate()).isCloseTo(new Date(), 30_000L);
    List<TaskSummary> johnTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
    TaskSummary johnTask = johnTasks.get(0);
    assertThat(johnTasks).hasSize(1);
    assertThat(johnTask.getName()).isEqualTo("Hello1");
    assertThat(johnTask.getProcessType()).isEqualTo(WorkflowProcess.CASE_TYPE);
    AbstractStringAssert<?> corKeyAssert = assertThat(johnTask.getCorrelationKey());
    if (!instances.isEmpty()) {
        corKeyAssert.isEqualTo(instances.get(0).getCorrelationKey());
    } else {
        corKeyAssert.isNull();
    }
    changeUser(USER_MARY);
    List<TaskSummary> maryTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_MARY, 0, 10);
    // No SLA escalation tasks for Mary yet
    assertThat(maryTasks).isEmpty();
    Long caseProcessInstanceId = johnTask.getProcessInstanceId();
    // Wait for SLA to expire
    KieServerSynchronization.waitForProcessInstanceSLAViolated(queryClient, caseProcessInstanceId, 8_000L);
    caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
    assertThat(caseInstance.getSlaCompliance()).isEqualTo(ProcessInstance.SLA_VIOLATED);
    assertThat(caseInstance.getSlaDueDate()).isCloseTo(new Date(), 30_000L);
    maryTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_MARY, 0, 10);
    // SLA Escalation task for Mary should be created
    assertThat(maryTasks).hasSize(1);
    TaskSummary escalationTask = maryTasks.get(0);
    assertThat(escalationTask.getName()).isEqualTo("SLA violation for case " + caseId);
    assertThat(escalationTask.getDescription()).isEqualTo("Service Level Agreement has been violated for case " + caseId);
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseFile(org.kie.server.api.model.cases.CaseFile) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 5 with CaseFile

use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.

the class CarInsuranceClaimCaseIntegrationTest method startCarInsuranceClaimCase.

private String startCarInsuranceClaimCase(String insured, String insuranceRep) {
    CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_INSURED_ROLE, insured).addUserAssignments(CASE_INS_REP_ROLE, insuranceRep).addUserAssignments(CASE_INS_ASSESSOR_ROLE, insuranceRep).build();
    String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
    assertNotNull(caseId);
    return caseId;
}
Also used : CaseFile(org.kie.server.api.model.cases.CaseFile)

Aggregations

CaseFile (org.kie.server.api.model.cases.CaseFile)23 HashMap (java.util.HashMap)17 Test (org.junit.Test)13 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 CaseInstance (org.kie.server.api.model.cases.CaseInstance)3 TaskSummary (org.kie.server.api.model.instance.TaskSummary)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 WebTarget (javax.ws.rs.client.WebTarget)1 CaseDefinitionNotFoundException (org.jbpm.casemgmt.api.CaseDefinitionNotFoundException)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseRuntimeDataService (org.jbpm.casemgmt.api.CaseRuntimeDataService)1 CaseService (org.jbpm.casemgmt.api.CaseService)1 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)1