Search in sources :

Example 96 with TaskService

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

the class PerRequestRuntimeManagerTest method testNonexistentDeploymentId.

@Test
public void testNonexistentDeploymentId() {
    // JBPM-4852
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
    RuntimeManager manager1 = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment, "id-1");
    RuntimeEngine runtime1 = manager1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    ProcessInstance processInstance = ksession1.startProcess("UserTask");
    manager1.disposeRuntimeEngine(runtime1);
    // simulating server reboot
    manager1.close();
    RuntimeManager manager2 = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment, "id-2");
    RuntimeEngine runtime2 = manager2.getRuntimeEngine(EmptyContext.get());
    TaskService taskService2 = runtime2.getTaskService();
    List<TaskSummary> taskList = taskService2.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, taskList.size());
    Long taskId = taskList.get(0).getId();
    Task task = taskService2.getTaskById(taskId);
    assertEquals("id-1", task.getTaskData().getDeploymentId());
    try {
        taskService2.start(taskId, "john");
        taskService2.complete(taskId, "john", null);
    } catch (NullPointerException npe) {
        fail("NullPointerException is thrown");
    } catch (IllegalStateException re) {
        assertEquals("Task instance " + task.getId() + " is owned by another deployment expected " + task.getTaskData().getDeploymentId() + " found id-2", re.getMessage());
    }
    manager2.disposeRuntimeEngine(runtime2);
    manager2.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 97 with TaskService

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

the class UserTaskServiceImpl method release.

@Override
public void release(String deploymentId, Long taskId, String userId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        taskService.release(taskId, userId);
    } catch (PermissionDeniedException e) {
        throw new TaskNotFoundException(e.getMessage());
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 98 with TaskService

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

the class UserTaskServiceImpl method complete.

@Override
public void complete(String deploymentId, Long taskId, String userId, Map<String, Object> params) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return;
    }
    if (manager instanceof InternalRuntimeManager) {
        params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        taskService.complete(taskId, userId, params);
    } catch (PermissionDeniedException e) {
        throw new TaskNotFoundException(e.getMessage());
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 99 with TaskService

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

the class UserTaskServiceImpl method getAttachmentsByTaskId.

@Override
public List<Attachment> getAttachmentsByTaskId(String deploymentId, Long taskId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return Collections.emptyList();
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return ((InternalTaskService) taskService).getAllAttachmentsByTaskId(taskId);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 100 with TaskService

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

the class UserTaskServiceImpl method execute.

@Override
public <T> T execute(String deploymentId, Context<?> context, Command<T> command) {
    RuntimeManager manager = getRuntimeManager(deploymentId, command);
    RuntimeEngine engine = manager.getRuntimeEngine(context);
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return taskService.execute(command);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Aggregations

TaskService (org.kie.api.task.TaskService)129 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)111 KieSession (org.kie.api.runtime.KieSession)79 Test (org.junit.Test)73 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)70 TaskSummary (org.kie.api.task.model.TaskSummary)66 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)53 InternalTaskService (org.kie.internal.task.api.InternalTaskService)52 HashMap (java.util.HashMap)41 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)39 UserTaskService (org.jbpm.services.api.UserTaskService)38 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34 ArrayList (java.util.ArrayList)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15 Task (org.kie.api.task.model.Task)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)12 BZ (qa.tools.ikeeper.annotation.BZ)10 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)9