use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class HumanTaskResolver method populateOrgEntity.
@Before
public void populateOrgEntity() {
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(getEmf()).getTaskService();
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("krisv"));
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("sales-rep"));
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("john"));
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("Administrator"));
((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("sales"));
((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("PM"));
((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("Administrators"));
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class PerCaseRuntimeManager method getRuntimeEngine.
@SuppressWarnings("unchecked")
@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 CaseContext)) {
logger.warn("ProcessInstanceIdContext or CaseContext shall be used when interacting with PerCase runtime manager");
}
if (engineInitEager) {
KieSession ksession = null;
Long ksessionId = null;
RuntimeEngine localRuntime = findLocalRuntime(contextId);
if (localRuntime != null) {
return localRuntime;
}
synchronized (this) {
ksessionId = mapper.findMapping(context, this.identifier);
if (ksessionId == null) {
ksession = factory.newKieSession();
ksessionId = ksession.getIdentifier();
if (context instanceof CaseContext) {
ksession.execute(new SaveMappingCommand(mapper, context, ksessionId, getIdentifier()));
}
} else {
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, (String) contextId));
if (context instanceof CaseContext) {
ksession.getEnvironment().set("CaseId", context.getContextId());
} else {
Object contexts = mapper.findContextId(ksession.getIdentifier(), this.identifier);
if (contexts instanceof Collection) {
RuntimeEngine finalRuntimeEngnie = runtime;
KieSession finalKieSession = ksession;
((Collection<Object>) contexts).forEach(o -> {
try {
saveLocalRuntime(null, Long.parseLong(o.toString()), finalRuntimeEngnie);
} catch (NumberFormatException e) {
saveLocalRuntime(o.toString(), null, finalRuntimeEngnie);
finalKieSession.getEnvironment().set("CaseId", o.toString());
}
});
}
}
} else {
RuntimeEngine localRuntime = findLocalRuntime(contextId);
if (localRuntime != null) {
return localRuntime;
}
// lazy initialization of ksession and task service
runtime = new RuntimeEngineImpl(context, new PerCaseInitializer());
((RuntimeEngineImpl) runtime).setManager(this);
}
String caseId = null;
Long processInstanceId = null;
if (context instanceof CaseContext) {
caseId = (String) contextId;
} else if (context instanceof ProcessInstanceIdContext) {
processInstanceId = (Long) contextId;
}
Long ksessionId = mapper.findMapping(context, this.identifier);
createLockOnGetEngine(ksessionId, runtime);
saveLocalRuntime(caseId, processInstanceId, runtime);
return runtime;
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class SupportProcessBaseTest method testSupportProcess.
@Test
public void testSupportProcess() {
DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnitSupport);
units.add(deploymentUnitSupport);
Map<String, Object> params = new HashMap<String, Object>();
params.put("customer", "polymita");
RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier());
assertNotNull(managerSupport);
int currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(0, currentNumberOfEvents);
RuntimeEngine engine = managerSupport.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
ProcessInstance pI = engine.getKieSession().startProcess("support.process", params);
assertNotNull(pI);
TaskService taskService = engine.getTaskService();
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(2, currentNumberOfEvents);
// Configure Release
List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, tasksAssignedToSalaboy.size());
assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName());
TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0);
taskService.start(createSupportTask.getId(), "salaboy");
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(4, currentNumberOfEvents);
Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId());
assertEquals("polymita", taskContent.get("input_customer"));
Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings(deploymentUnitSupport.getIdentifier(), "support.process", createSupportTask.getName());
assertEquals(1, taskOutputMappings.size());
assertEquals("output_customer", taskOutputMappings.keySet().iterator().next());
Map<String, Object> output = new HashMap<String, Object>();
output.put("output_customer", "polymita/redhat");
taskService.complete(createSupportTask.getId(), "salaboy", output);
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(8, currentNumberOfEvents);
tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, tasksAssignedToSalaboy.size());
assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName());
TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0);
taskService.start(resolveSupportTask.getId(), "salaboy");
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(10, currentNumberOfEvents);
taskService.complete(resolveSupportTask.getId(), "salaboy", null);
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(14, currentNumberOfEvents);
tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, tasksAssignedToSalaboy.size());
assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName());
TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0);
taskService.start(notifySupportTask.getId(), "salaboy");
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(16, currentNumberOfEvents);
output = new HashMap<String, Object>();
output.put("output_solution", "solved today");
taskService.complete(notifySupportTask.getId(), "salaboy", output);
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(18, currentNumberOfEvents);
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class UserTaskServiceImpl method getAttachmentsByTaskId.
@Override
public List<Attachment> getAttachmentsByTaskId(String deploymentId, Long taskId) {
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 Collections.emptyList();
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// perform actual operation
return ((InternalTaskService) taskService).getAllAttachmentsByTaskId(taskId);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class UserTaskServiceImpl method deleteAttachment.
@Override
public void deleteAttachment(String deploymentId, Long taskId, Long attachmentId) {
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;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// perform actual operation
((InternalTaskService) taskService).deleteAttachment(taskId, attachmentId);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
Aggregations