use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class MVELLifeCycleManager method evalCommand.
void evalCommand(final Operation operation, final List<OperationCommand> commands, final Task task, final User user, final OrganizationalEntity targetEntity, List<String> groupIds, OrganizationalEntity... entities) throws PermissionDeniedException {
boolean statusMatched = false;
final TaskData taskData = task.getTaskData();
for (OperationCommand command : commands) {
// first find out if we have a matching status
if (command.getStatus() != null) {
for (Status status : command.getStatus()) {
if (task.getTaskData().getStatus() == status) {
statusMatched = true;
// next find out if the user can execute this doOperation
if (!isAllowed(command, task, user, groupIds)) {
String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId();
throw new PermissionDeniedException(errorMessage);
}
commands(command, task, user, targetEntity, entities);
} else {
logger.debug("No match on status for task {} :status {} != {}", task.getId(), task.getTaskData().getStatus(), status);
}
}
}
if (command.getPreviousStatus() != null) {
for (Status status : command.getPreviousStatus()) {
if (taskData.getPreviousStatus() == status) {
statusMatched = true;
// next find out if the user can execute this doOperation
if (!isAllowed(command, task, user, groupIds)) {
String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId();
throw new PermissionDeniedException(errorMessage);
}
commands(command, task, user, targetEntity, entities);
} else {
logger.debug("No match on previous status for task {} :status {} != {}", task.getId(), task.getTaskData().getStatus(), status);
}
}
}
if (!command.isGroupTargetEntityAllowed() && targetEntity instanceof Group) {
String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to 'target entity cannot be group'";
throw new PermissionDeniedException(errorMessage);
}
}
if (!statusMatched) {
String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to a no 'current status' match";
throw new PermissionDeniedException(errorMessage);
}
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class MvelUserGroupCallbackImpl method existsGroup.
public boolean existsGroup(String groupId) {
Iterator<User> iter = userGroupMapping.keySet().iterator();
while (iter.hasNext()) {
User u = iter.next();
List<Group> groups = userGroupMapping.get(u);
for (Group g : groups) {
if (g.getId().equals(groupId)) {
return true;
}
}
}
return false;
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class UserTaskServiceImplTest method testNominate.
@Test
public void testNominate() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument.empty");
assertNotNull(processInstanceId);
List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
assertNotNull(taskIds);
assertEquals(1, taskIds.size());
Long taskId = taskIds.get(0);
List<OrganizationalEntity> owners = new ArrayList<OrganizationalEntity>();
User user = TaskModelProvider.getFactory().newUser("john");
owners.add(user);
user = TaskModelProvider.getFactory().newUser("salaboy");
owners.add(user);
Group group = TaskModelProvider.getFactory().newGroup("HR");
owners.add(group);
userTaskService.nominate(taskId, "Administrator", owners);
UserTaskInstanceDesc task = runtimeDataService.getTaskById(taskId);
assertNotNull(task);
assertEquals(Status.Ready.toString(), task.getStatus());
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method parseReassignment.
protected static List<Reassignment> parseReassignment(String reassignString) {
List<Reassignment> reassignments = new ArrayList<Reassignment>();
Map<String, String> parameters = asMap(reassignString);
if (parameters.containsKey("users") || parameters.containsKey("groups")) {
Reassignment reassignment = TaskModelProvider.getFactory().newReassignment();
List<OrganizationalEntity> reassignmentUsers = new ArrayList<OrganizationalEntity>();
String recipients = parameters.get("users");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(id.trim());
reassignmentUsers.add(user);
}
}
recipients = parameters.get("groups");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(id.trim());
reassignmentUsers.add(group);
}
}
reassignment.setPotentialOwners(reassignmentUsers);
reassignments.add(reassignment);
}
return reassignments;
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method parseNotifications.
protected static List<Notification> parseNotifications(String notificationString, List<OrganizationalEntity> businessAdministrators) {
List<Notification> notifications = new ArrayList<Notification>();
Map<String, String> parameters = asMap(notificationString);
if (parameters.containsKey("tousers") || parameters.containsKey("togroups")) {
String locale = parameters.get("locale");
if (locale == null) {
locale = "en-UK";
}
EmailNotification emailNotification = TaskModelProvider.getFactory().newEmialNotification();
notifications.add(emailNotification);
emailNotification.setBusinessAdministrators(businessAdministrators);
Map<Language, EmailNotificationHeader> emailHeaders = new HashMap<Language, EmailNotificationHeader>();
List<I18NText> subjects = new ArrayList<I18NText>();
List<I18NText> names = new ArrayList<I18NText>();
List<OrganizationalEntity> notificationRecipients = new ArrayList<OrganizationalEntity>();
EmailNotificationHeader emailHeader = TaskModelProvider.getFactory().newEmailNotificationHeader();
emailHeader.setBody(parameters.get("body"));
emailHeader.setFrom(parameters.get("from"));
emailHeader.setReplyTo(parameters.get("replyto"));
emailHeader.setLanguage(locale);
emailHeader.setSubject(parameters.get("subject"));
Language lang = TaskModelProvider.getFactory().newLanguage();
lang.setMapkey(locale);
emailHeaders.put(lang, emailHeader);
I18NText subject = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) subject).setLanguage(locale);
((InternalI18NText) subject).setText(emailHeader.getSubject());
;
subjects.add(subject);
names.add(subject);
String recipients = parameters.get("tousers");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(id.trim());
notificationRecipients.add(user);
}
}
String groupRecipients = parameters.get("togroups");
if (groupRecipients != null && groupRecipients.trim().length() > 0) {
String[] groupRecipientsIds = groupRecipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : groupRecipientsIds) {
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(id.trim());
notificationRecipients.add(group);
}
}
emailNotification.setEmailHeaders(emailHeaders);
emailNotification.setNames(names);
emailNotification.setRecipients(notificationRecipients);
emailNotification.setSubjects(subjects);
}
return notifications;
}
Aggregations