1 package org
.argeo
.slc
.xml
.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
.SlcException
;
15 import org
.argeo
.slc
.process
.SlcExecution
;
16 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
17 import org
.argeo
.slc
.process
.SlcExecutionStep
;
18 import org
.springframework
.oxm
.Marshaller
;
20 public class FileSlcExecutionNotifier
implements SlcExecutionNotifier
{
21 private final static SimpleDateFormat sdf
= new SimpleDateFormat(
24 private String basePath
;
25 private Marshaller marshaller
;
27 private Map
<String
, String
> uuidToDir
= new HashMap
<String
, String
>();
29 public void addSteps(SlcExecution slcExecution
,
30 List
<SlcExecutionStep
> additionalSteps
) {
31 writeSlcExecution(slcExecution
);
34 public void newExecution(SlcExecution slcExecution
) {
35 String dirPath
= basePath
+ File
.separator
+ sdf
.format(new Date())
36 + '-' + slcExecution
.getUuid();
37 File dir
= new File(dirPath
);
40 uuidToDir
.put(slcExecution
.getUuid(), dirPath
);
42 writeSlcExecution(slcExecution
);
45 public void updateExecution(SlcExecution slcExecution
) {
46 writeSlcExecution(slcExecution
);
49 public void updateStatus(SlcExecution slcExecution
, String oldStatus
,
51 writeSlcExecution(slcExecution
);
54 protected void writeSlcExecution(SlcExecution slcExecution
) {
55 FileWriter out
= null;
57 out
= new FileWriter(getFilePath(slcExecution
));
58 marshaller
.marshal(slcExecution
, new StreamResult(out
));
59 } catch (Exception e
) {
60 throw new SlcException("Cannot marshall SlcExecution to "
61 + getFilePath(slcExecution
), e
);
63 IOUtils
.closeQuietly(out
);
67 protected String
getFileName(SlcExecution slcExecution
) {
68 return "SlcExecution-" + slcExecution
.getUuid() + ".xml";
71 protected String
getFilePath(SlcExecution slcExecution
) {
72 String dirPath
= uuidToDir
.get(slcExecution
.getUuid());
73 return dirPath
+ File
.separator
+ "SlcExecution-"
74 + slcExecution
.getUuid() + ".xml";
77 public void setBasePath(String basePath
) {
78 this.basePath
= basePath
;
81 public void setMarshaller(Marshaller marshaller
) {
82 this.marshaller
= marshaller
;