Search in sources :

Example 31 with Content

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

the class TaskInstanceServiceImpl method addTask.

public long addTask(Task task, ContentData contentData) {
    taskEventSupport.fireBeforeTaskAdded(task, context);
    persistenceContext.persistTask(task);
    resolveTaskDetailsForTaskProperties(task);
    if (contentData != null) {
        Content content = TaskModelProvider.getFactory().newContent();
        ((InternalContent) content).setContent(contentData.getContent());
        persistenceContext.persistContent(content);
        persistenceContext.setDocumentToTask(content, contentData, task);
    }
    taskEventSupport.fireAfterTaskAdded(task, context);
    return task.getId();
}
Also used : Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalContent(org.kie.internal.task.api.model.InternalContent)

Example 32 with Content

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

the class TaskAttachmentBaseTest method testAttachmentWithStringInlineContent.

@Test
public void testAttachmentWithStringInlineContent() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [new User('Bobba Fet')], }),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsBusinessAdministrator("Bobba Fet", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSum = tasks.get(0);
    Attachment attach = TaskModelProvider.getFactory().newAttachment();
    ((InternalAttachment) attach).setAccessType(AccessType.Inline);
    ((InternalAttachment) attach).setAttachedAt(new Date());
    ((InternalAttachment) attach).setName("My first doc");
    ((InternalAttachment) attach).setContentType("String");
    Content content = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content).setContent(ContentMarshallerHelper.marshallContent(task, "This is my first inline document", null));
    long attachId = taskService.addAttachment(taskSum.getId(), attach, content);
    Assert.assertNotEquals(0, attachId);
    Attachment attachmentById = taskService.getAttachmentById(attachId);
    Assert.assertNotNull(attachmentById);
    Attachment attach2 = TaskModelProvider.getFactory().newAttachment();
    ((InternalAttachment) attach2).setAccessType(AccessType.Inline);
    ((InternalAttachment) attach2).setAttachedAt(new Date());
    ((InternalAttachment) attach2).setName("My second doc");
    ((InternalAttachment) attach2).setContentType("String");
    Content content2 = TaskModelProvider.getFactory().newContent();
    ((InternalContent) content2).setContent(ContentMarshallerHelper.marshallContent(task, "This is my second inline document", null));
    attachId = taskService.addAttachment(taskSum.getId(), attach2, content2);
    Assert.assertNotEquals(0, attachId);
    attachmentById = taskService.getAttachmentById(attachId);
    Assert.assertNotNull(attachmentById);
    List<Attachment> allAttachmentsByTaskId = taskService.getAllAttachmentsByTaskId(taskSum.getId());
    assertEquals(2, allAttachmentsByTaskId.size());
    Attachment firstAttach = allAttachmentsByTaskId.get(0);
    long firstAttachContentId = firstAttach.getAttachmentContentId();
    Content firstAttachContent = taskService.getContentById(firstAttachContentId);
    String firstDocString = (String) ContentMarshallerHelper.unmarshall(firstAttachContent.getContent(), null);
    assertEquals("This is my first inline document", firstDocString);
    Attachment secondAttach = allAttachmentsByTaskId.get(1);
    long secondAttachContentId = secondAttach.getAttachmentContentId();
    Content secondAttachContent = taskService.getContentById(secondAttachContentId);
    String secondDocString = (String) ContentMarshallerHelper.unmarshall(secondAttachContent.getContent(), null);
    assertEquals("This is my second inline document", secondDocString);
}
Also used : Task(org.kie.api.task.model.Task) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalContent(org.kie.internal.task.api.model.InternalContent) Date(java.util.Date) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 33 with Content

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

the class TaskAdminServiceImpl method removeTasks.

public int removeTasks(List<TaskSummary> tasks) {
    int removedTasks = 0;
    for (TaskSummary sum : tasks) {
        long taskId = sum.getId();
        // Only remove archived tasks
        Task task = persistenceContext.findTask(taskId);
        if (task != null) {
            Content content = persistenceContext.findContent(task.getTaskData().getDocumentContentId());
            Content outputContent = persistenceContext.findContent(task.getTaskData().getOutputContentId());
            if (((InternalTask) task).isArchived()) {
                persistenceContext.remove(task);
                if (content != null) {
                    persistenceContext.remove(content);
                }
                if (outputContent != null) {
                    persistenceContext.remove(outputContent);
                }
                removedTasks++;
            } else {
                logger.warn(" The Task cannot be removed if it wasn't archived first !!");
            }
        }
    }
    return removedTasks;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTask(org.kie.internal.task.api.model.InternalTask) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary)

Example 34 with Content

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

the class TaskAttachmentServiceImpl method deleteAttachment.

public void deleteAttachment(long taskId, long attachmentId) {
    Task task = persistenceContext.findTask(taskId);
    Attachment attachment = persistenceContext.removeAttachmentFromTask(task, attachmentId);
    Content content = persistenceContext.findContent(attachment.getAttachmentContentId());
    persistenceContext.removeContent(content);
}
Also used : Task(org.kie.api.task.model.Task) Content(org.kie.api.task.model.Content) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) Attachment(org.kie.api.task.model.Attachment)

Example 35 with Content

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

the class TaskContentServiceImpl method addOutputContent.

@SuppressWarnings("unchecked")
public long addOutputContent(long taskId, Map<String, Object> params) {
    Task task = persistenceContext.findTask(taskId);
    loadTaskVariables(task);
    long outputContentId = task.getTaskData().getOutputContentId();
    Content outputContent = persistenceContext.findContent(outputContentId);
    Map<String, Object> initialContent = new HashMap<>();
    long contentId = -1;
    if (outputContent == null) {
        ContentMarshallerContext context = getMarshallerContext(task);
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, params, context.getEnvironment());
        Content content = TaskModelProvider.getFactory().newContent();
        ((InternalContent) content).setContent(outputContentData.getContent());
        persistenceContext.persistContent(content);
        persistenceContext.setOutputToTask(content, outputContentData, task);
        contentId = content.getId();
    } else {
        // I need to merge it if it already exist
        ContentMarshallerContext context = getMarshallerContext(task);
        Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.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);
            ((Map<String, Object>) unmarshalledObject).putAll(params);
        }
        ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment());
        ((InternalContent) outputContent).setContent(outputContentData.getContent());
        persistenceContext.persistContent(outputContent);
        contentId = outputContentId;
    }
    taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
    ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(params);
    taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params);
    persistenceContext.updateTask(task);
    return contentId;
}
Also used : Task(org.kie.api.task.model.Task) 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) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) 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