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 | 0 | public PrimitiveAttributeDefinition() {} |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public String getSourceName() { |
49 | 0 | return sourceName; |
50 | |
} |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public void setSourceName(String sourceName) { |
58 | 0 | if (StringUtils.isBlank(sourceName)) { |
59 | 0 | throw new IllegalArgumentException("invalid (blank) sourceName"); |
60 | |
} |
61 | |
|
62 | 0 | this.sourceName = sourceName; |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public String getTargetName() { |
70 | 0 | return targetName; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public void setTargetName(String targetName) { |
79 | 0 | if (StringUtils.isBlank(targetName)) { |
80 | 0 | throw new IllegalArgumentException("invalid (blank) targetName"); |
81 | |
} |
82 | |
|
83 | 0 | this.targetName = targetName; |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { |
93 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, sourceName)) { |
94 | 0 | throw new AttributeValidationException("unable to find attribute '" + sourceName + "' in relationship class '" + rootBusinessObjectClass + "' (" + "" + ")"); |
95 | |
} |
96 | 0 | if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, targetName)) { |
97 | 0 | throw new AttributeValidationException("unable to find attribute '" + targetName + "' in related class '" + otherBusinessObjectClass.getName() + "' (" + "" + ")"); |
98 | |
} |
99 | |
|
100 | 0 | Class sourceClass = DataDictionary.getAttributeClass(rootBusinessObjectClass, sourceName); |
101 | 0 | Class targetClass = DataDictionary.getAttributeClass(otherBusinessObjectClass, targetName); |
102 | 0 | if ((null == sourceClass && null != targetClass) || (null != sourceClass && null == targetClass) || !StringUtils.equals(sourceClass.getName(), targetClass.getName())) { |
103 | 0 | String sourceClassName = rootBusinessObjectClass.getName(); |
104 | 0 | String targetClassName = otherBusinessObjectClass.getName(); |
105 | 0 | String sourcePath = sourceClassName + "." + sourceName; |
106 | 0 | String targetPath = targetClassName + "." + targetName; |
107 | |
|
108 | |
|
109 | 0 | if ((sourcePath != null && !StringUtils.contains(sourcePath, ".principalId")) && (targetPath != null && !StringUtils.contains(targetPath, ".principalId"))) { |
110 | 0 | throw new AttributeValidationException("source attribute '" + sourcePath + "' (" + sourceClass + ") and target attribute '" + targetPath + "' (" + targetClass + ") are of differing types (" + "" + ")"); |
111 | |
} |
112 | |
} |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
@Override |
120 | |
public String toString() { |
121 | 0 | return "PrimitiveAttributeDefinition (" + getSourceName()+","+getTargetName()+")"; |
122 | |
} |
123 | |
} |