View Javadoc
1   /**
2    * Copyright 2005-2015 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.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
22  import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
23  
24  /**
25   * Support attributes define additional attributes that can be used to generate
26   * lookup field conversions and lookup parameters.
27   *
28   * Field conversions and lookup parameters are normally generated using foreign key relationships
29   * defined within OJB and the DD.  Because Person objects are linked in a special way (i.e. they may
30   * come from an external data source and not from the DB, such as LDAP), it is often necessary to define
31   * extra fields that are related to each other, sort of like a supplemental foreign key.
32   *
33   * sourceName is the name of the POJO property of the business object
34   * targetName is the name of attribute that corresponds to the sourceName in the looked up BO
35   * identifier when true, only the field marked as an identifier will be passed in as a lookup parameter
36   * at most one supportAttribute for each relationship should be defined as identifier="true"
37   */
38  @BeanTag(name = "supportAttributeDefinition-bean")
39  public class SupportAttributeDefinition extends PrimitiveAttributeDefinition {
40      private static final long serialVersionUID = -1719022365280776405L;
41  
42      protected boolean identifier;
43  
44      public SupportAttributeDefinition() {}
45  
46      @BeanTagAttribute(name = "identifier")
47      public boolean isIdentifier() {
48          return identifier;
49      }
50  
51      /**
52       * identifier when true, only the field marked as an identifier will be passed in as a lookup parameter
53       * at most one supportAttribute for each relationship should be defined as identifier="true"
54       */
55      public void setIdentifier(boolean identifier) {
56          this.identifier = identifier;
57      }
58  
59      /**
60       * Directly validate simple fields.
61       *
62       * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class,
63       *      java.lang.Object)
64       */
65      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
66          if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getSourceName())) {
67              throw new AttributeValidationException("unable to find attribute '"
68                      + getSourceName()
69                      + "' in relationship class '"
70                      + rootBusinessObjectClass
71                      + "' ("
72                      + ""
73                      + ")");
74          }
75          if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, getTargetName())
76                  && !ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(
77                  otherBusinessObjectClass)) {
78              throw new AttributeValidationException(
79                      "unable to find attribute '" + getTargetName() + "' in related class '" + otherBusinessObjectClass
80                              .getName() + "' (" + "" + ")");
81          }
82      }
83  
84      /**
85       * Directly validate simple fields
86       *
87       * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace)
88       */
89      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
90              ValidationTrace tracer) {
91          tracer.addBean(this.getClass().getSimpleName(), ValidationTrace.NO_BEAN_ID);
92          try {
93              if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getSourceName())) {
94                  String currentValues[] = {"attribute = " + getSourceName(), "class = " + rootBusinessObjectClass};
95                  tracer.createError("Unable to find attribute in class", currentValues);
96              }
97              if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, getTargetName())
98                      && !ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(
99                      otherBusinessObjectClass)) {
100 
101                 String currentValues[] = {"attribute = " + getTargetName(), "class = " + otherBusinessObjectClass};
102                 tracer.createError("Unable to find attribute in class", currentValues);
103             }
104         } catch (RuntimeException ex) {
105             String currentValues[] = {"Exception = " + ex.getMessage()};
106             tracer.createError("Unable to validate attribute", currentValues);
107         }
108     }
109 
110     /**
111      * @see java.lang.Object#toString()
112      */
113     @Override
114     public String toString() {
115         return "SupportAttributeDefinition (" + getSourceName() + "," + getTargetName() + "," + identifier + ")";
116     }
117 
118 }
119