View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.businessobject.datadictionary;
20  
21  import org.kuali.rice.kim.api.group.Group;
22  import org.kuali.rice.kim.api.role.Role;
23  import org.kuali.rice.kim.framework.group.GroupEbo;
24  import org.kuali.rice.kim.framework.role.RoleEbo;
25  import org.kuali.rice.krad.bo.BusinessObject;
26  import org.kuali.rice.krad.datadictionary.DataDictionary;
27  import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
28  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
29  import org.kuali.rice.location.api.campus.Campus;
30  import org.kuali.rice.location.api.country.Country;
31  import org.kuali.rice.location.api.county.County;
32  import org.kuali.rice.location.api.postalcode.PostalCode;
33  import org.kuali.rice.location.api.state.State;
34  import org.kuali.rice.location.framework.campus.CampusEbo;
35  import org.kuali.rice.location.framework.country.CountryEbo;
36  import org.kuali.rice.location.framework.county.CountyEbo;
37  import org.kuali.rice.location.framework.postalcode.PostalCodeEbo;
38  import org.kuali.rice.location.framework.state.StateEbo;
39  
40  public class KfsRelationshipDefinition extends RelationshipDefinition {
41      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KfsRelationshipDefinition.class);
42  
43      @Override
44      public Class<?> getTargetClass() {
45          if (targetClass == null) {
46              Class propertyClass = DataDictionary.getAttributeClass(sourceClass, objectAttributeName);
47              if (propertyClass == null) {
48                  throw new AttributeValidationException("cannot get valid class for property '" + objectAttributeName + "' as an attribute of '" + sourceClass + "'");
49              }
50              // RICE20 - HACK ALERT!!!! - if the property class is one of the
51              // ones we use via BOs, change the type to an EBO to attempt to
52              // preserve the lookups
53              if ( Campus.class.isAssignableFrom(propertyClass) ) {
54                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
55                  propertyClass = CampusEbo.class;
56              } else if ( State.class.isAssignableFrom(propertyClass) ) {
57                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
58                  propertyClass = StateEbo.class;
59              } else if ( PostalCode.class.isAssignableFrom(propertyClass) ) {
60                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
61                  propertyClass = PostalCodeEbo.class;
62              } else if ( Country.class.isAssignableFrom(propertyClass) ) {
63                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
64                  propertyClass = CountryEbo.class;
65              } else if ( County.class.isAssignableFrom(propertyClass) ) {
66                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
67                  propertyClass = CountyEbo.class;
68              } else if ( Role.class.isAssignableFrom(propertyClass) ) {
69                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
70                  propertyClass = RoleEbo.class;
71              } else if ( Group.class.isAssignableFrom(propertyClass) ) {
72                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
73                  propertyClass = GroupEbo.class;
74              } else {
75                  if (!BusinessObject.class.isAssignableFrom(propertyClass)) {
76                      throw new AttributeValidationException("property '" + objectAttributeName + "' is not a BusinessObject (" + propertyClass.getName() + ") on sourceClass (" + sourceClass +")");
77                  }
78              }
79  
80  
81              targetClass = propertyClass;
82          }
83          return targetClass;
84      }
85  
86      @Override
87      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
88          if ( LOG.isDebugEnabled() ) {
89              LOG.debug( "Validating Relationships on BO: " + rootBusinessObjectClass.getSimpleName() + "." + objectAttributeName );
90          }
91          // TODO Auto-generated method stub
92          super.completeValidation(rootBusinessObjectClass, otherBusinessObjectClass);
93      }
94  
95  }