Search in sources :

Example 1 with CaseMilestone

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

the class CaseManagementRuntimeDataServiceBase method getMilestones.

public CaseMilestoneList getMilestones(String containerId, String caseId, boolean achievedOnly, Integer page, Integer pageSize) {
    Collection<CaseMilestoneInstance> caseMilestones = caseRuntimeDataService.getCaseInstanceMilestones(caseId, achievedOnly, ConvertUtils.buildQueryContext(page, pageSize));
    List<CaseMilestone> milestones = ConvertUtils.transformMilestones(caseMilestones);
    CaseMilestoneList milestoneList = new CaseMilestoneList(milestones);
    return milestoneList;
}
Also used : CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) CaseMilestoneList(org.kie.server.api.model.cases.CaseMilestoneList)

Example 2 with CaseMilestone

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

the class CaseRuntimeDataServiceIntegrationTest method testCreateCaseWithCaseFileAndTriggerMilestones.

@Test
public void testCreateCaseWithCaseFileAndTriggerMilestones() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    List<CaseInstance> caseInstances = caseClient.getCaseInstancesOwnedBy(USER_YODA, null, 0, 10);
    assertEquals(1, caseInstances.size());
    List<CaseMilestone> milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(0, milestones.size());
    caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, "Milestone1", null);
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(1, milestones.size());
    CaseMilestone milestone = milestones.get(0);
    assertNotNull(milestone);
    assertEquals("Milestone1", milestone.getName());
    assertEquals(true, milestone.isAchieved());
    assertEquals("2", milestone.getIdentifier());
    assertNotNull(milestone.getAchievedAt());
    caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, "Milestone2", null);
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(1, milestones.size());
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, false, 0, 10);
    assertNotNull(milestones);
    assertEquals(2, milestones.size());
    Map<String, CaseMilestone> mappedMilestones = milestones.stream().collect(Collectors.toMap(CaseMilestone::getName, d -> d));
    assertTrue(mappedMilestones.containsKey("Milestone1"));
    assertTrue(mappedMilestones.containsKey("Milestone2"));
    assertTrue(mappedMilestones.get("Milestone1").isAchieved());
    assertFalse(mappedMilestones.get("Milestone2").isAchieved());
    caseInstances = caseClient.getCaseInstances(0, 10);
    assertEquals(1, caseInstances.size());
    assertHrCaseInstance(caseInstances.get(0), caseId, USER_YODA);
    // now auto complete milestone by inserting data
    caseClient.putCaseInstanceData(CONTAINER_ID, caseId, "dataComplete", true);
    milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(2, milestones.size());
}
Also used : Arrays(java.util.Arrays) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) BiFunction(java.util.function.BiFunction) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) Reserved(org.kie.api.task.model.Status.Reserved) CaseInstance(org.kie.server.api.model.cases.CaseInstance) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) CaseServicesClient(org.kie.server.client.CaseServicesClient) Assert.fail(org.junit.Assert.fail) Ready(org.kie.api.task.model.Status.Ready) TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Collection(java.util.Collection) CaseComment(org.kie.server.api.model.cases.CaseComment) Collectors(java.util.stream.Collectors) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) List(java.util.List) CaseFileDataItem(org.kie.server.api.model.cases.CaseFileDataItem) CaseAdHocFragment(org.kie.server.api.model.cases.CaseAdHocFragment) CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) Assert.assertFalse(org.junit.Assert.assertFalse) Status(org.kie.api.task.model.Status) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) KieServicesException(org.kie.server.api.exception.KieServicesException) BeforeClass(org.junit.BeforeClass) STATE_ACTIVE(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE) CaseStage(org.kie.server.api.model.cases.CaseStage) HashMap(java.util.HashMap) Function(java.util.function.Function) CaseFile(org.kie.server.api.model.cases.CaseFile) ArrayList(java.util.ArrayList) KieServerAssert(org.kie.server.integrationtests.shared.KieServerAssert) KieServices(org.kie.api.KieServices) Assume(org.junit.Assume) STATE_ABORTED(org.kie.api.runtime.process.ProcessInstance.STATE_ABORTED) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) KieServerDeployer(org.kie.server.integrationtests.shared.KieServerDeployer) TestConfig(org.kie.server.integrationtests.config.TestConfig) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) STATE_COMPLETED(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) ReleaseId(org.kie.server.api.model.ReleaseId) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 3 with CaseMilestone

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

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseInstanceUserTaskCaseWithData.

@Test
public void testGetCaseInstanceUserTaskCaseWithData() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, "Milestone1", null);
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId, true, true, true, true);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    KieServerAssert.assertNullOrEmpty("Stages should be empty.", caseInstance.getStages());
    // Assert case file
    assertNotNull(caseInstance.getCaseFile());
    assertEquals("first case started", caseInstance.getCaseFile().getData().get("s"));
    // Assert role assignments
    assertNotNull(caseInstance.getRoleAssignments());
    assertEquals(3, caseInstance.getRoleAssignments().size());
    CaseRoleAssignment ownerRole = caseInstance.getRoleAssignments().get(0);
    assertEquals("owner", ownerRole.getName());
    assertEquals(1, ownerRole.getUsers().size());
    assertEquals(USER_YODA, ownerRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", ownerRole.getGroups());
    CaseRoleAssignment contactRole = caseInstance.getRoleAssignments().get(1);
    assertEquals("contact", contactRole.getName());
    assertEquals(1, contactRole.getUsers().size());
    assertEquals(USER_JOHN, contactRole.getUsers().get(0));
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", contactRole.getGroups());
    CaseRoleAssignment participantRole = caseInstance.getRoleAssignments().get(2);
    assertEquals("participant", participantRole.getName());
    KieServerAssert.assertNullOrEmpty("Users should be empty.", participantRole.getUsers());
    KieServerAssert.assertNullOrEmpty("Groups should be empty.", participantRole.getGroups());
    // Assert milestones
    assertNotNull(caseInstance.getMilestones());
    assertEquals(2, caseInstance.getMilestones().size());
    CaseMilestone milestone = caseInstance.getMilestones().get(0);
    assertNotNull(milestone.getIdentifier());
    assertEquals("Milestone2", milestone.getName());
    assertEquals("Available", milestone.getStatus());
    assertNull(milestone.getAchievedAt());
    assertFalse(milestone.isAchieved());
    milestone = caseInstance.getMilestones().get(1);
    assertEquals("2", milestone.getIdentifier());
    assertEquals("Milestone1", milestone.getName());
    assertEquals("Completed", milestone.getStatus());
    assertNotNull(milestone.getAchievedAt());
    assertTrue(milestone.isAchieved());
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseRoleAssignment(org.kie.server.api.model.cases.CaseRoleAssignment) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 4 with CaseMilestone

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

the class CaseRuntimeDataServiceIntegrationTest method testTriggerNotExistingAdHocFragments.

@Test
public void testTriggerNotExistingAdHocFragments() {
    String caseId = startUserTaskCase(USER_YODA, USER_JOHN);
    assertNotNull(caseId);
    assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
    CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
    assertHrCaseInstance(caseInstance, caseId, USER_YODA);
    List<CaseInstance> caseInstances = caseClient.getCaseInstancesOwnedBy(USER_YODA, null, 0, 10);
    assertEquals(1, caseInstances.size());
    List<CaseMilestone> milestones = caseClient.getMilestones(CONTAINER_ID, caseId, true, 0, 10);
    assertNotNull(milestones);
    assertEquals(0, milestones.size());
    final String nonExistingAdHocFragment = "not existing";
    assertClientException(() -> caseClient.triggerAdHocFragment(CONTAINER_ID, caseId, nonExistingAdHocFragment, Collections.EMPTY_MAP), 404, "AdHoc fragment '" + nonExistingAdHocFragment + "' not found in case " + caseId);
}
Also used : CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseMilestone(org.kie.server.api.model.cases.CaseMilestone) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Aggregations

CaseMilestone (org.kie.server.api.model.cases.CaseMilestone)4 Test (org.junit.Test)3 CaseInstance (org.kie.server.api.model.cases.CaseInstance)2 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Assertions (org.assertj.core.api.Assertions)1 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)1 CaseMilestoneInstance (org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance)1