Search in sources :

Example 6 with PeopleAssignments

use of org.kie.api.task.model.PeopleAssignments 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());
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 7 with PeopleAssignments

use of org.kie.api.task.model.PeopleAssignments in project jbpm by kiegroup.

the class AbstractHTWorkItemHandler method createTaskBasedOnWorkItemParams.

protected Task createTaskBasedOnWorkItemParams(KieSession session, WorkItem workItem) {
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    String taskName = (String) workItem.getParameter("NodeName");
    CaseData caseFile = null;
    String locale = (String) workItem.getParameter("Locale");
    if (locale == null) {
        locale = "en-UK";
    }
    if (taskName != null) {
        List<I18NText> names = new ArrayList<I18NText>();
        I18NText text = TaskModelProvider.getFactory().newI18NText();
        ((InternalI18NText) text).setLanguage(locale);
        ((InternalI18NText) text).setText(taskName);
        names.add(text);
        task.setNames(names);
    }
    task.setName(taskName);
    // this should be replaced by FormName filled by designer
    // TaskName shouldn't be trimmed if we are planning to use that for the task lists
    String formName = (String) workItem.getParameter("TaskName");
    if (formName != null) {
        task.setFormName(formName);
    }
    String comment = (String) workItem.getParameter("Comment");
    if (comment == null) {
        comment = "";
    }
    String description = (String) workItem.getParameter("Description");
    if (description == null) {
        description = comment;
    }
    List<I18NText> descriptions = new ArrayList<I18NText>();
    I18NText descText = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) descText).setLanguage(locale);
    ((InternalI18NText) descText).setText(description);
    descriptions.add(descText);
    task.setDescriptions(descriptions);
    task.setDescription(description);
    List<I18NText> subjects = new ArrayList<I18NText>();
    I18NText subjectText = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) subjectText).setLanguage(locale);
    ((InternalI18NText) subjectText).setText(comment);
    subjects.add(subjectText);
    task.setSubjects(subjects);
    task.setSubject(comment);
    String priorityString = (String) workItem.getParameter("Priority");
    int priority = 0;
    if (priorityString != null) {
        try {
            priority = new Integer(priorityString);
        } catch (NumberFormatException e) {
        // do nothing
        }
    }
    task.setPriority(priority);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setWorkItemId(workItem.getId());
    taskData.setProcessInstanceId(workItem.getProcessInstanceId());
    if (session != null) {
        if (session.getProcessInstance(workItem.getProcessInstanceId()) != null) {
            taskData.setProcessId(session.getProcessInstance(workItem.getProcessInstanceId()).getProcess().getId());
            String deploymentId = ((WorkItemImpl) workItem).getDeploymentId();
            taskData.setDeploymentId(deploymentId);
        }
        if (session instanceof KieSession) {
            taskData.setProcessSessionId(((KieSession) session).getIdentifier());
        }
        @SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) session.getObjects(new ClassObjectFilter(CaseData.class));
        if (caseFiles != null && caseFiles.size() == 1) {
            caseFile = caseFiles.iterator().next();
        }
    }
    taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
    // Sub Task Data
    Long parentId = (Long) workItem.getParameter("ParentId");
    if (parentId != null) {
        taskData.setParentId(parentId);
    }
    String createdBy = (String) workItem.getParameter("CreatedBy");
    if (createdBy != null && createdBy.trim().length() > 0) {
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId(createdBy);
        taskData.setCreatedBy(user);
    }
    String dueDateString = (String) workItem.getParameter("DueDate");
    Date date = null;
    if (dueDateString != null && !dueDateString.isEmpty()) {
        if (DateTimeUtils.isPeriod(dueDateString)) {
            Long longDateValue = DateTimeUtils.parseDateAsDuration(dueDateString.substring(1));
            date = new Date(System.currentTimeMillis() + longDateValue);
        } else {
            date = new Date(DateTimeUtils.parseDateTime(dueDateString));
        }
    }
    if (date != null) {
        taskData.setExpirationTime(date);
    }
    PeopleAssignmentHelper peopleAssignmentHelper = new PeopleAssignmentHelper(caseFile);
    peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
    PeopleAssignments peopleAssignments = task.getPeopleAssignments();
    List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
    taskData.initialize();
    task.setTaskData(taskData);
    task.setDeadlines(HumanTaskHandlerHelper.setDeadlines(workItem, businessAdministrators, session.getEnvironment()));
    return task;
}
Also used : CaseData(org.kie.api.runtime.process.CaseData) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) KieSession(org.kie.api.runtime.KieSession) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Date(java.util.Date) PeopleAssignmentHelper(org.jbpm.services.task.wih.util.PeopleAssignmentHelper) ClassObjectFilter(org.drools.core.ClassObjectFilter) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Collection(java.util.Collection)

Example 8 with PeopleAssignments

use of org.kie.api.task.model.PeopleAssignments in project jbpm by kiegroup.

the class PeopleAssignmentHelperTest method testAssignActors.

@Test
public void testAssignActors() {
    String actorId = "espiegelberg";
    Task task = TaskModelProvider.getFactory().newTask();
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    PeopleAssignments peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId);
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    OrganizationalEntity organizationalEntity1 = peopleAssignments.getPotentialOwners().get(0);
    assertTrue(organizationalEntity1 instanceof User);
    assertEquals(actorId, organizationalEntity1.getId());
    assertEquals(actorId, taskData.getCreatedBy().getId());
    workItem = new WorkItemImpl();
    peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId + ", drbug  ");
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    assertEquals(2, peopleAssignments.getPotentialOwners().size());
    organizationalEntity1 = peopleAssignments.getPotentialOwners().get(0);
    assertEquals(actorId, organizationalEntity1.getId());
    assertEquals(actorId, taskData.getCreatedBy().getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getPotentialOwners().get(1);
    assertEquals("drbug", organizationalEntity2.getId());
    workItem = new WorkItemImpl();
    peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, "");
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    assertEquals(0, peopleAssignments.getPotentialOwners().size());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 9 with PeopleAssignments

use of org.kie.api.task.model.PeopleAssignments in project jbpm by kiegroup.

the class MVELLifeCycleManager method commands.

private void commands(final OperationCommand command, final Task task, final User user, final OrganizationalEntity targetEntity, OrganizationalEntity... entities) {
    final PeopleAssignments people = task.getPeopleAssignments();
    final InternalTaskData taskData = (InternalTaskData) task.getTaskData();
    if (command.getNewStatus() != null) {
        taskData.setStatus(command.getNewStatus());
    } else if (command.isSetToPreviousStatus()) {
        taskData.setStatus(taskData.getPreviousStatus());
    }
    if (command.isAddTargetEntityToPotentialOwners() && !people.getPotentialOwners().contains(targetEntity)) {
        people.getPotentialOwners().add(targetEntity);
    }
    if (command.isRemoveUserFromPotentialOwners()) {
        people.getPotentialOwners().remove(user);
    }
    if (command.isSetNewOwnerToUser()) {
        taskData.setActualOwner(user);
    }
    if (command.isSetNewOwnerToNull()) {
        taskData.setActualOwner(null);
    }
    if (command.getExec() != null) {
        switch(command.getExec()) {
            case Claim:
                {
                    taskData.setActualOwner((User) targetEntity);
                    break;
                }
            case Nominate:
                {
                    if (entities != null && entities.length > 0) {
                        List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>(Arrays.asList(entities));
                        ((InternalPeopleAssignments) task.getPeopleAssignments()).setPotentialOwners(potentialOwners);
                        assignOwnerAndStatus((InternalTaskData) task.getTaskData(), potentialOwners);
                    }
                    break;
                }
        }
    }
}
Also used : User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) List(java.util.List) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) PeopleAssignments(org.kie.api.task.model.PeopleAssignments)

Aggregations

OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)9 PeopleAssignments (org.kie.api.task.model.PeopleAssignments)9 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)8 User (org.kie.api.task.model.User)8 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)8 InternalTask (org.kie.internal.task.api.model.InternalTask)8 WorkItem (org.drools.core.process.instance.WorkItem)7 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)7 Test (org.junit.Test)7 Task (org.kie.api.task.model.Task)7 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)5 Group (org.kie.api.task.model.Group)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 ClassObjectFilter (org.drools.core.ClassObjectFilter)1 PeopleAssignmentHelper (org.jbpm.services.task.wih.util.PeopleAssignmentHelper)1 KieSession (org.kie.api.runtime.KieSession)1 CaseData (org.kie.api.runtime.process.CaseData)1