1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.service.impl; |
17 | |
|
18 | |
import java.util.Collection; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.apache.commons.lang.StringUtils; |
22 | |
import org.kuali.rice.kew.api.KewApiServiceLocator; |
23 | |
import org.kuali.rice.kew.api.doctype.DocumentType; |
24 | |
import org.kuali.rice.krad.datadictionary.DataDictionary; |
25 | |
import org.kuali.rice.krad.datadictionary.DocumentEntry; |
26 | |
import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry; |
27 | |
import org.kuali.rice.krad.document.Document; |
28 | |
import org.kuali.rice.krad.document.MaintenanceDocument; |
29 | |
import org.kuali.rice.krad.maintenance.Maintainable; |
30 | |
import org.kuali.rice.krad.rule.BusinessRule; |
31 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
32 | |
import org.kuali.rice.krad.service.DocumentDictionaryService; |
33 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class DocumentDictionaryServiceImpl implements DocumentDictionaryService { |
42 | |
private DataDictionaryService dataDictionaryService; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@Override |
48 | |
public String getLabel(String documentTypeName) { |
49 | 0 | String label = null; |
50 | |
|
51 | 0 | DocumentType docType = getDocumentType(documentTypeName); |
52 | 0 | if (docType != null) { |
53 | 0 | label = docType.getLabel(); |
54 | |
} |
55 | |
|
56 | 0 | return label; |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@Override |
63 | |
public String getMaintenanceDocumentTypeName(Class dataObjectClass) { |
64 | 0 | String documentTypeName = null; |
65 | |
|
66 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(dataObjectClass); |
67 | 0 | if (entry != null) { |
68 | 0 | documentTypeName = entry.getDocumentTypeName(); |
69 | |
} |
70 | |
|
71 | 0 | return documentTypeName; |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Override |
78 | |
public String getDescription(String documentTypeName) { |
79 | 0 | String description = null; |
80 | |
|
81 | 0 | DocumentType docType = getDocumentType(documentTypeName); |
82 | 0 | if (docType != null) { |
83 | 0 | description = docType.getDescription(); |
84 | |
} |
85 | |
|
86 | 0 | return description; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
@Override |
93 | |
public Collection getDefaultExistenceChecks(Class dataObjectClass) { |
94 | 0 | return getDefaultExistenceChecks(getDocumentTypeName(dataObjectClass)); |
95 | |
} |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
@Override |
101 | |
public Collection getDefaultExistenceChecks(Document document) { |
102 | 0 | return getDefaultExistenceChecks(getDocumentEntry(document).getDocumentTypeName()); |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
@Override |
109 | |
public Collection getDefaultExistenceChecks(String docTypeName) { |
110 | 0 | Collection defaultExistenceChecks = null; |
111 | |
|
112 | 0 | DocumentEntry entry = getDocumentEntry(docTypeName); |
113 | 0 | if (entry != null) { |
114 | 0 | defaultExistenceChecks = entry.getDefaultExistenceChecks(); |
115 | |
} |
116 | |
|
117 | 0 | return defaultExistenceChecks; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
@Override |
124 | |
public Class<?> getMaintenanceDataObjectClass(String docTypeName) { |
125 | 0 | Class dataObjectClass = null; |
126 | |
|
127 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
128 | 0 | if (entry != null) { |
129 | 0 | dataObjectClass = entry.getDataObjectClass(); |
130 | |
} |
131 | |
|
132 | 0 | return dataObjectClass; |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
@Override |
139 | |
public Class<? extends Maintainable> getMaintainableClass(String docTypeName) { |
140 | 0 | Class maintainableClass = null; |
141 | |
|
142 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
143 | 0 | if (entry != null) { |
144 | 0 | maintainableClass = entry.getMaintainableClass(); |
145 | |
} |
146 | |
|
147 | 0 | return maintainableClass; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
@Override |
154 | |
public Class<? extends BusinessRule> getBusinessRulesClass(Document document) { |
155 | 0 | Class<? extends BusinessRule> businessRulesClass = null; |
156 | |
|
157 | 0 | String docTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(); |
158 | 0 | DocumentEntry entry = getDocumentEntry(docTypeName); |
159 | 0 | if (entry != null) { |
160 | 0 | businessRulesClass = entry.getBusinessRulesClass(); |
161 | |
} |
162 | |
|
163 | 0 | return businessRulesClass; |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
@Override |
170 | |
public Boolean getAllowsCopy(Document document) { |
171 | 0 | Boolean allowsCopy = Boolean.FALSE; |
172 | |
|
173 | 0 | if (document == null) { |
174 | 0 | return allowsCopy; |
175 | |
} |
176 | |
|
177 | 0 | DocumentEntry entry = null; |
178 | 0 | if (document instanceof MaintenanceDocument) { |
179 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document; |
180 | 0 | if (maintenanceDocument.getNewMaintainableObject() != null) { |
181 | 0 | entry = getMaintenanceDocumentEntry( |
182 | |
maintenanceDocument.getNewMaintainableObject().getDataObjectClass()); |
183 | |
} |
184 | 0 | } else { |
185 | 0 | entry = getDocumentEntry(document); |
186 | |
} |
187 | |
|
188 | 0 | if (entry != null) { |
189 | 0 | allowsCopy = Boolean.valueOf(entry.getAllowsCopy()); |
190 | |
} |
191 | |
|
192 | 0 | return allowsCopy; |
193 | |
} |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
@Override |
199 | |
public Boolean getAllowsNewOrCopy(String docTypeName) { |
200 | 0 | Boolean allowsNewOrCopy = Boolean.FALSE; |
201 | |
|
202 | 0 | if (docTypeName != null) { |
203 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
204 | 0 | if (entry != null) { |
205 | 0 | allowsNewOrCopy = Boolean.valueOf(entry.getAllowsNewOrCopy()); |
206 | |
} |
207 | |
} |
208 | |
|
209 | 0 | return allowsNewOrCopy; |
210 | |
} |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
@Override |
216 | |
public MaintenanceDocumentEntry getMaintenanceDocumentEntry(String docTypeName) { |
217 | 0 | if (StringUtils.isBlank(docTypeName)) { |
218 | 0 | throw new IllegalArgumentException("invalid (blank) docTypeName"); |
219 | |
} |
220 | |
|
221 | 0 | MaintenanceDocumentEntry entry = (MaintenanceDocumentEntry) getDataDictionary().getDocumentEntry(docTypeName); |
222 | 0 | return entry; |
223 | |
} |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
@Override |
229 | |
public Class<?> getDocumentClassByName(String documentTypeName) { |
230 | 0 | Class documentClass = null; |
231 | |
|
232 | 0 | DocumentEntry entry = getDocumentEntry(documentTypeName); |
233 | 0 | if (entry != null) { |
234 | 0 | documentClass = entry.getDocumentClass(); |
235 | |
} |
236 | |
|
237 | 0 | return documentClass; |
238 | |
} |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
@Override |
244 | |
public Boolean getAllowsRecordDeletion(Class dataObjectClass) { |
245 | 0 | Boolean allowsRecordDeletion = Boolean.FALSE; |
246 | |
|
247 | 0 | MaintenanceDocumentEntry docEntry = getMaintenanceDocumentEntry(dataObjectClass); |
248 | |
|
249 | 0 | if (docEntry != null) { |
250 | 0 | allowsRecordDeletion = Boolean.valueOf(docEntry.getAllowsRecordDeletion()); |
251 | |
} |
252 | |
|
253 | 0 | return allowsRecordDeletion; |
254 | |
} |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
@Override |
260 | |
public Boolean getAllowsRecordDeletion(MaintenanceDocument document) { |
261 | 0 | return document != null ? |
262 | |
this.getAllowsRecordDeletion(document.getNewMaintainableObject().getDataObjectClass()) : Boolean.FALSE; |
263 | |
} |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
@Override |
269 | |
public List<String> getLockingKeys(String docTypeName) { |
270 | 0 | List lockingKeys = null; |
271 | |
|
272 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(docTypeName); |
273 | 0 | if (entry != null) { |
274 | 0 | lockingKeys = entry.getLockingKeyFieldNames(); |
275 | |
} |
276 | |
|
277 | 0 | return lockingKeys; |
278 | |
} |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
@Override |
284 | |
public boolean getPreserveLockingKeysOnCopy(Class dataObjectClass) { |
285 | 0 | boolean preserveLockingKeysOnCopy = false; |
286 | |
|
287 | 0 | MaintenanceDocumentEntry docEntry = getMaintenanceDocumentEntry(dataObjectClass); |
288 | |
|
289 | 0 | if (docEntry != null) { |
290 | 0 | preserveLockingKeysOnCopy = docEntry.getPreserveLockingKeysOnCopy(); |
291 | |
} |
292 | |
|
293 | 0 | return preserveLockingKeysOnCopy; |
294 | |
} |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
protected MaintenanceDocumentEntry getMaintenanceDocumentEntry(Class dataObjectClass) { |
303 | 0 | if (dataObjectClass == null) { |
304 | 0 | throw new IllegalArgumentException("invalid (blank) dataObjectClass"); |
305 | |
} |
306 | |
|
307 | 0 | MaintenanceDocumentEntry entry = |
308 | |
getDataDictionary().getMaintenanceDocumentEntryForBusinessObjectClass(dataObjectClass); |
309 | 0 | return entry; |
310 | |
} |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
protected DocumentEntry getDocumentEntry(Document document) { |
319 | 0 | if (document == null) { |
320 | 0 | throw new IllegalArgumentException("invalid (null) document"); |
321 | |
} |
322 | |
|
323 | 0 | DocumentEntry entry = getDataDictionary().getDocumentEntry(document.getClass().getName()); |
324 | |
|
325 | 0 | return entry; |
326 | |
} |
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
protected DocumentEntry getDocumentEntry(String documentTypeName) { |
335 | 0 | if (documentTypeName == null) { |
336 | 0 | throw new IllegalArgumentException("invalid (null) document type name"); |
337 | |
} |
338 | |
|
339 | 0 | DocumentEntry entry = getDataDictionary().getDocumentEntry(documentTypeName); |
340 | |
|
341 | 0 | return entry; |
342 | |
} |
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
protected DocumentType getDocumentType(String documentTypeName) { |
351 | 0 | return KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName); |
352 | |
} |
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
protected String getDocumentTypeName(Class dataObjectClass) { |
362 | 0 | String documentTypeName = null; |
363 | |
|
364 | 0 | MaintenanceDocumentEntry entry = getMaintenanceDocumentEntry(dataObjectClass); |
365 | 0 | if (entry != null) { |
366 | 0 | documentTypeName = entry.getDocumentTypeName(); |
367 | |
} |
368 | |
|
369 | 0 | return documentTypeName; |
370 | |
} |
371 | |
|
372 | |
protected DataDictionary getDataDictionary() { |
373 | 0 | return getDataDictionaryService().getDataDictionary(); |
374 | |
} |
375 | |
|
376 | |
protected DataDictionaryService getDataDictionaryService() { |
377 | 0 | if (dataDictionaryService == null) { |
378 | 0 | this.dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); |
379 | |
} |
380 | 0 | return dataDictionaryService; |
381 | |
} |
382 | |
|
383 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
384 | 0 | this.dataDictionaryService = dataDictionaryService; |
385 | 0 | } |
386 | |
} |