Coverage Report - org.kuali.rice.krad.datadictionary.BusinessObjectEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessObjectEntry
3%
1/33
0%
0/24
3.571
 
 1  
 /*
 2  
  * Copyright 2005-2008 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  
 
 17  
 package org.kuali.rice.krad.datadictionary;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.krad.bo.BusinessObject;
 21  
 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
 22  
 
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * A single BusinessObject entry in the DataDictionary, which contains information relating to the display, validation,
 27  
  * and general maintenance of a BusinessObject and its attributes.
 28  
  *
 29  
  * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process
 30  
  *
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  64
 public class BusinessObjectEntry extends DataObjectEntry {
 34  
 
 35  
     protected Class<? extends BusinessObject> baseBusinessObjectClass;
 36  
 
 37  
     public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
 38  0
         super.setDataObjectClass(businessObjectClass);
 39  
 
 40  0
         if (businessObjectClass == null) {
 41  0
             throw new IllegalArgumentException("invalid (null) dataObjectClass");
 42  
         }
 43  
 
 44  0
         if (getRelationships() != null) {
 45  0
             for (RelationshipDefinition rd : getRelationships()) {
 46  0
                 rd.setSourceClass(businessObjectClass);
 47  
             }
 48  
         }
 49  0
     }
 50  
 
 51  
     public Class<? extends BusinessObject> getBusinessObjectClass() {
 52  0
         return (Class<? extends BusinessObject>) super.getDataObjectClass();
 53  
     }
 54  
 
 55  
     /**
 56  
      * The baseBusinessObjectClass is an optional parameter for specifying a superclass
 57  
      * for the dataObjectClass, allowing the data dictionary to index by superclass
 58  
      * in addition to the current class.
 59  
      */
 60  
 
 61  
     public void setBaseBusinessObjectClass(Class<? extends BusinessObject> baseBusinessObjectClass) {
 62  0
         this.baseBusinessObjectClass = baseBusinessObjectClass;
 63  0
     }
 64  
 
 65  
     public Class<? extends BusinessObject> getBaseBusinessObjectClass() {
 66  0
         return baseBusinessObjectClass;
 67  
     }
 68  
 
 69  
     /**
 70  
      * Directly validate simple fields, call completeValidation on Definition fields.
 71  
      */
 72  
     @Override
 73  
     public void completeValidation() {
 74  
         try {
 75  
 
 76  0
             if (baseBusinessObjectClass != null && !baseBusinessObjectClass.isAssignableFrom(getDataObjectClass())) {
 77  0
                 throw new ClassValidationException("The baseBusinessObjectClass " + baseBusinessObjectClass.getName() +
 78  
                         " is not a superclass of the dataObjectClass " + getDataObjectClass().getName());
 79  
             }
 80  
 
 81  0
             super.completeValidation();
 82  
 
 83  0
             if (inactivationBlockingDefinitions != null && !inactivationBlockingDefinitions.isEmpty()) {
 84  0
                 for (InactivationBlockingDefinition inactivationBlockingDefinition : inactivationBlockingDefinitions) {
 85  0
                     inactivationBlockingDefinition.completeValidation(getDataObjectClass(), null);
 86  
                 }
 87  
             }
 88  0
         } catch (DataDictionaryException ex) {
 89  
             // just rethrow
 90  0
             throw ex;
 91  0
         } catch (Exception ex) {
 92  0
             throw new DataDictionaryException("Exception validating " + this, ex);
 93  0
         }
 94  0
     }
 95  
 
 96  
     /**
 97  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase#afterPropertiesSet()
 98  
      */
 99  
     @SuppressWarnings("unchecked")
 100  
     @Override
 101  
     public void afterPropertiesSet() throws Exception {
 102  0
         super.afterPropertiesSet();
 103  0
         if (inactivationBlockingDefinitions != null) {
 104  0
             for (InactivationBlockingDefinition ibd : inactivationBlockingDefinitions) {
 105  0
                 ibd.setBusinessObjectClass(getBusinessObjectClass());
 106  0
                 if (StringUtils.isNotBlank(ibd.getBlockedReferencePropertyName()) &&
 107  
                         ibd.getBlockedBusinessObjectClass() == null) {
 108  
                     // if the user didn't specify a class name for the blocked reference, determine it here
 109  0
                     ibd.setBlockedBusinessObjectClass(DataDictionary
 110  
                             .getAttributeClass(getDataObjectClass(), ibd.getBlockedReferencePropertyName()));
 111  
                 }
 112  0
                 ibd.setBlockingReferenceBusinessObjectClass(getBusinessObjectClass());
 113  
             }
 114  
         }
 115  0
     }
 116  
 
 117  
     /**
 118  
      * @see java.lang.Object#toString()
 119  
      */
 120  
     @Override
 121  
     public String toString() {
 122  0
         return "BusinessObjectEntry for " + getBusinessObjectClass();
 123  
     }
 124  
 }