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