Coverage Report - org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintainableCollectionDefinition
0%
0/98
0%
0/36
2
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.kns.datadictionary;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.bo.BusinessObject;
 20  
 import org.kuali.rice.krad.datadictionary.DataDictionary;
 21  
 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
 22  
 import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.HashMap;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 
 29  
 /**
 30  
     The maintainableCollection element defines a set of data fields, nested
 31  
     collections, summaryFields and duplicateIdentificationsFields.
 32  
 
 33  
     JSTL: maintainableCollection is a Map which is accessed using a
 34  
     key of the name of the maintainableCollection.  Each entry
 35  
     contains the following keys and values:
 36  
         **Key**                **Value**
 37  
         collection             true
 38  
         name                   name of collection
 39  
         dataObjectClass    name of collection class
 40  
         
 41  
 * name is the name of the collection
 42  
 * dataObjectClass is the class name of the objects in the collection
 43  
 * sourceClassName is the class name of the BO used in a lookup
 44  
 * sourceAttributeName is the name of the attribute which returns the collection
 45  
 * includeAddLine is true if the user is given the ability to add multiple lines.
 46  
 * includeMultipleLookupLine whether to render a quickfinder icon for multiple value lookups on the collection.  Defaults to true
 47  
 * summaryTitle is the label of the summary
 48  
 * attributeToHighlightOnDuplicateKey is the name of an attribute to highlight
 49  
     if two records in the collection are the same based on the
 50  
     duplicateIdentificationFields element.
 51  
 
 52  
  *
 53  
  */
 54  
 @Deprecated
 55  
 public class MaintainableCollectionDefinition extends MaintainableItemDefinition implements CollectionDefinitionI {
 56  
     private static final long serialVersionUID = -5617868782623587053L;
 57  
 
 58  
         // logger
 59  
     //private static Log LOG = LogFactory.getLog(MaintainableCollectionDefinition.class);
 60  
 
 61  
         protected Class<? extends BusinessObject> businessObjectClass;
 62  
 
 63  
     protected Class<? extends BusinessObject> sourceClassName;
 64  
     protected String summaryTitle;
 65  
     protected String attributeToHighlightOnDuplicateKey;
 66  
 
 67  0
     protected boolean includeAddLine = true;
 68  0
     protected boolean includeMultipleLookupLine = true;
 69  0
     private boolean alwaysAllowCollectionDeletion = false;
 70  
 
 71  0
     protected Map<String,MaintainableFieldDefinition> maintainableFieldMap = new HashMap<String, MaintainableFieldDefinition>();
 72  0
     protected Map<String,MaintainableCollectionDefinition> maintainableCollectionMap = new HashMap<String, MaintainableCollectionDefinition>();
 73  0
     protected Map<String,MaintainableFieldDefinition> summaryFieldMap = new HashMap<String, MaintainableFieldDefinition>();
 74  0
     protected Map<String,MaintainableFieldDefinition> duplicateIdentificationFieldMap = new HashMap<String, MaintainableFieldDefinition>();
 75  0
     protected List<MaintainableFieldDefinition> maintainableFields = new ArrayList<MaintainableFieldDefinition>();
 76  0
     protected List<MaintainableCollectionDefinition> maintainableCollections = new ArrayList<MaintainableCollectionDefinition>();
 77  0
     protected List<MaintainableFieldDefinition> summaryFields = new ArrayList<MaintainableFieldDefinition>();
 78  0
     protected List<MaintainableFieldDefinition> duplicateIdentificationFields = new ArrayList<MaintainableFieldDefinition>();
 79  
 
 80  0
     public MaintainableCollectionDefinition() {}
 81  
 
 82  
 
 83  
 
 84  
     /**
 85  
      * @return businessObjectClass
 86  
      */
 87  
     public Class<? extends BusinessObject> getBusinessObjectClass() {
 88  0
         return businessObjectClass;
 89  
     }
 90  
 
 91  
     /**
 92  
      * The BusinessObject class used for each row of this collection.
 93  
      */
 94  
     public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
 95  0
         if (businessObjectClass == null) {
 96  0
             throw new IllegalArgumentException("invalid (null) dataObjectClass");
 97  
         }
 98  
 
 99  0
         this.businessObjectClass = businessObjectClass;
 100  0
     }
 101  
 
 102  
     /**
 103  
      * @return Collection of all lookupField MaintainableFieldDefinitions associated with this MaintainableCollectionDefinition, in
 104  
      *         the order in which they were added
 105  
      */
 106  
     public List<MaintainableFieldDefinition> getMaintainableFields() {
 107  0
         return maintainableFields;
 108  
     }
 109  
 
 110  
     public List<? extends FieldDefinitionI> getFields() {
 111  0
         return maintainableFields;
 112  
     }
 113  
 
 114  
     /**
 115  
      * Directly validate simple fields, call completeValidation on Definition fields.
 116  
      * 
 117  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 118  
      */
 119  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 120  0
         if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, getName())) {
 121  0
             throw new AttributeValidationException("unable to find collection named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 122  
         }
 123  
 
 124  0
         if (dissallowDuplicateKey()) {
 125  0
             if (!DataDictionary.isPropertyOf(businessObjectClass, attributeToHighlightOnDuplicateKey)) {
 126  0
                 throw new AttributeValidationException("unable to find attribute named '" + attributeToHighlightOnDuplicateKey + "'in dataObjectClass '" + businessObjectClass.getName() + "' of collection '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 127  
             }
 128  
         }
 129  
         
 130  0
         for (MaintainableFieldDefinition maintainableField : maintainableFields ) {
 131  0
             maintainableField.completeValidation(businessObjectClass, null);
 132  
         }
 133  
 
 134  0
         for (MaintainableCollectionDefinition maintainableCollection : maintainableCollections ) {
 135  0
             maintainableCollection.completeValidation(businessObjectClass, null);
 136  
         }
 137  
 
 138  
 //        for (MaintainableFieldDefinition summaryField : summaryFields ) {
 139  
 //            summaryField.completeValidation(dataObjectClass, null, validationCompletionUtils);
 140  
 //        }
 141  
 //        
 142  
 //        for (MaintainableFieldDefinition identifierField : duplicateIdentificationFields) {
 143  
 //            identifierField.completeValidation(dataObjectClass, null, validationCompletionUtils);
 144  
 //        }
 145  0
     }
 146  
 
 147  
 
 148  
     /**
 149  
      * @see java.lang.Object#toString()
 150  
      */
 151  
     public String toString() {
 152  0
         return "MaintainableCollectionDefinition for " + getName();
 153  
     }
 154  
 
 155  
 
 156  
     public Class<? extends BusinessObject> getSourceClassName() {
 157  0
         return sourceClassName;
 158  
     }
 159  
 
 160  
 
 161  
     /** BusinessObject class which should be used for multiple value lookups for this collection.
 162  
      */
 163  
     public void setSourceClassName(Class<? extends BusinessObject> sourceClass) {
 164  0
         this.sourceClassName = sourceClass;
 165  0
     }
 166  
 
 167  
     public boolean getIncludeAddLine() {
 168  0
         return includeAddLine;
 169  
     }
 170  
 
 171  
 
 172  
     /** Control whether an "add" line should be included at the top of this collection. */
 173  
     public void setIncludeAddLine(boolean includeAddLine) {
 174  0
         this.includeAddLine = includeAddLine;
 175  0
     }
 176  
 
 177  
     /**
 178  
      * @return Collection of all lookupField MaintainableCollectionDefinitions associated with this
 179  
      *         MaintainableCollectionDefinition, in the order in which they were added
 180  
      */
 181  
     public List<MaintainableCollectionDefinition> getMaintainableCollections() {
 182  0
         return maintainableCollections;
 183  
     }
 184  
 
 185  
     public List<? extends CollectionDefinitionI> getCollections() {
 186  0
         return maintainableCollections;
 187  
     }
 188  
 
 189  
     
 190  
     /**
 191  
      * @return Collection of all SummaryFieldDefinitions associated with this SummaryFieldDefinition, in the order in which they
 192  
      *         were added
 193  
      */
 194  
     public List<? extends FieldDefinitionI> getSummaryFields() {
 195  0
         return summaryFields;
 196  
     }
 197  
 
 198  
     public boolean hasSummaryField(String key) {
 199  0
         return summaryFieldMap.containsKey(key);
 200  
     }
 201  
 
 202  
     public boolean isIncludeMultipleLookupLine() {
 203  0
         return includeMultipleLookupLine;
 204  
     }
 205  
 
 206  
     /** Set whether the multiple lookup line (and link) should appear above this collection. */
 207  
     public void setIncludeMultipleLookupLine(boolean includeMultipleLookupLine) {
 208  0
         this.includeMultipleLookupLine = includeMultipleLookupLine;
 209  0
     }
 210  
 
 211  
     public String getSummaryTitle() {
 212  0
         return summaryTitle;
 213  
     }
 214  
 
 215  
     /**
 216  
 summaryTitle is the label of the summary
 217  
      */
 218  
     public void setSummaryTitle(String overrideSummaryName) {
 219  0
         this.summaryTitle = overrideSummaryName;
 220  0
     }
 221  
 
 222  
 
 223  
     public String getAttributeToHighlightOnDuplicateKey() {
 224  0
         return attributeToHighlightOnDuplicateKey;
 225  
     }
 226  
 
 227  
     /**
 228  
  attributeToHighlightOnDuplicateKey is the name of an attribute to highlight
 229  
                             if two records in the collection are the same based on the
 230  
                             duplicateIdentificationFields element.
 231  
     */
 232  
     public void setAttributeToHighlightOnDuplicateKey(String attributeToHighlightOnDuplicate) {
 233  0
         this.attributeToHighlightOnDuplicateKey = attributeToHighlightOnDuplicate;
 234  0
     }
 235  
 
 236  
     public boolean dissallowDuplicateKey() {
 237  0
         return StringUtils.isNotBlank(getAttributeToHighlightOnDuplicateKey());
 238  
     }
 239  
 
 240  
     public List<MaintainableFieldDefinition> getDuplicateIdentificationFields() {
 241  0
         return duplicateIdentificationFields;
 242  
     }
 243  
 
 244  
     /** The list of fields to include in this collection. */
 245  
     public void setMaintainableFields(List<MaintainableFieldDefinition> maintainableFields) {
 246  0
         maintainableFieldMap.clear();
 247  0
         for ( MaintainableFieldDefinition maintainableField : maintainableFields ) {
 248  0
             if (maintainableField == null) {
 249  0
                 throw new IllegalArgumentException("invalid (null) maintainableField");
 250  
             }
 251  
 
 252  0
             String fieldName = maintainableField.getName();
 253  0
             if (maintainableFieldMap.containsKey(fieldName)) {
 254  0
                 throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'");
 255  
             }
 256  
 
 257  0
             maintainableFieldMap.put(fieldName, maintainableField);
 258  0
         }
 259  0
         this.maintainableFields = maintainableFields;
 260  0
     }
 261  
 
 262  
     /** The list of sub-collections to include in this collection. */
 263  
     public void setMaintainableCollections(List<MaintainableCollectionDefinition> maintainableCollections) {
 264  0
         maintainableCollectionMap.clear();
 265  0
         for (MaintainableCollectionDefinition maintainableCollection : maintainableCollections ) {
 266  0
             if (maintainableCollection == null) {
 267  0
                 throw new IllegalArgumentException("invalid (null) maintainableCollection");
 268  
             }
 269  
 
 270  0
             String fieldName = maintainableCollection.getName();
 271  0
             if (maintainableCollectionMap.containsKey(fieldName)) {
 272  0
                 throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'");
 273  
             }
 274  
 
 275  0
             maintainableCollectionMap.put(fieldName, maintainableCollection);
 276  0
         }
 277  0
         this.maintainableCollections = maintainableCollections;
 278  0
     }
 279  
 
 280  
     /**
 281  
 
 282  
                         The summaryFields element defines a set of summaryField
 283  
                         elements.
 284  
      */
 285  
     public void setSummaryFields(List<MaintainableFieldDefinition> summaryFields) {
 286  0
         summaryFieldMap.clear();
 287  0
         for (MaintainableFieldDefinition summaryField : summaryFields ) {
 288  0
             if (summaryField == null) {
 289  0
                 throw new IllegalArgumentException("invalid (null) summaryField");
 290  
             }
 291  
 
 292  0
             String fieldName = summaryField.getName();
 293  0
             if (summaryFieldMap.containsKey(fieldName)) {
 294  0
                 throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'");
 295  
             }
 296  
 
 297  0
             summaryFieldMap.put(fieldName, summaryField);
 298  0
         }
 299  0
         this.summaryFields = summaryFields;
 300  0
     }
 301  
 
 302  
     /**
 303  
     The duplicateIdentificationFields element is used to define a set of
 304  
     fields that will be used to determine if two records in the collection
 305  
     are duplicates.
 306  
     */
 307  
     public void setDuplicateIdentificationFields(List<MaintainableFieldDefinition> duplicateIdentificationFields) {
 308  0
         duplicateIdentificationFieldMap.clear();
 309  0
         for (MaintainableFieldDefinition identifierField : duplicateIdentificationFields) {
 310  0
             if (identifierField == null) {
 311  0
                 throw new IllegalArgumentException("invalid (null) identifierField");
 312  
             }
 313  
 
 314  0
             String fieldName = identifierField.getName();
 315  0
             if (duplicateIdentificationFieldMap.containsKey(fieldName)) {
 316  0
                 throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'");
 317  
             }
 318  
 
 319  0
             duplicateIdentificationFieldMap.put(fieldName, identifierField);            
 320  0
         }
 321  0
         this.duplicateIdentificationFields = duplicateIdentificationFields;
 322  0
     }
 323  
 
 324  
 
 325  
 
 326  
         public boolean isAlwaysAllowCollectionDeletion() {
 327  0
                 return this.alwaysAllowCollectionDeletion;
 328  
         }
 329  
 
 330  
 
 331  
 
 332  
         public void setAlwaysAllowCollectionDeletion(
 333  
                         boolean alwaysAllowCollectionDeletion) {
 334  0
                 this.alwaysAllowCollectionDeletion = alwaysAllowCollectionDeletion;
 335  0
         }
 336  
     
 337  
 }