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.bo.BusinessObject;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23  
24  /**
25   * A single BusinessObject entry in the DataDictionary, which contains information relating to the display, validation,
26   * and general maintenance of a BusinessObject and its attributes.
27   *
28   * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @BeanTag(name = "businessObjectEntry")
33  public class BusinessObjectEntry extends DataObjectEntry {
34      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusinessObjectEntry.class);
35  
36      public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) {
37          super.setDataObjectClass(businessObjectClass);
38  
39          if (businessObjectClass == null) {
40              throw new IllegalArgumentException("invalid (null) dataObjectClass");
41          }
42  
43          if (getRelationships() != null) {
44              for (RelationshipDefinition rd : getRelationships()) {
45                  rd.setSourceClass(businessObjectClass);
46              }
47          }
48      }
49  
50      public Class<? extends BusinessObject> getBusinessObjectClass() {
51          return (Class<? extends BusinessObject>) super.getDataObjectClass();
52      }
53  
54      /**
55       * The baseBusinessObjectClass is an optional parameter for specifying a base class
56       * for the dataObjectClass, allowing the data dictionary to index by the base class
57       * in addition to the current class.
58       */
59  
60      public void setBaseBusinessObjectClass(Class<? extends BusinessObject> baseBusinessObjectClass) {
61          super.setBaseDataObjectClass(baseBusinessObjectClass);
62      }
63  
64      @BeanTagAttribute(name = "baseBusinessObjectClass")
65      public Class<? extends BusinessObject> getBaseBusinessObjectClass() {
66          return (Class<? extends BusinessObject>) super.getBaseDataObjectClass();
67      }
68  
69      /**
70       * Directly validate simple fields, call completeValidation on Definition fields.
71       */
72      @Override
73      public void completeValidation() {
74          completeValidation(new ValidationTrace());
75      }
76  
77      @Override
78      public void completeValidation(ValidationTrace tracer) {
79          super.completeValidation(tracer);
80          try {
81              if (inactivationBlockingDefinitions != null && !inactivationBlockingDefinitions.isEmpty()) {
82                  for (InactivationBlockingDefinition inactivationBlockingDefinition : inactivationBlockingDefinitions) {
83                      inactivationBlockingDefinition.completeValidation(getDataObjectClass(), null, tracer.getCopy());
84                  }
85              }
86          } catch (Exception ex) {
87              String currentValues[] =
88                  {"BO Class = " + getBusinessObjectClass(), "Exception = " + ex.getMessage()};
89              tracer.createError("Unable to validate BO Entry", currentValues);
90              LOG.error("Exception while validating BusinessObjectEntry: " + getBusinessObjectClass(), ex );
91          }
92      }
93  
94      @Override
95      public void dataDictionaryPostProcessing() {
96          super.dataDictionaryPostProcessing();
97          if (inactivationBlockingDefinitions != null) {
98              for (InactivationBlockingDefinition ibd : inactivationBlockingDefinitions) {
99                  ibd.setBusinessObjectClass(getBusinessObjectClass());
100                 if (StringUtils.isNotBlank(ibd.getBlockedReferencePropertyName())
101                         && ibd.getBlockedBusinessObjectClass() == null) {
102                     // if the user didn't specify a class name for the blocked reference, determine it here
103                     ibd.setBlockedBusinessObjectClass(DataDictionary.getAttributeClass(getDataObjectClass(),
104                             ibd.getBlockedReferencePropertyName()));
105                 }
106                 ibd.setBlockingReferenceBusinessObjectClass(getBusinessObjectClass());
107             }
108         }
109     }
110 }