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.krad.datadictionary.validation.constraint;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
21  
22  import java.util.List;
23  
24  /**
25   * CaseConstraint is imposed only when a certain condition is met
26   *
27   * <p>For example, if the country attribute value is "USA",
28   * then a prerequisite constraint may be imposed that the 'State' attribute is non-null.</p>
29   *
30   * <p>
31   * This class is a direct copy of one that was in Kuali Student.</p>
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   * @since 1.1
35   */
36  @BeanTag(name = "caseConstriant", parent = "CaseConstraint")
37  public class CaseConstraint extends BaseConstraint {
38  
39      protected String propertyName;
40      protected String operator;
41      protected boolean caseSensitive;
42  
43      protected List<WhenConstraint> whenConstraint;
44  
45      /**
46       * get the {@code WhenConstraint}'s defined by this case constraint
47       *
48       * @return a list of constraints, null if not initialized
49       */
50      @BeanTagAttribute(name = "whenConstraint", type = BeanTagAttribute.AttributeType.LISTBEAN)
51      public List<WhenConstraint> getWhenConstraint() {
52          return whenConstraint;
53      }
54  
55      /**
56       * sets the {@code WhenConstraint}'s defined by this case constraint
57       *
58       * @param whenConstraint - the list of constraints
59       */
60      public void setWhenConstraint(List<WhenConstraint> whenConstraint) {
61          this.whenConstraint = whenConstraint;
62      }
63  
64      /**
65       * gets the property name for the attribute to which the case constraint is applied to
66       *
67       * @return the property name
68       */
69      @BeanTagAttribute(name = "propertyName")
70      public String getPropertyName() {
71          return propertyName;
72      }
73  
74      /**
75       * setter for property name
76       *
77       * @param propertyName a valid property name
78       */
79      public void setPropertyName(String propertyName) {
80          this.propertyName = propertyName;
81      }
82  
83      /**
84       * specifies the kind of relationship to be checked between the actual value and the ones defined in the {@link
85       * #getWhenConstraint()}
86       *
87       * @return an operator name
88       * @see org.kuali.rice.krad.uif.UifConstants.CaseConstraintOperators
89       */
90      @BeanTagAttribute(name = "operator")
91      public String getOperator() {
92          return operator;
93      }
94  
95      /**
96       * setter for the operator
97       *
98       * @param operator
99       * @see org.kuali.rice.krad.uif.UifConstants.CaseConstraintOperators
100      */
101     public void setOperator(String operator) {
102         this.operator = operator;
103     }
104 
105     /**
106      * checks whether string comparison will be carried out in a case sensitive fashion
107      *
108      * @return true if string comparison is case sensitive, false if not
109      */
110     @BeanTagAttribute(name = "caseSensitive")
111     public boolean isCaseSensitive() {
112         return caseSensitive;
113     }
114 
115     /**
116      * setter for case sensitive
117      *
118      * @param caseSensitive - the case sensitive value to set
119      */
120     public void setCaseSensitive(boolean caseSensitive) {
121         this.caseSensitive = caseSensitive;
122     }
123 
124     /**
125      * Validates different requirements of component compiling a series of reports detailing information on errors
126      * found in the component.  Used by the RiceDictionaryValidator.
127      *
128      * @param tracer Record of component's location
129      */
130     @Override
131     public void completeValidation(ValidationTrace tracer) {
132         tracer.addBean("CaseConstraint", getMessageKey());
133 
134         if (getWhenConstraint() == null) {
135             String currentValues[] = {"whenCaseConstraint = " + getWhenConstraint()};
136             tracer.createWarning("WhenCaseConstraints should at least have 1 item", currentValues);
137         } else {
138             if (getWhenConstraint().size() == 0) {
139                 String currentValues[] = {"whenCaseConstraint.size() = " + getWhenConstraint().size()};
140                 tracer.createError("WhenCaseConstraints should at least have 1 item", currentValues);
141             } else {
142                 for (int i = 0; i < getWhenConstraint().size(); i++) {
143                     getWhenConstraint().get(i).completeValidation(tracer.getCopy());
144                 }
145             }
146         }
147     }
148 }