use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class AdminAPIsWithListenerTest method automaticCleanUpForSubProcessWithPerProcessInstanceStrategy.
@Test
public void automaticCleanUpForSubProcessWithPerProcessInstanceStrategy() throws Exception {
TaskCleanUpProcessEventListener taskCleanUpProcessEventListener = new TaskCleanUpProcessEventListener(null);
this.addProcessEventListener(taskCleanUpProcessEventListener);
RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "com.mycompany.sample", "org/jbpm/test/functional/task/ht-main.bpmn", "org/jbpm/test/functional/task/ht-sub.bpmn");
RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get());
taskCleanUpProcessEventListener.setTaskService((InternalTaskService) runtime.getTaskService());
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance pi = ksession.startProcess("com.mycompany.sample", params);
// obtain the task service
TaskService taskService = runtime.getTaskService();
List<TaskSummary> tasks1 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertFalse(tasks1.isEmpty());
TaskSummary task1 = tasks1.get(0);
System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
taskService.start(task1.getId(), "john");
Map<String, Object> results = new HashMap<String, Object>();
results.put("comment", "Agreed, existing laptop needs replacing");
results.put("outcome", "Accept");
// complete the human task of the main process
taskService.complete(task1.getId(), "john", results);
// abort the process instance
ksession.abortProcessInstance(pi.getId());
// main process instance shall be aborted
assertProcessInstanceAborted(pi.getId());
AuditService logService = runtime.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findProcessInstances("com.mycompany.sample");
assertNotNull(logs);
assertEquals(1, logs.size());
assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
logs = logService.findProcessInstances("com.mycompany.sample.subprocess");
assertNotNull(logs);
assertEquals(1, logs.size());
assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
manager.close();
final EntityManager em = emfTasks.createEntityManager();
assertEquals(0, em.createQuery("select t from TaskImpl t").getResultList().size());
assertEquals(0, em.createQuery("select i from I18NTextImpl i").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_BAs").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_ExclOwners").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_PotOwners").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Recipients").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Stakeholders").getResultList().size());
assertEquals(0, em.createQuery("select c from ContentImpl c").getResultList().size());
em.close();
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class KModuleWithDependenciesDeploymentServiceTest method testDeploymentOfProcesses.
@Test
public void testDeploymentOfProcesses() throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertEquals("org.jbpm.test:jbpm-module:1.0.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
assertTrue(deployed instanceof DeployedUnitImpl);
assertEquals(2, ((DeployedUnitImpl) deployed).getDeployedClasses().size());
List<String> classnames = new ArrayList<String>();
for (Class<?> clazz : ((DeployedUnitImpl) deployed).getDeployedClasses()) {
classnames.add(clazz.getName());
}
assertTrue(classnames.contains("org.jbpm.data.rest.CustomDataObject"));
assertTrue(classnames.contains("org.jbpm.test.Person"));
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object instance = clazz.newInstance();
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", instance);
ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
assertTrue(content.containsKey("personIn"));
Object person = content.get("personIn");
assertEquals(clazz.getName(), person.getClass().getName());
engine.getTaskService().start(taskId, "salaboy");
Map<String, Object> data = new HashMap<String, Object>();
data.put("personOut", instance);
engine.getTaskService().complete(taskId, "salaboy", data);
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class ClassloaderKModuleDeploymentServiceTest method testDeploymentOfProcesses.
@Test
public void testDeploymentOfProcesses() throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
deploymentUnit.setStrategy(RuntimeStrategy.PER_REQUEST);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertEquals("org.jbpm.test:jbpm-module:1.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object instance = clazz.newInstance();
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", instance);
ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
assertTrue(content.containsKey("personIn"));
Object person = content.get("personIn");
assertEquals(clazz.getName(), person.getClass().getName());
engine.getTaskService().start(taskId, "salaboy");
Map<String, Object> data = new HashMap<String, Object>();
data.put("personOut", instance);
engine.getTaskService().complete(taskId, "salaboy", data);
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class ConcurrentGlobalTimerServiceTest method testSessionPerProcessInstance.
@Test
public void testSessionPerProcessInstance() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
long startTimeStamp = System.currentTimeMillis();
long maxEndTime = startTimeStamp + maxWaitTime;
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
// prepare task service with users and groups
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = engine.getTaskService();
Group grouphr = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) grouphr).setId("HR");
User mary = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) mary).setId("mary");
User john = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) john).setId("john");
((InternalTaskService) taskService).addGroup(grouphr);
((InternalTaskService) taskService).addUser(mary);
((InternalTaskService) taskService).addUser(john);
manager.disposeRuntimeEngine(engine);
completedStart = 0;
for (int i = 0; i < nbThreadsProcess; i++) {
new StartProcessPerProcessInstanceRunnable(manager, i).run();
}
completedTask = 0;
for (int i = 0; i < nbThreadsTask; i++) {
new Thread(new CompleteTaskPerProcessInstanceRunnable(manager, i)).start();
}
while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) {
Thread.sleep(100);
if (System.currentTimeMillis() > maxEndTime) {
fail("Failure, did not finish in time most likely hanging");
}
}
// make sure all process instance were completed
engine = manager.getRuntimeEngine(EmptyContext.get());
AuditService logService = engine.getAuditService();
// active
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertNotNull(logs);
for (ProcessInstanceLog log : logs) {
logger.debug("Left over {}", log.getProcessInstanceId());
}
assertEquals(0, logs.size());
// completed
logs = logService.findProcessInstances("IntermediateCatchEvent");
assertNotNull(logs);
assertEquals(nbThreadsProcess, logs.size());
manager.disposeRuntimeEngine(engine);
logger.debug("Done");
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class GlobalTimerServiceVolumeTest method testRuntimeManagerStrategyWithTimerService.
@Test(timeout = 30000)
public void testRuntimeManagerStrategyWithTimerService() throws Exception {
// prepare task service with users and groups
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = engine.getTaskService();
Group grouphr = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) grouphr).setId("HR");
Group groupadmins = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) groupadmins).setId("Administrators");
User mary = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) mary).setId("mary");
User john = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) john).setId("john");
User admin = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) admin).setId("Administrator");
((InternalTaskService) taskService).addGroup(grouphr);
((InternalTaskService) taskService).addGroup(groupadmins);
((InternalTaskService) taskService).addUser(mary);
((InternalTaskService) taskService).addUser(john);
((InternalTaskService) taskService).addUser(admin);
manager.disposeRuntimeEngine(engine);
int counter = numberOfProcesses;
// start processes until oom
while (counter > 0) {
new GlobalTimerServiceVolumeTest.StartProcessPerProcessInstanceRunnable(manager).run();
counter--;
}
Collection<TimerJobInstance> timers = null;
Map<Long, List<GlobalJobHandle>> jobs = null;
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
if (timerService instanceof GlobalTimerService) {
jobs = ((GlobalTimerService) timerService).getTimerJobsPerSession();
timers = ((GlobalTimerService) timerService).getTimerJobFactoryManager().getTimerJobInstances();
}
}
assertNotNull("Jobs should not be null as number of timers have been created", jobs);
assertEquals("There should be no jobs in the global timer service", 0, jobs.size());
assertNotNull("Timer instances should not be null as number of timers have been created", timers);
assertEquals("There should be no timer instances in the global timer service manager", 0, timers.size());
RuntimeEngine empty = manager.getRuntimeEngine(EmptyContext.get());
AuditService logService = empty.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertEquals("Active process instances should be " + numberOfProcesses, numberOfProcesses, logs.size());
countDownListener.waitTillCompleted();
List<TaskSummary> tasks = empty.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals("Number of John's tasks should be " + numberOfProcesses, numberOfProcesses, tasks.size());
for (TaskSummary task : tasks) {
RuntimeEngine piEngine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
piEngine.getTaskService().start(task.getId(), "john");
piEngine.getTaskService().complete(task.getId(), "john", null);
manager.disposeRuntimeEngine(piEngine);
}
logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertEquals("Active process instances should be 0", 0, logs.size());
logService.dispose();
manager.disposeRuntimeEngine(empty);
}
Aggregations