use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManager method getRuntimeEngine.
@Override
public RuntimeEngine getRuntimeEngine(Context<?> context) {
if (isClosed()) {
throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
}
checkPermission();
RuntimeEngine runtime = null;
Object contextId = context.getContextId();
if (!(context instanceof ProcessInstanceIdContext || context instanceof CorrelationKeyContext)) {
logger.warn("ProcessInstanceIdContext or CorrelationKeyContext shall be used when interacting with PerProcessInstance runtime manager");
}
if (engineInitEager) {
KieSession ksession = null;
Long ksessionId = null;
if (contextId == null || context instanceof EmptyContext) {
ksession = factory.newKieSession();
ksessionId = ksession.getIdentifier();
} else {
RuntimeEngine localRuntime = findLocalRuntime(contextId);
if (localRuntime != null) {
return localRuntime;
}
ksessionId = mapper.findMapping(context, this.identifier);
if (ksessionId == null) {
throw new SessionNotFoundException("No session found for context " + context.getContextId());
}
ksession = factory.findKieSessionById(ksessionId);
}
InternalTaskService internalTaskService = newTaskService(taskServiceFactory);
runtime = new RuntimeEngineImpl(ksession, internalTaskService);
((RuntimeEngineImpl) runtime).setManager(this);
((RuntimeEngineImpl) runtime).setContext(context);
configureRuntimeOnTaskService(internalTaskService, runtime);
registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime), ksession.getEnvironment());
registerItems(runtime);
attachManager(runtime);
ksession.addEventListener(new MaintainMappingListener(ksessionId, runtime, this.identifier));
} else {
RuntimeEngine localRuntime = findLocalRuntime(contextId);
if (localRuntime != null) {
return localRuntime;
}
// lazy initialization of ksession and task service
runtime = new RuntimeEngineImpl(context, new PerProcessInstanceInitializer());
((RuntimeEngineImpl) runtime).setManager(this);
}
createLockOnGetEngine(context, runtime);
saveLocalRuntime(contextId, runtime);
return runtime;
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class PerRequestRuntimeManager method getRuntimeEngine.
@Override
public RuntimeEngine getRuntimeEngine(Context<?> context) {
if (isClosed()) {
throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
}
checkPermission();
RuntimeEngine runtime = null;
if (local.get().get(identifier) != null) {
RuntimeEngine engine = local.get().get(identifier);
// check if engine is not already disposed as afterCompletion might be issued from another thread
if (engine != null && ((RuntimeEngineImpl) engine).isDisposed()) {
return null;
}
return engine;
}
if (engineInitEager) {
InternalTaskService internalTaskService = newTaskService(taskServiceFactory);
runtime = new RuntimeEngineImpl(factory.newKieSession(), internalTaskService);
((RuntimeEngineImpl) runtime).setManager(this);
configureRuntimeOnTaskService(internalTaskService, runtime);
registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime), runtime.getKieSession().getEnvironment());
registerDisposeCallback(runtime, new DestroySessionTransactionSynchronization(runtime.getKieSession()), runtime.getKieSession().getEnvironment());
registerItems(runtime);
attachManager(runtime);
} else {
runtime = new RuntimeEngineImpl(context, new PerRequestInitializer());
((RuntimeEngineImpl) runtime).setManager(this);
}
local.get().put(identifier, runtime);
return runtime;
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class AbstractRuntimeManager method newTaskService.
protected InternalTaskService newTaskService(TaskServiceFactory factory) {
InternalTaskService internalTaskService = (InternalTaskService) factory.newTaskService();
if (internalTaskService instanceof CommandBasedTaskService) {
((CommandBasedTaskService) internalTaskService).getEnvironment().set(EnvironmentName.DEPLOYMENT_ID, this.getIdentifier());
((CommandBasedTaskService) internalTaskService).getEnvironment().set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, ((SimpleRuntimeEnvironment) environment).getEnvironmentTemplate().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES));
}
return internalTaskService;
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class CallActivitiesWithUserTasksProcessTest method testCallActivitiesWith2ndUserTaskInSub.
@Test
public void testCallActivitiesWith2ndUserTaskInSub() throws Exception {
TaskCleanUpProcessEventListener taskListener = new TaskCleanUpProcessEventListener(null);
addWorkItemHandler("Sysout", new SystemOutWorkItemHandler());
addProcessEventListener(taskListener);
InitialContext context = new InitialContext();
UserTransaction ut = (UserTransaction) context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
RuntimeManager manager = createRuntimeManager(strategy, (String) null, "org/jbpm/test/functional/subprocess/CallActivityWithTaskInSub-Main.bpmn2", "org/jbpm/test/functional/subprocess/CallActivityWithTaskInSub-Sub.bpmn2");
RuntimeEngine runtimeEngine;
if (Strategy.SINGLETON.equals(strategy)) {
runtimeEngine = getRuntimeEngine();
} else if (Strategy.PROCESS_INSTANCE.equals(strategy)) {
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
} else {
throw new IllegalStateException("Not possible!");
}
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
// set created task service on listener
taskListener.setTaskService((InternalTaskService) taskService);
if (userManagedTx) {
ut.begin();
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("pActorId", "john");
ProcessInstance processInstance = ksession.startProcess("PolicyValueAnalysis", params);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
Long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
// sub process task
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
// sub process task
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
// since we are checking in same transaction it will already see it as completed
assertProcessInstanceCompleted(processInstance.getId());
ut.commit();
}
assertProcessInstanceCompleted(processInstance.getId());
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class CallActivitiesWithUserTasksProcessTest method testCallActivitiesWithUserTasks.
@Test
public void testCallActivitiesWithUserTasks() throws Exception {
TaskCleanUpProcessEventListener taskListener = new TaskCleanUpProcessEventListener(null);
addWorkItemHandler("Sysout", new SystemOutWorkItemHandler());
addProcessEventListener(taskListener);
InitialContext context = new InitialContext();
UserTransaction ut = (UserTransaction) context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
RuntimeManager manager = createRuntimeManager(strategy, (String) null, "org/jbpm/test/functional/subprocess/CallActivityWithTask-Main.bpmn2", "org/jbpm/test/functional/subprocess/CallActivityWithTask-Sub.bpmn2");
RuntimeEngine runtimeEngine;
if (Strategy.SINGLETON.equals(strategy)) {
runtimeEngine = getRuntimeEngine();
} else if (Strategy.PROCESS_INSTANCE.equals(strategy)) {
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
} else {
throw new IllegalStateException("Not possible!");
}
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
// set created task service on listener
taskListener.setTaskService((InternalTaskService) taskService);
if (userManagedTx) {
ut.begin();
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("pActorId", "john");
ProcessInstance processInstance = ksession.startProcess("PolicyValueAnalysis", params);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
Long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
ut.begin();
}
assertProcessInstanceCompleted(processInstance.getId());
if (userManagedTx) {
ut.commit();
}
}
Aggregations