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 java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 @BeanTag(name = "relationshipDefinition")
49 public class RelationshipDefinition extends DataDictionaryDefinitionBase {
50 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RelationshipDefinition.class);
51 private static final long serialVersionUID = 2946722646095412576L;
52
53 protected String objectAttributeName;
54 protected Class<?> sourceClass;
55
56
57
58
59
60
61 protected Class<?> targetClass;
62
63 protected List<PrimitiveAttributeDefinition> primitiveAttributes = new ArrayList<PrimitiveAttributeDefinition>();
64
65 protected List<SupportAttributeDefinition> supportAttributes = new ArrayList<SupportAttributeDefinition>();
66
67
68 public RelationshipDefinition() {}
69
70 @BeanTagAttribute(name = "objectAttributeName")
71 public String getObjectAttributeName() {
72 return objectAttributeName;
73 }
74
75 @BeanTagAttribute(name = "sourceClass")
76 public Class<?> getSourceClass() {
77 return sourceClass;
78 }
79
80
81
82
83 @BeanTagAttribute(name = "targetClass")
84 public Class<?> getTargetClass() {
85 return targetClass;
86 }
87
88
89
90
91
92
93 public void setTargetClass(Class<?> targetClass) {
94 this.targetClass = targetClass;
95 }
96
97
98
99
100
101 public void setObjectAttributeName(String objectAttributeName) {
102 if (StringUtils.isBlank(objectAttributeName)) {
103 throw new IllegalArgumentException("invalid (blank) objectAttributeName");
104 }
105
106 this.objectAttributeName = objectAttributeName;
107 }
108
109 @BeanTagAttribute(name = "primitiveAttributes", type = BeanTagAttribute.AttributeType.LISTBEAN)
110 public List<PrimitiveAttributeDefinition> getPrimitiveAttributes() {
111 return primitiveAttributes;
112 }
113
114 @BeanTagAttribute(name = "supportAttributes", type = BeanTagAttribute.AttributeType.LISTBEAN)
115 public List<SupportAttributeDefinition> getSupportAttributes() {
116 return supportAttributes;
117 }
118
119 public boolean hasIdentifier() {
120 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
121 if (supportAttributeDefinition.isIdentifier()) {
122 return true;
123 }
124 }
125 return false;
126 }
127
128 public SupportAttributeDefinition getIdentifier() {
129 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
130 if (supportAttributeDefinition.isIdentifier()) {
131 return supportAttributeDefinition;
132 }
133 }
134 return null;
135 }
136
137
138
139
140
141
142 @Override
143 public void dataDictionaryPostProcessing() {
144 super.dataDictionaryPostProcessing();
145 if (targetClass == null) {
146 Class<?> propertyClass = DataDictionary.getAttributeClass(sourceClass, objectAttributeName);
147 if (propertyClass != null) {
148 targetClass = propertyClass;
149 }
150 }
151 for (PrimitiveAttributeDefinition primitiveAttributeDefinition : primitiveAttributes) {
152 primitiveAttributeDefinition.dataDictionaryPostProcessing();
153 }
154 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
155 supportAttributeDefinition.dataDictionaryPostProcessing();
156 }
157 }
158
159
160
161
162
163
164 @Override
165 @Deprecated
166 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
167 completeValidation(rootBusinessObjectClass, otherBusinessObjectClass, new ValidationTrace());
168 }
169
170
171
172
173
174
175 @Override
176 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
177 ValidationTrace tracer) {
178 tracer.addBean(this.getClass().getSimpleName(), "Attribute: " + getObjectAttributeName());
179 try {
180 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getObjectAttributeName())) {
181 String currentValues[] =
182 {"property = " + getObjectAttributeName(), "Class =" + rootBusinessObjectClass};
183 tracer.createError("Property is not an attribute of the class", currentValues);
184 }
185 } catch (RuntimeException ex) {
186 String currentValues[] = {"attribute = " + getObjectAttributeName(), "Exception = " + ex.getMessage()};
187 tracer.createError("Unable to validate attribute", currentValues);
188 LOG.error( "Exception while validating attribute: " + getObjectAttributeName(), ex );
189 }
190
191 if (targetClass == null) {
192 String currentValues[] =
193 {"property = " + getObjectAttributeName(), "sourceClass = " + getSourceClass()};
194 tracer.createError("Cannot get valid class for property", currentValues);
195 } else {
196
197 for (PrimitiveAttributeDefinition primitiveAttributeDefinition : primitiveAttributes) {
198 primitiveAttributeDefinition.completeValidation(rootBusinessObjectClass, targetClass, tracer.getCopy());
199 }
200 for (SupportAttributeDefinition supportAttributeDefinition : supportAttributes) {
201 supportAttributeDefinition.completeValidation(rootBusinessObjectClass, targetClass, tracer.getCopy());
202 }
203 }
204 }
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 public void setPrimitiveAttributes(List<PrimitiveAttributeDefinition> primitiveAttributes) {
222 this.primitiveAttributes = primitiveAttributes;
223 }
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239 public void setSupportAttributes(List<SupportAttributeDefinition> supportAttributes) {
240 this.supportAttributes = supportAttributes;
241 }
242
243
244
245
246 public void setSourceClass(Class<?> sourceClass) {
247 this.sourceClass = sourceClass;
248 }
249
250 @Override
251 public String toString() {
252 StringBuilder builder = new StringBuilder();
253 builder.append("RelationshipDefinition [objectAttributeName=").append(this.objectAttributeName)
254 .append(", sourceClass=").append(this.sourceClass).append(", targetClass=").append(this.targetClass)
255 .append(", primitiveAttributes=").append(this.primitiveAttributes).append(", supportAttributes=")
256 .append(this.supportAttributes).append("]");
257 return builder.toString();
258 }
259 }
260