1 package org
.argeo
.slc
.core
.execution
.tasks
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
9 import org
.argeo
.slc
.SlcException
;
10 import org
.argeo
.slc
.attachment
.Attachment
;
11 import org
.argeo
.slc
.attachment
.AttachmentsEnabled
;
12 import org
.argeo
.slc
.core
.attachment
.AttachmentUploader
;
13 import org
.springframework
.core
.io
.Resource
;
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;
24 if (attachment
!= null) {
26 throw new SlcException("A resource must be specified.");
27 uploadAndAdd(attachment
, resource
);
30 for (Attachment attachmentT
: attachments
.keySet()) {
31 Resource resourceT
= attachments
.get(attachmentT
);
32 uploadAndAdd(attachmentT
, resourceT
);
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
);
46 public void setAttachmentUploader(AttachmentUploader attachmentUploader
) {
47 this.attachmentUploader
= attachmentUploader
;
50 public void setAttachments(Map
<Attachment
, Resource
> attachments
) {
51 this.attachments
= attachments
;
54 public void setAttachTo(List
<AttachmentsEnabled
> attachTo
) {
55 this.attachTo
= attachTo
;
58 public void setAttachment(Attachment attachment
) {
59 this.attachment
= attachment
;
62 public void setResource(Resource resource
) {
63 this.resource
= resource
;
66 public void setNewUuidPerExecution(Boolean newUuidPerExecution
) {
67 this.newUuidPerExecution
= newUuidPerExecution
;