use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class UserTaskServiceImpl method getCommentById.
@Override
public Comment getCommentById(String deploymentId, Long taskId, Long commentId) {
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 null;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// perform actual operation
return ((InternalTaskService) taskService).getCommentById(commentId);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerRecordExecutionErrorProcessAutoAck.
@Test(timeout = 20000)
public void testRunProcessWithAsyncHandlerRecordExecutionErrorProcessAutoAck() throws Exception {
CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
((ExecutorServiceImpl) executorService).setRetries(0);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = runtime.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
Map<String, Object> results = new HashMap<>();
results.put("output1", "rollback");
try {
taskService.complete(taskId, "john", results);
fail("Complete task should fail due to broken script");
} catch (Throwable e) {
// expected
}
manager.disposeRuntimeEngine(runtime);
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
assertNotNull("ErrorManager is null", errorManager);
ExecutionErrorStorage errorStorage = errorManager.getStorage();
assertNotNull("ErrorStorage is null", errorStorage);
List<ExecutionError> errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
ExecutionError error = errors.get(0);
assertNotNull(error);
assertEquals("Process", error.getType());
assertEquals("UserTaskWithRollback", error.getProcessId());
assertEquals("Script Task 1", error.getActivityName());
assertEquals(manager.getIdentifier(), error.getDeploymentId());
assertNotNull(error.getError());
assertNotNull(error.getErrorMessage());
assertNotNull(error.getActivityId());
assertNotNull(error.getProcessInstanceId());
assertNull(error.getAcknowledgedAt());
assertNull(error.getAcknowledgedBy());
assertFalse(error.isAcknowledged());
countDownListener.reset(1);
// first run should not ack the job as it's in error state
CommandContext ctx = new CommandContext();
ctx.setData("SingleRun", "true");
ctx.setData("EmfName", "org.jbpm.persistence.complete");
executorService.scheduleRequest(ProcessAutoAckErrorCommand.class.getName(), ctx);
countDownListener.waitTillCompleted();
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
error = errors.get(0);
assertNotNull(error);
assertFalse(error.isAcknowledged());
runtime = manager.getRuntimeEngine(EmptyContext.get());
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
results = new HashMap<>();
results.put("output1", "ok");
taskService.complete(taskId, "john", results);
manager.disposeRuntimeEngine(runtime);
countDownListener.reset(1);
// since task was completed auto ack should work
executorService.scheduleRequest(ProcessAutoAckErrorCommand.class.getName(), ctx);
countDownListener.waitTillCompleted();
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
error = errors.get(0);
assertNotNull(error);
assertTrue(error.isAcknowledged());
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class AbstractCaseServicesBaseTest method configureServices.
protected void configureServices() {
buildDatasource();
emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.domain");
identityProvider = new TestIdentityProvider();
authorizationManager = new AuthorizationManagerImpl(identityProvider, new TransactionalCommandService(emf));
// build definition service
bpmn2Service = new BPMN2DataServiceImpl();
DeploymentRolesManager deploymentRolesManager = new DeploymentRolesManager();
queryService = new QueryServiceImpl();
((QueryServiceImpl) queryService).setIdentityProvider(identityProvider);
((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
((QueryServiceImpl) queryService).init();
// build deployment service
deploymentService = new KModuleDeploymentService();
((KModuleDeploymentService) deploymentService).setBpmn2Service(bpmn2Service);
((KModuleDeploymentService) deploymentService).setEmf(emf);
((KModuleDeploymentService) deploymentService).setIdentityProvider(identityProvider);
((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
((KModuleDeploymentService) deploymentService).setFormManagerService(new FormManagerServiceImpl());
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).getTaskService();
// build runtime data service
runtimeDataService = new RuntimeDataServiceImpl();
((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(identityProvider);
((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
((RuntimeDataServiceImpl) runtimeDataService).setDeploymentRolesManager(deploymentRolesManager);
((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
// build process service
processService = new ProcessServiceImpl();
((ProcessServiceImpl) processService).setDataService(runtimeDataService);
((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
// build user task service
userTaskService = new UserTaskServiceImpl();
((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
// build case id generator
caseIdGenerator = new TableCaseIdGenerator(new TransactionalCommandService(emf));
// build case runtime data service
caseRuntimeDataService = new CaseRuntimeDataServiceImpl();
((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setCaseIdGenerator(caseIdGenerator);
((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setRuntimeDataService(runtimeDataService);
((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setCommandService(new TransactionalCommandService(emf));
((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setIdentityProvider(identityProvider);
((CaseRuntimeDataServiceImpl) caseRuntimeDataService).setDeploymentRolesManager(deploymentRolesManager);
// build case service
caseService = new CaseServiceImpl();
((CaseServiceImpl) caseService).setCaseIdGenerator(caseIdGenerator);
((CaseServiceImpl) caseService).setCaseRuntimeDataService(caseRuntimeDataService);
((CaseServiceImpl) caseService).setProcessService(processService);
((CaseServiceImpl) caseService).setDeploymentService(deploymentService);
((CaseServiceImpl) caseService).setRuntimeDataService(runtimeDataService);
((CaseServiceImpl) caseService).setCommandService(new TransactionalCommandService(emf));
((CaseServiceImpl) caseService).setAuthorizationManager(authorizationManager);
((CaseServiceImpl) caseService).setIdentityProvider(identityProvider);
CaseConfigurationDeploymentListener configurationListener = new CaseConfigurationDeploymentListener(identityProvider);
// set runtime data service as listener on deployment service
((KModuleDeploymentService) deploymentService).addListener((RuntimeDataServiceImpl) runtimeDataService);
((KModuleDeploymentService) deploymentService).addListener((BPMN2DataServiceImpl) bpmn2Service);
((KModuleDeploymentService) deploymentService).addListener((QueryServiceImpl) queryService);
((KModuleDeploymentService) deploymentService).addListener((CaseRuntimeDataServiceImpl) caseRuntimeDataService);
((KModuleDeploymentService) deploymentService).addListener(configurationListener);
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class SingletonRuntimeManagerTest method testInterceptorAfterRollback.
@Test
public void testInterceptorAfterRollback() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
assertEquals(PersistableRunner.class, commandService.getClass());
ChainableRunner internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
TaskService taskService = runtime.getTaskService();
List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstance.getId());
taskService.start(taskIds.get(0), "john");
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("output1", "rollback");
try {
// rollback transaction
taskService.complete(taskIds.get(0), "john", result);
} catch (WorkflowRuntimeException e) {
// ignore
}
result = new HashMap<String, Object>();
result.put("output1", "ok");
// this time, execute normally
taskService.complete(taskIds.get(0), "john", result);
internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((TransactionLockInterceptor) internalCommandService).getNext();
assertEquals(OptimisticLockRetryInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((OptimisticLockRetryInterceptor) internalCommandService).getNext();
assertEquals("org.drools.persistence.PersistableRunner$TransactionInterceptor", internalCommandService.getClass().getName());
// close manager which will close session maintained by the manager
manager.close();
}
use of org.kie.api.task.TaskService 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);
}
Aggregations