]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/UploadAttachments.java
Improve executions and system calls
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / UploadAttachments.java
1 package org.argeo.slc.core.execution.tasks;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7 import java.util.UUID;
8
9 import org.argeo.slc.SlcException;
10 import org.argeo.slc.core.attachment.Attachment;
11 import org.argeo.slc.core.attachment.AttachmentUploader;
12 import org.argeo.slc.core.attachment.AttachmentsEnabled;
13 import org.springframework.core.io.Resource;
14
15 public class UploadAttachments implements Runnable {
16 private AttachmentUploader attachmentUploader;
17 private Attachment attachment = null;
18 private Resource resource = null;
19 private Map<Attachment, Resource> attachments = new HashMap<Attachment, Resource>();
20 private List<AttachmentsEnabled> attachTo = new ArrayList<AttachmentsEnabled>();
21 private Boolean newUuidPerExecution = true;
22
23 public void run() {
24 if (attachment != null) {
25 if (resource == null)
26 throw new SlcException("A resource must be specified.");
27 uploadAndAdd(attachment, resource);
28 }
29
30 for (Attachment attachmentT : attachments.keySet()) {
31 Resource resourceT = attachments.get(attachmentT);
32 uploadAndAdd(attachmentT, resourceT);
33 }
34
35 }
36
37 protected void uploadAndAdd(Attachment attachment, Resource resource) {
38 if (newUuidPerExecution)
39 attachment.setUuid(UUID.randomUUID().toString());
40 attachmentUploader.upload(attachment, resource);
41 for (AttachmentsEnabled attachmentsEnabled : attachTo) {
42 attachmentsEnabled.addAttachment(attachment);
43 }
44 }
45
46 public void setAttachmentUploader(AttachmentUploader attachmentUploader) {
47 this.attachmentUploader = attachmentUploader;
48 }
49
50 public void setAttachments(Map<Attachment, Resource> attachments) {
51 this.attachments = attachments;
52 }
53
54 public void setAttachTo(List<AttachmentsEnabled> attachTo) {
55 this.attachTo = attachTo;
56 }
57
58 public void setAttachment(Attachment attachment) {
59 this.attachment = attachment;
60 }
61
62 public void setResource(Resource resource) {
63 this.resource = resource;
64 }
65
66 public void setNewUuidPerExecution(Boolean newUuidPerExecution) {
67 this.newUuidPerExecution = newUuidPerExecution;
68 }
69
70 }