| 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 | 1 | 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 | 77 | 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 | 3 | this(resultDetails, null, eventType, source, environment, result); |
| 43 | 3 | } |
| 44 | |
|
| 45 | |
public BasicResult(Map<String, ?> resultDetails, String description, String eventType, Object source, ExecutionEnvironment environment, boolean result) { |
| 46 | 3 | this(eventType, source, environment); |
| 47 | 3 | this.resultDetails = resultDetails; |
| 48 | 3 | this.result = new Boolean(result); |
| 49 | 3 | this.description = (description == null) ? StringUtils.EMPTY : description; |
| 50 | 3 | } |
| 51 | |
|
| 52 | |
public BasicResult(String description, String eventType, Object source, ExecutionEnvironment environment, boolean result) { |
| 53 | 0 | this(eventType, source, environment); |
| 54 | 0 | this.result = new Boolean(result); |
| 55 | 0 | this.description = description; |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
public BasicResult(String eventType, Object source, ExecutionEnvironment environment, boolean result) { |
| 59 | 73 | this(eventType, source, environment); |
| 60 | 73 | this.result = new Boolean(result); |
| 61 | 73 | } |
| 62 | |
|
| 63 | |
public BasicResult(String eventType, Object source, ExecutionEnvironment environment) { |
| 64 | 77 | super(source); |
| 65 | 77 | this.type = eventType; |
| 66 | 77 | this.timestamp = new DateTime(); |
| 67 | 77 | this.environment = environment; |
| 68 | 77 | } |
| 69 | |
|
| 70 | |
@Override |
| 71 | |
public String getType() { |
| 72 | 0 | return type; |
| 73 | |
} |
| 74 | |
|
| 75 | |
@Override |
| 76 | |
public DateTime getTimestamp() { |
| 77 | 0 | return timestamp; |
| 78 | |
} |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public ExecutionEnvironment getEnvironment(){ |
| 82 | 77 | return environment; |
| 83 | |
} |
| 84 | |
|
| 85 | |
@Override |
| 86 | |
public Boolean getResult(){ |
| 87 | 0 | return result; |
| 88 | |
} |
| 89 | |
|
| 90 | |
@Override |
| 91 | |
public String getDescription() { |
| 92 | 0 | return description; |
| 93 | |
} |
| 94 | |
|
| 95 | |
@Override |
| 96 | |
public Map<String, ?> getResultDetails() { |
| 97 | 0 | if (resultDetails == null) { |
| 98 | 0 | return Collections.emptyMap(); |
| 99 | |
} else { |
| 100 | 0 | return Collections.unmodifiableMap(resultDetails); |
| 101 | |
} |
| 102 | |
} |
| 103 | |
|
| 104 | |
public String toString(){ |
| 105 | 0 | StringBuffer sb = new StringBuffer(); |
| 106 | 0 | sb.append(fmt.print(this.getTimestamp())); |
| 107 | 0 | sb.append(" EventType: "+ getType()); |
| 108 | 0 | sb.append(" ( "+ this.getSource().toString()); |
| 109 | 0 | if (this.getResult() != null){ |
| 110 | 0 | sb.append(" evaluated to: "+ this.getResult().toString()); |
| 111 | |
} |
| 112 | 0 | sb.append(" )"); |
| 113 | 0 | return sb.toString(); |
| 114 | |
} |
| 115 | |
} |