Search in sources :

Example 21 with InternalTask

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

the class UpdateTaskCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskEventSupport taskEventSupport = context.getTaskEventSupport();
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    Task task = persistenceContext.findTask(taskId);
    // security check
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context) && !isOwner(userId, task.getPeopleAssignments().getPotentialOwners(), task.getTaskData().getActualOwner(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin or potential owner of task " + taskId);
    }
    taskEventSupport.fireBeforeTaskUpdated(task, context);
    // process task meta data
    if (userTask.getFormName() != null) {
        ((InternalTask) task).setFormName(userTask.getFormName());
    }
    if (userTask.getName() != null) {
        ((InternalTask) task).setName(userTask.getName());
    }
    if (userTask.getDescription() != null) {
        ((InternalTask) task).setDescription(userTask.getDescription());
    }
    if (userTask.getPriority() != null) {
        ((InternalTask) task).setPriority(userTask.getPriority());
    }
    if (userTask.getDueDate() != null) {
        ((InternalTaskData) task.getTaskData()).setExpirationTime(userTask.getDueDate());
    }
    // process task inputs
    long inputContentId = task.getTaskData().getDocumentContentId();
    Content inputContent = persistenceContext.findContent(inputContentId);
    Map<String, Object> mergedContent = inputs;
    if (inputs != null) {
        if (inputContent == null) {
            ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
            ContentData outputContentData = ContentMarshallerHelper.marshal(task, inputs, mcontext.getEnvironment());
            Content content = TaskModelProvider.getFactory().newContent();
            ((InternalContent) content).setContent(outputContentData.getContent());
            persistenceContext.persistContent(content);
            ((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
        } else {
            ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
            Object unmarshalledObject = ContentMarshallerHelper.unmarshall(inputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
            if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
                ((Map<String, Object>) unmarshalledObject).putAll(inputs);
                mergedContent = ((Map<String, Object>) unmarshalledObject);
            }
            ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
            ((InternalContent) inputContent).setContent(outputContentData.getContent());
            persistenceContext.persistContent(inputContent);
        }
        ((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
    }
    if (outputs != null) {
        // process task outputs
        context.getTaskContentService().addOutputContent(taskId, outputs);
    }
    persistenceContext.updateTask(task);
    // finally trigger event support after the updates
    taskEventSupport.fireAfterTaskUpdated(task, context);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalContent(org.kie.internal.task.api.model.InternalContent) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 22 with InternalTask

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

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

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

the class LocalTaskAuditWithDeadlineTest method testDelayedReassignmentOnDeadline.

@Test(timeout = 10000)
public void testDelayedReassignmentOnDeadline() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, true, false);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithReassignment));
    Task task = (InternalTask) TaskFactory.evalTask(reader, vars);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    taskService.claim(taskId, "Tony Stark");
    task = taskService.getTaskById(taskId);
    List<OrganizationalEntity> potentialOwners = (List<OrganizationalEntity>) task.getPeopleAssignments().getPotentialOwners();
    List<String> ids = new ArrayList<String>(potentialOwners.size());
    for (OrganizationalEntity entity : potentialOwners) {
        ids.add(entity.getId());
    }
    assertTrue(ids.contains("Tony Stark"));
    assertTrue(ids.contains("Luke Cage"));
    List<AuditTask> tasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    assertEquals(1, tasks.size());
    AuditTask auditTask = tasks.get(0);
    assertEquals(Status.Reserved.toString(), auditTask.getStatus());
    assertEquals("Tony Stark", auditTask.getActualOwner());
    // should have re-assigned by now
    countDownListener.waitTillCompleted();
    task = taskService.getTaskById(taskId);
    assertNull(task.getTaskData().getActualOwner());
    assertEquals(Status.Ready, task.getTaskData().getStatus());
    potentialOwners = (List<OrganizationalEntity>) task.getPeopleAssignments().getPotentialOwners();
    ids = new ArrayList<String>(potentialOwners.size());
    for (OrganizationalEntity entity : potentialOwners) {
        ids.add(entity.getId());
    }
    assertTrue(ids.contains("Bobba Fet"));
    assertTrue(ids.contains("Jabba Hutt"));
    tasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    assertEquals(1, tasks.size());
    auditTask = tasks.get(0);
    assertEquals(Status.Ready.toString(), auditTask.getStatus());
    assertEquals("", auditTask.getActualOwner());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) AuditTask(org.kie.internal.task.api.AuditTask) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Date(java.util.Date) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) List(java.util.List) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 25 with InternalTask

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

the class AddTaskCommand method execute.

public Long execute(Context cntxt) {
    Long taskId = null;
    TaskContext context = (TaskContext) cntxt;
    if (task == null) {
        task = jaxbTask;
    }
    Task taskImpl = null;
    if (task instanceof JaxbTask) {
        taskImpl = ((JaxbTask) task).getTask();
    } else {
        taskImpl = task;
    }
    initializeTask(taskImpl);
    context.getTaskRuleService().executeRules(taskImpl, userId, data != null ? data : params, TaskRuleService.ADD_TASK_SCOPE);
    // use assignment service to directly assign actual owner if enabled
    AssignmentService assignmentService = AssignmentServiceProvider.get();
    if (assignmentService.isEnabled()) {
        assignmentService.assignTask(taskImpl, context);
    }
    doCallbackOperationForPeopleAssignments((InternalPeopleAssignments) taskImpl.getPeopleAssignments(), context);
    doCallbackOperationForTaskData((InternalTaskData) taskImpl.getTaskData(), context);
    doCallbackOperationForTaskDeadlines(((InternalTask) taskImpl).getDeadlines(), context);
    if (data != null) {
        taskId = context.getTaskInstanceService().addTask(taskImpl, data);
    } else {
        ((InternalTaskData) taskImpl.getTaskData()).setTaskInputVariables(params);
        taskId = context.getTaskInstanceService().addTask(taskImpl, params);
    }
    scheduleDeadlinesForTask((InternalTask) taskImpl, context.getTaskDeadlinesService());
    return taskId;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) AssignmentService(org.jbpm.services.task.assignment.AssignmentService)

Aggregations

InternalTask (org.kie.internal.task.api.model.InternalTask)50 Task (org.kie.api.task.model.Task)29 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)21 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)18 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)17 InputStreamReader (java.io.InputStreamReader)16 Reader (java.io.Reader)16 User (org.kie.api.task.model.User)16 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)15 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)15 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Date (java.util.Date)12 HashMap (java.util.HashMap)11 ContentData (org.kie.internal.task.api.model.ContentData)11 InternalContent (org.kie.internal.task.api.model.InternalContent)11 I18NText (org.kie.api.task.model.I18NText)10 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)8 TaskSummary (org.kie.api.task.model.TaskSummary)6 StringReader (java.io.StringReader)5