]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/tasks/UploadAttachments.java
Attachments management
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / 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
8 import org.argeo.slc.SlcException;
9 import org.argeo.slc.core.attachment.Attachment;
10 import org.argeo.slc.core.attachment.AttachmentUploader;
11 import org.argeo.slc.core.attachment.AttachmentsEnabled;
12 import org.springframework.core.io.Resource;
13
14 public class UploadAttachments implements Runnable {
15 private AttachmentUploader attachmentUploader;
16 private Attachment attachment = null;
17 private Resource resource = null;
18 private Map<Attachment, Resource> attachments = new HashMap<Attachment, Resource>();
19 private List<AttachmentsEnabled> attachTo = new ArrayList<AttachmentsEnabled>();
20
21 public void run() {
22 if (attachment != null) {
23 if (resource == null)
24 throw new SlcException("A resource must be specified.");
25 uploadAndAdd(attachment, resource);
26 }
27
28 for (Attachment attachmentT : attachments.keySet()) {
29 Resource resourceT = attachments.get(attachmentT);
30 uploadAndAdd(attachmentT, resourceT);
31 }
32
33 }
34
35 protected void uploadAndAdd(Attachment attachment, Resource resource) {
36 attachmentUploader.upload(attachment, resource);
37 for (AttachmentsEnabled attachmentsEnabled : attachTo) {
38 attachmentsEnabled.addAttachment(attachment);
39 }
40 }
41
42 public void setAttachmentUploader(AttachmentUploader attachmentUploader) {
43 this.attachmentUploader = attachmentUploader;
44 }
45
46 public void setAttachments(Map<Attachment, Resource> attachments) {
47 this.attachments = attachments;
48 }
49
50 public void setAttachTo(List<AttachmentsEnabled> attachTo) {
51 this.attachTo = attachTo;
52 }
53
54 public void setAttachment(Attachment attachment) {
55 this.attachment = attachment;
56 }
57
58 public void setResource(Resource resource) {
59 this.resource = resource;
60 }
61
62 }