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();
}
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);
}
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;
}
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);
}
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;
}
Aggregations