View Javadoc

1   /**
2    * Copyright 2005-2012 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.api.engine;
17  
18  import java.util.Collections;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.joda.time.DateTime;
23  
24  public final class SelectionCriteria {
25  
26  	private final Long effectiveExecutionTime;
27  	private final Map<String, String> contextQualifiers;
28  	private final Map<String, String> agendaQualifiers;
29  
30  	private SelectionCriteria(DateTime effectiveDate) {
31  		if (effectiveDate != null) {
32  			this.effectiveExecutionTime = effectiveDate.getMillis();
33  		} else {
34  			this.effectiveExecutionTime = null;
35  		}
36  		
37  		this.contextQualifiers = new HashMap<String, String>();
38  		this.agendaQualifiers = new HashMap<String, String>();
39  	}
40  
41  	/**
42  	 * This static factory method creates a SelectionCriteria used to select an Agenda to execute.
43  	 * 
44  	 * @param effectiveExecutionTime the time that the rule is being executed at.  If null, the time of engine execution will be used.
45  	 * @param contextQualifiers qualifiers used to select the context
46  	 * @param agendaQualifiers qualifiers used to select the agenda from the context
47  	 * @return the {@link SelectionCriteria}
48  	 */
49  	public static SelectionCriteria createCriteria(DateTime effectiveExecutionTime, Map<String, String> contextQualifiers, Map<String, String> agendaQualifiers) {
50  		SelectionCriteria criteria = new SelectionCriteria(effectiveExecutionTime);
51          if (contextQualifiers != null) {
52  		    criteria.contextQualifiers.putAll(contextQualifiers);
53          }
54          if (agendaQualifiers != null) {
55  		    criteria.agendaQualifiers.putAll(agendaQualifiers);
56          }
57  		return criteria;
58  	}
59  
60  	/**
61  	 * This method gets the effective date/time in epoch time, suitable for 
62  	 * converting to a {@link java.util.Date} via {@link java.util.Date#Date(long)}
63  	 * @return the epoch time for effective execution, or null 
64  	 * (which defers to the {@link Engine} but implies that the actual time when execution begins will be used).
65  	 */
66  	public Long getEffectiveExecutionTime() {
67  		return effectiveExecutionTime;
68  	}
69  
70      /**
71       * @return the map of context qualifiers.  May be empty, will never be null.
72       */
73  	public Map<String, String> getContextQualifiers() {
74  		return Collections.unmodifiableMap(contextQualifiers);
75  	}
76  
77      /**
78       * @return the map of agenda qualifiers.  May be empty, will never be null.
79       */
80  	public Map<String, String> getAgendaQualifiers() {
81  		return Collections.unmodifiableMap(agendaQualifiers);
82  	}
83  
84  }