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
.springframework
.oxm
.Marshaller
;
15 import org
.apache
.commons
.io
.IOUtils
;
17 import org
.argeo
.slc
.core
.SlcException
;
19 public class FileSlcExecutionNotifier
implements SlcExecutionNotifier
{
20 private final static SimpleDateFormat sdf
= new SimpleDateFormat(
23 private String basePath
;
24 private Marshaller marshaller
;
26 private Map
<String
, String
> uuidToDir
= new HashMap
<String
, String
>();
28 public void addSteps(SlcExecution slcExecution
,
29 List
<SlcExecutionStep
> additionalSteps
) {
30 writeSlcExecution(slcExecution
);
33 public void newExecution(SlcExecution slcExecution
) {
34 String dirPath
= basePath
+ File
.separator
+ sdf
.format(new Date())
35 + '-' + slcExecution
.getUuid();
36 File dir
= new File(dirPath
);
39 uuidToDir
.put(slcExecution
.getUuid(), dirPath
);
41 writeSlcExecution(slcExecution
);
44 public void updateExecution(SlcExecution slcExecution
) {
45 writeSlcExecution(slcExecution
);
48 public void updateStatus(SlcExecution slcExecution
, String oldStatus
,
50 writeSlcExecution(slcExecution
);
53 protected void writeSlcExecution(SlcExecution slcExecution
) {
54 FileWriter out
= null;
56 out
= new FileWriter(getFilePath(slcExecution
));
57 marshaller
.marshal(slcExecution
, new StreamResult(out
));
58 } catch (Exception e
) {
59 throw new SlcException("Cannot marshall SlcExecution to "
60 + getFilePath(slcExecution
), e
);
62 IOUtils
.closeQuietly(out
);
66 protected String
getFileName(SlcExecution slcExecution
) {
67 return "SlcExecution-" + slcExecution
.getUuid() + ".xml";
70 protected String
getFilePath(SlcExecution slcExecution
) {
71 String dirPath
= uuidToDir
.get(slcExecution
.getUuid());
72 return dirPath
+ File
.separator
+ "SlcExecution-"
73 + slcExecution
.getUuid() + ".xml";
76 public void setBasePath(String basePath
) {
77 this.basePath
= basePath
;
80 public void setMarshaller(Marshaller marshaller
) {
81 this.marshaller
= marshaller
;