Search in sources :

Example 46 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class SubCaseServiceImplTest method testStartCaseWithIndependentDynamicSubCase.

private void testStartCaseWithIndependentDynamicSubCase(String idependent, Consumer<String> finishCase) {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "John Doe");
    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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("CaseDefinitionId", "UserTaskCase");
        parameters.put("DeploymentId", deploymentUnit.getIdentifier());
        parameters.put("UserRole_owner", "john");
        parameters.put("Data_s", "#{name}");
        parameters.put("Independent", idependent);
        TaskSpecification taskSpecification = caseService.newTaskSpec("StartCaseInstance", "Sub Case", parameters);
        caseService.addDynamicTask(caseId, taskSpecification);
        Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
        assertNotNull(caseInstances);
        assertEquals(2, caseInstances.size());
        Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
        assertTrue(byCaseId.containsKey(FIRST_CASE_ID));
        assertTrue(byCaseId.containsKey(HR_CASE_ID));
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertEquals("Hello1", tasks.get(0).getName());
        CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
        assertNotNull(mainCaseFile);
        assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
        assertEquals("John Doe", mainCaseFile.getData("s"));
        finishCase.accept(HR_CASE_ID);
        mainCaseFile = caseService.getCaseFileInstance(caseId);
        assertNotNull(mainCaseFile);
        assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
        assertEquals("John Doe", mainCaseFile.getData("s"));
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Collectors.toMap(java.util.stream.Collectors.toMap) ProcessInstance(org.jbpm.process.instance.ProcessInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) QueryContext(org.kie.api.runtime.query.QueryContext) Consumer(java.util.function.Consumer) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Assert.assertNull(org.junit.Assert.assertNull) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) TaskSummary(org.kie.api.task.model.TaskSummary)

Example 47 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testUserTaskFromKjar.

@Test
public void testUserTaskFromKjar() {
    KieServices ks = KieServices.Factory.get();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params);
    List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    engine.getTaskService().start(taskId, "john");
    engine.getTaskService().complete(taskId, "john", null);
    processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    manager.disposeRuntimeEngine(engine);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) KieServices(org.kie.api.KieServices) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 48 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testUserTaskFromKjarPPI.

@Test
public void testUserTaskFromKjarPPI() {
    KieServices ks = KieServices.Factory.get();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params);
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    engine.getTaskService().start(taskId, "john");
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    engine.getTaskService().complete(taskId, "john", null);
    manager.disposeRuntimeEngine(engine);
    try {
        engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
        assertNull(processInstance);
        fail("Should fail as process instance is already completed");
    } catch (Exception e) {
    }
    manager.disposeRuntimeEngine(engine);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) KieServices(org.kie.api.KieServices) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 49 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class TimerInitFailureRuntimeManagerTest method testPerCaseRuntimeManager.

@Test(timeout = 10000)
@BMScript(value = "byteman-scripts/failOnRuntimeManagerInitRules.btm")
public void testPerCaseRuntimeManager() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Intermediate Catch Event 1", 1);
    RuntimeEnvironment environment = createEnvironment(countDownListener);
    manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<>();
    ProcessInstance pi = ksession.startProcess("TimerInitFailure", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi.getState());
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted();
    // User access
    runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
    runtime.getKieSession();
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, list.size());
    long taskId = list.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
    AuditService auditService = runtime.getAuditService();
    ProcessInstanceLog log = auditService.findProcessInstance(pi.getId());
    assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
    auditService.dispose();
    manager.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 50 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.

@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
    Map<String, String> resources = new HashMap<String, String>();
    String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
    String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
    String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
    String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
    String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    String drl = "package org.jbpm; global java.util.List service; " + "	rule \"Start Hello1\"" + "	  when" + "	  then" + "	    System.out.println(\"Hello\");" + "	end";
    resources.put("src/main/resources/simple.drl", drl);
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
    RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
    assertNotNull(factory);
    assertTrue(factory instanceof InternalRegisterableItemsFactory);
    assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
    DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
    assertNotNull(descriptor);
    assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
    assertEquals(1, descriptor.getMarshallingStrategies().size());
    // assertEquals(1, descriptor.getConfiguration().size());
    assertEquals(1, descriptor.getEnvironmentEntries().size());
    assertEquals(1, descriptor.getEventListeners().size());
    assertEquals(1, descriptor.getGlobals().size());
    assertEquals(1, descriptor.getTaskEventListeners().size());
    assertEquals(1, descriptor.getWorkItemHandlers().size());
    assertEquals(0, descriptor.getRequiredRoles().size());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    KieSession kieSession = engine.getKieSession();
    // configuration
    assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
    BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
    assertNotNull(bc);
    assertTrue(bc instanceof TestBusinessCalendar);
    // globals
    Object service = kieSession.getGlobal("service");
    assertNotNull(service);
    assertTrue(service instanceof ArrayList);
    // work item handler
    ProcessInstance processInstance = kieSession.startProcess("ManualTask");
    long processInstanceId = processInstance.getId();
    assertNotNull(kieSession.getProcessInstance(processInstanceId));
    kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
    assertNull(kieSession.getProcessInstance(processInstanceId));
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    kieSession = engine.getKieSession();
    // process event listener
    assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
    processEvents.clear();
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    kieSession = engine.getKieSession();
    // task event listener
    processInstance = kieSession.startProcess("UserTask");
    processInstanceId = processInstance.getId();
    assertNotNull(kieSession.getProcessInstance(processInstanceId));
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    TaskService taskService = engine.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    long taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    kieSession = engine.getKieSession();
    // marshalling strategy
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "marshal");
    processInstance = kieSession.startProcess("ParentProcess", params);
    processInstanceId = processInstance.getId();
    ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
    assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
    manager.disposeRuntimeEngine(engine);
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) ArrayList(java.util.ArrayList) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) RegisterableItemsFactory(org.kie.api.runtime.manager.RegisterableItemsFactory) KieServices(org.kie.api.KieServices) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) KieSession(org.kie.api.runtime.KieSession) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) ReleaseId(org.kie.api.builder.ReleaseId) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) TaskSummary(org.kie.api.task.model.TaskSummary) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.api.task.model.TaskSummary)371 Test (org.junit.Test)327 HashMap (java.util.HashMap)132 QueryFilter (org.kie.internal.query.QueryFilter)126 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)100 Task (org.kie.api.task.model.Task)91 ArrayList (java.util.ArrayList)87 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)86 KieSession (org.kie.api.runtime.KieSession)84 TaskService (org.kie.api.task.TaskService)66 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)58 StringReader (java.io.StringReader)55 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 Status (org.kie.api.task.model.Status)47 InternalTask (org.kie.internal.task.api.model.InternalTask)47 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)41 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)38 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)36 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)28