]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java
Adapt for agents
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / process / SlcExecutionStep.java
1 package org.argeo.slc.process;
2
3 import java.io.IOException;
4 import java.io.StringReader;
5 import java.io.StringWriter;
6 import java.util.ArrayList;
7 import java.util.Date;
8 import java.util.List;
9 import java.util.UUID;
10
11 import org.apache.commons.io.IOUtils;
12
13 public class SlcExecutionStep {
14 public final static String TYPE_LOG = "LOG";
15
16 private String uuid;
17 private String type;
18 private Date begin;
19 private List<String> logLines = new ArrayList<String>();
20
21 /** Empty constructor */
22 public SlcExecutionStep() {
23 }
24
25 public SlcExecutionStep(String log) {
26 this.type = TYPE_LOG;
27 this.begin = new Date();
28 this.uuid = UUID.randomUUID().toString();
29 addLog(log);
30 }
31
32 public String getUuid() {
33 return uuid;
34 }
35
36 public void setUuid(String uuid) {
37 this.uuid = uuid;
38 }
39
40 public String getType() {
41 return type;
42 }
43
44 public void setType(String type) {
45 this.type = type;
46 }
47
48 public Date getBegin() {
49 return begin;
50 }
51
52 public void setBegin(Date begin) {
53 this.begin = begin;
54 }
55
56 public List<String> getLogLines() {
57 return logLines;
58 }
59
60 public void setLogLines(List<String> logLines) {
61 this.logLines = logLines;
62 }
63
64 public String logAsString() {
65 StringWriter writer = new StringWriter();
66 String log = writer.toString();
67 IOUtils.closeQuietly(writer);
68 return log;
69 }
70
71 public void addLog(String log) {
72 if (log == null)
73 return;
74
75 try {
76 List<String> lines = IOUtils.readLines(new StringReader(log));
77 logLines.addAll(lines);
78 } catch (IOException e) {
79 throw new RuntimeException("Cannot add log", e);
80 }
81 }
82
83 @Override
84 public String toString() {
85 return getClass().getSimpleName() + "#" + uuid;
86 }
87
88 }