1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.maintenance.rules; |
17 | |
|
18 | |
import java.security.GeneralSecurityException; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Iterator; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
import java.util.Properties; |
25 | |
import java.util.Set; |
26 | |
|
27 | |
import org.apache.commons.lang.StringUtils; |
28 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
29 | |
import org.kuali.rice.kim.service.RoleService; |
30 | |
import org.kuali.rice.kns.bo.GlobalBusinessObject; |
31 | |
import org.kuali.rice.kns.bo.Inactivateable; |
32 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
33 | |
import org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata; |
34 | |
import org.kuali.rice.kns.document.Document; |
35 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
36 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizer; |
37 | |
import org.kuali.rice.kns.exception.ValidationException; |
38 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
39 | |
import org.kuali.rice.kns.rule.AddCollectionLineRule; |
40 | |
import org.kuali.rice.kns.rule.event.ApproveDocumentEvent; |
41 | |
import org.kuali.rice.kns.rules.DocumentRuleBase; |
42 | |
import org.kuali.rice.kns.service.BusinessObjectAuthorizationService; |
43 | |
import org.kuali.rice.kns.service.BusinessObjectDictionaryService; |
44 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
45 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
46 | |
import org.kuali.rice.kns.service.DateTimeService; |
47 | |
import org.kuali.rice.kns.service.DictionaryValidationService; |
48 | |
import org.kuali.rice.kns.service.DocumentHelperService; |
49 | |
import org.kuali.rice.kns.service.InactivationBlockingDetectionService; |
50 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
51 | |
import org.kuali.rice.kns.service.KualiConfigurationService; |
52 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
53 | |
import org.kuali.rice.kns.service.PersistenceService; |
54 | |
import org.kuali.rice.kns.service.PersistenceStructureService; |
55 | |
import org.kuali.rice.kns.util.ErrorMessage; |
56 | |
import org.kuali.rice.kns.util.ForeignKeyFieldsPopulationState; |
57 | |
import org.kuali.rice.kns.util.GlobalVariables; |
58 | |
import org.kuali.rice.kns.util.KNSConstants; |
59 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
60 | |
import org.kuali.rice.kns.util.MessageMap; |
61 | |
import org.kuali.rice.kns.util.ObjectUtils; |
62 | |
import org.kuali.rice.kns.util.RiceKeyConstants; |
63 | |
import org.kuali.rice.kns.util.TypedArrayList; |
64 | |
import org.kuali.rice.kns.util.UrlFactory; |
65 | |
import org.kuali.rice.kns.web.format.Formatter; |
66 | |
import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; |
67 | |
import org.kuali.rice.kns.workflow.service.WorkflowDocumentService; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public class MaintenanceDocumentRuleBase extends DocumentRuleBase implements MaintenanceDocumentRule, AddCollectionLineRule { |
76 | 0 | protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentRuleBase.class); |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public static final String MAINTAINABLE_ERROR_PREFIX = KNSConstants.MAINTENANCE_NEW_MAINTAINABLE; |
83 | |
public static final String DOCUMENT_ERROR_PREFIX = "document."; |
84 | |
public static final String MAINTAINABLE_ERROR_PATH = DOCUMENT_ERROR_PREFIX + "newMaintainableObject"; |
85 | |
|
86 | |
protected PersistenceStructureService persistenceStructureService; |
87 | |
protected PersistenceService persistenceService; |
88 | |
protected DataDictionaryService ddService; |
89 | |
protected DocumentHelperService documentHelperService; |
90 | |
protected BusinessObjectService boService; |
91 | |
protected BusinessObjectDictionaryService boDictionaryService; |
92 | |
protected DictionaryValidationService dictionaryValidationService; |
93 | |
protected KualiConfigurationService configService; |
94 | |
protected MaintenanceDocumentDictionaryService maintDocDictionaryService; |
95 | |
protected WorkflowDocumentService workflowDocumentService; |
96 | |
protected org.kuali.rice.kim.service.PersonService personService; |
97 | |
protected RoleService roleService; |
98 | |
protected BusinessObjectAuthorizationService businessObjectAuthorizationService; |
99 | |
|
100 | |
private PersistableBusinessObject oldBo; |
101 | |
private PersistableBusinessObject newBo; |
102 | |
private Class boClass; |
103 | |
|
104 | |
protected List priorErrorPath; |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | 0 | public MaintenanceDocumentRuleBase() { |
112 | |
|
113 | 0 | priorErrorPath = new ArrayList(); |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
try { |
122 | 0 | this.setPersistenceStructureService(KNSServiceLocator.getPersistenceStructureService()); |
123 | 0 | this.setDdService(KNSServiceLocator.getDataDictionaryService()); |
124 | 0 | this.setPersistenceService(KNSServiceLocator.getPersistenceService()); |
125 | 0 | this.setBoService(KNSServiceLocator.getBusinessObjectService()); |
126 | 0 | this.setBoDictionaryService(KNSServiceLocator.getBusinessObjectDictionaryService()); |
127 | 0 | this.setDictionaryValidationService(KNSServiceLocator.getDictionaryValidationService()); |
128 | 0 | this.setConfigService(KNSServiceLocator.getKualiConfigurationService()); |
129 | 0 | this.setDocumentHelperService(KNSServiceLocator.getDocumentHelperService()); |
130 | 0 | this.setMaintDocDictionaryService(KNSServiceLocator.getMaintenanceDocumentDictionaryService()); |
131 | 0 | this.setWorkflowDocumentService(KNSServiceLocator.getWorkflowDocumentService()); |
132 | 0 | this.setPersonService( org.kuali.rice.kim.service.KIMServiceLocator.getPersonService() ); |
133 | 0 | this.setBusinessObjectAuthorizationService(KNSServiceLocator.getBusinessObjectAuthorizationService()); |
134 | 0 | } catch ( Exception ex ) { |
135 | |
|
136 | 0 | } |
137 | 0 | } |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
@Override |
143 | |
public boolean processSaveDocument(Document document) { |
144 | |
|
145 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document; |
146 | |
|
147 | |
|
148 | |
|
149 | 0 | clearErrorPath(); |
150 | |
|
151 | |
|
152 | 0 | setupBaseConvenienceObjects(maintenanceDocument); |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | 0 | if (!isDocumentValidForSave(maintenanceDocument)) { |
159 | 0 | resumeErrorPath(); |
160 | 0 | return false; |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | 0 | processCustomSaveDocumentBusinessRules(maintenanceDocument); |
167 | |
|
168 | |
|
169 | 0 | resumeErrorPath(); |
170 | |
|
171 | |
|
172 | |
|
173 | 0 | return true; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
@Override |
180 | |
public boolean processRouteDocument(Document document) { |
181 | 0 | LOG.info("processRouteDocument called"); |
182 | |
|
183 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document; |
184 | |
|
185 | |
|
186 | 0 | MaintenanceDocumentAuthorizer documentAuthorizer = (MaintenanceDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(document); |
187 | |
|
188 | |
|
189 | |
|
190 | 0 | clearErrorPath(); |
191 | |
|
192 | |
|
193 | 0 | setupBaseConvenienceObjects(maintenanceDocument); |
194 | |
|
195 | |
|
196 | 0 | processGlobalSaveDocumentBusinessRules(maintenanceDocument); |
197 | |
|
198 | |
|
199 | |
|
200 | 0 | boolean success = true; |
201 | |
|
202 | 0 | KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
203 | 0 | if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved()){ |
204 | 0 | success &= documentAuthorizer.canCreateOrMaintain((MaintenanceDocument)document, GlobalVariables.getUserSession().getPerson()); |
205 | 0 | if (success == false) { |
206 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.DOCUMENT_ERRORS, RiceKeyConstants.AUTHORIZATION_ERROR_DOCUMENT, new String[]{GlobalVariables.getUserSession().getPerson().getPrincipalName(), "Create/Maintain", this.getMaintDocDictionaryService().getDocumentTypeName(newBo.getClass())}); |
207 | |
} |
208 | |
} |
209 | |
|
210 | 0 | success &= processGlobalRouteDocumentBusinessRules(maintenanceDocument); |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | 0 | success &= processCustomRouteDocumentBusinessRules(maintenanceDocument); |
216 | |
|
217 | 0 | success &= processInactivationBlockChecking(maintenanceDocument); |
218 | |
|
219 | |
|
220 | |
|
221 | 0 | resumeErrorPath(); |
222 | |
|
223 | 0 | return success; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
protected boolean isDocumentInactivatingBusinessObject(MaintenanceDocument maintenanceDocument) { |
233 | 0 | if (maintenanceDocument.isEdit()) { |
234 | 0 | Class boClass = maintenanceDocument.getNewMaintainableObject().getBoClass(); |
235 | |
|
236 | 0 | if (boClass != null && Inactivateable.class.isAssignableFrom(boClass)) { |
237 | 0 | Inactivateable oldInactivateableBO = (Inactivateable) oldBo; |
238 | 0 | Inactivateable newInactivateableBO = (Inactivateable) newBo; |
239 | |
|
240 | 0 | return oldInactivateableBO.isActive() && !newInactivateableBO.isActive(); |
241 | |
} |
242 | |
} |
243 | 0 | return false; |
244 | |
} |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
protected boolean processInactivationBlockChecking(MaintenanceDocument maintenanceDocument) { |
253 | 0 | if (isDocumentInactivatingBusinessObject(maintenanceDocument)) { |
254 | 0 | Class boClass = maintenanceDocument.getNewMaintainableObject().getBoClass(); |
255 | 0 | Set<InactivationBlockingMetadata> inactivationBlockingMetadatas = ddService.getAllInactivationBlockingDefinitions(boClass); |
256 | |
|
257 | 0 | if (inactivationBlockingMetadatas != null) { |
258 | 0 | for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockingMetadatas) { |
259 | |
|
260 | |
|
261 | |
|
262 | 0 | if (!processInactivationBlockChecking(maintenanceDocument, inactivationBlockingMetadata)) { |
263 | 0 | return false; |
264 | |
} |
265 | |
} |
266 | |
} |
267 | |
} |
268 | 0 | return true; |
269 | |
} |
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
protected boolean processInactivationBlockChecking(MaintenanceDocument maintenanceDocument, InactivationBlockingMetadata inactivationBlockingMetadata) { |
280 | |
|
281 | 0 | String inactivationBlockingDetectionServiceBeanName = inactivationBlockingMetadata.getInactivationBlockingDetectionServiceBeanName(); |
282 | 0 | if (StringUtils.isBlank(inactivationBlockingDetectionServiceBeanName)) { |
283 | 0 | inactivationBlockingDetectionServiceBeanName = KNSServiceLocator.DEFAULT_INACTIVATION_BLOCKING_DETECTION_SERVICE; |
284 | |
} |
285 | 0 | InactivationBlockingDetectionService inactivationBlockingDetectionService = KNSServiceLocator.getInactivationBlockingDetectionService(inactivationBlockingDetectionServiceBeanName); |
286 | |
|
287 | 0 | boolean foundBlockingRecord = inactivationBlockingDetectionService.hasABlockingRecord(newBo, inactivationBlockingMetadata); |
288 | |
|
289 | 0 | if (foundBlockingRecord) { |
290 | 0 | putInactivationBlockingErrorOnPage(maintenanceDocument, inactivationBlockingMetadata); |
291 | |
} |
292 | |
|
293 | 0 | return !foundBlockingRecord; |
294 | |
} |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
protected void putInactivationBlockingErrorOnPage(MaintenanceDocument document, InactivationBlockingMetadata inactivationBlockingMetadata) { |
303 | 0 | if (!persistenceStructureService.hasPrimaryKeyFieldValues(newBo)) { |
304 | 0 | throw new RuntimeException("Maintenance document did not have all primary key values filled in."); |
305 | |
} |
306 | 0 | Map fieldValues = persistenceService.getPrimaryKeyFieldValues(newBo); |
307 | 0 | Properties parameters = new Properties(); |
308 | 0 | parameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, inactivationBlockingMetadata.getBlockedBusinessObjectClass().getName()); |
309 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.METHOD_DISPLAY_ALL_INACTIVATION_BLOCKERS); |
310 | |
|
311 | 0 | List keys = new ArrayList(); |
312 | 0 | if (getPersistenceStructureService().isPersistable(newBo.getClass())) { |
313 | 0 | keys = getPersistenceStructureService().listPrimaryKeyFieldNames(newBo.getClass()); |
314 | |
} |
315 | |
|
316 | |
|
317 | 0 | String keyName = null; |
318 | 0 | for (Iterator iter = keys.iterator(); iter.hasNext();) { |
319 | 0 | keyName = (String) iter.next(); |
320 | |
|
321 | 0 | Object keyValue = null; |
322 | 0 | if (keyName != null) { |
323 | 0 | keyValue = ObjectUtils.getPropertyValue(newBo, keyName); |
324 | |
} |
325 | |
|
326 | 0 | if (keyValue == null) { |
327 | 0 | keyValue = ""; |
328 | 0 | } else if (keyValue instanceof java.sql.Date) { |
329 | 0 | if (Formatter.findFormatter(keyValue.getClass()) != null) { |
330 | 0 | Formatter formatter = Formatter.getFormatter(keyValue.getClass()); |
331 | 0 | keyValue = (String) formatter.format(keyValue); |
332 | 0 | } |
333 | |
} else { |
334 | 0 | keyValue = keyValue.toString(); |
335 | |
} |
336 | |
|
337 | |
|
338 | 0 | if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(inactivationBlockingMetadata.getBlockedBusinessObjectClass(), keyName)) { |
339 | |
try { |
340 | 0 | keyValue = KNSServiceLocator.getEncryptionService().encrypt(keyValue); |
341 | |
} |
342 | 0 | catch (GeneralSecurityException e) { |
343 | 0 | LOG.error("Exception while trying to encrypted value for inquiry framework.", e); |
344 | 0 | throw new RuntimeException(e); |
345 | 0 | } |
346 | |
} |
347 | |
|
348 | 0 | parameters.put(keyName, keyValue); |
349 | 0 | } |
350 | |
|
351 | 0 | String blockingUrl = UrlFactory.parameterizeUrl(KNSConstants.DISPLAY_ALL_INACTIVATION_BLOCKERS_ACTION, parameters); |
352 | |
|
353 | |
|
354 | 0 | GlobalVariables.getMessageMap().putError(KNSConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INACTIVATION_BLOCKED, blockingUrl); |
355 | 0 | } |
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
@Override |
361 | |
public boolean processApproveDocument(ApproveDocumentEvent approveEvent) { |
362 | |
|
363 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) approveEvent.getDocument(); |
364 | |
|
365 | |
|
366 | |
|
367 | 0 | clearErrorPath(); |
368 | |
|
369 | |
|
370 | 0 | setupBaseConvenienceObjects(maintenanceDocument); |
371 | |
|
372 | |
|
373 | 0 | processGlobalSaveDocumentBusinessRules(maintenanceDocument); |
374 | |
|
375 | |
|
376 | |
|
377 | 0 | boolean success = true; |
378 | |
|
379 | |
|
380 | 0 | success &= processGlobalApproveDocumentBusinessRules(maintenanceDocument); |
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | 0 | success &= processCustomApproveDocumentBusinessRules(maintenanceDocument); |
386 | |
|
387 | |
|
388 | |
|
389 | 0 | resumeErrorPath(); |
390 | |
|
391 | 0 | return success; |
392 | |
} |
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
protected void putGlobalError(String errorConstant) { |
403 | 0 | if (!errorAlreadyExists(KNSConstants.DOCUMENT_ERRORS, errorConstant)) { |
404 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KNSConstants.DOCUMENT_ERRORS, errorConstant); |
405 | |
} |
406 | 0 | } |
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
protected void putGlobalError(String errorConstant, String parameter) { |
418 | 0 | if (!errorAlreadyExists(KNSConstants.DOCUMENT_ERRORS, errorConstant)) { |
419 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KNSConstants.DOCUMENT_ERRORS, errorConstant, parameter); |
420 | |
} |
421 | 0 | } |
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
protected void putGlobalError(String errorConstant, String[] parameters) { |
433 | 0 | if (!errorAlreadyExists(KNSConstants.DOCUMENT_ERRORS, errorConstant)) { |
434 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KNSConstants.DOCUMENT_ERRORS, errorConstant, parameters); |
435 | |
} |
436 | 0 | } |
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
protected void putFieldError(String propertyName, String errorConstant) { |
449 | 0 | if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) { |
450 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant); |
451 | |
} |
452 | 0 | } |
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
protected void putFieldError(String propertyName, String errorConstant, String parameter) { |
467 | 0 | if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) { |
468 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant, parameter); |
469 | |
} |
470 | 0 | } |
471 | |
|
472 | |
|
473 | |
|
474 | |
|
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
|
483 | |
|
484 | |
protected void putFieldError(String propertyName, String errorConstant, String[] parameters) { |
485 | 0 | if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) { |
486 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant, parameters); |
487 | |
} |
488 | 0 | } |
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | |
|
497 | |
protected void putFieldErrorWithShortLabel(String propertyName, String errorConstant) { |
498 | 0 | String shortLabel = ddService.getAttributeShortLabel(boClass, propertyName); |
499 | 0 | putFieldError(propertyName, errorConstant, shortLabel); |
500 | 0 | } |
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
protected void putDocumentError(String propertyName, String errorConstant, String parameter) { |
515 | 0 | if (!errorAlreadyExists(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant)) { |
516 | 0 | GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant, parameter); |
517 | |
} |
518 | 0 | } |
519 | |
|
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
protected void putDocumentError(String propertyName, String errorConstant, String[] parameters) { |
533 | 0 | GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant, parameters); |
534 | 0 | } |
535 | |
|
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
|
546 | |
|
547 | |
protected boolean errorAlreadyExists(String propertyName, String errorConstant) { |
548 | |
|
549 | 0 | if (GlobalVariables.getMessageMap().fieldHasMessage(propertyName, errorConstant)) { |
550 | 0 | return true; |
551 | |
} |
552 | |
else { |
553 | 0 | return false; |
554 | |
} |
555 | |
} |
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
|
561 | |
|
562 | |
|
563 | |
|
564 | |
|
565 | |
protected void putGlobalsError(String propertyName, String errorConstant) { |
566 | 0 | if (!errorAlreadyExists(propertyName, errorConstant)) { |
567 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(propertyName, errorConstant); |
568 | |
} |
569 | 0 | } |
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
protected void putGlobalsError(String propertyName, String errorConstant, String parameter) { |
581 | 0 | if (!errorAlreadyExists(propertyName, errorConstant)) { |
582 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(propertyName, errorConstant, parameter); |
583 | |
} |
584 | 0 | } |
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | |
|
593 | |
|
594 | |
|
595 | |
|
596 | |
protected void clearErrorPath() { |
597 | |
|
598 | |
|
599 | 0 | priorErrorPath.addAll(GlobalVariables.getMessageMap().getErrorPath()); |
600 | |
|
601 | |
|
602 | 0 | GlobalVariables.getMessageMap().getErrorPath().clear(); |
603 | |
|
604 | 0 | } |
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
protected void resumeErrorPath() { |
616 | |
|
617 | |
|
618 | 0 | GlobalVariables.getMessageMap().getErrorPath().addAll(priorErrorPath); |
619 | 0 | } |
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
protected boolean dataDictionaryValidate(MaintenanceDocument document) { |
629 | |
|
630 | 0 | LOG.debug("MaintenanceDocument validation beginning"); |
631 | |
|
632 | |
|
633 | 0 | GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject"); |
634 | |
|
635 | |
|
636 | 0 | Maintainable newMaintainable = document.getNewMaintainableObject(); |
637 | 0 | if (newMaintainable == null) { |
638 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject"); |
639 | 0 | throw new ValidationException("Maintainable object from Maintenance Document '" + document.getDocumentTitle() + "' is null, unable to proceed."); |
640 | |
} |
641 | |
|
642 | |
|
643 | 0 | PersistableBusinessObject businessObject = newMaintainable.getBusinessObject(); |
644 | 0 | if (businessObject == null) { |
645 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject."); |
646 | 0 | throw new ValidationException("Maintainable's component business object is null."); |
647 | |
} |
648 | |
|
649 | |
|
650 | 0 | maintDocDictionaryService.validateMaintenanceRequiredFields(document); |
651 | |
|
652 | |
|
653 | 0 | maintDocDictionaryService.validateMaintainableCollectionsForDuplicateEntries(document); |
654 | |
|
655 | |
|
656 | 0 | dictionaryValidationService.validateBusinessObjectOnMaintenanceDocument(businessObject, |
657 | |
document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
658 | |
|
659 | |
|
660 | 0 | dictionaryValidationService.validateDefaultExistenceChecks(businessObject); |
661 | |
|
662 | |
|
663 | 0 | dictionaryValidationService.validateApcRules(businessObject); |
664 | |
|
665 | |
|
666 | |
|
667 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject"); |
668 | |
|
669 | 0 | LOG.debug("MaintenanceDocument validation ending"); |
670 | 0 | return true; |
671 | |
} |
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
|
682 | |
|
683 | |
|
684 | |
|
685 | |
|
686 | |
|
687 | |
|
688 | |
|
689 | |
protected boolean primaryKeyCheck(MaintenanceDocument document) { |
690 | |
|
691 | |
|
692 | 0 | boolean success = true; |
693 | 0 | Class boClass = document.getNewMaintainableObject().getBoClass(); |
694 | |
|
695 | 0 | PersistableBusinessObject oldBo = document.getOldMaintainableObject().getBusinessObject(); |
696 | 0 | PersistableBusinessObject newBo = document.getNewMaintainableObject().getBusinessObject(); |
697 | |
|
698 | |
|
699 | |
|
700 | |
|
701 | |
|
702 | |
|
703 | 0 | if (newBo instanceof GlobalBusinessObject) { |
704 | 0 | return success; |
705 | |
} |
706 | |
|
707 | |
|
708 | |
|
709 | 0 | if (document.isEdit()) { |
710 | 0 | if (!ObjectUtils.equalByKeys(oldBo, newBo)) { |
711 | |
|
712 | |
|
713 | 0 | putDocumentError(KNSConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PRIMARY_KEYS_CHANGED_ON_EDIT, getHumanReadablePrimaryKeyFieldNames(boClass)); |
714 | 0 | success &= false; |
715 | |
} |
716 | |
} |
717 | |
|
718 | |
|
719 | |
|
720 | 0 | else if (document.isNew()) { |
721 | |
|
722 | |
|
723 | 0 | Map newPkFields = persistenceService.getPrimaryKeyFieldValues(newBo); |
724 | |
|
725 | |
|
726 | |
|
727 | |
|
728 | |
|
729 | |
|
730 | |
|
731 | 0 | PersistableBusinessObject testBo = boService.findByPrimaryKey(boClass, newPkFields); |
732 | |
|
733 | |
|
734 | |
|
735 | 0 | if (testBo != null) { |
736 | 0 | putDocumentError(KNSConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_KEYS_ALREADY_EXIST_ON_CREATE_NEW, getHumanReadablePrimaryKeyFieldNames(boClass)); |
737 | 0 | success &= false; |
738 | |
} |
739 | |
} |
740 | 0 | return success; |
741 | |
} |
742 | |
|
743 | |
|
744 | |
|
745 | |
|
746 | |
|
747 | |
|
748 | |
|
749 | |
|
750 | |
protected String getHumanReadablePrimaryKeyFieldNames(Class boClass) { |
751 | |
|
752 | 0 | String delim = ""; |
753 | 0 | StringBuffer pkFieldNames = new StringBuffer(); |
754 | |
|
755 | |
|
756 | 0 | List pkFields = persistenceStructureService.getPrimaryKeys(boClass); |
757 | 0 | for (Iterator iter = pkFields.iterator(); iter.hasNext();) { |
758 | 0 | String pkFieldName = (String) iter.next(); |
759 | |
|
760 | |
|
761 | 0 | String humanReadableFieldName = ddService.getAttributeLabel(boClass, pkFieldName); |
762 | |
|
763 | |
|
764 | 0 | pkFieldNames.append(delim + humanReadableFieldName); |
765 | |
|
766 | |
|
767 | 0 | if (delim.equalsIgnoreCase("")) { |
768 | 0 | delim = ", "; |
769 | |
} |
770 | 0 | } |
771 | |
|
772 | 0 | return pkFieldNames.toString(); |
773 | |
} |
774 | |
|
775 | |
|
776 | |
|
777 | |
|
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
|
785 | |
protected boolean processGlobalApproveDocumentBusinessRules(MaintenanceDocument document) { |
786 | 0 | return true; |
787 | |
} |
788 | |
|
789 | |
|
790 | |
|
791 | |
|
792 | |
|
793 | |
|
794 | |
|
795 | |
|
796 | |
|
797 | |
|
798 | |
|
799 | |
|
800 | |
protected boolean processGlobalRouteDocumentBusinessRules(MaintenanceDocument document) { |
801 | |
|
802 | 0 | boolean success = true; |
803 | |
|
804 | |
|
805 | 0 | success &= checkEmptyDocumentField(KNSPropertyConstants.DOCUMENT_HEADER + "." + KNSPropertyConstants.DOCUMENT_DESCRIPTION, document.getDocumentHeader().getDocumentDescription(), "Description"); |
806 | |
|
807 | 0 | return success; |
808 | |
} |
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
|
815 | |
|
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
protected boolean processGlobalSaveDocumentBusinessRules(MaintenanceDocument document) { |
826 | |
|
827 | |
|
828 | 0 | boolean success = true; |
829 | |
|
830 | |
|
831 | 0 | primaryKeyCheck(document); |
832 | |
|
833 | |
|
834 | |
|
835 | 0 | this.dataDictionaryValidate(document); |
836 | |
|
837 | 0 | return success; |
838 | |
} |
839 | |
|
840 | |
|
841 | |
|
842 | |
|
843 | |
|
844 | |
|
845 | |
|
846 | |
protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { |
847 | 0 | return true; |
848 | |
} |
849 | |
|
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
|
857 | |
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { |
858 | 0 | return true; |
859 | |
} |
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
|
867 | |
protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) { |
868 | 0 | return true; |
869 | |
} |
870 | |
|
871 | |
|
872 | |
|
873 | |
|
874 | |
|
875 | |
|
876 | |
|
877 | |
|
878 | |
|
879 | |
|
880 | |
|
881 | |
|
882 | |
|
883 | |
|
884 | |
|
885 | |
protected boolean isDocumentValidForSave(MaintenanceDocument maintenanceDocument) { |
886 | |
|
887 | 0 | boolean success = true; |
888 | |
|
889 | 0 | success &= super.isDocumentOverviewValid(maintenanceDocument); |
890 | 0 | success &= validateDocumentStructure((Document) maintenanceDocument); |
891 | 0 | success &= validateMaintenanceDocument(maintenanceDocument); |
892 | 0 | success &= validateGlobalBusinessObjectPersistable(maintenanceDocument); |
893 | 0 | return success; |
894 | |
} |
895 | |
|
896 | |
|
897 | |
|
898 | |
|
899 | |
|
900 | |
|
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
protected boolean validateDocumentStructure(Document document) { |
907 | 0 | boolean success = true; |
908 | |
|
909 | |
|
910 | 0 | String documentHeaderId = document.getDocumentNumber(); |
911 | 0 | if (documentHeaderId == null || StringUtils.isEmpty(documentHeaderId)) { |
912 | 0 | throw new ValidationException("Document has no document number, unable to proceed."); |
913 | |
} |
914 | |
|
915 | 0 | return success; |
916 | |
} |
917 | |
|
918 | |
|
919 | |
|
920 | |
|
921 | |
|
922 | |
|
923 | |
|
924 | |
|
925 | |
|
926 | |
|
927 | |
|
928 | |
|
929 | |
protected boolean validateMaintenanceDocument(MaintenanceDocument maintenanceDocument) { |
930 | 0 | boolean success = true; |
931 | 0 | Maintainable newMaintainable = maintenanceDocument.getNewMaintainableObject(); |
932 | |
|
933 | |
|
934 | 0 | if (newMaintainable == null) { |
935 | 0 | throw new ValidationException("Maintainable object from Maintenance Document '" + maintenanceDocument.getDocumentTitle() + "' is null, unable to proceed."); |
936 | |
} |
937 | |
|
938 | |
|
939 | 0 | if (newMaintainable.getBusinessObject() == null) { |
940 | 0 | throw new ValidationException("Maintainable's component business object is null."); |
941 | |
} |
942 | |
|
943 | |
|
944 | 0 | if (!PersistableBusinessObject.class.isAssignableFrom(newMaintainable.getBoClass())) { |
945 | 0 | throw new ValidationException("Maintainable's component object is not descended from BusinessObject."); |
946 | |
} |
947 | 0 | return success; |
948 | |
} |
949 | |
|
950 | |
|
951 | |
|
952 | |
|
953 | |
|
954 | |
|
955 | |
|
956 | |
|
957 | |
|
958 | |
|
959 | |
|
960 | |
|
961 | |
protected boolean validateGlobalBusinessObjectPersistable(MaintenanceDocument document) { |
962 | 0 | boolean success = true; |
963 | |
|
964 | 0 | if (document.getNewMaintainableObject() == null) { |
965 | 0 | return success; |
966 | |
} |
967 | 0 | if (document.getNewMaintainableObject().getBusinessObject() == null) { |
968 | 0 | return success; |
969 | |
} |
970 | 0 | if (!(document.getNewMaintainableObject().getBusinessObject() instanceof GlobalBusinessObject)) { |
971 | 0 | return success; |
972 | |
} |
973 | |
|
974 | 0 | PersistableBusinessObject bo = (PersistableBusinessObject) document.getNewMaintainableObject().getBusinessObject(); |
975 | 0 | GlobalBusinessObject gbo = (GlobalBusinessObject) bo; |
976 | 0 | return gbo.isPersistable(); |
977 | |
} |
978 | |
|
979 | |
|
980 | |
|
981 | |
|
982 | |
|
983 | |
|
984 | |
|
985 | |
|
986 | |
|
987 | |
|
988 | |
|
989 | |
|
990 | |
protected boolean isCorrectMaintenanceClass(MaintenanceDocument document, Class clazz) { |
991 | |
|
992 | |
|
993 | 0 | if (document == null || clazz == null) { |
994 | 0 | throw new IllegalArgumentException("Null arguments were passed in."); |
995 | |
} |
996 | |
|
997 | |
|
998 | 0 | if (clazz.toString().equals(document.getNewMaintainableObject().getBoClass().toString())) { |
999 | 0 | return true; |
1000 | |
} |
1001 | |
else { |
1002 | 0 | return false; |
1003 | |
} |
1004 | |
} |
1005 | |
|
1006 | |
|
1007 | |
|
1008 | |
|
1009 | |
|
1010 | |
|
1011 | |
|
1012 | |
|
1013 | |
|
1014 | |
|
1015 | |
|
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
protected boolean checkEmptyBOField(String propertyName, Object valueToTest, String parameter) { |
1020 | |
|
1021 | 0 | boolean success = true; |
1022 | |
|
1023 | 0 | success = checkEmptyValue(valueToTest); |
1024 | |
|
1025 | |
|
1026 | 0 | if (!success) { |
1027 | 0 | putFieldError(propertyName, RiceKeyConstants.ERROR_REQUIRED, parameter); |
1028 | |
} |
1029 | |
|
1030 | 0 | return success; |
1031 | |
} |
1032 | |
|
1033 | |
|
1034 | |
|
1035 | |
|
1036 | |
|
1037 | |
|
1038 | |
|
1039 | |
|
1040 | |
|
1041 | |
|
1042 | |
|
1043 | |
|
1044 | |
|
1045 | |
|
1046 | |
protected boolean checkEmptyDocumentField(String propertyName, Object valueToTest, String parameter) { |
1047 | 0 | boolean success = true; |
1048 | 0 | success = checkEmptyValue(valueToTest); |
1049 | 0 | if (!success) { |
1050 | 0 | putDocumentError(propertyName, RiceKeyConstants.ERROR_REQUIRED, parameter); |
1051 | |
} |
1052 | 0 | return success; |
1053 | |
} |
1054 | |
|
1055 | |
|
1056 | |
|
1057 | |
|
1058 | |
|
1059 | |
|
1060 | |
|
1061 | |
|
1062 | |
|
1063 | |
|
1064 | |
|
1065 | |
|
1066 | |
protected boolean checkEmptyValue(Object valueToTest) { |
1067 | 0 | boolean success = true; |
1068 | |
|
1069 | |
|
1070 | 0 | if (valueToTest == null) { |
1071 | 0 | success = false; |
1072 | |
} |
1073 | |
else { |
1074 | |
|
1075 | 0 | if (valueToTest instanceof String) { |
1076 | 0 | if (StringUtils.isBlank((String) valueToTest)) { |
1077 | 0 | success = false; |
1078 | |
} |
1079 | |
} |
1080 | |
} |
1081 | |
|
1082 | 0 | return success; |
1083 | |
} |
1084 | |
|
1085 | |
|
1086 | |
|
1087 | |
|
1088 | |
|
1089 | |
|
1090 | |
|
1091 | |
protected void showErrorMap() { |
1092 | |
|
1093 | 0 | if (GlobalVariables.getMessageMap().hasNoErrors()) { |
1094 | 0 | return; |
1095 | |
} |
1096 | |
|
1097 | 0 | for (Iterator i = GlobalVariables.getMessageMap().getAllPropertiesAndErrors().iterator(); i.hasNext();) { |
1098 | 0 | Map.Entry e = (Map.Entry) i.next(); |
1099 | |
|
1100 | 0 | TypedArrayList errorList = (TypedArrayList) e.getValue(); |
1101 | 0 | for (Iterator j = errorList.iterator(); j.hasNext();) { |
1102 | 0 | ErrorMessage em = (ErrorMessage) j.next(); |
1103 | |
|
1104 | 0 | if (em.getMessageParameters() == null) { |
1105 | 0 | LOG.error(e.getKey().toString() + " = " + em.getErrorKey()); |
1106 | |
} |
1107 | |
else { |
1108 | 0 | LOG.error(e.getKey().toString() + " = " + em.getErrorKey() + " : " + em.getMessageParameters().toString()); |
1109 | |
} |
1110 | 0 | } |
1111 | 0 | } |
1112 | |
|
1113 | 0 | } |
1114 | |
|
1115 | |
|
1116 | |
|
1117 | |
|
1118 | |
public void setupBaseConvenienceObjects(MaintenanceDocument document) { |
1119 | |
|
1120 | |
|
1121 | 0 | oldBo = (PersistableBusinessObject) document.getOldMaintainableObject().getBusinessObject(); |
1122 | 0 | if (oldBo != null) { |
1123 | 0 | oldBo.refreshNonUpdateableReferences(); |
1124 | |
} |
1125 | |
|
1126 | |
|
1127 | 0 | newBo = (PersistableBusinessObject) document.getNewMaintainableObject().getBusinessObject(); |
1128 | 0 | newBo.refreshNonUpdateableReferences(); |
1129 | |
|
1130 | 0 | boClass = document.getNewMaintainableObject().getBoClass(); |
1131 | |
|
1132 | |
|
1133 | 0 | setupConvenienceObjects(); |
1134 | 0 | } |
1135 | |
|
1136 | |
public void setupConvenienceObjects() { |
1137 | |
|
1138 | 0 | } |
1139 | |
|
1140 | |
|
1141 | |
|
1142 | |
|
1143 | |
|
1144 | |
|
1145 | |
|
1146 | |
|
1147 | |
|
1148 | |
|
1149 | |
|
1150 | |
|
1151 | |
|
1152 | |
protected boolean checkForPartiallyFilledOutReferenceForeignKeys(String referenceName) { |
1153 | |
|
1154 | |
boolean success; |
1155 | |
|
1156 | |
ForeignKeyFieldsPopulationState fkFieldsState; |
1157 | 0 | fkFieldsState = persistenceStructureService.getForeignKeyFieldsPopulationState(newBo, referenceName); |
1158 | |
|
1159 | |
|
1160 | 0 | if (fkFieldsState.isAnyFieldsPopulated() && !fkFieldsState.isAllFieldsPopulated()) { |
1161 | 0 | success = false; |
1162 | |
} |
1163 | |
else { |
1164 | 0 | success = true; |
1165 | |
} |
1166 | |
|
1167 | |
|
1168 | 0 | if (!success) { |
1169 | |
|
1170 | |
|
1171 | 0 | List fKeys = new ArrayList(persistenceStructureService.getForeignKeysForReference(newBo.getClass(), referenceName).keySet()); |
1172 | 0 | String fKeysReadable = consolidateFieldNames(fKeys, ", ").toString(); |
1173 | |
|
1174 | |
|
1175 | 0 | for (Iterator iter = fkFieldsState.getUnpopulatedFieldNames().iterator(); iter.hasNext();) { |
1176 | 0 | String fieldName = (String) iter.next(); |
1177 | |
|
1178 | |
|
1179 | 0 | String fieldNameReadable = ddService.getAttributeLabel(newBo.getClass(), fieldName); |
1180 | |
|
1181 | |
|
1182 | 0 | putFieldError(fieldName, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PARTIALLY_FILLED_OUT_REF_FKEYS, new String[] { fieldNameReadable, fKeysReadable }); |
1183 | 0 | } |
1184 | |
} |
1185 | |
|
1186 | 0 | return success; |
1187 | |
} |
1188 | |
|
1189 | |
|
1190 | |
|
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
|
1195 | |
|
1196 | |
|
1197 | |
|
1198 | |
|
1199 | |
|
1200 | |
|
1201 | |
|
1202 | |
|
1203 | |
|
1204 | |
|
1205 | |
|
1206 | |
|
1207 | |
protected boolean apcRuleFails(String parameterNamespace, String parameterDetailTypeCode, String parameterName, String valueToTest) { |
1208 | 0 | if (applyApcRule(parameterNamespace, parameterDetailTypeCode, parameterName, valueToTest) == false) { |
1209 | 0 | return true; |
1210 | |
} |
1211 | 0 | return false; |
1212 | |
} |
1213 | |
|
1214 | |
|
1215 | |
|
1216 | |
|
1217 | |
|
1218 | |
|
1219 | |
|
1220 | |
|
1221 | |
|
1222 | |
|
1223 | |
|
1224 | |
|
1225 | |
|
1226 | |
|
1227 | |
|
1228 | |
|
1229 | |
protected boolean applyApcRule(String parameterNamespace, String parameterDetailTypeCode, String parameterName, String valueToTest) { |
1230 | |
|
1231 | |
|
1232 | 0 | boolean success = true; |
1233 | |
|
1234 | |
|
1235 | 0 | if (!KNSServiceLocator.getParameterService().getParameterEvaluator(parameterNamespace, parameterDetailTypeCode, parameterName, valueToTest).evaluationSucceeds()) { |
1236 | 0 | success = false; |
1237 | |
} |
1238 | |
|
1239 | 0 | return success; |
1240 | |
} |
1241 | |
|
1242 | |
|
1243 | |
|
1244 | |
|
1245 | |
|
1246 | |
|
1247 | |
|
1248 | |
|
1249 | |
|
1250 | |
protected StringBuffer consolidateFieldNames(List fieldNames, String delimiter) { |
1251 | |
|
1252 | 0 | StringBuffer sb = new StringBuffer(); |
1253 | |
|
1254 | |
|
1255 | 0 | boolean firstPass = true; |
1256 | 0 | String delim = ""; |
1257 | |
|
1258 | |
|
1259 | 0 | for (Iterator iter = fieldNames.iterator(); iter.hasNext();) { |
1260 | 0 | String fieldName = (String) iter.next(); |
1261 | |
|
1262 | |
|
1263 | |
|
1264 | 0 | sb.append(delim + ddService.getAttributeLabel(newBo.getClass(), fieldName)); |
1265 | |
|
1266 | |
|
1267 | 0 | if (firstPass) { |
1268 | 0 | delim = delimiter; |
1269 | 0 | firstPass = false; |
1270 | |
} |
1271 | 0 | } |
1272 | |
|
1273 | 0 | return sb; |
1274 | |
} |
1275 | |
|
1276 | |
|
1277 | |
|
1278 | |
|
1279 | |
|
1280 | |
|
1281 | |
|
1282 | |
|
1283 | |
|
1284 | |
|
1285 | |
|
1286 | |
protected String getFieldLabel(String fieldName) { |
1287 | 0 | return ddService.getAttributeLabel(newBo.getClass(), fieldName) + "(" + ddService.getAttributeShortLabel(newBo.getClass(), fieldName) + ")"; |
1288 | |
} |
1289 | |
|
1290 | |
|
1291 | |
|
1292 | |
|
1293 | |
|
1294 | |
|
1295 | |
|
1296 | |
|
1297 | |
|
1298 | |
|
1299 | |
|
1300 | |
|
1301 | |
protected String getFieldLabel(Class boClass, String fieldName) { |
1302 | 0 | return ddService.getAttributeLabel(boClass, fieldName) + "(" + ddService.getAttributeShortLabel(boClass, fieldName) + ")"; |
1303 | |
} |
1304 | |
|
1305 | |
|
1306 | |
|
1307 | |
|
1308 | |
|
1309 | |
|
1310 | |
protected final BusinessObjectDictionaryService getBoDictionaryService() { |
1311 | 0 | return boDictionaryService; |
1312 | |
} |
1313 | |
|
1314 | |
|
1315 | |
|
1316 | |
|
1317 | |
|
1318 | |
|
1319 | |
public final void setBoDictionaryService(BusinessObjectDictionaryService boDictionaryService) { |
1320 | 0 | this.boDictionaryService = boDictionaryService; |
1321 | 0 | } |
1322 | |
|
1323 | |
|
1324 | |
|
1325 | |
|
1326 | |
|
1327 | |
|
1328 | |
protected final BusinessObjectService getBoService() { |
1329 | 0 | return boService; |
1330 | |
} |
1331 | |
|
1332 | |
|
1333 | |
|
1334 | |
|
1335 | |
|
1336 | |
|
1337 | |
public final void setBoService(BusinessObjectService boService) { |
1338 | 0 | this.boService = boService; |
1339 | 0 | } |
1340 | |
|
1341 | |
|
1342 | |
|
1343 | |
|
1344 | |
|
1345 | |
|
1346 | |
protected final KualiConfigurationService getConfigService() { |
1347 | 0 | return configService; |
1348 | |
} |
1349 | |
|
1350 | |
|
1351 | |
|
1352 | |
|
1353 | |
|
1354 | |
|
1355 | |
public final void setConfigService(KualiConfigurationService configService) { |
1356 | 0 | this.configService = configService; |
1357 | 0 | } |
1358 | |
|
1359 | |
|
1360 | |
|
1361 | |
|
1362 | |
|
1363 | |
|
1364 | |
protected final DataDictionaryService getDdService() { |
1365 | 0 | return ddService; |
1366 | |
} |
1367 | |
|
1368 | |
|
1369 | |
|
1370 | |
|
1371 | |
|
1372 | |
|
1373 | |
public final void setDdService(DataDictionaryService ddService) { |
1374 | 0 | this.ddService = ddService; |
1375 | 0 | } |
1376 | |
|
1377 | |
|
1378 | |
|
1379 | |
|
1380 | |
|
1381 | |
|
1382 | |
protected final DictionaryValidationService getDictionaryValidationService() { |
1383 | 0 | return dictionaryValidationService; |
1384 | |
} |
1385 | |
|
1386 | |
|
1387 | |
|
1388 | |
|
1389 | |
|
1390 | |
|
1391 | |
public final void setDictionaryValidationService(DictionaryValidationService dictionaryValidationService) { |
1392 | 0 | this.dictionaryValidationService = dictionaryValidationService; |
1393 | 0 | } |
1394 | |
|
1395 | |
|
1396 | |
|
1397 | |
|
1398 | |
|
1399 | |
|
1400 | |
protected final MaintenanceDocumentDictionaryService getMaintDocDictionaryService() { |
1401 | 0 | return maintDocDictionaryService; |
1402 | |
} |
1403 | |
|
1404 | |
|
1405 | |
|
1406 | |
|
1407 | |
|
1408 | |
|
1409 | |
public final void setMaintDocDictionaryService(MaintenanceDocumentDictionaryService maintDocDictionaryService) { |
1410 | 0 | this.maintDocDictionaryService = maintDocDictionaryService; |
1411 | 0 | } |
1412 | |
|
1413 | |
|
1414 | |
|
1415 | |
|
1416 | |
|
1417 | |
|
1418 | |
protected final PersistableBusinessObject getNewBo() { |
1419 | 0 | return newBo; |
1420 | |
} |
1421 | |
|
1422 | |
protected void setNewBo(PersistableBusinessObject newBo) { |
1423 | 0 | this.newBo = newBo; |
1424 | 0 | } |
1425 | |
|
1426 | |
|
1427 | |
|
1428 | |
|
1429 | |
|
1430 | |
|
1431 | |
protected final PersistableBusinessObject getOldBo() { |
1432 | 0 | return oldBo; |
1433 | |
} |
1434 | |
|
1435 | |
|
1436 | |
|
1437 | |
|
1438 | |
|
1439 | |
|
1440 | |
protected final PersistenceService getPersistenceService() { |
1441 | 0 | return persistenceService; |
1442 | |
} |
1443 | |
|
1444 | |
|
1445 | |
|
1446 | |
|
1447 | |
|
1448 | |
|
1449 | |
public final void setPersistenceService(PersistenceService persistenceService) { |
1450 | 0 | this.persistenceService = persistenceService; |
1451 | 0 | } |
1452 | |
|
1453 | |
|
1454 | |
|
1455 | |
|
1456 | |
|
1457 | |
|
1458 | |
protected final PersistenceStructureService getPersistenceStructureService() { |
1459 | 0 | return persistenceStructureService; |
1460 | |
} |
1461 | |
|
1462 | |
|
1463 | |
|
1464 | |
|
1465 | |
|
1466 | |
|
1467 | |
public final void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) { |
1468 | 0 | this.persistenceStructureService = persistenceStructureService; |
1469 | 0 | } |
1470 | |
|
1471 | |
|
1472 | |
|
1473 | |
|
1474 | |
|
1475 | |
|
1476 | |
public WorkflowDocumentService getWorkflowDocumentService() { |
1477 | 0 | return workflowDocumentService; |
1478 | |
} |
1479 | |
|
1480 | |
|
1481 | |
|
1482 | |
|
1483 | |
|
1484 | |
|
1485 | |
public void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) { |
1486 | 0 | this.workflowDocumentService = workflowDocumentService; |
1487 | 0 | } |
1488 | |
|
1489 | |
public boolean processAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) { |
1490 | 0 | LOG.debug("processAddCollectionLineBusinessRules"); |
1491 | |
|
1492 | |
|
1493 | 0 | setupBaseConvenienceObjects(document); |
1494 | |
|
1495 | |
|
1496 | 0 | this.validateMaintenanceDocument( document ); |
1497 | |
|
1498 | 0 | boolean success = true; |
1499 | 0 | MessageMap map = GlobalVariables.getMessageMap(); |
1500 | 0 | int errorCount = map.getErrorCount(); |
1501 | 0 | map.addToErrorPath( MAINTAINABLE_ERROR_PATH ); |
1502 | 0 | if ( LOG.isDebugEnabled() ) { |
1503 | 0 | LOG.debug( "processAddCollectionLineBusinessRules - BO: " + bo ); |
1504 | 0 | LOG.debug( "Before Validate: " + map ); |
1505 | |
} |
1506 | |
|
1507 | 0 | getMaintDocDictionaryService().validateMaintainableCollectionsAddLineRequiredFields( document, document.getNewMaintainableObject().getBusinessObject(), collectionName ); |
1508 | 0 | String errorPath = KNSConstants.MAINTENANCE_ADD_PREFIX + collectionName; |
1509 | 0 | map.addToErrorPath( errorPath ); |
1510 | |
|
1511 | 0 | getDictionaryValidationService().validateBusinessObject( bo, false ); |
1512 | 0 | success &= map.getErrorCount() == errorCount; |
1513 | 0 | success &= dictionaryValidationService.validateDefaultExistenceChecksForNewCollectionItem(document.getNewMaintainableObject().getBusinessObject(), bo, collectionName); |
1514 | 0 | success &= validateDuplicateIdentifierInDataDictionary(document, collectionName, bo); |
1515 | 0 | success &= processCustomAddCollectionLineBusinessRules( document, collectionName, bo ); |
1516 | |
|
1517 | 0 | map.removeFromErrorPath( errorPath ); |
1518 | 0 | map.removeFromErrorPath( MAINTAINABLE_ERROR_PATH ); |
1519 | 0 | if ( LOG.isDebugEnabled() ) { |
1520 | 0 | LOG.debug( "After Validate: " + map ); |
1521 | 0 | LOG.debug( "processAddCollectionLineBusinessRules returning: " + success ); |
1522 | |
} |
1523 | |
|
1524 | 0 | return success; |
1525 | |
} |
1526 | |
|
1527 | |
|
1528 | |
|
1529 | |
|
1530 | |
|
1531 | |
|
1532 | |
|
1533 | |
|
1534 | |
|
1535 | |
|
1536 | |
|
1537 | |
|
1538 | |
|
1539 | |
protected boolean validateDuplicateIdentifierInDataDictionary(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) { |
1540 | 0 | boolean valid = true; |
1541 | 0 | PersistableBusinessObject maintBo = document.getNewMaintainableObject().getBusinessObject(); |
1542 | 0 | Collection maintCollection = (Collection) ObjectUtils.getPropertyValue(maintBo, collectionName); |
1543 | 0 | List<String> duplicateIdentifier = document.getNewMaintainableObject().getDuplicateIdentifierFieldsFromDataDictionary(document.getDocumentHeader().getWorkflowDocument().getDocumentType(), collectionName); |
1544 | 0 | if (duplicateIdentifier.size()>0) { |
1545 | 0 | List<String> existingIdentifierString = document.getNewMaintainableObject().getMultiValueIdentifierList(maintCollection, duplicateIdentifier); |
1546 | 0 | if (document.getNewMaintainableObject().hasBusinessObjectExisted(bo, existingIdentifierString, duplicateIdentifier)) { |
1547 | 0 | valid = false; |
1548 | 0 | GlobalVariables.getMessageMap().putError(duplicateIdentifier.get(0), RiceKeyConstants.ERROR_DUPLICATE_ELEMENT, "entries in ", document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
1549 | |
} |
1550 | |
} |
1551 | 0 | return valid; |
1552 | |
} |
1553 | |
|
1554 | |
public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject line) { |
1555 | 0 | return true; |
1556 | |
} |
1557 | |
|
1558 | |
public org.kuali.rice.kim.service.PersonService getPersonService() { |
1559 | 0 | return personService; |
1560 | |
} |
1561 | |
|
1562 | |
public void setPersonService(org.kuali.rice.kim.service.PersonService personService) { |
1563 | 0 | this.personService = personService; |
1564 | 0 | } |
1565 | |
|
1566 | |
public DateTimeService getDateTimeService() { |
1567 | 0 | return KNSServiceLocator.getDateTimeService(); |
1568 | |
} |
1569 | |
|
1570 | |
|
1571 | |
|
1572 | |
|
1573 | |
public DocumentHelperService getDocumentHelperService() { |
1574 | 0 | return this.documentHelperService; |
1575 | |
} |
1576 | |
|
1577 | |
|
1578 | |
|
1579 | |
|
1580 | |
public void setDocumentHelperService(DocumentHelperService documentHelperService) { |
1581 | 0 | this.documentHelperService = documentHelperService; |
1582 | 0 | } |
1583 | |
|
1584 | |
|
1585 | |
|
1586 | |
|
1587 | |
public BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
1588 | 0 | return this.businessObjectAuthorizationService; |
1589 | |
} |
1590 | |
|
1591 | |
|
1592 | |
|
1593 | |
|
1594 | |
public void setBusinessObjectAuthorizationService( |
1595 | |
BusinessObjectAuthorizationService businessObjectAuthorizationService) { |
1596 | 0 | this.businessObjectAuthorizationService = businessObjectAuthorizationService; |
1597 | 0 | } |
1598 | |
|
1599 | |
protected RoleService getRoleService(){ |
1600 | 0 | if(this.roleService==null){ |
1601 | 0 | this.roleService = KIMServiceLocator.getRoleService(); |
1602 | |
} |
1603 | 0 | return this.roleService; |
1604 | |
} |
1605 | |
|
1606 | |
} |
1607 | |
|