1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
48
49
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
89 super.completeValidation(rootBusinessObjectClass, otherBusinessObjectClass);
90 }
91
92 }