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 java.util.ArrayList; |
19 | |
import java.util.LinkedHashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import org.kuali.rice.kns.bo.BusinessObject; |
24 | |
import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; |
25 | |
import org.kuali.rice.kns.datadictionary.exception.ClassValidationException; |
26 | |
import org.kuali.rice.kns.datadictionary.exception.DuplicateEntryException; |
27 | |
import org.kuali.rice.kns.document.Document; |
28 | |
import org.kuali.rice.kns.document.MaintenanceDocumentBase; |
29 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizer; |
30 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class MaintenanceDocumentEntry extends DocumentEntry { |
38 | |
|
39 | |
protected Class<? extends BusinessObject> businessObjectClass; |
40 | |
protected Class<? extends Maintainable> maintainableClass; |
41 | |
|
42 | 0 | protected List<MaintainableSectionDefinition> maintainableSections = new ArrayList<MaintainableSectionDefinition>(); |
43 | 0 | protected List<String> lockingKeys = new ArrayList<String>(); |
44 | 0 | protected List<ApcRuleDefinition> apcRules = new ArrayList<ApcRuleDefinition>(); |
45 | 0 | protected Map<String,MaintainableSectionDefinition> maintainableSectionMap = new LinkedHashMap<String, MaintainableSectionDefinition>(); |
46 | 0 | protected Map<String,ApcRuleDefinition> apcRuleMap = new LinkedHashMap<String, ApcRuleDefinition>(); |
47 | |
|
48 | 0 | protected boolean allowsNewOrCopy = true; |
49 | |
protected String additionalSectionsFile; |
50 | |
|
51 | |
|
52 | 0 | protected boolean preserveLockingKeysOnCopy = false; |
53 | |
|
54 | |
|
55 | 0 | protected boolean allowsRecordDeletion = false; |
56 | |
|
57 | 0 | protected boolean translateCodes = false; |
58 | |
|
59 | |
public MaintenanceDocumentEntry() { |
60 | 0 | super(); |
61 | 0 | setDocumentClass(getStandardDocumentBaseClass()); |
62 | 0 | } |
63 | |
|
64 | |
public Class<? extends Document> getStandardDocumentBaseClass() { |
65 | 0 | return MaintenanceDocumentBase.class; |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) { |
73 | 0 | if (businessObjectClass == null) { |
74 | 0 | throw new IllegalArgumentException("invalid (null) businessObjectClass"); |
75 | |
} |
76 | |
|
77 | 0 | this.businessObjectClass = businessObjectClass; |
78 | 0 | } |
79 | |
|
80 | |
public Class<? extends BusinessObject> getBusinessObjectClass() { |
81 | 0 | return businessObjectClass; |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
@SuppressWarnings("unchecked") |
88 | |
@Override |
89 | |
public Class getEntryClass() { |
90 | 0 | return businessObjectClass; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public void setMaintainableClass(Class<? extends Maintainable> maintainableClass) { |
100 | 0 | if (maintainableClass == null) { |
101 | 0 | throw new IllegalArgumentException("invalid (null) maintainableClass"); |
102 | |
} |
103 | 0 | this.maintainableClass = maintainableClass; |
104 | 0 | } |
105 | |
|
106 | |
public Class<? extends Maintainable> getMaintainableClass() { |
107 | 0 | return maintainableClass; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public List<MaintainableSectionDefinition> getMaintainableSections() { |
114 | 0 | return maintainableSections; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public List<String> getLockingKeyFieldNames() { |
121 | 0 | return lockingKeys; |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public List<ApcRuleDefinition> getApcRules() { |
131 | 0 | return apcRules; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public List<String> getApcRuleFieldNames() { |
140 | 0 | List<String> fieldNames = new ArrayList<String>(); |
141 | 0 | fieldNames.addAll(this.apcRuleMap.keySet()); |
142 | |
|
143 | 0 | return fieldNames; |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public boolean getAllowsNewOrCopy() { |
152 | 0 | return allowsNewOrCopy; |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
public void setAllowsNewOrCopy(boolean allowsNewOrCopy) { |
162 | 0 | this.allowsNewOrCopy = allowsNewOrCopy; |
163 | 0 | } |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
public void completeValidation() { |
172 | 0 | super.completeValidation(); |
173 | |
|
174 | 0 | for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) { |
175 | 0 | maintainableSectionDefinition.completeValidation(businessObjectClass, null); |
176 | |
} |
177 | |
|
178 | 0 | for ( String lockingKey : lockingKeys ) { |
179 | 0 | if (!DataDictionary.isPropertyOf(businessObjectClass, lockingKey)) { |
180 | 0 | throw new AttributeValidationException("unable to find attribute '" + lockingKey + "' for lockingKey in businessObjectClass '" + businessObjectClass.getName() ); |
181 | |
} |
182 | |
} |
183 | |
|
184 | 0 | for ( ReferenceDefinition reference : defaultExistenceChecks ) { |
185 | 0 | reference.completeValidation(businessObjectClass, null); |
186 | |
} |
187 | |
|
188 | 0 | for ( ApcRuleDefinition apcRule : apcRules ) { |
189 | 0 | apcRule.completeValidation(businessObjectClass, null); |
190 | |
} |
191 | |
|
192 | 0 | if (documentAuthorizerClass != null && !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) { |
193 | 0 | throw new ClassValidationException("This maintenance document for '" + businessObjectClass.getName() + "' has an invalid " + "documentAuthorizerClass ('" + documentAuthorizerClass.getName() + "'). " + "Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer."); |
194 | |
} |
195 | 0 | } |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public String toString() { |
202 | 0 | return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName(); |
203 | |
} |
204 | |
|
205 | |
|
206 | |
public String getAdditionalSectionsFile() { |
207 | 0 | return additionalSectionsFile; |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public void setAdditionalSectionsFile(String additionalSectionsFile) { |
218 | 0 | this.additionalSectionsFile = additionalSectionsFile; |
219 | 0 | } |
220 | |
|
221 | |
|
222 | |
public List<String> getLockingKeys() { |
223 | 0 | return lockingKeys; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public void setLockingKeys(List<String> lockingKeys) { |
233 | 0 | for ( String lockingKey : lockingKeys ) { |
234 | 0 | if (lockingKey == null) { |
235 | 0 | throw new IllegalArgumentException("invalid (null) lockingKey"); |
236 | |
} |
237 | |
} |
238 | 0 | this.lockingKeys = lockingKeys; |
239 | 0 | } |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
public void setMaintainableSections(List<MaintainableSectionDefinition> maintainableSections) { |
256 | 0 | maintainableSectionMap.clear(); |
257 | 0 | for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) { |
258 | 0 | if (maintainableSectionDefinition == null) { |
259 | 0 | throw new IllegalArgumentException("invalid (null) maintainableSectionDefinition"); |
260 | |
} |
261 | |
|
262 | 0 | String sectionTitle = maintainableSectionDefinition.getTitle(); |
263 | 0 | if (maintainableSectionMap.containsKey(sectionTitle)) { |
264 | 0 | throw new DuplicateEntryException("section '" + sectionTitle + "' already defined for maintenanceDocument '" + getDocumentTypeName() + "'"); |
265 | |
} |
266 | |
|
267 | 0 | maintainableSectionMap.put(sectionTitle, maintainableSectionDefinition); |
268 | 0 | } |
269 | 0 | this.maintainableSections = maintainableSections; |
270 | 0 | } |
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
public void setApcRules(List<ApcRuleDefinition> apcRules) { |
288 | 0 | apcRuleMap.clear(); |
289 | 0 | for ( ApcRuleDefinition apcRule : apcRules ) { |
290 | 0 | if (apcRule == null) { |
291 | 0 | throw new IllegalArgumentException("invalid (null) apcRule"); |
292 | |
} |
293 | |
|
294 | 0 | String keyName = apcRule.getAttributeName(); |
295 | 0 | if (apcRuleMap.containsKey(keyName)) { |
296 | 0 | throw new DuplicateEntryException("duplicate apcRule entry for attribute '" + keyName + "'"); |
297 | |
} |
298 | |
|
299 | 0 | apcRuleMap.put(keyName, apcRule); |
300 | 0 | } |
301 | 0 | this.apcRules = apcRules; |
302 | 0 | } |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public boolean getPreserveLockingKeysOnCopy() { |
308 | 0 | return this.preserveLockingKeysOnCopy; |
309 | |
} |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) { |
315 | 0 | this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy; |
316 | 0 | } |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
public boolean getAllowsRecordDeletion() { |
322 | 0 | return this.allowsRecordDeletion; |
323 | |
} |
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
public void setAllowsRecordDeletion(boolean allowsRecordDeletion) { |
329 | 0 | this.allowsRecordDeletion = allowsRecordDeletion; |
330 | 0 | } |
331 | |
|
332 | |
public boolean isTranslateCodes() { |
333 | 0 | return this.translateCodes; |
334 | |
} |
335 | |
|
336 | |
public void setTranslateCodes(boolean translateCodes) { |
337 | 0 | this.translateCodes = translateCodes; |
338 | 0 | } |
339 | |
|
340 | |
} |