Search in sources :

Example 26 with Group

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;
}
Also used : Group(org.kie.api.task.model.Group) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Example 27 with Group

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);
    }
}
Also used : Status(org.kie.api.task.model.Status) Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData)

Example 28 with Group

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;
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) TaskIdentityService(org.kie.internal.task.api.TaskIdentityService)

Example 29 with Group

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);
}
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) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Test(org.junit.Test)

Example 30 with Group

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;
}
Also used : Status(org.kie.api.task.model.Status) Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException)

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