]> 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
Reduce log verbosity
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / UploadAttachments.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution.tasks;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.UUID;
24
25 import org.argeo.slc.SlcException;
26 import org.argeo.slc.core.attachment.Attachment;
27 import org.argeo.slc.core.attachment.AttachmentUploader;
28 import org.argeo.slc.core.attachment.AttachmentsEnabled;
29 import org.springframework.core.io.Resource;
30
31 public class UploadAttachments implements Runnable {
32 private AttachmentUploader attachmentUploader;
33 private Attachment attachment = null;
34 private Resource resource = null;
35 private Map<Attachment, Resource> attachments = new HashMap<Attachment, Resource>();
36 private List<AttachmentsEnabled> attachTo = new ArrayList<AttachmentsEnabled>();
37 private Boolean newUuidPerExecution = true;
38
39 public void run() {
40 if (attachment != null) {
41 if (resource == null)
42 throw new SlcException("A resource must be specified.");
43 uploadAndAdd(attachment, resource);
44 }
45
46 for (Attachment attachmentT : attachments.keySet()) {
47 Resource resourceT = attachments.get(attachmentT);
48 uploadAndAdd(attachmentT, resourceT);
49 }
50
51 }
52
53 protected void uploadAndAdd(Attachment attachment, Resource resource) {
54 if (newUuidPerExecution)
55 attachment.setUuid(UUID.randomUUID().toString());
56 attachmentUploader.upload(attachment, resource);
57 for (AttachmentsEnabled attachmentsEnabled : attachTo) {
58 attachmentsEnabled.addAttachment(attachment);
59 }
60 }
61
62 public void setAttachmentUploader(AttachmentUploader attachmentUploader) {
63 this.attachmentUploader = attachmentUploader;
64 }
65
66 public void setAttachments(Map<Attachment, Resource> attachments) {
67 this.attachments = attachments;
68 }
69
70 public void setAttachTo(List<AttachmentsEnabled> attachTo) {
71 this.attachTo = attachTo;
72 }
73
74 public void setAttachment(Attachment attachment) {
75 this.attachment = attachment;
76 }
77
78 public void setResource(Resource resource) {
79 this.resource = resource;
80 }
81
82 public void setNewUuidPerExecution(Boolean newUuidPerExecution) {
83 this.newUuidPerExecution = newUuidPerExecution;
84 }
85
86 }