Search in sources :

Example 26 with Content

use of org.kie.api.task.model.Content 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 27 with Content

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

the class LifeCycleBaseTest method getTaskOutput.

protected Map<String, Object> getTaskOutput(Task task) {
    long documentContentId = task.getTaskData().getOutputContentId();
    if (documentContentId > 0) {
        Content contentById = taskService.getContentById(documentContentId);
        if (contentById == null) {
            return new HashMap<String, Object>();
        }
        Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
        return (Map<String, Object>) unmarshall;
    }
    return new HashMap<String, Object>();
}
Also used : HashMap(java.util.HashMap) Content(org.kie.api.task.model.Content) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with Content

use of org.kie.api.task.model.Content 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 29 with Content

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

the class TaskInstanceServiceImpl method setFault.

public void setFault(long taskId, String userId, FaultData fault) {
    Task task = persistenceContext.findTask(taskId);
    Content content = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content).setContent(fault.getContent());
    persistenceContext.persistContent(content);
    persistenceContext.setFaultToTask(content, fault, task);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalContent(org.kie.internal.task.api.model.InternalContent)

Example 30 with Content

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

Content (org.kie.api.task.model.Content)40 Task (org.kie.api.task.model.Task)32 HashMap (java.util.HashMap)23 Map (java.util.Map)21 InternalContent (org.kie.internal.task.api.model.InternalContent)17 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)15 InternalTask (org.kie.internal.task.api.model.InternalTask)14 ContentData (org.kie.internal.task.api.model.ContentData)11 Test (org.junit.Test)10 JaxbContent (org.jbpm.services.task.impl.model.xml.JaxbContent)9 StringReader (java.io.StringReader)8 TaskService (org.kie.api.task.TaskService)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)6 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 InternalTaskService (org.kie.internal.task.api.InternalTaskService)5 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4 Attachment (org.kie.api.task.model.Attachment)4