use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class UserGroupCallbackTaskCommand method doCallbackOperationForPeopleAssignments.
protected void doCallbackOperationForPeopleAssignments(InternalPeopleAssignments assignments, TaskContext context) {
List<OrganizationalEntity> nonExistingEntities = new ArrayList<OrganizationalEntity>();
if (assignments != null) {
List<? extends OrganizationalEntity> businessAdmins = assignments.getBusinessAdministrators();
if (businessAdmins != null) {
for (OrganizationalEntity admin : businessAdmins) {
if (admin instanceof User) {
boolean userExists = doCallbackUserOperation(admin.getId(), context);
if (!userExists) {
nonExistingEntities.add(admin);
}
}
if (admin instanceof Group) {
boolean groupExists = doCallbackGroupOperation(admin.getId(), context);
if (!groupExists) {
nonExistingEntities.add(admin);
}
}
}
if (!nonExistingEntities.isEmpty()) {
businessAdmins.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
if (businessAdmins == null || businessAdmins.isEmpty()) {
// throw an exception as it should not be allowed to create task without administrator
throw new CannotAddTaskException("There are no known Business Administrators, task cannot be created according to WS-HT specification");
}
List<? extends OrganizationalEntity> potentialOwners = assignments.getPotentialOwners();
if (potentialOwners != null) {
for (OrganizationalEntity powner : potentialOwners) {
if (powner instanceof User) {
boolean userExists = doCallbackUserOperation(powner.getId(), context);
if (!userExists) {
nonExistingEntities.add(powner);
}
}
if (powner instanceof Group) {
boolean groupExists = doCallbackGroupOperation(powner.getId(), context);
if (!groupExists) {
nonExistingEntities.add(powner);
}
}
}
if (!nonExistingEntities.isEmpty()) {
potentialOwners.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
if (assignments.getTaskInitiator() != null && assignments.getTaskInitiator().getId() != null) {
doCallbackUserOperation(assignments.getTaskInitiator().getId(), context);
}
List<? extends OrganizationalEntity> excludedOwners = assignments.getExcludedOwners();
if (excludedOwners != null) {
for (OrganizationalEntity exowner : excludedOwners) {
if (exowner instanceof User) {
boolean userExists = doCallbackUserOperation(exowner.getId(), context);
if (!userExists) {
nonExistingEntities.add(exowner);
}
}
if (exowner instanceof Group) {
boolean groupExists = doCallbackGroupOperation(exowner.getId(), context);
if (!groupExists) {
nonExistingEntities.add(exowner);
}
}
}
if (!nonExistingEntities.isEmpty()) {
excludedOwners.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
List<? extends OrganizationalEntity> recipients = assignments.getRecipients();
if (recipients != null) {
for (OrganizationalEntity recipient : recipients) {
if (recipient instanceof User) {
boolean userExists = doCallbackUserOperation(recipient.getId(), context);
if (!userExists) {
nonExistingEntities.add(recipient);
}
}
if (recipient instanceof Group) {
boolean groupExists = doCallbackGroupOperation(recipient.getId(), context);
if (!groupExists) {
nonExistingEntities.add(recipient);
}
}
}
if (!nonExistingEntities.isEmpty()) {
recipients.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
List<? extends OrganizationalEntity> stakeholders = assignments.getTaskStakeholders();
if (stakeholders != null) {
for (OrganizationalEntity stakeholder : stakeholders) {
if (stakeholder instanceof User) {
boolean userExists = doCallbackUserOperation(stakeholder.getId(), context);
if (!userExists) {
nonExistingEntities.add(stakeholder);
}
}
if (stakeholder instanceof Group) {
boolean groupExists = doCallbackGroupOperation(stakeholder.getId(), context);
if (!groupExists) {
nonExistingEntities.add(stakeholder);
}
}
}
if (!nonExistingEntities.isEmpty()) {
stakeholders.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
}
}
use of org.kie.api.task.model.Group 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.api.task.model.Group 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);
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class NonManagedLocalHTWorkItemHandler method abortWorkItem.
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
Task task = taskService.getTaskByWorkItemId(workItem.getId());
if (task != null) {
try {
String adminUser = ADMIN_USER;
List<OrganizationalEntity> businessAdmins = task.getPeopleAssignments().getBusinessAdministrators();
for (OrganizationalEntity admin : businessAdmins) {
if (admin instanceof Group) {
continue;
}
if (!admin.getId().equals(ADMIN_USER)) {
adminUser = admin.getId();
break;
}
}
logger.debug("Task {} is going to be exited by {} who is business admin", task.getId(), adminUser);
taskService.exit(task.getId(), adminUser);
} catch (PermissionDeniedException e) {
logger.info(e.getMessage());
}
}
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class PeopleAssignmentHelper method assignBusinessAdministrators.
@SuppressWarnings("unchecked")
protected void assignBusinessAdministrators(WorkItem workItem, PeopleAssignments peopleAssignments) {
List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
Object businessAdminGroupIds = adjustParam(workItem.getParameter(BUSINESSADMINISTRATOR_GROUP_ID), groupFilter);
Object businessAdministratorIds = adjustParam(workItem.getParameter(BUSINESSADMINISTRATOR_ID), userFilter);
if (!hasAdminAssigned(businessAdministrators)) {
User administrator = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) administrator).setId(administratorUser);
businessAdministrators.add(administrator);
Group adminGroup = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) adminGroup).setId(administratorGroup);
businessAdministrators.add(adminGroup);
}
if (businessAdministratorIds instanceof Collection) {
processPeopleAssignments((Collection<OrganizationalEntity>) businessAdministratorIds, businessAdministrators);
} else {
processPeopleAssignments((String) businessAdministratorIds, businessAdministrators, true);
}
if (businessAdminGroupIds instanceof Collection) {
processPeopleAssignments((Collection<OrganizationalEntity>) businessAdminGroupIds, businessAdministrators);
} else {
processPeopleAssignments((String) businessAdminGroupIds, businessAdministrators, false);
}
}
Aggregations