Search in sources :

Example 11 with Group

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();
            }
        }
    }
}
Also used : Group(org.kie.api.task.model.Group) CannotAddTaskException(org.jbpm.services.task.exception.CannotAddTaskException) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) ArrayList(java.util.ArrayList)

Example 12 with Group

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");
}
Also used : Group(org.kie.api.task.model.Group) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) User(org.kie.api.task.model.User) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test)

Example 13 with Group

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);
}
Also used : Group(org.kie.api.task.model.Group) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) User(org.kie.api.task.model.User) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) TaskSummary(org.kie.api.task.model.TaskSummary) List(java.util.List) ArrayList(java.util.ArrayList) AuditService(org.kie.api.runtime.manager.audit.AuditService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) Test(org.junit.Test)

Example 14 with Group

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());
        }
    }
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException)

Example 15 with Group

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);
    }
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Collection(java.util.Collection) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Aggregations

Group (org.kie.api.task.model.Group)38 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)29 User (org.kie.api.task.model.User)27 ArrayList (java.util.ArrayList)17 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Task (org.kie.api.task.model.Task)11 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)9 Test (org.junit.Test)8 List (java.util.List)6 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 WorkItem (org.drools.core.process.instance.WorkItem)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 PeopleAssignments (org.kie.api.task.model.PeopleAssignments)4 Iterator (java.util.Iterator)3