Search in sources :

Example 1 with Attachment

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

the class ETaskAttachmentTest method testAttachment.

@Test
public void testAttachment() {
    ejb.startProcess(ProcessDefinitions.HUMAN_TASK);
    List<TaskSummary> taskSummaryList = ejb.getTasksAssignedAsPotentialOwner(userId);
    Assertions.assertThat(taskSummaryList.size()).isEqualTo(1);
    // Add a attachment
    Long taskId = taskSummaryList.get(0).getId();
    ejb.addAttachment(taskId, userId, STRING_ATTACHMENT_NAME, STRING_ATTACHMENT);
    // Get the attachment
    Attachment attachment = getAttachment(taskId);
    Assertions.assertThat(attachment.getName()).isEqualTo(STRING_ATTACHMENT_NAME);
    Assertions.assertThat(attachment.getAttachedBy().getId()).isEqualTo(userId);
    Assertions.assertThat(attachment.getContentType()).isEqualTo(STRING_ATTACHMENT.getClass().getName());
    Assertions.assertThat(attachment.getSize()).isEqualTo(persist(STRING_ATTACHMENT).length);
    Object content = getContent(taskId, attachment.getId());
    Assertions.assertThat(content).isEqualTo(STRING_ATTACHMENT);
    // Delete the attachment
    ejb.deleteAttachment(taskId, attachment.getId());
    attachment = getAttachment(taskId);
    Assertions.assertThat(attachment).isNull();
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Attachment(org.kie.api.task.model.Attachment) RemoteEjbTest(org.jbpm.remote.ejb.test.RemoteEjbTest) Test(org.junit.Test)

Example 2 with Attachment

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

the class ETaskAttachmentTest method testCustomAttachment.

@Test
public void testCustomAttachment() throws IOException {
    ejb.startProcess(ProcessDefinitions.HUMAN_TASK);
    List<TaskSummary> taskSummaryList = ejb.getTasksAssignedAsPotentialOwner(userId);
    Long taskId = taskSummaryList.get(0).getId();
    // Add attachment
    Person lisa = new Person("Lisa Simpson", 7);
    ejb.addAttachment(taskId, userId, "Lisa", lisa);
    // Get the attachment
    Attachment attachment = getAttachment(taskId);
    Assertions.assertThat(attachment.getContentType()).isEqualTo(lisa.getClass().getName());
    Assertions.assertThat(attachment.getSize()).isEqualTo(persist(lisa).length);
    // Get the attachment content
    Object content = getContent(taskId, attachment.getId());
    Assertions.assertThat(content).isEqualTo(lisa);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Attachment(org.kie.api.task.model.Attachment) Person(org.jboss.qa.bpms.remote.ejb.domain.Person) RemoteEjbTest(org.jbpm.remote.ejb.test.RemoteEjbTest) Test(org.junit.Test)

Example 3 with Attachment

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

the class CollectionUtils method readAttachmentList.

public static List<Attachment> readAttachmentList(ObjectInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    List<Attachment> list = new ArrayList<Attachment>(size);
    for (int i = 0; i < size; i++) {
        Attachment item = new AttachmentImpl();
        item.readExternal(in);
        list.add(item);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Attachment(org.kie.api.task.model.Attachment) AttachmentImpl(org.jbpm.services.task.impl.model.AttachmentImpl)

Example 4 with Attachment

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

the class AddAttachmentCommand method execute.

public Long execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Attachment attachmentImpl = attachment;
    if (attachmentImpl == null) {
        attachmentImpl = jaxbAttachment;
    }
    Content contentImpl = content;
    if (contentImpl == null) {
        contentImpl = jaxbContent;
    }
    if (rawContent != null && contentImpl == null) {
        Task task = context.getPersistenceContext().findTask(taskId);
        contentImpl = TaskModelProvider.getFactory().newContent();
        ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getTaskData().getDeploymentId());
        ((InternalContent) contentImpl).setContent(ContentMarshallerHelper.marshallContent(task, rawContent, ctx.getEnvironment()));
        ((InternalAttachment) attachmentImpl).setSize(contentImpl.getContent().length);
    }
    doCallbackOperationForAttachment(attachmentImpl, context);
    return context.getTaskAttachmentService().addAttachment(taskId, attachmentImpl, contentImpl);
}
Also used : Task(org.kie.api.task.model.Task) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) Content(org.kie.api.task.model.Content) InternalContent(org.kie.internal.task.api.model.InternalContent) JaxbContent(org.jbpm.services.task.impl.model.xml.JaxbContent) JaxbAttachment(org.jbpm.services.task.impl.model.xml.JaxbAttachment) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalContent(org.kie.internal.task.api.model.InternalContent) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 5 with Attachment

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

the class ETaskAttachmentTest method getAttachment.

private Attachment getAttachment(Long taskId) {
    List<Attachment> attachmentList = getAttachments(taskId);
    Attachment attachment = null;
    if (!attachmentList.isEmpty()) {
        attachment = attachmentList.get(0);
    }
    return attachment;
}
Also used : Attachment(org.kie.api.task.model.Attachment)

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