Search in sources :

Example 1 with ContentData

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

the class LifeCycleBaseTest method testNewTaskWithMapContentAndOutput.

/*
     * This test shows how to work with a task and save severeal intermediate steps of the content that the 
     * task is handling. 
     * The input parameters for this task are: (key1,value1) (key3,value3). 
     * 
     * (key2, null) is a variable that is input/output, this means that is a variable that comes defined, but it value can be changed
     * by the user
     * 
     * The expected outputs for the task are: (key2, value2), (key4, value4) (key5, value5) (key6, value6)
     */
@Test
public void testNewTaskWithMapContentAndOutput() {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
    str += "name =  'This is my task name' })";
    Map<String, Object> variablesMap = new HashMap<String, Object>();
    variablesMap.put("key1", "value1");
    variablesMap.put("key2", null);
    variablesMap.put("key3", "value3");
    ContentData data = ContentMarshallerHelper.marshal(null, variablesMap, null);
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, data);
    long taskId = task.getId();
    // Task should be assigned to the single potential owner and state set to Reserved
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType());
    assertEquals("java.util.HashMap", task1.getTaskData().getDocumentType());
    long contentId = task1.getTaskData().getDocumentContentId();
    assertTrue(contentId != -1);
    Content content = taskService.getContentById(contentId);
    Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    if (!(unmarshalledObject instanceof Map)) {
        fail("The variables should be a Map");
    }
    xmlRoundTripContent(content);
    Map<String, Object> unmarshalledvars = (Map<String, Object>) unmarshalledObject;
    assertEquals("value1", unmarshalledvars.get("key1"));
    assertNull(unmarshalledvars.get("key2"));
    assertEquals("value3", unmarshalledvars.get("key3"));
    taskService.start(taskId, "Bobba Fet");
    task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    // Once the task has being started the user decide to start working on it.
    Map<String, Object> intermediateOutputContentMap = new HashMap<String, Object>();
    intermediateOutputContentMap.put("key2", "value2");
    intermediateOutputContentMap.put("key4", "value4");
    taskService.addContent(taskId, intermediateOutputContentMap);
    Map<String, Object> finalOutputContentMap = new HashMap<String, Object>();
    finalOutputContentMap.put("key5", "value5");
    finalOutputContentMap.put("key6", "value6");
    taskService.complete(taskId, "Bobba Fet", finalOutputContentMap);
    task1 = taskService.getTaskById(taskId);
    assertEquals(Status.Completed, task1.getTaskData().getStatus());
    long outputContentId = task1.getTaskData().getOutputContentId();
    Content contentById = taskService.getContentById(outputContentId);
    unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
    assertNotNull(unmarshalledObject);
    if (!(unmarshalledObject instanceof Map)) {
        fail("The variables should be a Map");
    }
    assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key2"));
    assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key4"));
    assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key5"));
    assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key6"));
    xmlRoundTripContent(contentById);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) ContentData(org.kie.internal.task.api.model.ContentData) HashMap(java.util.HashMap) Content(org.kie.api.task.model.Content) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ContentData

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

the class LifeCycleBaseTest method testNewTaskWithContent.

@Test
public void testNewTaskWithContent() {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
    str += "name =  'This is my task name' })";
    ContentData data = ContentMarshallerHelper.marshal(null, "content", null);
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, data);
    long taskId = task.getId();
    // Task should be assigned to the single potential owner and state set to Reserved
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType());
    assertEquals("java.lang.String", task1.getTaskData().getDocumentType());
    long contentId = task1.getTaskData().getDocumentContentId();
    assertTrue(contentId != -1);
    Content content = taskService.getContentById(contentId);
    Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    assertEquals("content", unmarshalledObject.toString());
    xmlRoundTripContent(content);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) ContentData(org.kie.internal.task.api.model.ContentData) Content(org.kie.api.task.model.Content) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 3 with ContentData

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

the class ContentMarshallerHelper method marshal.

public static ContentData marshal(Task task, Object o, Environment env) {
    if (o == null) {
        return null;
    }
    ContentData content = null;
    byte[] toByteArray = marshallContent(task, o, env);
    content = TaskModelProvider.getFactory().newContentData();
    content.setContent(toByteArray);
    content.setType(o.getClass().getCanonicalName());
    content.setAccessType(AccessType.Inline);
    return content;
}
Also used : ContentData(org.kie.internal.task.api.model.ContentData)

Example 4 with ContentData

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompleted.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskCompleted() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    taskService.complete(taskId, "Administrator", null);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 5 with ContentData

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadline.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadline() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    Task task = (Task) TaskFactory.evalTask(reader, vars);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // 1 email with two recipients should now exist
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(1);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Aggregations

ContentData (org.kie.internal.task.api.model.ContentData)30 InternalContent (org.kie.internal.task.api.model.InternalContent)21 InternalTask (org.kie.internal.task.api.model.InternalTask)21 Test (org.junit.Test)19 Task (org.kie.api.task.model.Task)16 InputStreamReader (java.io.InputStreamReader)14 Reader (java.io.Reader)14 HashMap (java.util.HashMap)14 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 Content (org.kie.api.task.model.Content)11 User (org.kie.api.task.model.User)11 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)11 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)10 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)10 Date (java.util.Date)8 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)6 StringReader (java.io.StringReader)5