001/**
002 * Copyright 2005-2015 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;
020
021import java.util.ArrayList;
022import java.util.List;
023
024/**
025 * Prerequisite constraints require that some other attribute be non-empty in order for the constraint to be valid.
026 * So, a 7-digit US phone number might have a prerequisite of an area code, or an address street2 might have a
027 * prerequisite that street1 is non-empty.
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 * @since 1.1
031 */
032@BeanTag(name = "prerequisiteConstraint", parent = "PrerequisiteConstraint")
033public class PrerequisiteConstraint extends BaseConstraint {
034    protected String propertyName;
035
036    @BeanTagAttribute(name = "propertyName")
037    public String getPropertyName() {
038        return propertyName;
039    }
040
041    public void setPropertyName(String propertyName) {
042        this.propertyName = propertyName;
043    }
044
045    @Override
046    /**
047     * @see BaseConstraint#getValidationMessageParams()
048     * @return the validation message list if defined. If not defined,  return  the property name
049     */
050    public List<String> getValidationMessageParams() {
051        if (super.getValidationMessageParams() == null) {
052            ArrayList<String> params = new ArrayList<String>(1);
053            params.add(getPropertyName());
054            return params;
055        } else {
056            return super.getValidationMessageParams();
057        }
058    }
059}