2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.xml
.process
;
19 import java
.io
.FileWriter
;
20 import java
.util
.HashMap
;
21 import java
.util
.List
;
24 import javax
.xml
.transform
.stream
.StreamResult
;
26 import org
.apache
.commons
.io
.IOUtils
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.argeo
.slc
.execution
.ExecutionProcess
;
29 import org
.argeo
.slc
.process
.SlcExecution
;
30 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
31 import org
.argeo
.slc
.execution
.ExecutionStep
;
32 import org
.argeo
.slc
.process
.SlcExecutionStep
;
33 import org
.springframework
.oxm
.Marshaller
;
35 /** @deprecated Probably not even working anymore */
36 public class FileSlcExecutionNotifier
implements SlcExecutionNotifier
{
37 // private final static SimpleDateFormat sdf = new SimpleDateFormat(
38 // "yyyyMMdd-HHmmss");
40 // private String basePath;
41 private Marshaller marshaller
;
43 private Map
<String
, String
> uuidToDir
= new HashMap
<String
, String
>();
45 public void addSteps(ExecutionProcess slcExecution
,
46 List
<ExecutionStep
> additionalSteps
) {
47 writeSlcExecution(slcExecution
);
50 public void updateStatus(ExecutionProcess slcExecution
, String oldStatus
,
52 writeSlcExecution(slcExecution
);
55 protected void writeSlcExecution(ExecutionProcess process
) {
56 if (!(process
instanceof SlcExecution
))
57 throw new SlcException("Unsupported process type "
58 + process
.getClass());
59 SlcExecution slcExecution
= (SlcExecution
) process
;
60 FileWriter out
= null;
62 out
= new FileWriter(getFilePath(slcExecution
));
63 marshaller
.marshal(slcExecution
, new StreamResult(out
));
64 } catch (Exception e
) {
65 throw new SlcException("Cannot marshall SlcExecution to "
66 + getFilePath(slcExecution
), e
);
68 IOUtils
.closeQuietly(out
);
72 protected String
getFileName(SlcExecution slcExecution
) {
73 return "SlcExecution-" + slcExecution
.getUuid() + ".xml";
76 protected String
getFilePath(SlcExecution slcExecution
) {
77 String dirPath
= uuidToDir
.get(slcExecution
.getUuid());
78 return dirPath
+ File
.separator
+ "SlcExecution-"
79 + slcExecution
.getUuid() + ".xml";
82 public void setBasePath(String basePath
) {
83 // this.basePath = basePath;
86 public void setMarshaller(Marshaller marshaller
) {
87 this.marshaller
= marshaller
;