View Javadoc
1   /**
2    * Copyright 2005-2016 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;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21  import org.kuali.rice.krad.datadictionary.validation.capability.CollectionSizeConstrainable;
22  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23  
24  /**
25   * CollectionDefinition defines a single Collection attribute definition in the DataDictionary
26   *
27   * <p>It contains information relating to the display, validation,
28   * and general maintenance of a specific Collection attribute of an entry. It helps to provide meaningful labels for
29   * collections on a business or data object.
30   * It can be used to define collections that are generated at runtime and marked using @{@code Transient} in the
31   * containing
32   * business or data object class.</p>
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @BeanTag(name = "collectionDefinition-bean")
37  public class CollectionDefinition extends DataDictionaryDefinitionBase implements CollectionSizeConstrainable {
38      private static final long serialVersionUID = -2644072136271281041L;
39  
40      protected String dataObjectClass;
41  
42      protected String name;
43  
44      protected String label;
45  
46      protected String shortLabel;
47  
48      protected String elementLabel;
49  
50      protected String summary;
51  
52      protected String description;
53  
54      protected Integer minOccurs;
55  
56      protected Integer maxOccurs;
57  
58      /**
59       * default constructor
60       */
61      public CollectionDefinition() {
62          //empty
63      }
64  
65      /**
66       * gets the name of the collection
67       *
68       * @return the collection name
69       */
70      public String getName() {
71          return name;
72      }
73  
74      /**
75       * sets the name of the collection
76       *
77       * @param name - the collection name
78       * @throws IllegalArgumentException if the name is blank
79       */
80      public void setName(String name) {
81          if (StringUtils.isBlank(name)) {
82              throw new IllegalArgumentException("invalid (blank) name");
83          }
84          this.name = name;
85      }
86  
87      /**
88       * gets the label
89       *
90       * @return the label
91       */
92      public String getLabel() {
93          return label;
94      }
95  
96      /**
97       * sets the label
98       *
99       * @param label - a descriptive string to use for a label
100      */
101     public void setLabel(String label) {
102         if (StringUtils.isBlank(label)) {
103             throw new IllegalArgumentException("invalid (blank) label");
104         }
105         this.label = label;
106     }
107 
108     /**
109      * gets the short label
110      *
111      * @return the shortLabel, or the label if no shortLabel has been set
112      */
113     public String getShortLabel() {
114         return (shortLabel != null) ? shortLabel : label;
115     }
116 
117     /**
118      * sets the short label
119      *
120      * @param shortLabel - the short label
121      * @throws IllegalArgumentException when {@code shortLabel} is blank
122      */
123     public void setShortLabel(String shortLabel) {
124         if (StringUtils.isBlank(shortLabel)) {
125             throw new IllegalArgumentException("invalid (blank) shortLabel");
126         }
127         this.shortLabel = shortLabel;
128     }
129 
130     /**
131      * Gets the elementLabel attribute
132      *
133      * @return the element Label
134      */
135     public String getElementLabel() {
136         return elementLabel;
137     }
138 
139     /**
140      * gets the element label
141      *
142      * <p>The elementLabel defines the name to be used for a single object within the collection.
143      * For example: "Address" may be the name
144      * of one object within the "Addresses" collection.</p>
145      */
146     public void setElementLabel(String elementLabel) {
147         this.elementLabel = elementLabel;
148     }
149 
150     /**
151      * gets the summary
152      *
153      * <p>summary element is used to provide a short description of the
154      * attribute or collection. This is designed to be used for help purposes.</p>
155      *
156      * @return the summary
157      */
158     public String getSummary() {
159         return summary;
160     }
161 
162     /**
163      * gets the summary
164      */
165     public void setSummary(String summary) {
166         this.summary = summary;
167     }
168 
169     /**
170      * gets the description
171      *
172      * <p>The description element is used to provide a long description of the
173      * attribute or collection.  This is designed to be used for help purposes.</p>
174      *
175      * @return the description
176      */
177     public String getDescription() {
178         return description;
179     }
180 
181     /**
182      * sets the description
183      *
184      * @param description - the description to set
185      */
186     public void setDescription(String description) {
187         this.description = description;
188     }
189 
190     /**
191      * gets the data object class
192      *
193      * <p>This is the Java class type of the object contained in this collection</p>
194      *
195      * @return the dataObjectClass
196      */
197     public String getDataObjectClass() {
198         return this.dataObjectClass;
199     }
200 
201     /**
202      * sets the data object class
203      *
204      * @param dataObjectClass the dataObjectClass to set
205      */
206     public void setDataObjectClass(String dataObjectClass) {
207         this.dataObjectClass = dataObjectClass;
208     }
209 
210     /**
211      * Directly validate simple fields, call completeValidation on Definition fields
212      *
213      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation()
214      */
215     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
216         if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
217             throw new AttributeValidationException("property '"
218                     + name
219                     + "' is not a collection property of class '"
220                     + rootBusinessObjectClass
221                     + "' ("
222                     + ""
223                     + ")");
224         }
225     }
226 
227     /**
228      * Directly validate simple fields, call completeValidation on Definition
229      * fields.
230      *
231      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace)
232      */
233     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
234             ValidationTrace tracer) {
235         tracer.addBean(this.getClass().getSimpleName(), "Attribute: " + getName());
236         if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, name)) {
237             String currentValues[] = {"property = " + getName(), "Class =" + rootBusinessObjectClass};
238             tracer.createError("Property is not collection property of the class", currentValues);
239         }
240     }
241 
242     /**
243      * @return a descriptive string with the collection name
244      * @see java.lang.Object#toString()
245      */
246     @Override
247     public String toString() {
248         return "CollectionDefinition for collection " + getName();
249     }
250 
251     /**
252      * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMaximumNumberOfElements()
253      */
254     @Override
255     public Integer getMaximumNumberOfElements() {
256         return this.maxOccurs;
257     }
258 
259     /**
260      * @see org.kuali.rice.krad.datadictionary.validation.constraint.CollectionSizeConstraint#getMinimumNumberOfElements()
261      */
262     @Override
263     public Integer getMinimumNumberOfElements() {
264         return this.minOccurs;
265     }
266 
267     /**
268      * gets the minimum amount of items in this collection
269      *
270      * @return the minOccurs
271      */
272     public Integer getMinOccurs() {
273         return this.minOccurs;
274     }
275 
276     /**
277      * gets the minimum amount of items in this collection
278      *
279      * @param minOccurs the minOccurs to set
280      */
281     public void setMinOccurs(Integer minOccurs) {
282         this.minOccurs = minOccurs;
283     }
284 
285     /**
286      * gets maximum amount of items in this collection
287      *
288      * @return the maxOccurs
289      */
290     public Integer getMaxOccurs() {
291         return this.maxOccurs;
292     }
293 
294     /**
295      * sets maximum amount of items in this collection
296      *
297      * @param maxOccurs the maxOccurs to set
298      */
299     public void setMaxOccurs(Integer maxOccurs) {
300         this.maxOccurs = maxOccurs;
301     }
302 
303 }