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.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @BeanTag(name = "primitiveAttributeDefinition-bean")
39 public class PrimitiveAttributeDefinition extends DataDictionaryDefinitionBase {
40 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PrimitiveAttributeDefinition.class);
41 private static final long serialVersionUID = -715128943756700821L;
42
43 protected String sourceName;
44 protected String targetName;
45
46 public PrimitiveAttributeDefinition() {}
47
48 @BeanTagAttribute(name = "sourceName")
49 public String getSourceName() {
50 return sourceName;
51 }
52
53
54
55
56
57
58 public void setSourceName(String sourceName) {
59 if (StringUtils.isBlank(sourceName)) {
60 throw new IllegalArgumentException("invalid (blank) sourceName");
61 }
62
63 this.sourceName = sourceName;
64 }
65
66 @BeanTagAttribute(name = "targetName")
67 public String getTargetName() {
68 return targetName;
69 }
70
71
72
73
74
75
76 public void setTargetName(String targetName) {
77 if (StringUtils.isBlank(targetName)) {
78 throw new IllegalArgumentException("invalid (blank) targetName");
79 }
80
81 this.targetName = targetName;
82 }
83
84
85
86
87
88
89
90 @Override
91 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
92 completeValidation(rootBusinessObjectClass, otherBusinessObjectClass, new ValidationTrace());
93 }
94
95
96
97
98
99
100 @Override
101 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass,
102 ValidationTrace tracer) {
103 tracer.addBean(this.getClass().getSimpleName(), ValidationTrace.NO_BEAN_ID);
104
105 try {
106 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, sourceName)) {
107 String currentValues[] = {"attribute = " + getSourceName(), "class = " + rootBusinessObjectClass};
108 tracer.createError("Unable to find attribute on class", currentValues);
109 }
110 } catch (RuntimeException ex) {
111 String currentValues[] = {"attribute = " + getSourceName(), "class = " + rootBusinessObjectClass,
112 "Exception = " + ex.getMessage()};
113 tracer.createError("Unable to find attribute on class", currentValues);
114 LOG.error( "Exception while validating PrimitiveAttributeDefintion on " + rootBusinessObjectClass + ": " + this, ex);
115 }
116 try {
117 if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, targetName)) {
118 String currentValues[] = {"attribute = " + getTargetName(), "class = " + otherBusinessObjectClass};
119 tracer.createError("Unable to find attribute on class", currentValues);
120 }
121 } catch (RuntimeException ex) {
122 String currentValues[] = {"attribute = " + getTargetName(), "class = " + otherBusinessObjectClass,
123 "Exception = " + ex.getMessage()};
124 tracer.createError("Unable to find attribute on class", currentValues);
125 LOG.error( "Exception while validating PrimitiveAttributeDefintion on " + rootBusinessObjectClass + ": " + this, ex);
126 }
127 try {
128 Class sourceClass = DataDictionary.getAttributeClass(rootBusinessObjectClass, sourceName);
129 Class targetClass = DataDictionary.getAttributeClass(otherBusinessObjectClass, targetName);
130 if ((null == sourceClass && null != targetClass)
131 || (null != sourceClass && null == targetClass)
132 || !StringUtils.equals(sourceClass.getName(), targetClass.getName())) {
133 String sourceClassName = rootBusinessObjectClass.getName();
134 String targetClassName = otherBusinessObjectClass.getName();
135 String sourcePath = sourceClassName + "." + sourceName;
136 String targetPath = targetClassName + "." + targetName;
137
138
139 if ((sourcePath != null && !StringUtils.contains(sourcePath, ".principalId"))
140 && (targetPath != null && !StringUtils.contains(targetPath, ".principalId")) ) {
141 String currentValues[] = {"source = " + sourcePath + "' (" + sourceClass + ")",
142 "target = " + targetPath + "' (" + targetClass + ")"};
143 tracer.createError("Source and target of different types", currentValues);
144 }
145 }
146 } catch (RuntimeException ex) {
147 String currentValues[] = {"Exception = " + ex.getMessage()};
148 tracer.createError("Unable to validate property", currentValues);
149 LOG.error( "Exception while validating PrimitiveAttributeDefintion on " + rootBusinessObjectClass + ": " + this, ex);
150 }
151 }
152
153 @Override
154 public String toString() {
155 StringBuilder builder = new StringBuilder();
156 builder.append("PrimitiveAttributeDefinition [sourceName=").append(this.sourceName).append(", targetName=")
157 .append(this.targetName).append("]");
158 return builder.toString();
159 }
160
161 }