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());
}
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());
}
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());
}
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());
}
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);
}
}
}
Aggregations