]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/xml/process/FileSlcExecutionNotifier.java
Improve logging
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.castor / src / main / java / org / argeo / slc / xml / process / FileSlcExecutionNotifier.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.xml.process;
18
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.xml.transform.stream.StreamResult;
26
27 import org.apache.commons.io.IOUtils;
28 import org.argeo.slc.SlcException;
29 import org.argeo.slc.execution.ExecutionProcess;
30 import org.argeo.slc.process.SlcExecution;
31 import org.argeo.slc.process.SlcExecutionNotifier;
32 import org.argeo.slc.execution.ExecutionStep;
33 import org.argeo.slc.process.SlcExecutionStep;
34 import org.springframework.oxm.Marshaller;
35
36 /** @deprecated Probably not even working anymore */
37 public class FileSlcExecutionNotifier implements SlcExecutionNotifier {
38 // private final static SimpleDateFormat sdf = new SimpleDateFormat(
39 // "yyyyMMdd-HHmmss");
40 //
41 // private String basePath;
42 private Marshaller marshaller;
43
44 private Map<String, String> uuidToDir = new HashMap<String, String>();
45
46 public void addSteps(ExecutionProcess slcExecution,
47 List<ExecutionStep> additionalSteps) {
48 writeSlcExecution(slcExecution);
49 }
50
51 public void updateStatus(ExecutionProcess slcExecution, String oldStatus,
52 String newStatus) {
53 writeSlcExecution(slcExecution);
54 }
55
56 protected void writeSlcExecution(ExecutionProcess process) {
57 if (!(process instanceof SlcExecution))
58 throw new SlcException("Unsupported process type "
59 + process.getClass());
60 SlcExecution slcExecution = (SlcExecution) process;
61 FileWriter out = null;
62 try {
63 out = new FileWriter(getFilePath(slcExecution));
64 marshaller.marshal(slcExecution, new StreamResult(out));
65 } catch (Exception e) {
66 throw new SlcException("Cannot marshall SlcExecution to "
67 + getFilePath(slcExecution), e);
68 } finally {
69 IOUtils.closeQuietly(out);
70 }
71 }
72
73 protected String getFileName(SlcExecution slcExecution) {
74 return "SlcExecution-" + slcExecution.getUuid() + ".xml";
75 }
76
77 protected String getFilePath(SlcExecution slcExecution) {
78 String dirPath = uuidToDir.get(slcExecution.getUuid());
79 return dirPath + File.separator + "SlcExecution-"
80 + slcExecution.getUuid() + ".xml";
81 }
82
83 public void setBasePath(String basePath) {
84 // this.basePath = basePath;
85 }
86
87 public void setMarshaller(Marshaller marshaller) {
88 this.marshaller = marshaller;
89 }
90
91 }