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.List; 025 026/** 027 * Must occur constraints are constraints that indicate some range of acceptable valid results. So a must occur constraint 028 * might indicate that between 1 and 3 prequisite constraints must be valid. For example, on a person object, it might be 029 * that one of three fields must be filled in: 030 * 031 * 1. username 032 * 2. email 033 * 3. phone number 034 * 035 * By imposing a must occur constraint on the person object iself, and setting three prequisite constraints below it, with a min of 1 036 * and a max of 3, this requirement can be enforced. 037 * 038 * A more complicated example might be that a US address is only valid if it provides either: 039 * (a) a city and state, or 040 * (b) a postal code 041 * 042 * To enforce this, a single must occur constraint would have two children: (1) a prequisite constraint on postal code, and (2) a must occur constraint 043 * with two child prequisite constraints, on city and state, respectively. By setting min=1/max=2 at the top must occur constraint, 044 * and min=2/max=2 at the leaf constraint, this requirement can be enforced. 045 * 046 * @author Kuali Rice Team (rice.collab@kuali.org) 047 * @since 1.1 048 */ 049@XmlAccessorType(XmlAccessType.FIELD) 050public class MustOccurConstraint extends BaseConstraint { 051 052 @XmlElement 053 private List<PrerequisiteConstraint> prerequisiteConstraints; 054 @XmlElement 055 private List<MustOccurConstraint> mustOccurConstraints; 056 @XmlElement 057 private Integer min; 058 @XmlElement 059 private Integer max; 060 061 public List<PrerequisiteConstraint> getPrerequisiteConstraints() { 062 return prerequisiteConstraints; 063 } 064 065 public void setPrerequisiteConstraints(List<PrerequisiteConstraint> prerequisiteConstraints) { 066 this.prerequisiteConstraints = prerequisiteConstraints; 067 } 068 069 public List<MustOccurConstraint> getMustOccurConstraints() { 070 return mustOccurConstraints; 071 } 072 073 public void setMustOccurConstraints(List<MustOccurConstraint> occurs) { 074 this.mustOccurConstraints = occurs; 075 } 076 077 public Integer getMin() { 078 return min; 079 } 080 081 public void setMin(Integer min) { 082 this.min = min; 083 } 084 085 public Integer getMax() { 086 return max; 087 } 088 089 public void setMax(Integer max) { 090 this.max = max; 091 } 092 093 @Override 094 public String getLabelKey(){ 095 if(StringUtils.isBlank(this.labelKey)){ 096 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "mustoccursFallback"; 097 } 098 else{ 099 return super.getLabelKey(); 100 } 101 } 102}