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.krad.datadictionary.validation.constraint;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.uif.UifConstants;
20
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlElement;
24 import java.util.List;
25
26 /**
27 * Must occur constraints are constraints that indicate some range of acceptable valid results. So a must occur constraint
28 * might indicate that between 1 and 3 prequisite constraints must be valid. For example, on a person object, it might be
29 * that one of three fields must be filled in:
30 *
31 * 1. username
32 * 2. email
33 * 3. phone number
34 *
35 * By imposing a must occur constraint on the person object iself, and setting three prequisite constraints below it, with a min of 1
36 * and a max of 3, this requirement can be enforced.
37 *
38 * A more complicated example might be that a US address is only valid if it provides either:
39 * (a) a city and state, or
40 * (b) a postal code
41 *
42 * To enforce this, a single must occur constraint would have two children: (1) a prequisite constraint on postal code, and (2) a must occur constraint
43 * with two child prequisite constraints, on city and state, respectively. By setting min=1/max=2 at the top must occur constraint,
44 * and min=2/max=2 at the leaf constraint, this requirement can be enforced.
45 *
46 * @author Kuali Rice Team (rice.collab@kuali.org)
47 * @since 1.1
48 */
49 @XmlAccessorType(XmlAccessType.FIELD)
50 public class MustOccurConstraint extends BaseConstraint {
51
52 @XmlElement
53 private List<PrerequisiteConstraint> prerequisiteConstraints;
54 @XmlElement
55 private List<MustOccurConstraint> mustOccurConstraints;
56 @XmlElement
57 private Integer min;
58 @XmlElement
59 private Integer max;
60
61 public List<PrerequisiteConstraint> getPrerequisiteConstraints() {
62 return prerequisiteConstraints;
63 }
64
65 public void setPrerequisiteConstraints(List<PrerequisiteConstraint> prerequisiteConstraints) {
66 this.prerequisiteConstraints = prerequisiteConstraints;
67 }
68
69 public List<MustOccurConstraint> getMustOccurConstraints() {
70 return mustOccurConstraints;
71 }
72
73 public void setMustOccurConstraints(List<MustOccurConstraint> occurs) {
74 this.mustOccurConstraints = occurs;
75 }
76
77 public Integer getMin() {
78 return min;
79 }
80
81 public void setMin(Integer min) {
82 this.min = min;
83 }
84
85 public Integer getMax() {
86 return max;
87 }
88
89 public void setMax(Integer max) {
90 this.max = max;
91 }
92
93 @Override
94 public String getLabelKey(){
95 if(StringUtils.isBlank(this.labelKey)){
96 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "mustoccursFallback";
97 }
98 else{
99 return super.getLabelKey();
100 }
101 }
102 }