001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.datadictionary.validation.constraint; 017 018import org.kuali.rice.krad.datadictionary.parse.BeanTag; 019import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 020import org.kuali.rice.krad.datadictionary.validator.ValidationTrace; 021 022import java.util.List; 023 024/** 025 * CaseConstraint is imposed only when a certain condition is met 026 * 027 * <p>For example, if the country attribute value is "USA", 028 * then a prerequisite constraint may be imposed that the 'State' attribute is non-null.</p> 029 * 030 * <p> 031 * This class is a direct copy of one that was in Kuali Student.</p> 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 * @since 1.1 035 */ 036@BeanTag(name = "caseConstriant", parent = "CaseConstraint") 037public class CaseConstraint extends BaseConstraint { 038 039 protected String propertyName; 040 protected String operator; 041 protected boolean caseSensitive; 042 043 protected List<WhenConstraint> whenConstraint; 044 045 /** 046 * get the {@code WhenConstraint}'s defined by this case constraint 047 * 048 * @return a list of constraints, null if not initialized 049 */ 050 @BeanTagAttribute(name = "whenConstraint", type = BeanTagAttribute.AttributeType.LISTBEAN) 051 public List<WhenConstraint> getWhenConstraint() { 052 return whenConstraint; 053 } 054 055 /** 056 * sets the {@code WhenConstraint}'s defined by this case constraint 057 * 058 * @param whenConstraint - the list of constraints 059 */ 060 public void setWhenConstraint(List<WhenConstraint> whenConstraint) { 061 this.whenConstraint = whenConstraint; 062 } 063 064 /** 065 * gets the property name for the attribute to which the case constraint is applied to 066 * 067 * @return the property name 068 */ 069 @BeanTagAttribute(name = "propertyName") 070 public String getPropertyName() { 071 return propertyName; 072 } 073 074 /** 075 * setter for property name 076 * 077 * @param propertyName a valid property name 078 */ 079 public void setPropertyName(String propertyName) { 080 this.propertyName = propertyName; 081 } 082 083 /** 084 * specifies the kind of relationship to be checked between the actual value and the ones defined in the {@link 085 * #getWhenConstraint()} 086 * 087 * @return an operator name 088 * @see org.kuali.rice.krad.uif.UifConstants.CaseConstraintOperators 089 */ 090 @BeanTagAttribute(name = "operator") 091 public String getOperator() { 092 return operator; 093 } 094 095 /** 096 * setter for the operator 097 * 098 * @param operator 099 * @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}