Search in sources :

Example 11 with Attachment

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

the class UserTaskServiceImpl method getAttachmentContentById.

@Override
public Object getAttachmentContentById(String deploymentId, Long taskId, Long attachmentId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        // perform actual operation
        TaskService taskService = engine.getTaskService();
        Attachment attachment = ((InternalTaskService) taskService).getAttachmentById(attachmentId);
        long documentContentId = attachment.getAttachmentContentId();
        if (documentContentId > 0) {
            Content contentById = taskService.getContentById(documentContentId);
            if (contentById == null) {
                return null;
            }
            ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getDeploymentId());
            Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), ctx.getEnvironment(), ctx.getClassloader());
            return unmarshall;
        }
        return null;
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) Content(org.kie.api.task.model.Content) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 12 with Attachment

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

the class UserTaskServiceEJBIntegrationTest method testAttachmentOperations.

@Test
public void testAttachmentOperations() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
    assertNotNull(taskIds);
    assertEquals(1, taskIds.size());
    Long taskId = taskIds.get(0);
    List<Attachment> attachments = userTaskService.getAttachmentsByTaskId(taskId);
    assertNotNull(attachments);
    assertEquals(0, attachments.size());
    Long attId = userTaskService.addAttachment(taskId, "john", "my attachment", "String attachment");
    assertNotNull(attId);
    attachments = userTaskService.getAttachmentsByTaskId(taskId);
    assertNotNull(attachments);
    assertEquals(1, attachments.size());
    String content = (String) userTaskService.getAttachmentContentById(taskId, attId);
    assertNotNull(content);
    assertEquals("String attachment", content);
    Attachment attachment = userTaskService.getAttachmentById(taskId, attId);
    assertNotNull(attachment);
    assertEquals("john", attachment.getAttachedBy().getId());
    assertEquals("my attachment", attachment.getName());
    assertNotNull(attachment.getAttachmentContentId());
    userTaskService.deleteAttachment(taskId, attId);
    attachments = userTaskService.getAttachmentsByTaskId(taskId);
    assertNotNull(attachments);
    assertEquals(0, attachments.size());
}
Also used : Attachment(org.kie.api.task.model.Attachment) Test(org.junit.Test)

Aggregations

Attachment (org.kie.api.task.model.Attachment)12 Test (org.junit.Test)5 InternalAttachment (org.kie.internal.task.api.model.InternalAttachment)5 Content (org.kie.api.task.model.Content)4 Task (org.kie.api.task.model.Task)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 ArrayList (java.util.ArrayList)2 RemoteEjbTest (org.jbpm.remote.ejb.test.RemoteEjbTest)2 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)2 InternalContent (org.kie.internal.task.api.model.InternalContent)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 StringReader (java.io.StringReader)1 Date (java.util.Date)1 List (java.util.List)1 Person (org.jboss.qa.bpms.remote.ejb.domain.Person)1 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)1 TaskInstanceView (org.jbpm.persistence.api.integration.model.TaskInstanceView)1 UserTaskService (org.jbpm.services.api.UserTaskService)1 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)1 AttachmentImpl (org.jbpm.services.task.impl.model.AttachmentImpl)1