Search in sources :

Example 21 with InternalTaskData

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

the class PeopleAssignmentHelperTest method testAssignActorsWithCustomSeparatorViaSysProp.

@Test
public void testAssignActorsWithCustomSeparatorViaSysProp() {
    System.setProperty("org.jbpm.ht.user.separator", ";");
    peopleAssignmentHelper = new PeopleAssignmentHelper();
    String actorId = "user1;user2";
    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("user1", organizationalEntity1.getId());
    assertEquals("user1", taskData.getCreatedBy().getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getPotentialOwners().get(1);
    assertTrue(organizationalEntity2 instanceof User);
    assertEquals("user2", organizationalEntity2.getId());
    workItem = new WorkItemImpl();
    peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId + "; drbug  ");
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    assertEquals(3, peopleAssignments.getPotentialOwners().size());
    organizationalEntity1 = peopleAssignments.getPotentialOwners().get(0);
    assertEquals("user1", organizationalEntity1.getId());
    assertEquals("user1", taskData.getCreatedBy().getId());
    organizationalEntity2 = peopleAssignments.getPotentialOwners().get(1);
    assertTrue(organizationalEntity2 instanceof User);
    assertEquals("user2", organizationalEntity2.getId());
    OrganizationalEntity organizationalEntity3 = peopleAssignments.getPotentialOwners().get(2);
    assertEquals("drbug", organizationalEntity3.getId());
    workItem = new WorkItemImpl();
    peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, "");
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    assertEquals(0, peopleAssignments.getPotentialOwners().size());
    System.clearProperty("org.jbpm.ht.user.separator");
}
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 22 with InternalTaskData

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

the class PeopleAssignmentHelperTest method testHandleMultiPeopleAssignments.

@Test
public void testHandleMultiPeopleAssignments() {
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    InternalPeopleAssignments peopleAssignment = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    assertNotNull(peopleAssignment);
    assertEquals(0, peopleAssignment.getPotentialOwners().size());
    assertEquals(0, peopleAssignment.getBusinessAdministrators().size());
    assertEquals(0, peopleAssignment.getTaskStakeholders().size());
    String actorId = "espiegelberg,john";
    String taskStakeholderId = "drmary,krisv";
    String businessAdministratorId = "drbug,peter";
    String businessAdministratorGroupId = "Super users,Flow administrators";
    String excludedOwnerId = "john,poul";
    String recipientId = "mary,steve";
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId);
    workItem.setParameter(PeopleAssignmentHelper.TASKSTAKEHOLDER_ID, taskStakeholderId);
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_ID, businessAdministratorId);
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_GROUP_ID, businessAdministratorGroupId);
    workItem.setParameter(PeopleAssignmentHelper.EXCLUDED_OWNER_ID, excludedOwnerId);
    workItem.setParameter(PeopleAssignmentHelper.RECIPIENT_ID, recipientId);
    peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    assertEquals(2, potentialOwners.size());
    assertEquals("espiegelberg", potentialOwners.get(0).getId());
    assertEquals("john", potentialOwners.get(1).getId());
    List<OrganizationalEntity> businessAdministrators = task.getPeopleAssignments().getBusinessAdministrators();
    assertEquals(6, businessAdministrators.size());
    assertEquals("Administrator", businessAdministrators.get(0).getId());
    // Admin group
    assertEquals("Administrators", businessAdministrators.get(1).getId());
    assertEquals("drbug", businessAdministrators.get(2).getId());
    assertEquals("peter", businessAdministrators.get(3).getId());
    assertEquals("Super users", businessAdministrators.get(4).getId());
    assertEquals("Flow administrators", businessAdministrators.get(5).getId());
    List<OrganizationalEntity> taskStakehoders = ((InternalPeopleAssignments) task.getPeopleAssignments()).getTaskStakeholders();
    assertEquals(2, taskStakehoders.size());
    assertEquals("drmary", taskStakehoders.get(0).getId());
    assertEquals("krisv", taskStakehoders.get(1).getId());
    List<OrganizationalEntity> excludedOwners = ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners();
    assertEquals(2, excludedOwners.size());
    assertEquals("john", excludedOwners.get(0).getId());
    assertEquals("poul", excludedOwners.get(1).getId());
    List<OrganizationalEntity> recipients = ((InternalPeopleAssignments) task.getPeopleAssignments()).getRecipients();
    assertEquals(2, recipients.size());
    assertEquals("mary", recipients.get(0).getId());
    assertEquals("steve", recipients.get(1).getId());
}
Also used : InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 23 with InternalTaskData

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

the class TestPersistenceContext method createSomeTask.

public void createSomeTask() {
    testIsInitialized();
    TaskImpl task = new TaskImpl();
    InternalI18NText name = (InternalI18NText) TaskModelProvider.getFactory().newI18NText();
    name.setText("Some Task");
    List<I18NText> names = new ArrayList<I18NText>();
    names.add(name);
    task.setNames(names);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setWorkItemId(12);
    taskData.setProcessInstanceId(1);
    taskData.setProcessId("someprocess");
    taskData.setDeploymentId("org.jbpm.test:someprocess:1.0");
    taskData.setProcessSessionId(1);
    task.setTaskData(taskData);
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    peopleAssignments.setPotentialOwners(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setBusinessAdministrators(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setExcludedOwners(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setRecipients(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setTaskStakeholders(new ArrayList<OrganizationalEntity>());
    InternalOrganizationalEntity jdoe = (InternalOrganizationalEntity) TaskModelProvider.getFactory().newUser();
    jdoe.setId("jdoe");
    peopleAssignments.getPotentialOwners().add(jdoe);
    peopleAssignments.getBusinessAdministrators().add(jdoe);
    task.setPeopleAssignments(peopleAssignments);
    final boolean txOwner = transactionManager.begin();
    try {
        EntityManager em = entityManagerFactory.createEntityManager();
        em.persist(jdoe);
        em.persist(task);
        transactionManager.commit(txOwner);
    } catch (Exception ex) {
        ex.printStackTrace();
        transactionManager.rollback(txOwner);
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
Also used : 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) TaskImpl(org.jbpm.persistence.scripts.oldentities.TaskImpl) ArrayList(java.util.ArrayList) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) IOException(java.io.IOException) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) EntityManager(javax.persistence.EntityManager)

Example 24 with InternalTaskData

use of org.kie.internal.task.api.model.InternalTaskData 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 25 with InternalTaskData

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

the class AssignmentServiceImpl method assignTask.

@Override
public void assignTask(Task task, TaskContext context, String excludedUser) {
    if (!isEnabled()) {
        logger.debug("AssignmentService is not enabled - to enable it set system property '" + ENABLED_PROPERTY + "' to true");
        return;
    }
    Assignment assignTo = this.strategy.apply(task, context, excludedUser);
    if (assignTo == null || assignTo.getUser() == null) {
        logger.warn("Strategy {} did not return any assignment for task {}", strategy, task);
        return;
    }
    logger.debug("Actual owner returned by strategy {} is {} for task {}", strategy, assignTo, task);
    User actualOwner = taskModelFactory.newUser(assignTo.getUser());
    ((InternalTaskData) task.getTaskData()).setActualOwner(actualOwner);
    ((InternalTaskData) task.getTaskData()).setStatus(Status.Reserved);
}
Also used : Assignment(org.kie.internal.task.api.assignment.Assignment) User(org.kie.api.task.model.User) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData)

Aggregations

InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)45 InternalTask (org.kie.internal.task.api.model.InternalTask)23 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)22 Task (org.kie.api.task.model.Task)22 Test (org.junit.Test)21 User (org.kie.api.task.model.User)20 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)20 InternalContent (org.kie.internal.task.api.model.InternalContent)15 ContentData (org.kie.internal.task.api.model.ContentData)14 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 ArrayList (java.util.ArrayList)13 InputStreamReader (java.io.InputStreamReader)11 Reader (java.io.Reader)11 HashMap (java.util.HashMap)10 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)10 Date (java.util.Date)7 StringReader (java.io.StringReader)6 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 Content (org.kie.api.task.model.Content)6 Map (java.util.Map)5