Coverage Report - org.kuali.rice.krad.datadictionary.BusinessObjectEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessObjectEntry
5%
2/40
0%
0/24
2.636
 
 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  33
 public class BusinessObjectEntry extends DataObjectEntry {
 34  
 
 35  
     protected Class<? extends BusinessObject> baseBusinessObjectClass;
 36  
 
 37  33
     protected boolean boNotesEnabled = false;
 38  
 
 39  
     protected List<InactivationBlockingDefinition> inactivationBlockingDefinitions;
 40  
 
 41  
     public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
 42  0
         super.setDataObjectClass(businessObjectClass);
 43  
 
 44  0
         if (businessObjectClass == null) {
 45  0
             throw new IllegalArgumentException("invalid (null) dataObjectClass");
 46  
         }
 47  
 
 48  0
         if (getRelationships() != null) {
 49  0
             for (RelationshipDefinition rd : getRelationships()) {
 50  0
                 rd.setSourceClass(businessObjectClass);
 51  
             }
 52  
         }
 53  0
     }
 54  
 
 55  
     public Class<? extends BusinessObject> getBusinessObjectClass() {
 56  0
         return (Class<? extends BusinessObject>) super.getDataObjectClass();
 57  
     }
 58  
 
 59  
     /**
 60  
      * The baseBusinessObjectClass is an optional parameter for specifying a superclass
 61  
      * for the dataObjectClass, allowing the data dictionary to index by superclass
 62  
      * in addition to the current class.
 63  
      */
 64  
 
 65  
     public void setBaseBusinessObjectClass(Class<? extends BusinessObject> baseBusinessObjectClass) {
 66  0
         this.baseBusinessObjectClass = baseBusinessObjectClass;
 67  0
     }
 68  
 
 69  
     public Class<? extends BusinessObject> getBaseBusinessObjectClass() {
 70  0
         return baseBusinessObjectClass;
 71  
     }
 72  
 
 73  
     public boolean isBoNotesEnabled() {
 74  0
         return boNotesEnabled;
 75  
     }
 76  
 
 77  
     /**
 78  
      * boNotesEnabled = true or false
 79  
      * true indicates that notes and attachments will be permanently
 80  
      * associated with the business object
 81  
      * false indicates that notes and attachments are associated
 82  
      * with the document used to create or edit the business object.
 83  
      */
 84  
     public void setBoNotesEnabled(boolean boNotesEnabled) {
 85  0
         this.boNotesEnabled = boNotesEnabled;
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Directly validate simple fields, call completeValidation on Definition fields.
 90  
      */
 91  
     @Override
 92  
     public void completeValidation() {
 93  
         try {
 94  
 
 95  0
             if (baseBusinessObjectClass != null && !baseBusinessObjectClass.isAssignableFrom(getDataObjectClass())) {
 96  0
                 throw new ClassValidationException("The baseBusinessObjectClass " + baseBusinessObjectClass.getName() +
 97  
                         " is not a superclass of the dataObjectClass " + getDataObjectClass().getName());
 98  
             }
 99  
 
 100  0
             super.completeValidation();
 101  
 
 102  0
             if (inactivationBlockingDefinitions != null && !inactivationBlockingDefinitions.isEmpty()) {
 103  0
                 for (InactivationBlockingDefinition inactivationBlockingDefinition : inactivationBlockingDefinitions) {
 104  0
                     inactivationBlockingDefinition.completeValidation(getDataObjectClass(), null);
 105  
                 }
 106  
             }
 107  0
         } catch (DataDictionaryException ex) {
 108  
             // just rethrow
 109  0
             throw ex;
 110  0
         } catch (Exception ex) {
 111  0
             throw new DataDictionaryException("Exception validating " + this, ex);
 112  0
         }
 113  0
     }
 114  
 
 115  
     public List<InactivationBlockingDefinition> getInactivationBlockingDefinitions() {
 116  0
         return this.inactivationBlockingDefinitions;
 117  
     }
 118  
 
 119  
     public void setInactivationBlockingDefinitions(
 120  
             List<InactivationBlockingDefinition> inactivationBlockingDefinitions) {
 121  0
         this.inactivationBlockingDefinitions = inactivationBlockingDefinitions;
 122  0
     }
 123  
 
 124  
     /**
 125  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase#afterPropertiesSet()
 126  
      */
 127  
     @SuppressWarnings("unchecked")
 128  
     @Override
 129  
     public void afterPropertiesSet() throws Exception {
 130  0
         super.afterPropertiesSet();
 131  0
         if (inactivationBlockingDefinitions != null) {
 132  0
             for (InactivationBlockingDefinition ibd : inactivationBlockingDefinitions) {
 133  0
                 ibd.setBusinessObjectClass(getBusinessObjectClass());
 134  0
                 if (StringUtils.isNotBlank(ibd.getBlockedReferencePropertyName()) &&
 135  
                         ibd.getBlockedBusinessObjectClass() == null) {
 136  
                     // if the user didn't specify a class name for the blocked reference, determine it here
 137  0
                     ibd.setBlockedBusinessObjectClass(DataDictionary
 138  
                             .getAttributeClass(getDataObjectClass(), ibd.getBlockedReferencePropertyName()));
 139  
                 }
 140  0
                 ibd.setBlockingReferenceBusinessObjectClass(getBusinessObjectClass());
 141  
             }
 142  
         }
 143  0
     }
 144  
 
 145  
     /**
 146  
      * @see java.lang.Object#toString()
 147  
      */
 148  
     @Override
 149  
     public String toString() {
 150  0
         return "BusinessObjectEntry for " + getBusinessObjectClass();
 151  
     }
 152  
 }