001/** 002 * Copyright 2005-2016 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.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.uif.UifConstants; 020 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlElement; 024import java.util.ArrayList; 025import java.util.List; 026 027/** 028 * Prerequisite constraints require that some other attribute be non-empty in order for the constraint to be valid. 029 * So, a 7-digit US phone number might have a prerequisite of an area code, or an address street2 might have a prerequisite 030 * that street1 is non-empty. 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 * @since 1.1 034 */ 035@XmlAccessorType(XmlAccessType.FIELD) 036public class PrerequisiteConstraint extends BaseConstraint { 037 @XmlElement 038 protected String propertyName; 039 040 public String getPropertyName() { 041 return propertyName; 042 } 043 044 public void setPropertyName(String propertyName) { 045 this.propertyName = propertyName; 046 } 047 048 @Override 049 public String getLabelKey(){ 050 if(StringUtils.isBlank(this.labelKey)){ 051 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "prerequisiteFallback"; 052 } 053 else{ 054 return super.getLabelKey(); 055 } 056 } 057 058 @Override 059 /** 060 * @see BaseConstraint#getValidationMessageParams() 061 * @return the validation message list if defined. If not defined, return the property name 062 */ 063 public List<String> getValidationMessageParams() { 064 if(super.getValidationMessageParams() == null) { 065 ArrayList<String> params = new ArrayList<String>(1); 066 params.add(getPropertyName()); 067 return params; 068 } else { 069 return super.getValidationMessageParams(); 070 } 071 } 072}