1 package org
.argeo
.slc
.core
.execution
.tasks
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
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
;
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
>();
22 if (attachment
!= null) {
24 throw new SlcException("A resource must be specified.");
25 uploadAndAdd(attachment
, resource
);
28 for (Attachment attachmentT
: attachments
.keySet()) {
29 Resource resourceT
= attachments
.get(attachmentT
);
30 uploadAndAdd(attachmentT
, resourceT
);
35 protected void uploadAndAdd(Attachment attachment
, Resource resource
) {
36 attachmentUploader
.upload(attachment
, resource
);
37 for (AttachmentsEnabled attachmentsEnabled
: attachTo
) {
38 attachmentsEnabled
.addAttachment(attachment
);
42 public void setAttachmentUploader(AttachmentUploader attachmentUploader
) {
43 this.attachmentUploader
= attachmentUploader
;
46 public void setAttachments(Map
<Attachment
, Resource
> attachments
) {
47 this.attachments
= attachments
;
50 public void setAttachTo(List
<AttachmentsEnabled
> attachTo
) {
51 this.attachTo
= attachTo
;
54 public void setAttachment(Attachment attachment
) {
55 this.attachment
= attachment
;
58 public void setResource(Resource resource
) {
59 this.resource
= resource
;