Coverage Report - org.kuali.rice.krad.datadictionary.ReferenceDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
ReferenceDefinition
0%
0/40
0%
0/20
1.941
 
 1  
 /*
 2  
  * Copyright 2006-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.krad.datadictionary;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.bo.BusinessObject;
 20  
 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
 21  
 
 22  
 /**
 23  
  *                     The reference element specifies the name of a reference
 24  
                     object that is required to exist in order for the primary
 25  
                     business object to be created or modified on a BO.
 26  
 
 27  
                     DD: See ReferenceDefinition.java
 28  
 
 29  
                     JSTL: references are Maps with the following keys:
 30  
                     * attributeName (String)
 31  
                     * activeIndicatorAttributeName (String)
 32  
                     * activeIndicatorReversed (boolean String)
 33  
                     * attributeToHighlightOnFail (String)
 34  
                     * displayFieldName (String)
 35  
 
 36  
  *
 37  
  */
 38  
 public class ReferenceDefinition extends DataDictionaryDefinitionBase {
 39  
     private static final long serialVersionUID = 1737968024207302931L;
 40  
     
 41  
         protected String attributeName;
 42  
     protected String attributeToHighlightOnFail;
 43  
     protected String displayFieldName;
 44  
     protected String collection;
 45  
     protected Class<? extends BusinessObject> collectionBusinessObjectClass;
 46  
     protected Class<? extends BusinessObject> businessObjectClass;
 47  
     
 48  0
     public ReferenceDefinition() {}
 49  
 
 50  
     /**
 51  
      * @return attributeName
 52  
      */
 53  
     public String getAttributeName() {
 54  0
         return attributeName;
 55  
     }
 56  
 
 57  
     /**
 58  
      * attributeName is the name of a reference object that
 59  
                         must exist and not be null.  In the case of a collection,
 60  
                         then this is the name of a reference object within the
 61  
                         collection element.
 62  
      * 
 63  
      * @throws IllegalArgumentException if the given attributeName is blank
 64  
      */
 65  
     public void setAttributeName(String attributeName) {
 66  0
         if (StringUtils.isBlank(attributeName)) {
 67  0
             throw new IllegalArgumentException("invalid (blank) attributeName");
 68  
         }
 69  0
         this.attributeName = attributeName;
 70  0
     }
 71  
 
 72  
     /**
 73  
      * Gets the attributeToHighlightOnFail attribute.
 74  
      * 
 75  
      * @return Returns the attributeToHighlightOnFail.
 76  
      */
 77  
     public String getAttributeToHighlightOnFail() {
 78  0
         return attributeToHighlightOnFail;
 79  
     }
 80  
 
 81  
     /**
 82  
             attributeToHighlightOnFail is the name of the busines
 83  
                         object attribute which will be highlighted when
 84  
                         the default existence check fails.
 85  
      */
 86  
     public void setAttributeToHighlightOnFail(String attributeToHighlightOnFail) {
 87  0
         if (StringUtils.isBlank(attributeToHighlightOnFail)) {
 88  0
             throw new IllegalArgumentException("invalid (blank) attributeToHighlightOnFail");
 89  
         }
 90  0
         this.attributeToHighlightOnFail = attributeToHighlightOnFail;
 91  0
     }
 92  
 
 93  
     /**
 94  
      * Gets the displayFieldName attribute.
 95  
      * 
 96  
      * @return Returns the displayFieldName.
 97  
      */
 98  
     public String getDisplayFieldName() {
 99  0
         return displayFieldName;
 100  
     }
 101  
 
 102  
     /**
 103  
         displayFieldName is the name of the field to pull the label as it will
 104  
                         appear in an error message.  e.g. "chartOfAccountsCode".
 105  
      */
 106  
     public void setDisplayFieldName(String displayFieldName) {
 107  0
         this.displayFieldName = displayFieldName;
 108  0
     }
 109  
 
 110  
     /**
 111  
      * This method returns true if the displayFieldName is set, otherwise it returns false. Whether the displayFieldName is set is
 112  
      * defined by whether it has any non-whitespace content in it.
 113  
      * 
 114  
      * @return
 115  
      */
 116  
     public boolean isDisplayFieldNameSet() {
 117  0
         return StringUtils.isNotBlank(displayFieldName);
 118  
     }
 119  
 
 120  
     public String getCollection() {
 121  0
         return collection;
 122  
     }
 123  
 
 124  
     /**
 125  
         collection is the name of a collection that must exist
 126  
      */
 127  
     public void setCollection(String collection) {
 128  0
         this.collection = collection;
 129  0
     }
 130  
 
 131  
     public boolean isCollectionReference() {
 132  0
         return StringUtils.isNotBlank(getCollection());
 133  
     }
 134  
 
 135  
     public Class<? extends BusinessObject> getCollectionBusinessObjectClass() {
 136  0
         if( collectionBusinessObjectClass == null && isCollectionReference() ){
 137  0
             collectionBusinessObjectClass=DataDictionary.getCollectionElementClass(businessObjectClass, collection);
 138  
         }
 139  
 
 140  0
         return collectionBusinessObjectClass;
 141  
     }
 142  
 
 143  
     /** Class that the specified collection represents.  Does not need to be set.  The DD
 144  
      * Will set this attribute through introspection.
 145  
      */
 146  
     public void setCollectionBusinessObjectClass(Class<? extends BusinessObject> collectionBusinessObjectClass) {
 147  0
         this.collectionBusinessObjectClass = collectionBusinessObjectClass;
 148  0
     }
 149  
 
 150  
     /**
 151  
      * Directly validate simple fields.
 152  
      * 
 153  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 154  
      */
 155  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 156  
 
 157  
 
 158  
         // make sure the attributeName is actually a property of the BO
 159  0
         String tmpAttributeName = isCollectionReference() ? collection : attributeName;
 160  0
         if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, tmpAttributeName)) {
 161  0
             throw new AttributeValidationException("unable to find attribute '" + tmpAttributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 162  
         }
 163  
         // make sure the attributeToHighlightOnFail is actually a property of the BO
 164  0
         if (isCollectionReference()) {
 165  0
             getCollectionBusinessObjectClass(); // forces loading of the class
 166  0
             if ( collectionBusinessObjectClass == null ) {
 167  0
                 throw new AttributeValidationException("Unable to determine collectionBusinessObjectClass for collection '" + businessObjectClass.getName() + "." + collection + "'");
 168  
             }
 169  
             
 170  0
             if (!DataDictionary.isPropertyOf(collectionBusinessObjectClass, attributeToHighlightOnFail)) {
 171  0
                 throw new AttributeValidationException("unable to find attribute '" + attributeToHighlightOnFail + "' in collectionBusinessObjectClass '" + collectionBusinessObjectClass.getName() + "' (" + "" + ")");
 172  
             }
 173  
         }
 174  
         else {
 175  0
             if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeToHighlightOnFail)) {
 176  0
                 throw new AttributeValidationException("unable to find attribute '" + attributeToHighlightOnFail + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 177  
             }
 178  
         }
 179  
 
 180  0
     }
 181  
 
 182  
 
 183  
     /**
 184  
      * @see java.lang.Object#toString()
 185  
      */
 186  
     public String toString() {
 187  0
         return "ReferenceDefinition for attribute " + getAttributeName();
 188  
     }
 189  
 
 190  
     public Class<? extends BusinessObject> getBusinessObjectClass() {
 191  0
         return businessObjectClass;
 192  
     }
 193  
 
 194  
     public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
 195  0
         this.businessObjectClass = businessObjectClass;
 196  0
     }
 197  
 }