use of org.jbpm.services.task.impl.command.CommandBasedTaskService 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.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.
the class ParentChildMarshallingJpaTest method testProcess.
@Test
public void testProcess() throws Exception {
emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.parent-child");
addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/jpa/parent-child.bpmn");
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
Application application = new Application();
application.setType("A");
params.put("application", application);
ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
System.out.println("A process instance started : pid = " + pi.getId());
TaskService taskService = runtime.getTaskService();
assertTrue(taskService instanceof CommandBasedTaskService);
assertTrue(((CommandBasedTaskService) taskService).getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null);
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
for (TaskSummary taskSummary : list) {
System.out.println("john starts a task : taskId = " + taskSummary.getId());
Task task = taskService.getTaskById(taskSummary.getId());
long documentContentId = task.getTaskData().getDocumentContentId();
Content content = taskService.getContentById(documentContentId);
HashMap<String, Object> contents = (HashMap<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment());
Application outputApplication = (Application) contents.get("input1_application");
Person person = new Person();
person.setFullName("John Doe");
outputApplication.setPerson(person);
Map<String, Object> results = new LinkedHashMap<String, Object>();
results.put("output1_application", outputApplication);
taskService.start(taskSummary.getId(), "john");
taskService.complete(taskSummary.getId(), "john", results);
}
list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
for (TaskSummary taskSummary : list) {
System.out.println("mary starts a task : taskId = " + taskSummary.getId());
taskService.start(taskSummary.getId(), "mary");
taskService.complete(taskSummary.getId(), "mary", null);
}
manager.disposeRuntimeEngine(runtime);
// Check!
EntityManager em = emfDomain.createEntityManager();
int size = em.createQuery("select i from Person i").getResultList().size();
assertEquals(1, size);
}
use of org.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.
the class HumanTaskConfigurator method getTaskService.
@SuppressWarnings("unchecked")
public TaskService getTaskService() {
if (service == null) {
TaskEventSupport taskEventSupport = new TaskEventSupport();
this.commandExecutor = new TaskCommandExecutorImpl(this.environment, taskEventSupport);
if (userGroupCallback == null) {
userGroupCallback = new MvelUserGroupCallbackImpl(true);
}
environment.set(EnvironmentName.TASK_USER_GROUP_CALLBACK, userGroupCallback);
if (userInfo == null) {
userInfo = new DefaultUserInfo(true);
}
environment.set(EnvironmentName.TASK_USER_INFO, userInfo);
addDefaultInterceptor();
addTransactionLockInterceptor();
addOptimisticLockInterceptor();
addErrorHandlingInterceptor();
for (PriorityInterceptor pInterceptor : interceptors) {
this.commandExecutor.addInterceptor(pInterceptor.getInterceptor());
}
service = new CommandBasedTaskService(this.commandExecutor, taskEventSupport, this.environment);
// register listeners
for (TaskLifeCycleEventListener listener : listeners) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(listener);
}
if (AssignmentServiceProvider.get().isEnabled()) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(new AssignmentTaskEventListener());
}
// initialize deadline service with command executor for processing
if (TaskDeadlinesServiceImpl.getInstance() == null) {
TaskDeadlinesServiceImpl.initialize(commandExecutor);
}
}
return service;
}
use of org.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.
the class CustomHumanTaskServiceProducer method produceTaskService.
@Produces
@CustomHumanTaskService
@Override
public CommandBasedTaskService produceTaskService() {
CommandBasedTaskService taskServiceMock = Mockito.mock(CommandBasedTaskService.class);
Mockito.when(taskServiceMock.execute(Mockito.any())).thenAnswer((InvocationOnMock invocation) -> {
throw new CustomTaskServiceInUse();
});
return taskServiceMock;
}
Aggregations