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