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 public class BasicResult extends EventObject implements ResultEvent {
30 private static final long serialVersionUID = -4124200802034785921L;
31
32 private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH.mm.ss.SSS");
33
34 protected String type;
35 protected DateTime timestamp;
36 protected ExecutionEnvironment environment;
37 protected Boolean result = null;
38 protected String description;
39 protected Map<String, ?> resultDetails;
40
41 public BasicResult(Map<String, ?> resultDetails, String eventType, Object source, ExecutionEnvironment environment, boolean result) {
42 this(resultDetails, null, eventType, source, environment, result);
43 }
44
45 public BasicResult(Map<String, ?> resultDetails, String description, String eventType, Object source, ExecutionEnvironment environment, boolean result) {
46 this(eventType, source, environment);
47 this.resultDetails = resultDetails;
48 this.result = new Boolean(result);
49 this.description = (description == null) ? StringUtils.EMPTY : description;
50 }
51
52 public BasicResult(String description, String eventType, Object source, ExecutionEnvironment environment, boolean result) {
53 this(eventType, source, environment);
54 this.result = new Boolean(result);
55 this.description = description;
56 }
57
58 public BasicResult(String eventType, Object source, ExecutionEnvironment environment, boolean result) {
59 this(eventType, source, environment);
60 this.result = new Boolean(result);
61 }
62
63 public BasicResult(String eventType, Object source, ExecutionEnvironment environment) {
64 super(source);
65 this.type = eventType;
66 this.timestamp = new DateTime();
67 this.environment = environment;
68 }
69
70 @Override
71 public String getType() {
72 return type;
73 }
74
75 @Override
76 public DateTime getTimestamp() {
77 return timestamp;
78 }
79
80 @Override
81 public ExecutionEnvironment getEnvironment(){
82 return environment;
83 }
84
85 @Override
86 public Boolean getResult(){
87 return result;
88 }
89
90 @Override
91 public String getDescription() {
92 return description;
93 }
94
95 @Override
96 public Map<String, ?> getResultDetails() {
97 if (resultDetails == null) {
98 return Collections.emptyMap();
99 } else {
100 return Collections.unmodifiableMap(resultDetails);
101 }
102 }
103
104 public String toString(){
105 StringBuffer sb = new StringBuffer();
106 sb.append(fmt.print(this.getTimestamp()));
107 sb.append(" EventType: "+ getType());
108 sb.append(" ( "+ this.getSource().toString());
109 if (this.getResult() != null){
110 sb.append(" evaluated to: "+ this.getResult().toString());
111 }
112 sb.append(" )");
113 return sb.toString();
114 }
115 }