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();
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations