// listeners to be registered
private List<TaskLifeCycleEventListener> listeners;
@Override
public Object getObject() throws Exception {
if (instance == null) {
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator();
configurator
.entityManagerFactory(entityManagerFactory)
.userGroupCallback(userGroupCallback)
.userInfo(userInfo);
if (listeners != null) {
for(TaskLifeCycleEventListener listener : listeners) {
configurator.listener(listener);
}
}
Environment environment = EnvironmentFactory.newEnvironment();
environment.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);
environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, entityManagerFactory);
if (entityManager != null) {
environment.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, entityManager);
environment.set(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, entityManager);
environment.set("IS_JTA_TRANSACTION", false);
environment.set("IS_SHARED_ENTITY_MANAGER", true);
}
configurator.environment(environment);
instance = configurator.getTaskService();
}
return instance;
}