use of org.jbpm.services.task.HumanTaskConfigurator in project jbpm by kiegroup.
the class HumanTaskServiceProducer method createHumanTaskConfigurator.
protected HumanTaskConfigurator createHumanTaskConfigurator() {
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator();
configureHumanTaskConfigurator(configurator);
return configurator;
}
use of org.jbpm.services.task.HumanTaskConfigurator in project jbpm by kiegroup.
the class PessimisticLockTasksServiceTest method testPessimisticLockingOnTask.
@Test
public void testPessimisticLockingOnTask() throws Exception {
final List<Exception> exceptions = new ArrayList<Exception>();
addEnvironmentEntry(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
createRuntimeManager("org/jbpm/test/functional/task/Evaluation2.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
final KieSession ksession = runtimeEngine.getKieSession();
final TaskService taskService = runtimeEngine.getTaskService();
// setup another instance of task service to allow not synchronized access to cause pessimistic lock exception
RuntimeEnvironment runtimeEnv = ((InternalRuntimeManager) manager).getEnvironment();
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().environment(runtimeEnv.getEnvironment()).entityManagerFactory((EntityManagerFactory) runtimeEnv.getEnvironment().get(EnvironmentName.ENTITY_MANAGER_FACTORY)).userGroupCallback(runtimeEnv.getUserGroupCallback());
// register task listeners if any
RegisterableItemsFactory itemsFactory = runtimeEnv.getRegisterableItemsFactory();
for (TaskLifeCycleEventListener taskListener : itemsFactory.getTaskListeners()) {
configurator.listener(taskListener);
}
final TaskService internalTaskService = configurator.getTaskService();
logger.info("### Starting process ###");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("employee", "salaboy");
ProcessInstance process = ksession.startProcess("com.sample.evaluation", parameters);
// The process is in the first Human Task waiting for its completion
assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());
// gets salaboy's tasks
List<TaskSummary> salaboysTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, salaboysTasks.size());
final long taskId = salaboysTasks.get(0).getId();
final CountDownLatch t2StartLockedTask = new CountDownLatch(1);
final CountDownLatch t1Continue = new CountDownLatch(1);
Thread t1 = new Thread() {
@Override
public void run() {
try {
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
logger.info("Attempting to lock task instance");
taskService.start(taskId, "salaboy");
t2StartLockedTask.countDown();
t1Continue.await();
} finally {
ut.rollback();
}
} catch (Exception e) {
logger.error("Error on thread ", e);
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
try {
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
t2StartLockedTask.await();
logger.info("Trying to start locked task instance");
try {
internalTaskService.start(taskId, "salaboy");
} catch (Exception e) {
logger.info("Abort failed with error {}", e.getMessage());
exceptions.add(e);
} finally {
t1Continue.countDown();
}
} finally {
ut.rollback();
}
} catch (Exception e) {
logger.error("Error on thread ", e);
}
}
};
t1.start();
t2.start();
t1.join();
t2.join();
assertEquals(1, exceptions.size());
assertEquals(PessimisticLockException.class.getName(), exceptions.get(0).getClass().getName());
taskService.start(salaboysTasks.get(0).getId(), "salaboy");
// complete task within user transaction to make sure no deadlock happens as both task service and ksession are under tx lock
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
taskService.complete(salaboysTasks.get(0).getId(), "salaboy", null);
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
List<TaskSummary> pmsTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, pmsTasks.size());
List<TaskSummary> hrsTasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(1, hrsTasks.size());
ksession.abortProcessInstance(process.getId());
assertProcessInstanceAborted(process.getId());
}
use of org.jbpm.services.task.HumanTaskConfigurator in project jbpm by kiegroup.
the class TaskServiceEJBImpl method configureDelegate.
@PostConstruct
public void configureDelegate() {
UserGroupCallback callback = UserDataServiceProvider.getUserGroupCallback();
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(callback);
DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
DeploymentDescriptor descriptor = manager.getDefaultDescriptor();
// in case there is descriptor with enabled audit register then by default
if (!descriptor.getAuditMode().equals(AuditMode.NONE)) {
JPATaskLifeCycleEventListener listener = new JPATaskLifeCycleEventListener(false);
BAMTaskEventListener bamListener = new BAMTaskEventListener(false);
// if the audit persistence unit is different than default for the engine perform proper init
if (!"org.jbpm.domain".equals(descriptor.getAuditPersistenceUnit())) {
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit());
listener = new JPATaskLifeCycleEventListener(emf);
bamListener = new BAMTaskEventListener(emf);
}
configurator.listener(listener);
configurator.listener(bamListener);
}
delegate = (InternalTaskService) configurator.getTaskService();
}
use of org.jbpm.services.task.HumanTaskConfigurator in project jbpm by kiegroup.
the class JBPMHelper method startTaskService.
@Deprecated
public static TaskService startTaskService() {
Properties properties = getProperties();
String dialect = properties.getProperty("persistence.persistenceunit.dialect", "org.hibernate.dialect.H2Dialect");
Map<String, String> map = new HashMap<String, String>();
map.put("hibernate.dialect", dialect);
EntityManagerFactory emf = Persistence.createEntityManagerFactory(properties.getProperty("taskservice.datasource.name", "org.jbpm.services.task"), map);
System.setProperty("jbpm.user.group.mapping", properties.getProperty("taskservice.usergroupmapping", "classpath:/usergroups.properties"));
TaskService taskService = new HumanTaskConfigurator().entityManagerFactory(emf).userGroupCallback(getUserGroupCallback()).getTaskService();
return taskService;
}
use of org.jbpm.services.task.HumanTaskConfigurator in project jbpm by kiegroup.
the class LocalTaskServiceFactory method newTaskService.
@Override
public TaskService newTaskService() {
// all to reuse an already given instance of task service instead of producing new one
TaskService providedTaskService = (TaskService) ((SimpleRuntimeEnvironment) runtimeEnvironment).getEnvironmentTemplate().get("org.kie.api.task.TaskService");
if (providedTaskService != null) {
return providedTaskService;
}
EntityManagerFactory emf = ((SimpleRuntimeEnvironment) runtimeEnvironment).getEmf();
if (emf != null) {
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().environment(runtimeEnvironment.getEnvironment()).entityManagerFactory(emf).userGroupCallback(runtimeEnvironment.getUserGroupCallback()).userInfo(UserDataServiceProvider.getUserInfo());
TaskService internalTaskService = configurator.getTaskService();
return internalTaskService;
} else {
return null;
}
}
Aggregations