use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class AddGroupCommand method execute.
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(groupId);
context.getTaskIdentityService().addGroup(group);
return null;
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class AddTaskCommand method initializeTask.
private void initializeTask(Task task) {
Status assignedStatus = null;
if (task.getPeopleAssignments() != null && task.getPeopleAssignments().getPotentialOwners() != null && task.getPeopleAssignments().getPotentialOwners().size() == 1) {
// if there is a single potential owner, assign and set status to Reserved
OrganizationalEntity potentialOwner = task.getPeopleAssignments().getPotentialOwners().get(0);
// if there is a single potential user owner, assign and set status to Reserved
if (potentialOwner instanceof User) {
((InternalTaskData) task.getTaskData()).setActualOwner((User) potentialOwner);
assignedStatus = Status.Reserved;
}
// If there is a group set as potentialOwners, set the status to Ready ??
if (potentialOwner instanceof Group) {
assignedStatus = Status.Ready;
}
} else if (task.getPeopleAssignments() != null && task.getPeopleAssignments().getPotentialOwners() != null && task.getPeopleAssignments().getPotentialOwners().size() > 1) {
// multiple potential owners, so set to Ready so one can claim.
assignedStatus = Status.Ready;
} else {
// @TODO: we have no potential owners
}
if (assignedStatus != null) {
((InternalTaskData) task.getTaskData()).setStatus(assignedStatus);
}
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class AddUsersGroupsCommand method execute.
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskIdentityService identityService = context.getTaskIdentityService();
for (User user : users.values()) {
identityService.addUser(user);
}
for (Group group : groups.values()) {
identityService.addGroup(group);
}
return null;
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNominateToGroup.
@Test
public void testNominateToGroup() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [ new User('Darth Vader'), new User('Bobba Fet') ] } ),";
str += "name = 'This is my task name'})";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
List<OrganizationalEntity> potentialGroups = new ArrayList<OrganizationalEntity>();
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId("Knights Templer");
potentialGroups.add(group);
taskService.nominate(taskId, "Darth Vader", potentialGroups);
// shouldn't affect the assignments
Task task1 = taskService.getTaskById(taskId);
assertTrue(task1.getPeopleAssignments().getPotentialOwners().contains(group));
assertEquals(task1.getTaskData().getStatus(), Status.Ready);
}
use of org.kie.api.task.model.Group in project jbpm by kiegroup.
the class MVELLifeCycleManager method assignOwnerAndStatus.
/**
* This method will potentially assign the actual owner of this TaskData and set the status
* of the data.
* <li>If there is only 1 potential owner, and it is a <code>User</code>, that will become the actual
* owner of the TaskData and the status will be set to <code>Status.Reserved</code>.</li>
* <li>f there is only 1 potential owner, and it is a <code>Group</code>, no owner will be assigned
* and the status will be set to <code>Status.Ready</code>.</li>
* <li>If there are more than 1 potential owners, the status will be set to <code>Status.Ready</code>.</li>
* <li>otherwise, the task data will be unchanged</li>
*
* @param taskdata - task data
* @param potentialOwners - list of potential owners
* @return current status of task data
*/
public static Status assignOwnerAndStatus(InternalTaskData taskData, List<OrganizationalEntity> potentialOwners) {
if (taskData.getStatus() != Status.Created) {
throw new PermissionDeniedException("Can only assign task owner if status is Created!");
}
Status assignedStatus = null;
if (potentialOwners.size() == 1) {
// if there is a single potential owner, assign and set status to Reserved
OrganizationalEntity potentialOwner = potentialOwners.get(0);
// if there is a single potential user owner, assign and set status to Reserved
if (potentialOwner instanceof User) {
taskData.setActualOwner((User) potentialOwner);
assignedStatus = Status.Reserved;
}
// If there is a group set as potentialOwners, set the status to Ready ??
if (potentialOwner instanceof Group) {
assignedStatus = Status.Ready;
}
} else if (potentialOwners.size() > 1) {
// multiple potential owners, so set to Ready so one can claim.
assignedStatus = Status.Ready;
} else {
// @TODO we have no potential owners
}
if (assignedStatus != null) {
taskData.setStatus(assignedStatus);
} else {
// status wasn't assigned, so just return the currrent status
assignedStatus = taskData.getStatus();
}
return assignedStatus;
}
Aggregations