use of org.kie.internal.task.api.TaskModelFactory 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