1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.datadictionary; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.krad.bo.BusinessObject; |
20 | |
import org.kuali.rice.krad.datadictionary.DataDictionary; |
21 | |
import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; |
22 | |
import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.HashMap; |
26 | |
import java.util.List; |
27 | |
import java.util.Map; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@Deprecated |
55 | |
public class MaintainableCollectionDefinition extends MaintainableItemDefinition implements CollectionDefinitionI { |
56 | |
private static final long serialVersionUID = -5617868782623587053L; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
protected Class<? extends BusinessObject> businessObjectClass; |
62 | |
|
63 | |
protected Class<? extends BusinessObject> sourceClassName; |
64 | |
protected String summaryTitle; |
65 | |
protected String attributeToHighlightOnDuplicateKey; |
66 | |
|
67 | 0 | protected boolean includeAddLine = true; |
68 | 0 | protected boolean includeMultipleLookupLine = true; |
69 | 0 | private boolean alwaysAllowCollectionDeletion = false; |
70 | |
|
71 | 0 | protected Map<String,MaintainableFieldDefinition> maintainableFieldMap = new HashMap<String, MaintainableFieldDefinition>(); |
72 | 0 | protected Map<String,MaintainableCollectionDefinition> maintainableCollectionMap = new HashMap<String, MaintainableCollectionDefinition>(); |
73 | 0 | protected Map<String,MaintainableFieldDefinition> summaryFieldMap = new HashMap<String, MaintainableFieldDefinition>(); |
74 | 0 | protected Map<String,MaintainableFieldDefinition> duplicateIdentificationFieldMap = new HashMap<String, MaintainableFieldDefinition>(); |
75 | 0 | protected List<MaintainableFieldDefinition> maintainableFields = new ArrayList<MaintainableFieldDefinition>(); |
76 | 0 | protected List<MaintainableCollectionDefinition> maintainableCollections = new ArrayList<MaintainableCollectionDefinition>(); |
77 | 0 | protected List<MaintainableFieldDefinition> summaryFields = new ArrayList<MaintainableFieldDefinition>(); |
78 | 0 | protected List<MaintainableFieldDefinition> duplicateIdentificationFields = new ArrayList<MaintainableFieldDefinition>(); |
79 | |
|
80 | 0 | public MaintainableCollectionDefinition() {} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public Class<? extends BusinessObject> getBusinessObjectClass() { |
88 | 0 | return businessObjectClass; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) { |
95 | 0 | if (businessObjectClass == null) { |
96 | 0 | throw new IllegalArgumentException("invalid (null) dataObjectClass"); |
97 | |
} |
98 | |
|
99 | 0 | this.businessObjectClass = businessObjectClass; |
100 | 0 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public List<MaintainableFieldDefinition> getMaintainableFields() { |
107 | 0 | return maintainableFields; |
108 | |
} |
109 | |
|
110 | |
public List<? extends FieldDefinitionI> getFields() { |
111 | 0 | return maintainableFields; |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { |
120 | 0 | if (!DataDictionary.isCollectionPropertyOf(rootBusinessObjectClass, getName())) { |
121 | 0 | throw new AttributeValidationException("unable to find collection named '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
122 | |
} |
123 | |
|
124 | 0 | if (dissallowDuplicateKey()) { |
125 | 0 | if (!DataDictionary.isPropertyOf(businessObjectClass, attributeToHighlightOnDuplicateKey)) { |
126 | 0 | throw new AttributeValidationException("unable to find attribute named '" + attributeToHighlightOnDuplicateKey + "'in dataObjectClass '" + businessObjectClass.getName() + "' of collection '" + getName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")"); |
127 | |
} |
128 | |
} |
129 | |
|
130 | 0 | for (MaintainableFieldDefinition maintainableField : maintainableFields ) { |
131 | 0 | maintainableField.completeValidation(businessObjectClass, null); |
132 | |
} |
133 | |
|
134 | 0 | for (MaintainableCollectionDefinition maintainableCollection : maintainableCollections ) { |
135 | 0 | maintainableCollection.completeValidation(businessObjectClass, null); |
136 | |
} |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | 0 | } |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public String toString() { |
152 | 0 | return "MaintainableCollectionDefinition for " + getName(); |
153 | |
} |
154 | |
|
155 | |
|
156 | |
public Class<? extends BusinessObject> getSourceClassName() { |
157 | 0 | return sourceClassName; |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public void setSourceClassName(Class<? extends BusinessObject> sourceClass) { |
164 | 0 | this.sourceClassName = sourceClass; |
165 | 0 | } |
166 | |
|
167 | |
public boolean getIncludeAddLine() { |
168 | 0 | return includeAddLine; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
public void setIncludeAddLine(boolean includeAddLine) { |
174 | 0 | this.includeAddLine = includeAddLine; |
175 | 0 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public List<MaintainableCollectionDefinition> getMaintainableCollections() { |
182 | 0 | return maintainableCollections; |
183 | |
} |
184 | |
|
185 | |
public List<? extends CollectionDefinitionI> getCollections() { |
186 | 0 | return maintainableCollections; |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public List<? extends FieldDefinitionI> getSummaryFields() { |
195 | 0 | return summaryFields; |
196 | |
} |
197 | |
|
198 | |
public boolean hasSummaryField(String key) { |
199 | 0 | return summaryFieldMap.containsKey(key); |
200 | |
} |
201 | |
|
202 | |
public boolean isIncludeMultipleLookupLine() { |
203 | 0 | return includeMultipleLookupLine; |
204 | |
} |
205 | |
|
206 | |
|
207 | |
public void setIncludeMultipleLookupLine(boolean includeMultipleLookupLine) { |
208 | 0 | this.includeMultipleLookupLine = includeMultipleLookupLine; |
209 | 0 | } |
210 | |
|
211 | |
public String getSummaryTitle() { |
212 | 0 | return summaryTitle; |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
public void setSummaryTitle(String overrideSummaryName) { |
219 | 0 | this.summaryTitle = overrideSummaryName; |
220 | 0 | } |
221 | |
|
222 | |
|
223 | |
public String getAttributeToHighlightOnDuplicateKey() { |
224 | 0 | return attributeToHighlightOnDuplicateKey; |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public void setAttributeToHighlightOnDuplicateKey(String attributeToHighlightOnDuplicate) { |
233 | 0 | this.attributeToHighlightOnDuplicateKey = attributeToHighlightOnDuplicate; |
234 | 0 | } |
235 | |
|
236 | |
public boolean dissallowDuplicateKey() { |
237 | 0 | return StringUtils.isNotBlank(getAttributeToHighlightOnDuplicateKey()); |
238 | |
} |
239 | |
|
240 | |
public List<MaintainableFieldDefinition> getDuplicateIdentificationFields() { |
241 | 0 | return duplicateIdentificationFields; |
242 | |
} |
243 | |
|
244 | |
|
245 | |
public void setMaintainableFields(List<MaintainableFieldDefinition> maintainableFields) { |
246 | 0 | maintainableFieldMap.clear(); |
247 | 0 | for ( MaintainableFieldDefinition maintainableField : maintainableFields ) { |
248 | 0 | if (maintainableField == null) { |
249 | 0 | throw new IllegalArgumentException("invalid (null) maintainableField"); |
250 | |
} |
251 | |
|
252 | 0 | String fieldName = maintainableField.getName(); |
253 | 0 | if (maintainableFieldMap.containsKey(fieldName)) { |
254 | 0 | throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'"); |
255 | |
} |
256 | |
|
257 | 0 | maintainableFieldMap.put(fieldName, maintainableField); |
258 | 0 | } |
259 | 0 | this.maintainableFields = maintainableFields; |
260 | 0 | } |
261 | |
|
262 | |
|
263 | |
public void setMaintainableCollections(List<MaintainableCollectionDefinition> maintainableCollections) { |
264 | 0 | maintainableCollectionMap.clear(); |
265 | 0 | for (MaintainableCollectionDefinition maintainableCollection : maintainableCollections ) { |
266 | 0 | if (maintainableCollection == null) { |
267 | 0 | throw new IllegalArgumentException("invalid (null) maintainableCollection"); |
268 | |
} |
269 | |
|
270 | 0 | String fieldName = maintainableCollection.getName(); |
271 | 0 | if (maintainableCollectionMap.containsKey(fieldName)) { |
272 | 0 | throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'"); |
273 | |
} |
274 | |
|
275 | 0 | maintainableCollectionMap.put(fieldName, maintainableCollection); |
276 | 0 | } |
277 | 0 | this.maintainableCollections = maintainableCollections; |
278 | 0 | } |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
public void setSummaryFields(List<MaintainableFieldDefinition> summaryFields) { |
286 | 0 | summaryFieldMap.clear(); |
287 | 0 | for (MaintainableFieldDefinition summaryField : summaryFields ) { |
288 | 0 | if (summaryField == null) { |
289 | 0 | throw new IllegalArgumentException("invalid (null) summaryField"); |
290 | |
} |
291 | |
|
292 | 0 | String fieldName = summaryField.getName(); |
293 | 0 | if (summaryFieldMap.containsKey(fieldName)) { |
294 | 0 | throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'"); |
295 | |
} |
296 | |
|
297 | 0 | summaryFieldMap.put(fieldName, summaryField); |
298 | 0 | } |
299 | 0 | this.summaryFields = summaryFields; |
300 | 0 | } |
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public void setDuplicateIdentificationFields(List<MaintainableFieldDefinition> duplicateIdentificationFields) { |
308 | 0 | duplicateIdentificationFieldMap.clear(); |
309 | 0 | for (MaintainableFieldDefinition identifierField : duplicateIdentificationFields) { |
310 | 0 | if (identifierField == null) { |
311 | 0 | throw new IllegalArgumentException("invalid (null) identifierField"); |
312 | |
} |
313 | |
|
314 | 0 | String fieldName = identifierField.getName(); |
315 | 0 | if (duplicateIdentificationFieldMap.containsKey(fieldName)) { |
316 | 0 | throw new DuplicateEntryException("duplicate fieldName entry for field '" + fieldName + "'"); |
317 | |
} |
318 | |
|
319 | 0 | duplicateIdentificationFieldMap.put(fieldName, identifierField); |
320 | 0 | } |
321 | 0 | this.duplicateIdentificationFields = duplicateIdentificationFields; |
322 | 0 | } |
323 | |
|
324 | |
|
325 | |
|
326 | |
public boolean isAlwaysAllowCollectionDeletion() { |
327 | 0 | return this.alwaysAllowCollectionDeletion; |
328 | |
} |
329 | |
|
330 | |
|
331 | |
|
332 | |
public void setAlwaysAllowCollectionDeletion( |
333 | |
boolean alwaysAllowCollectionDeletion) { |
334 | 0 | this.alwaysAllowCollectionDeletion = alwaysAllowCollectionDeletion; |
335 | 0 | } |
336 | |
|
337 | |
} |