1 package org
.argeo
.slc
.core
.process
;
4 import java
.io
.FileWriter
;
5 import java
.text
.SimpleDateFormat
;
7 import java
.util
.HashMap
;
11 import javax
.xml
.transform
.stream
.StreamResult
;
13 import org
.apache
.commons
.io
.IOUtils
;
14 import org
.argeo
.slc
.core
.SlcException
;
15 import org
.springframework
.oxm
.Marshaller
;
17 public class FileSlcExecutionNotifier
implements SlcExecutionNotifier
{
18 private final static SimpleDateFormat sdf
= new SimpleDateFormat(
21 private String basePath
;
22 private Marshaller marshaller
;
24 private Map
<String
, String
> uuidToDir
= new HashMap
<String
, String
>();
26 public void addSteps(SlcExecution slcExecution
,
27 List
<SlcExecutionStep
> additionalSteps
) {
28 writeSlcExecution(slcExecution
);
31 public void newExecution(SlcExecution slcExecution
) {
32 String dirPath
= basePath
+ File
.separator
+ sdf
.format(new Date())
33 + '-' + slcExecution
.getUuid();
34 File dir
= new File(dirPath
);
37 uuidToDir
.put(slcExecution
.getUuid(), dirPath
);
39 writeSlcExecution(slcExecution
);
42 public void updateExecution(SlcExecution slcExecution
) {
43 writeSlcExecution(slcExecution
);
46 public void updateStatus(SlcExecution slcExecution
, String oldStatus
,
48 writeSlcExecution(slcExecution
);
51 protected void writeSlcExecution(SlcExecution slcExecution
) {
52 FileWriter out
= null;
54 out
= new FileWriter(getFilePath(slcExecution
));
55 marshaller
.marshal(slcExecution
, new StreamResult(out
));
56 } catch (Exception e
) {
57 throw new SlcException("Cannot marshall SlcExecution to "
58 + getFilePath(slcExecution
), e
);
60 IOUtils
.closeQuietly(out
);
64 protected String
getFileName(SlcExecution slcExecution
) {
65 return "SlcExecution-" + slcExecution
.getUuid() + ".xml";
68 protected String
getFilePath(SlcExecution slcExecution
) {
69 String dirPath
= uuidToDir
.get(slcExecution
.getUuid());
70 return dirPath
+ File
.separator
+ "SlcExecution-"
71 + slcExecution
.getUuid() + ".xml";
74 public void setBasePath(String basePath
) {
75 this.basePath
= basePath
;
78 public void setMarshaller(Marshaller marshaller
) {
79 this.marshaller
= marshaller
;