| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SelectionCriteria |
|
| 1.6;1.6 |
| 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.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 | 0 | private SelectionCriteria(DateTime effectiveDate) { |
| 31 | 0 | if (effectiveDate != null) { |
| 32 | 0 | this.effectiveExecutionTime = effectiveDate.getMillis(); |
| 33 | } else { | |
| 34 | 0 | this.effectiveExecutionTime = null; |
| 35 | } | |
| 36 | ||
| 37 | 0 | this.contextQualifiers = new HashMap<String, String>(); |
| 38 | 0 | this.agendaQualifiers = new HashMap<String, String>(); |
| 39 | 0 | } |
| 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 | 0 | SelectionCriteria criteria = new SelectionCriteria(effectiveExecutionTime); |
| 51 | 0 | if (contextQualifiers != null) { |
| 52 | 0 | criteria.contextQualifiers.putAll(contextQualifiers); |
| 53 | } | |
| 54 | 0 | if (agendaQualifiers != null) { |
| 55 | 0 | criteria.agendaQualifiers.putAll(agendaQualifiers); |
| 56 | } | |
| 57 | 0 | 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 | 0 | return effectiveExecutionTime; |
| 68 | } | |
| 69 | ||
| 70 | public Map<String, String> getContextQualifiers() { | |
| 71 | 0 | return Collections.unmodifiableMap(contextQualifiers); |
| 72 | } | |
| 73 | ||
| 74 | public Map<String, String> getAgendaQualifiers() { | |
| 75 | 0 | return Collections.unmodifiableMap(agendaQualifiers); |
| 76 | } | |
| 77 | ||
| 78 | } |