1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework.engine.result;
17
18 import java.util.Collections;
19 import java.util.EventObject;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.joda.time.DateTime;
24 import org.joda.time.format.DateTimeFormat;
25 import org.joda.time.format.DateTimeFormatter;
26 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
27 import org.kuali.rice.krms.api.engine.ResultEvent;
28
29
30
31
32
33 public class BasicResult extends EventObject implements ResultEvent {
34 private static final long serialVersionUID = -4124200802034785921L;
35
36 private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH.mm.ss.SSS");
37
38 protected String type;
39 protected DateTime timestamp;
40 protected ExecutionEnvironment environment;
41 protected Boolean result = null;
42 protected String description;
43 protected Map<String, ?> resultDetails;
44
45
46
47
48
49
50
51
52
53
54
55 public BasicResult(Map<String, ?> resultDetails, String eventType, Object source, ExecutionEnvironment environment, boolean result) {
56 this(resultDetails, null, eventType, source, environment, result);
57 }
58
59
60
61
62
63
64
65
66
67
68 public BasicResult(Map<String, ?> resultDetails, String description, String eventType, Object source, ExecutionEnvironment environment, boolean result) {
69 this(eventType, source, environment);
70 this.resultDetails = resultDetails;
71 this.result = new Boolean(result);
72 this.description = (description == null) ? StringUtils.EMPTY : description;
73 }
74
75
76
77
78
79
80
81
82
83 public BasicResult(String description, String eventType, Object source, ExecutionEnvironment environment, boolean result) {
84 this(eventType, source, environment);
85 this.result = new Boolean(result);
86 this.description = description;
87 }
88
89
90
91
92
93
94
95
96 public BasicResult(String eventType, Object source, ExecutionEnvironment environment, boolean result) {
97 this(eventType, source, environment);
98 this.result = new Boolean(result);
99 }
100
101
102
103
104
105
106
107 public BasicResult(String eventType, Object source, ExecutionEnvironment environment) {
108 super(source);
109 this.type = eventType;
110 this.timestamp = new DateTime();
111 this.environment = environment;
112 }
113
114 @Override
115 public String getType() {
116 return type;
117 }
118
119 @Override
120 public DateTime getTimestamp() {
121 return timestamp;
122 }
123
124 @Override
125 public ExecutionEnvironment getEnvironment(){
126 return environment;
127 }
128
129 @Override
130 public Boolean getResult(){
131 return result;
132 }
133
134 @Override
135 public String getDescription() {
136 return description;
137 }
138
139
140
141
142
143 @Override
144 public Map<String, ?> getResultDetails() {
145 if (resultDetails == null) {
146 return Collections.emptyMap();
147 } else {
148 return Collections.unmodifiableMap(resultDetails);
149 }
150 }
151
152 @Override
153 public String toString(){
154 StringBuffer sb = new StringBuffer();
155 sb.append(fmt.print(this.getTimestamp()));
156 sb.append(" EventType: "+ getType());
157 sb.append(" ( "+ this.getSource().toString());
158 if (this.getResult() != null){
159 sb.append(" evaluated to: "+ this.getResult().toString());
160 }
161 sb.append(" )");
162 return sb.toString();
163 }
164 }