Search in sources :

Example 1 with JaxbTask

use of org.jbpm.services.task.impl.model.xml.JaxbTask 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)

Example 2 with JaxbTask

use of org.jbpm.services.task.impl.model.xml.JaxbTask in project jbpm by kiegroup.

the class AbstractTaskSerializationTest method jaxbTaskTest.

// TESTS ----------------------------------------------------------------------------------------------------------------------
@Test
public void jaxbTaskTest() throws Exception {
    // Yaml serialization requires major changes in order to be supported.. :/
    Assume.assumeTrue(!getType().equals(TestType.YAML));
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    InputStream stream = getClass().getResourceAsStream(MvelFilePath.FullTask);
    assertNotNull("Could not load file: " + MvelFilePath.FullTask, stream);
    Reader reader = new InputStreamReader(stream);
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    // fill task
    task.setFormName("Bruno's Form");
    task.setId(23L);
    task.setSubTaskStrategy(SubTasksStrategy.EndParentOnAllSubTasksEnd);
    for (I18NText text : task.getNames()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    for (I18NText text : task.getSubjects()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    for (I18NText text : task.getDescriptions()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    // fill task -> task data
    InternalTaskData taskData = (InternalTaskData) task.getTaskData();
    taskData.setOutputAccessType(AccessType.Inline);
    taskData.setFaultAccessType(AccessType.Unknown);
    taskData.setTaskInputVariables(new HashMap<String, Object>());
    taskData.setTaskOutputVariables(new HashMap<String, Object>());
    // fill task -> task data -> comment
    String payload = "brainwashArmitageRecruitCaseGetPasswordFromLady3JaneAscentToStraylightIcebreakerUniteWithNeuromancer";
    InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
    comment.setId(42);
    comment.setText(payload);
    comment.setAddedAt(new Date());
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Case");
    comment.setAddedBy(user);
    taskData.addComment(comment);
    // fill task -> task data -> attachment
    InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
    attach.setId(10);
    attach.setName("virus");
    attach.setContentType("ROM");
    attach.setAttachedAt(new Date());
    user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Wintermute");
    attach.setAttachedBy(user);
    attach.setSize(payload.getBytes().length);
    attach.setAttachmentContentId(comment.getId());
    taskData.addAttachment(attach);
    JaxbTask xmlTask = new JaxbTask(task);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask, InternalTask.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData(), TaskData.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getAttachments().get(0), Attachment.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getComments().get(0), Comment.class);
    assertNotNull(xmlTask.getNames());
    assertTrue(xmlTask.getNames().size() > 0);
    JaxbTask bornAgainTask = testRoundTrip(xmlTask);
    assertNotNull(bornAgainTask.getNames());
    assertTrue("Round-tripped task has empty 'names' list!", !bornAgainTask.getNames().isEmpty());
    Assertions.assertThat(xmlTask).isEqualToComparingFieldByFieldRecursively(bornAgainTask);
    assertNotNull(((InternalTask) xmlTask).getFormName());
    assertEquals(((InternalTask) xmlTask).getFormName(), ((InternalTask) bornAgainTask).getFormName());
    Task realTask = xmlTask.getTask();
    verifyThatXmlFieldsAreFilled(realTask, xmlTask, InternalTask.class, "deadlines");
    verifyThatXmlFieldsAreFilled(realTask.getTaskData(), xmlTask.getTaskData(), TaskData.class, "taskInputVariables", "taskOutputVariables");
}
Also used : I18NText(org.kie.api.task.model.I18NText) JaxbI18NText(org.jbpm.services.task.impl.model.xml.JaxbI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) User(org.kie.api.task.model.User) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InputStream(java.io.InputStream) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JaxbTask (org.jbpm.services.task.impl.model.xml.JaxbTask)2 Task (org.kie.api.task.model.Task)2 InternalTask (org.kie.internal.task.api.model.InternalTask)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 AssignmentService (org.jbpm.services.task.assignment.AssignmentService)1 JaxbI18NText (org.jbpm.services.task.impl.model.xml.JaxbI18NText)1 Test (org.junit.Test)1 I18NText (org.kie.api.task.model.I18NText)1 User (org.kie.api.task.model.User)1 InternalAttachment (org.kie.internal.task.api.model.InternalAttachment)1 InternalComment (org.kie.internal.task.api.model.InternalComment)1 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)1 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)1