|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.kns.datadictionary;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  20 |     | 
   import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;  | 
  |  21 |     | 
     | 
  |  22 |     | 
     | 
  |  23 |     | 
     | 
  |  24 |     | 
     | 
  |  25 |     | 
     | 
  |  26 |     | 
     | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |     | 
     | 
  |  34 |     | 
     | 
  |  35 |     | 
     | 
  |  36 |     | 
     | 
  |  37 |     | 
   public class PrimitiveAttributeDefinition extends DataDictionaryDefinitionBase { | 
  |  38 |     | 
       private static final long serialVersionUID = -715128943756700821L;  | 
  |  39 |     | 
         | 
  |  40 |     | 
           protected String sourceName;  | 
  |  41 |     | 
       protected String targetName;  | 
  |  42 |     | 
     | 
  |  43 |    0 |        public PrimitiveAttributeDefinition() {} | 
  |  44 |     | 
     | 
  |  45 |     | 
     | 
  |  46 |     | 
         | 
  |  47 |     | 
     | 
  |  48 |     | 
     | 
  |  49 |     | 
       public String getSourceName() { | 
  |  50 |    0 |            return sourceName;  | 
  |  51 |     | 
       }  | 
  |  52 |     | 
     | 
  |  53 |     | 
         | 
  |  54 |     | 
     | 
  |  55 |     | 
     | 
  |  56 |     | 
     | 
  |  57 |     | 
     | 
  |  58 |     | 
       public void setSourceName(String sourceName) { | 
  |  59 |    0 |            if (StringUtils.isBlank(sourceName)) { | 
  |  60 |    0 |                throw new IllegalArgumentException("invalid (blank) sourceName"); | 
  |  61 |     | 
           }  | 
  |  62 |     | 
     | 
  |  63 |    0 |            this.sourceName = sourceName;  | 
  |  64 |    0 |        }  | 
  |  65 |     | 
     | 
  |  66 |     | 
     | 
  |  67 |     | 
         | 
  |  68 |     | 
     | 
  |  69 |     | 
     | 
  |  70 |     | 
       public String getTargetName() { | 
  |  71 |    0 |            return targetName;  | 
  |  72 |     | 
       }  | 
  |  73 |     | 
     | 
  |  74 |     | 
         | 
  |  75 |     | 
     | 
  |  76 |     | 
     | 
  |  77 |     | 
     | 
  |  78 |     | 
     | 
  |  79 |     | 
       public void setTargetName(String targetName) { | 
  |  80 |    0 |            if (StringUtils.isBlank(targetName)) { | 
  |  81 |    0 |                throw new IllegalArgumentException("invalid (blank) targetName"); | 
  |  82 |     | 
           }  | 
  |  83 |     | 
     | 
  |  84 |    0 |            this.targetName = targetName;  | 
  |  85 |    0 |        }  | 
  |  86 |     | 
     | 
  |  87 |     | 
     | 
  |  88 |     | 
         | 
  |  89 |     | 
     | 
  |  90 |     | 
     | 
  |  91 |     | 
     | 
  |  92 |     | 
     | 
  |  93 |     | 
       public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { | 
  |  94 |    0 |            if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, sourceName)) { | 
  |  95 |    0 |                throw new AttributeValidationException("unable to find attribute '" + sourceName + "' in relationship class '" + rootBusinessObjectClass + "' (" + "" + ")"); | 
  |  96 |     | 
           }  | 
  |  97 |    0 |            if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, targetName)) { | 
  |  98 |    0 |                throw new AttributeValidationException("unable to find attribute '" + targetName + "' in related class '" + otherBusinessObjectClass.getName() + "' (" + "" + ")"); | 
  |  99 |     | 
           }  | 
  |  100 |     | 
     | 
  |  101 |    0 |            Class sourceClass = DataDictionary.getAttributeClass(rootBusinessObjectClass, sourceName);  | 
  |  102 |    0 |            Class targetClass = DataDictionary.getAttributeClass(otherBusinessObjectClass, targetName);  | 
  |  103 |    0 |            if ((null == sourceClass && null != targetClass) || (null != sourceClass && null == targetClass) || !StringUtils.equals(sourceClass.getName(), targetClass.getName())) {             | 
  |  104 |    0 |                    String sourceClassName = rootBusinessObjectClass.getName();  | 
  |  105 |    0 |                String targetClassName = otherBusinessObjectClass.getName();  | 
  |  106 |    0 |                String sourcePath = sourceClassName + "." + sourceName;  | 
  |  107 |    0 |                String targetPath = targetClassName + "." + targetName;  | 
  |  108 |     | 
                 | 
  |  109 |     | 
                 | 
  |  110 |    0 |                if ((sourcePath != null && !StringUtils.contains(sourcePath, ".principalId")) && (targetPath != null && !StringUtils.contains(targetPath, ".principalId"))) { | 
  |  111 |    0 |                        throw new AttributeValidationException("source attribute '" + sourcePath + "' (" + sourceClass + ") and target attribute '" + targetPath + "' (" + targetClass + ") are of differing types (" + "" + ")"); | 
  |  112 |     | 
               }  | 
  |  113 |     | 
           }  | 
  |  114 |    0 |        }  | 
  |  115 |     | 
     | 
  |  116 |     | 
     | 
  |  117 |     | 
         | 
  |  118 |     | 
     | 
  |  119 |     | 
     | 
  |  120 |     | 
       @Override  | 
  |  121 |     | 
       public String toString() { | 
  |  122 |    0 |            return "PrimitiveAttributeDefinition (" + getSourceName()+","+getTargetName()+")"; | 
  |  123 |     | 
       }  | 
  |  124 |     | 
   }  |