Search in sources :

Example 16 with ContentData

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

the class LifeCycleBaseTest method testNewTaskWithMapContent.

@Test
public void testNewTaskWithMapContent() {
    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 content = taskService.getContentById(contentId);
    Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    if (!(unmarshalledObject instanceof Map)) {
        fail("The variables should be a Map");
    }
    Map<String, Object> unmarshalledvars = (Map<String, Object>) unmarshalledObject;
    JaxbContent jaxbContent = xmlRoundTripContent(content);
    assertNotNull("Jaxb Content map not filled", jaxbContent.getContentMap());
    assertEquals("value1", unmarshalledvars.get("key1"));
    assertNull(unmarshalledvars.get("key2"));
    assertEquals("value3", unmarshalledvars.get("key3"));
}
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) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) Test(org.junit.Test)

Example 17 with ContentData

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

the class LifeCycleBaseTest method testNewTaskWithLargeContent.

@Test
public void testNewTaskWithLargeContent() {
    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' })";
    String largeContent = "";
    for (int i = 0; i < 1000; i++) {
        largeContent += i + "xxxxxxxxx";
    }
    ContentData data = ContentMarshallerHelper.marshal(null, largeContent, 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(largeContent, 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 18 with ContentData

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

the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData.

@Test
public void testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),";
    str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], ";
    str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], ";
    str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
    Task task = (Task) TaskFactory.evalTask(new StringReader(str));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("manager", "John");
    ContentData data = ContentMarshallerHelper.marshal(task, params, null);
    try {
        taskService.addTask(task, data);
        fail("Task should not be created due to rule violation");
    } catch (CannotAddTaskException e) {
        assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1);
    }
}
Also used : Task(org.kie.api.task.model.Task) CannotAddTaskException(org.jbpm.services.task.exception.CannotAddTaskException) ContentData(org.kie.internal.task.api.model.ContentData) HashMap(java.util.HashMap) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 19 with ContentData

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

the class TaskInstanceServiceImpl method setOutput.

public void setOutput(long taskId, String userId, Object outputContentData) {
    Task task = persistenceContext.findTask(taskId);
    ContentData contentData = ContentMarshallerHelper.marshal(task, outputContentData, environment);
    Content content = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content).setContent(contentData.getContent());
    persistenceContext.persistContent(content);
    persistenceContext.setOutputToTask(content, contentData, task);
}
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) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalContent(org.kie.internal.task.api.model.InternalContent)

Example 20 with ContentData

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

the class TaskInstanceServiceImpl method deleteOutput.

public void deleteOutput(long taskId, String userId) {
    Task task = persistenceContext.findTask(taskId);
    long contentId = task.getTaskData().getOutputContentId();
    Content content = persistenceContext.findContent(contentId);
    Map<String, Object> initialContent = new HashMap<>();
    ContentMarshallerContext context = TaskContentRegistry.get().getMarshallerContext(task);
    Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), context.getEnvironment(), context.getClassloader());
    if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
        // set initial content before updating with this params
        initialContent.putAll((Map<String, Object>) unmarshalledObject);
    }
    taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, this.context, initialContent);
    ContentData data = TaskModelProvider.getFactory().newContentData();
    persistenceContext.removeContent(content);
    persistenceContext.setOutputToTask(null, data, task);
    taskEventSupport.fireAfterTaskOutputVariablesChanged(task, this.context, null);
}
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) InternalContent(org.kie.internal.task.api.model.InternalContent) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

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