View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  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 }