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