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); }
public JaxbAttachment(Attachment attachment) { super(attachment, Attachment.class); User attacher = attachment.getAttachedBy(); if( attacher != null ) { this.attachedBy = attacher.getId(); } }
@Override public Attachment persistAttachment(Attachment attachment) { check(); this.em.persist( attachment ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(AttachmentImpl.class, attachment.getId(), LockModeType.PESSIMISTIC_WRITE ); } return attachment; }
for( Attachment jaxbAttach : jaxbAttachments ) { InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment(); if( jaxbAttach.getId() != null ) { attach.setId(jaxbAttach.getId()); attach.setName(jaxbAttach.getName()); attach.setContentType(jaxbAttach.getContentType()); attach.setAttachedAt(jaxbAttach.getAttachedAt()); attach.setAttachedBy(createUser(((JaxbAttachment) jaxbAttach).getAttachedById())); attach.setSize(jaxbAttach.getSize()); attach.setAttachmentContentId(jaxbAttach.getAttachmentContentId()); attachments.add(attach);
assertEquals("john", attachment.getAttachedBy().getId()); assertEquals("my attachment", attachment.getName()); assertNotNull(attachment.getAttachmentContentId());
import java.io.File; import java.sql.*; import net.ucanaccess.complex.Attachment; ... String dbFileSpec = "C:/Users/Public/AttachmentsDB.accdb"; String connStr = "jdbc:ucanaccess://" + dbFileSpec; try (Connection conn = DriverManager.getConnection(connStr)) { try (Statement s = conn.createStatement()) { try (ResultSet rs = s.executeQuery( "SELECT Attachments FROM AttachmentsTable WHERE ID=1")) { rs.next(); // retrieve array of net.ucanaccess.complex.Attachment objects Attachment[] atts = (Attachment[]) rs.getObject(1); for (Attachment att : atts) { System.out.println(att.getName()); org.apache.commons.io.FileUtils.writeByteArrayToFile( new File("C:/Users/Gord/Desktop/" + att.getName()), att.getData()); } } } }
public String getAttachmentById(String containerId, Number taskId, Number attachmentId, String marshallingType) { containerId = context.getContainerId(containerId, new ByTaskIdContainerLocator(taskId.longValue())); Attachment attachment = userTaskService.getAttachmentById(containerId, taskId.longValue(), attachmentId.longValue()); TaskAttachment taskAttachment = TaskAttachment.builder() .id(attachment.getId()) .name(attachment.getName()) .addedBy(attachment.getAttachedBy().getId()) .addedAt(attachment.getAttachedAt()) .attachmentContentId(attachment.getAttachmentContentId()) .contentType(attachment.getContentType()) .size(attachment.getSize()) .build(); logger.debug("About to marshal task '{}' attachment {} with content {}", taskId, attachmentId, taskAttachment); String response = marshallerHelper.marshal(containerId, marshallingType, taskAttachment); return response; }
public String getAttachmentsByTaskId(String containerId, Number taskId, String marshallingType) { containerId = context.getContainerId(containerId, new ByTaskIdContainerLocator(taskId.longValue())); List<Attachment> attachments = userTaskService.getAttachmentsByTaskId(containerId, taskId.longValue()); TaskAttachment[] taskComments = new TaskAttachment[attachments.size()]; int counter = 0; for (Attachment attachment : attachments) { TaskAttachment taskComment = TaskAttachment.builder() .id(attachment.getId()) .name(attachment.getName()) .addedBy(attachment.getAttachedBy().getId()) .addedAt(attachment.getAttachedAt()) .contentType(attachment.getContentType()) .attachmentContentId(attachment.getAttachmentContentId()) .size(attachment.getSize()) .build(); taskComments[counter] = taskComment; counter++; } TaskAttachmentList result = new TaskAttachmentList(taskComments); logger.debug("About to marshal task '{}' attachments {}", taskId, result); String response = marshallerHelper.marshal(containerId, marshallingType, result); return response; }
/** * Removes the Attachment specified by the attachmentId. * * @param attachmentId id of attachment to remove * @return removed Attachment or null if one was not found with the id */ public Attachment removeAttachment(final long attachmentId) { Attachment removedAttachment = null; if (attachments != null) { for (int index = attachments.size() - 1; index >= 0; --index) { Attachment currentAttachment = attachments.get(index); if (currentAttachment.getId() == attachmentId) { removedAttachment = attachments.remove(index); break; } } } return removedAttachment; }
long firstAttachContentId = firstAttach.getAttachmentContentId(); Content firstAttachContent = taskService.getContentById(firstAttachContentId); String firstDocString = (String)ContentMarshallerHelper.unmarshall(firstAttachContent.getContent(), null); long secondAttachContentId = secondAttach.getAttachmentContentId(); Content secondAttachContent = taskService.getContentById(secondAttachContentId); String secondDocString = (String)ContentMarshallerHelper.unmarshall(secondAttachContent.getContent(), null);
protected void doCallbackOperationForAttachment(Attachment attachment, TaskContext context) { if (attachment != null) { if (attachment.getAttachedBy() != null) { User entity = doCallbackAndReturnUserOperation(attachment.getAttachedBy().getId(), context); if (entity != null) { ((InternalAttachment)attachment).setAttachedBy(entity); } } } }
for( Attachment attach : attachs ) { org.kie.remote.jaxb.gen.Attachment genAttach = new org.kie.remote.jaxb.gen.Attachment(); genAttach.setId(attach.getId()); genAttach.setName(attach.getName()); genAttach.setContentType(attach.getContentType()); genAttach.setAttachedAt(convertDateToXmlGregorianCalendar(attach.getAttachedAt())); genAttach.setAttachedBy(attach.getAttachedBy().getId()); genAttach.setSize(attach.getSize()); genAttach.setAttachmentContentId(attach.getAttachmentContentId()); genTaskData.getAttachments().add(genAttach);
public long addAttachment(long taskId, Attachment attachment, Content content) { Task task = persistenceContext.findTask(taskId); persistenceContext.persistAttachment(attachment); persistenceContext.persistContent(content); ((InternalAttachment) attachment).setContent(content); persistenceContext.addAttachmentToTask(attachment, task); return attachment.getId(); }
/** * Removes the Attachment specified by the attachmentId. * * @param attachmentId id of attachment to remove * @return removed Attachment or null if one was not found with the id */ public Attachment removeAttachment(final long attachmentId) { Attachment removedAttachment = null; if (attachments != null) { for (int index = attachments.size() - 1; index >= 0; --index) { Attachment currentAttachment = attachments.get(index); if (currentAttachment.getId() == attachmentId) { removedAttachment = attachments.remove(index); break; } } } return removedAttachment; }
@Override public Attachment persistAttachment(Attachment attachment) { check(); this.em.persist( attachment ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(AttachmentImpl.class, attachment.getId(), LockModeType.PESSIMISTIC_WRITE ); } return attachment; }