View Javadoc
1   /**
2    * Copyright 2005-2014 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.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
21  import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
22  
23  /**
24   * Support attributes define additional attributes that can be used to generate
25   * lookup field conversions and lookup parameters.
26   *
27   * Field conversions and lookup parameters are normally generated using foreign key relationships
28   * defined within OJB and the DD.  Because Person objects are linked in a special way (i.e. they may
29   * come from an external data source and not from the DB, such as LDAP), it is often necessary to define
30   * extra fields that are related to each other, sort of like a supplemental foreign key.
31   *
32   * sourceName is the name of the POJO property of the business object
33   * targetName is the name of attribute that corresponds to the sourceName in the looked up BO
34   * identifier when true, only the field marked as an identifier will be passed in as a lookup parameter
35   * at most one supportAttribute for each relationship should be defined as identifier="true"
36   */
37  @BeanTag(name = "supportAttributeDefinition-bean")
38  public class SupportAttributeDefinition extends PrimitiveAttributeDefinition {
39      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SupportAttributeDefinition.class);
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       * {@inheritDoc}
63       */
64      @Override
65      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
66          completeValidation(rootBusinessObjectClass, otherBusinessObjectClass, new ValidationTrace());
67      }
68  
69      /**
70       * Directly validate simple fields
71       *
72       * @see org.kuali.rice.krad.datadictionary.DataDictionaryEntry#completeValidation(org.kuali.rice.krad.datadictionary.validator.ValidationTrace)
73       */
74      @Override
75      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
76              ValidationTrace tracer) {
77          tracer.addBean(this.getClass().getSimpleName(), ValidationTrace.NO_BEAN_ID);
78          try {
79              if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getSourceName())) {
80                  String currentValues[] = {"attribute = " + getSourceName(), "class = " + rootBusinessObjectClass};
81                  tracer.createError("Unable to find attribute in class", currentValues);
82              }
83              if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, getTargetName())
84                      && !ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface(
85                      otherBusinessObjectClass)) {
86  
87                  String currentValues[] = {"attribute = " + getTargetName(), "class = " + otherBusinessObjectClass};
88                  tracer.createError("Unable to find attribute in class", currentValues);
89              }
90          } catch (RuntimeException ex) {
91              String currentValues[] = {"Exception = " + ex.getMessage()};
92              tracer.createError("Unable to validate attribute", currentValues);
93              LOG.error( "Exception while validating SupportAttributeDefintion on " + rootBusinessObjectClass + ": " + this, ex);
94          }
95      }
96  
97      @Override
98      public String toString() {
99          StringBuilder builder = new StringBuilder();
100         builder.append("SupportAttributeDefinition [identifier=").append(this.identifier).append(", sourceName=")
101                 .append(this.sourceName).append(", targetName=").append(this.targetName).append("]");
102         return builder.toString();
103     }
104 
105 }
106