View Javadoc
1   /*
2    * Copyright 2011 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.ole.sys.businessobject.datadictionary;
17  
18  import org.kuali.rice.kim.api.group.Group;
19  import org.kuali.rice.kim.api.role.Role;
20  import org.kuali.rice.kim.framework.group.GroupEbo;
21  import org.kuali.rice.kim.framework.role.RoleEbo;
22  import org.kuali.rice.krad.bo.BusinessObject;
23  import org.kuali.rice.krad.datadictionary.DataDictionary;
24  import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
25  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
26  import org.kuali.rice.location.api.campus.Campus;
27  import org.kuali.rice.location.api.country.Country;
28  import org.kuali.rice.location.api.county.County;
29  import org.kuali.rice.location.api.postalcode.PostalCode;
30  import org.kuali.rice.location.api.state.State;
31  import org.kuali.rice.location.framework.campus.CampusEbo;
32  import org.kuali.rice.location.framework.country.CountryEbo;
33  import org.kuali.rice.location.framework.county.CountyEbo;
34  import org.kuali.rice.location.framework.postalcode.PostalCodeEbo;
35  import org.kuali.rice.location.framework.state.StateEbo;
36  
37  public class KfsRelationshipDefinition extends RelationshipDefinition {
38      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KfsRelationshipDefinition.class);
39  
40      @Override
41      public Class<?> getTargetClass() {
42          if (targetClass == null) {
43              Class propertyClass = DataDictionary.getAttributeClass(sourceClass, objectAttributeName);
44              if (propertyClass == null) {
45                  throw new AttributeValidationException("cannot get valid class for property '" + objectAttributeName + "' as an attribute of '" + sourceClass + "'");
46              }
47              // RICE20 - HACK ALERT!!!! - if the property class is one of the
48              // ones we use via BOs, change the type to an EBO to attempt to
49              // preserve the lookups
50              if ( Campus.class.isAssignableFrom(propertyClass) ) {
51                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
52                  propertyClass = CampusEbo.class;
53              } else if ( State.class.isAssignableFrom(propertyClass) ) {
54                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
55                  propertyClass = StateEbo.class;
56              } else if ( PostalCode.class.isAssignableFrom(propertyClass) ) {
57                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
58                  propertyClass = PostalCodeEbo.class;
59              } else if ( Country.class.isAssignableFrom(propertyClass) ) {
60                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
61                  propertyClass = CountryEbo.class;
62              } else if ( County.class.isAssignableFrom(propertyClass) ) {
63                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
64                  propertyClass = CountyEbo.class;
65              } else if ( Role.class.isAssignableFrom(propertyClass) ) {
66                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
67                  propertyClass = RoleEbo.class;
68              } else if ( Group.class.isAssignableFrom(propertyClass) ) {
69                  LOG.error( "ALERT! : " + propertyClass.getName() + " Reference Unconverted to Ebo class: " + sourceClass.getName() + "." + objectAttributeName );
70                  propertyClass = GroupEbo.class;
71              } else {
72                  if (!BusinessObject.class.isAssignableFrom(propertyClass)) {
73                      throw new AttributeValidationException("property '" + objectAttributeName + "' is not a BusinessObject (" + propertyClass.getName() + ") on sourceClass (" + sourceClass +")");
74                  }
75              }
76  
77  
78              targetClass = propertyClass;
79          }
80          return targetClass;
81      }
82  
83      @Override
84      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
85          if ( LOG.isDebugEnabled() ) {
86              LOG.debug( "Validating Relationships on BO: " + rootBusinessObjectClass.getSimpleName() + "." + objectAttributeName );
87          }
88          // TODO Auto-generated method stub
89          super.completeValidation(rootBusinessObjectClass, otherBusinessObjectClass);
90      }
91  
92  }