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.ArrayList;
25 import java.util.List;
26
27 /**
28 * Prerequisite constraints require that some other attribute be non-empty in order for the constraint to be valid.
29 * So, a 7-digit US phone number might have a prerequisite of an area code, or an address street2 might have a prerequisite
30 * that street1 is non-empty.
31 *
32 * @author Kuali Rice Team (rice.collab@kuali.org)
33 * @since 1.1
34 */
35 @XmlAccessorType(XmlAccessType.FIELD)
36 public class PrerequisiteConstraint extends BaseConstraint {
37 @XmlElement
38 protected String propertyName;
39
40 public String getPropertyName() {
41 return propertyName;
42 }
43
44 public void setPropertyName(String propertyName) {
45 this.propertyName = propertyName;
46 }
47
48 @Override
49 public String getLabelKey(){
50 if(StringUtils.isBlank(this.labelKey)){
51 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "prerequisiteFallback";
52 }
53 else{
54 return super.getLabelKey();
55 }
56 }
57
58 @Override
59 /**
60 * @see BaseConstraint#getValidationMessageParams()
61 * @return the validation message list if defined. If not defined, return the property name
62 */
63 public List<String> getValidationMessageParams() {
64 if(super.getValidationMessageParams() == null) {
65 ArrayList<String> params = new ArrayList<String>(1);
66 params.add(getPropertyName());
67 return params;
68 } else {
69 return super.getValidationMessageParams();
70 }
71 }
72 }