Search in sources :

Example 16 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class PeopleAssignmentHelperTest method testAssignBusinessAdministrators.

@Test
public void testAssignBusinessAdministrators() {
    String businessAdministratorId = "espiegelberg";
    Task task = TaskModelProvider.getFactory().newTask();
    PeopleAssignments peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_ID, businessAdministratorId);
    peopleAssignmentHelper.assignBusinessAdministrators(workItem, peopleAssignments);
    assertEquals(3, peopleAssignments.getBusinessAdministrators().size());
    OrganizationalEntity organizationalEntity1 = peopleAssignments.getBusinessAdministrators().get(0);
    assertTrue(organizationalEntity1 instanceof User);
    assertEquals("Administrator", organizationalEntity1.getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getBusinessAdministrators().get(1);
    assertTrue(organizationalEntity2 instanceof Group);
    assertEquals("Administrators", organizationalEntity2.getId());
    OrganizationalEntity organizationalEntity3 = peopleAssignments.getBusinessAdministrators().get(2);
    assertTrue(organizationalEntity3 instanceof User);
    assertEquals(businessAdministratorId, organizationalEntity3.getId());
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 17 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class PeopleAssignmentHelperTest method testAssignGroups.

@Test
public void testAssignGroups() {
    String groupId = "Software Developers, Project Managers";
    Task task = TaskModelProvider.getFactory().newTask();
    PeopleAssignments peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.GROUP_ID, groupId);
    peopleAssignmentHelper.assignGroups(workItem, peopleAssignments);
    OrganizationalEntity organizationalEntity1 = peopleAssignments.getPotentialOwners().get(0);
    assertTrue(organizationalEntity1 instanceof Group);
    assertEquals("Software Developers", organizationalEntity1.getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getPotentialOwners().get(1);
    assertTrue(organizationalEntity2 instanceof Group);
    assertEquals("Project Managers", organizationalEntity2.getId());
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 18 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class PeopleAssignmentHelperTest method testAssignBusinessAdministratorGroups.

@Test
public void testAssignBusinessAdministratorGroups() {
    String businessAdministratorGroupId = "Super users";
    Task task = TaskModelProvider.getFactory().newTask();
    PeopleAssignments peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_GROUP_ID, businessAdministratorGroupId);
    peopleAssignmentHelper.assignBusinessAdministrators(workItem, peopleAssignments);
    assertEquals(3, peopleAssignments.getBusinessAdministrators().size());
    OrganizationalEntity organizationalEntity1 = peopleAssignments.getBusinessAdministrators().get(0);
    assertTrue(organizationalEntity1 instanceof User);
    assertEquals("Administrator", organizationalEntity1.getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getBusinessAdministrators().get(1);
    assertTrue(organizationalEntity2 instanceof Group);
    assertEquals("Administrators", organizationalEntity2.getId());
    OrganizationalEntity organizationalEntity3 = peopleAssignments.getBusinessAdministrators().get(2);
    assertTrue(organizationalEntity3 instanceof Group);
    assertEquals(businessAdministratorGroupId, organizationalEntity3.getId());
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 19 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class PeopleAssignmentHelperTest method testAssignBusinessAdministratorsChangedDefaults.

@Test
public void testAssignBusinessAdministratorsChangedDefaults() {
    peopleAssignmentHelper = new PeopleAssignmentHelper("myadmin", "mygroup");
    Task task = TaskModelProvider.getFactory().newTask();
    PeopleAssignments peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    WorkItem workItem = new WorkItemImpl();
    peopleAssignmentHelper.assignBusinessAdministrators(workItem, peopleAssignments);
    assertEquals(2, peopleAssignments.getBusinessAdministrators().size());
    OrganizationalEntity organizationalEntity1 = peopleAssignments.getBusinessAdministrators().get(0);
    assertTrue(organizationalEntity1 instanceof User);
    assertEquals("myadmin", organizationalEntity1.getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getBusinessAdministrators().get(1);
    assertTrue(organizationalEntity2 instanceof Group);
    assertEquals("mygroup", organizationalEntity2.getId());
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 20 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class StartCaseWorkItemHandler method parseParameters.

protected void parseParameters(WorkItem workItem, Map<String, Object> caseFileData, Map<String, OrganizationalEntity> roleAssignments, Map<String, List<String>> accessRestrictions) {
    TaskModelFactory taskModelFactory = TaskModelProvider.getFactory();
    CaseFileInstance caseFile = getCaseFile(ksession);
    for (Entry<String, Object> entry : workItem.getParameters().entrySet()) {
        if (entry.getKey().startsWith(DATA_PREFIX)) {
            String name = entry.getKey().replaceFirst(DATA_PREFIX, "");
            caseFileData.put(name, entry.getValue());
            logger.debug("Added {} item to case file with value {}", name, entry.getValue());
        } else if (entry.getKey().startsWith(USER_ROLE_PREFIX)) {
            String name = entry.getKey().replaceFirst(USER_ROLE_PREFIX, "");
            User user = taskModelFactory.newUser((String) entry.getValue());
            if (caseFile != null) {
                try {
                    Collection<OrganizationalEntity> caseAssignments = ((CaseAssignment) caseFile).getAssignments(name);
                    user = (User) caseAssignments.stream().filter(oe -> oe instanceof User).findFirst().orElseThrow(() -> new IllegalArgumentException());
                } catch (IllegalArgumentException e) {
                    logger.debug("no such role {} or there is no user found for given role name", name);
                }
            }
            roleAssignments.put(name, user);
            logger.debug("Added user {} as assignment to the role {}", entry.getValue(), entry.getKey());
        } else if (entry.getKey().startsWith(GROUP_ROLE_PREFIX)) {
            String name = entry.getKey().replaceFirst(GROUP_ROLE_PREFIX, "");
            Group group = taskModelFactory.newGroup((String) entry.getValue());
            if (caseFile != null) {
                try {
                    Collection<OrganizationalEntity> caseAssignments = ((CaseAssignment) caseFile).getAssignments(name);
                    group = (Group) caseAssignments.stream().filter(oe -> oe instanceof Group).findFirst().orElseThrow(() -> new IllegalArgumentException());
                } catch (IllegalArgumentException e) {
                    logger.debug("no such role {} or there is no group found for given role name", name);
                }
            }
            roleAssignments.put(name, group);
            logger.debug("Added group {} as assignment to the role {}", entry.getValue(), entry.getKey());
        } else if (entry.getKey().startsWith(DATA_ACCESS_PREFIX)) {
            String name = entry.getKey().replaceFirst(DATA_ACCESS_PREFIX, "");
            String[] roles = ((String) entry.getValue()).split(",");
            List<String> restrictedTo = new ArrayList<>(Arrays.asList(roles));
            accessRestrictions.put(name, restrictedTo);
            logger.debug("Added access restriction for {} with following roles {}", name, restrictedTo);
        }
    }
}
Also used : Arrays(java.util.Arrays) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) RuntimeManagerRegistry(org.kie.internal.runtime.manager.RuntimeManagerRegistry) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ArrayList(java.util.ArrayList) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Map(java.util.Map) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) KieSession(org.kie.api.runtime.KieSession) User(org.kie.api.task.model.User) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Logger(org.slf4j.Logger) WorkItem(org.kie.api.runtime.process.WorkItem) Collection(java.util.Collection) CaseService(org.jbpm.casemgmt.api.CaseService) TaskModelProvider(org.kie.internal.task.api.TaskModelProvider) ClassObjectFilter(org.drools.core.ClassObjectFilter) List(java.util.List) Group(org.kie.api.task.model.Group) Entry(java.util.Map.Entry) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

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