View Javadoc

1   package org.kuali.rice.krms.api.engine;
2   
3   import java.util.Collections;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import org.joda.time.DateTime;
8   
9   public final class SelectionCriteria {
10  
11  	private final Long effectiveExecutionTime;
12  	private final String eventName;
13  	private final Map<String, String> contextQualifiers;
14  	private final Map<String, String> agendaQualifiers;
15  	
16  	private SelectionCriteria(String eventName, DateTime effectiveDate) {
17  		if (eventName == null || "".equals(eventName.trim())) {
18  			throw new IllegalArgumentException("Event name must not be null or empty.");
19  		}
20  		this.eventName = eventName;
21  		
22  		if (effectiveDate != null) {
23  			this.effectiveExecutionTime = effectiveDate.getMillis();
24  		} else {
25  			this.effectiveExecutionTime = null;
26  		}
27  		
28  		this.contextQualifiers = new HashMap<String, String>();
29  		this.agendaQualifiers = new HashMap<String, String>();
30  	}
31  	
32  	/**
33  	 * This static factory method creates a SelectionCriteria used to select an Agenda to execute.
34  	 * 
35  	 * @param eventName the event that is triggering rule execution.  Must not be null.
36  	 * @param effectiveExecutionTime the time that the rule is being executed at.  If null, the time of engine execution will be used.
37  	 * @param contextQualifiers qualifiers used to select the context
38  	 * @param agendaQualifiers qualifiers used to select the agenda from the context
39  	 * @return the {@link SelectionCriteria}
40  	 */
41  	public static SelectionCriteria createCriteria(String eventName, DateTime effectiveExecutionTime, Map<String, String> contextQualifiers, Map<String, String> agendaQualifiers) {
42  		SelectionCriteria criteria = new SelectionCriteria(eventName, effectiveExecutionTime);
43          if (contextQualifiers != null) {
44  		    criteria.contextQualifiers.putAll(contextQualifiers);
45          }
46          if (agendaQualifiers != null) {
47  		    criteria.agendaQualifiers.putAll(agendaQualifiers);
48          }
49  		return criteria;
50  	}
51  
52  	public String getEventName() {
53  		return eventName;
54  	}
55  	
56  	/**
57  	 * This method gets the effective date/time in epoch time, suitable for 
58  	 * converting to a {@link java.util.Date} via {@link java.util.Date#Date(long)}
59  	 * @return the epoch time for effective execution, or null 
60  	 * (which defers to the {@link Engine} but implies that the actual time when execution begins will be used).
61  	 */
62  	public Long getEffectiveExecutionTime() {
63  		return effectiveExecutionTime;
64  	}
65  
66  	public Map<String, String> getContextQualifiers() {
67  		return Collections.unmodifiableMap(contextQualifiers);
68  	}
69  
70  	public Map<String, String> getAgendaQualifiers() {
71  		return Collections.unmodifiableMap(agendaQualifiers);
72  	}
73  
74  }