View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.rules;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.CoreApiServiceLocator;
20  import org.kuali.rice.core.api.config.property.ConfigurationService;
21  import org.kuali.rice.core.api.datetime.DateTimeService;
22  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
23  import org.kuali.rice.core.api.util.RiceKeyConstants;
24  import org.kuali.rice.core.web.format.Formatter;
25  import org.kuali.rice.kew.api.WorkflowDocument;
26  import org.kuali.rice.kim.api.identity.PersonService;
27  import org.kuali.rice.kim.api.role.RoleService;
28  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29  import org.kuali.rice.krad.bo.GlobalBusinessObject;
30  import org.kuali.rice.krad.bo.PersistableBusinessObject;
31  import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata;
32  import org.kuali.rice.krad.document.Document;
33  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
34  import org.kuali.rice.krad.exception.ValidationException;
35  import org.kuali.rice.krad.maintenance.Maintainable;
36  import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizer;
37  import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
38  import org.kuali.rice.krad.service.BusinessObjectService;
39  import org.kuali.rice.krad.service.DataDictionaryService;
40  import org.kuali.rice.krad.service.DataObjectAuthorizationService;
41  import org.kuali.rice.krad.service.DataObjectMetaDataService;
42  import org.kuali.rice.krad.service.DictionaryValidationService;
43  import org.kuali.rice.krad.service.InactivationBlockingDetectionService;
44  import org.kuali.rice.krad.service.KRADServiceLocator;
45  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
46  import org.kuali.rice.krad.service.PersistenceStructureService;
47  import org.kuali.rice.krad.util.ErrorMessage;
48  import org.kuali.rice.krad.util.ForeignKeyFieldsPopulationState;
49  import org.kuali.rice.krad.util.GlobalVariables;
50  import org.kuali.rice.krad.util.KRADConstants;
51  import org.kuali.rice.krad.util.KRADPropertyConstants;
52  import org.kuali.rice.krad.util.ObjectUtils;
53  import org.kuali.rice.krad.util.UrlFactory;
54  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
55  import org.springframework.util.AutoPopulatingList;
56  
57  import java.security.GeneralSecurityException;
58  import java.util.ArrayList;
59  import java.util.Iterator;
60  import java.util.List;
61  import java.util.Map;
62  import java.util.Properties;
63  import java.util.Set;
64  
65  /**
66   * Contains all of the business rules that are common to all maintenance documents
67   *
68   * @author Kuali Rice Team (rice.collab@kuali.org)
69   */
70  public class MaintenanceDocumentRuleBase extends DocumentRuleBase implements MaintenanceDocumentRule {
71      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentRuleBase.class);
72  
73      // these two constants are used to correctly prefix errors added to
74      // the global errors
75      public static final String MAINTAINABLE_ERROR_PREFIX = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE;
76      public static final String DOCUMENT_ERROR_PREFIX = "document.";
77      public static final String MAINTAINABLE_ERROR_PATH = DOCUMENT_ERROR_PREFIX + "newMaintainableObject";
78  
79      private PersistenceStructureService persistenceStructureService;
80      private DataDictionaryService ddService;
81      private BusinessObjectService boService;
82      private DictionaryValidationService dictionaryValidationService;
83      private ConfigurationService configService;
84      private WorkflowDocumentService workflowDocumentService;
85      private PersonService personService;
86      private RoleService roleService;
87      private DataObjectMetaDataService dataObjectMetaDataService;
88      private DataObjectAuthorizationService dataObjectAuthorizationService;
89  
90      private Object oldDataObject;
91      private Object newDataObject;
92      private Class dataObjectClass;
93  
94      protected List priorErrorPath;
95  
96      /**
97       * Default constructor a MaintenanceDocumentRuleBase.java.
98       */
99      public MaintenanceDocumentRuleBase() {
100         priorErrorPath = new ArrayList();
101     }
102 
103     /**
104      * @see MaintenanceDocumentRule#processSaveDocument(org.kuali.rice.krad.document.Document)
105      */
106     @Override
107     public boolean processSaveDocument(Document document) {
108         MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
109 
110         // remove all items from the errorPath temporarily (because it may not
111         // be what we expect, or what we need)
112         clearErrorPath();
113 
114         // setup convenience pointers to the old & new bo
115         setupBaseConvenienceObjects(maintenanceDocument);
116 
117         // the document must be in a valid state for saving. this does not include business
118         // rules, but just enough testing that the document is populated and in a valid state
119         // to not cause exceptions when saved. if this passes, then the save will always occur,
120         // regardless of business rules.
121         if (!isDocumentValidForSave(maintenanceDocument)) {
122             resumeErrorPath();
123             return false;
124         }
125 
126         // apply rules that are specific to the class of the maintenance document
127         // (if implemented). this will always succeed if not overloaded by the
128         // subclass
129         processCustomSaveDocumentBusinessRules(maintenanceDocument);
130 
131         // return the original set of items to the errorPath
132         resumeErrorPath();
133 
134         // return the original set of items to the errorPath, to ensure no impact
135         // on other upstream or downstream items that rely on the errorPath
136         return true;
137     }
138 
139     /**
140      * @see MaintenanceDocumentRule#processRouteDocument(org.kuali.rice.krad.document.Document)
141      */
142     @Override
143     public boolean processRouteDocument(Document document) {
144         LOG.info("processRouteDocument called");
145 
146         MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
147 
148         // get the documentAuthorizer for this document
149         MaintenanceDocumentAuthorizer documentAuthorizer =
150                 (MaintenanceDocumentAuthorizer) getDocumentDictionaryService().getDocumentAuthorizer(document);
151 
152         // remove all items from the errorPath temporarily (because it may not
153         // be what we expect, or what we need)
154         clearErrorPath();
155 
156         // setup convenience pointers to the old & new bo
157         setupBaseConvenienceObjects(maintenanceDocument);
158 
159         // apply rules that are common across all maintenance documents, regardless of class
160         processGlobalSaveDocumentBusinessRules(maintenanceDocument);
161 
162         // from here on, it is in a default-success mode, and will route unless one of the
163         // business rules stop it.
164         boolean success = true;
165 
166         WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
167         if (workflowDocument.isInitiated() || workflowDocument.isSaved()){
168         	success &= documentAuthorizer.canCreateOrMaintain((MaintenanceDocument)document, GlobalVariables.getUserSession().getPerson());
169             if (success == false) {
170                 GlobalVariables.getMessageMap()
171                         .putError(KRADConstants.DOCUMENT_ERRORS, RiceKeyConstants.AUTHORIZATION_ERROR_DOCUMENT,
172                                 new String[]{GlobalVariables.getUserSession().getPerson().getPrincipalName(),
173                                         "Create/Maintain", getDocumentDictionaryService()
174                                         .getMaintenanceDocumentTypeName(newDataObject.getClass())});
175             }
176         }
177         // apply rules that are common across all maintenance documents, regardless of class
178         success &= processGlobalRouteDocumentBusinessRules(maintenanceDocument);
179 
180         // apply rules that are specific to the class of the maintenance document
181         // (if implemented). this will always succeed if not overloaded by the
182         // subclass
183         success &= processCustomRouteDocumentBusinessRules(maintenanceDocument);
184 
185         success &= processInactivationBlockChecking(maintenanceDocument);
186 
187         // return the original set of items to the errorPath, to ensure no impact
188         // on other upstream or downstream items that rely on the errorPath
189         resumeErrorPath();
190 
191         return success;
192     }
193 
194     /**
195      * Determines whether a document is inactivating the record being maintained
196      *
197      * @param maintenanceDocument
198      * @return true iff the document is inactivating the business object; false otherwise
199      */
200     protected boolean isDocumentInactivatingBusinessObject(MaintenanceDocument maintenanceDocument) {
201         if (maintenanceDocument.isEdit()) {
202             Class dataObjectClass = maintenanceDocument.getNewMaintainableObject().getDataObjectClass();
203             // we can only be inactivating a business object if we're editing it
204             if (dataObjectClass != null && MutableInactivatable.class.isAssignableFrom(dataObjectClass)) {
205                 MutableInactivatable oldInactivateableBO = (MutableInactivatable) oldDataObject;
206                 MutableInactivatable newInactivateableBO = (MutableInactivatable) newDataObject;
207 
208                 return oldInactivateableBO.isActive() && !newInactivateableBO.isActive();
209             }
210         }
211         return false;
212     }
213 
214     /**
215      * Determines whether this document has been inactivation blocked
216      *
217      * @param maintenanceDocument
218      * @return true iff there is NOTHING that blocks this record
219      */
220     protected boolean processInactivationBlockChecking(MaintenanceDocument maintenanceDocument) {
221         if (isDocumentInactivatingBusinessObject(maintenanceDocument)) {
222             Class dataObjectClass = maintenanceDocument.getNewMaintainableObject().getDataObjectClass();
223             Set<InactivationBlockingMetadata> inactivationBlockingMetadatas =
224                     getDataDictionaryService().getAllInactivationBlockingDefinitions(dataObjectClass);
225 
226             if (inactivationBlockingMetadatas != null) {
227                 for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockingMetadatas) {
228                     // for the purposes of maint doc validation, we only need to look for the first blocking record
229 
230                     // we found a blocking record, so we return false
231                     if (!processInactivationBlockChecking(maintenanceDocument, inactivationBlockingMetadata)) {
232                         return false;
233                     }
234                 }
235             }
236         }
237         return true;
238     }
239 
240     /**
241      * Given a InactivationBlockingMetadata, which represents a relationship that may block inactivation of a BO, it
242      * determines whether there
243      * is a record that violates the blocking definition
244      *
245      * @param maintenanceDocument
246      * @param inactivationBlockingMetadata
247      * @return true iff, based on the InactivationBlockingMetadata, the maintenance document should be allowed to route
248      */
249     protected boolean processInactivationBlockChecking(MaintenanceDocument maintenanceDocument,
250             InactivationBlockingMetadata inactivationBlockingMetadata) {
251         if (newDataObject instanceof PersistableBusinessObject) {
252             String inactivationBlockingDetectionServiceBeanName =
253                     inactivationBlockingMetadata.getInactivationBlockingDetectionServiceBeanName();
254             if (StringUtils.isBlank(inactivationBlockingDetectionServiceBeanName)) {
255                 inactivationBlockingDetectionServiceBeanName =
256                         KRADServiceLocatorWeb.DEFAULT_INACTIVATION_BLOCKING_DETECTION_SERVICE;
257             }
258             InactivationBlockingDetectionService inactivationBlockingDetectionService = KRADServiceLocatorWeb
259                     .getInactivationBlockingDetectionService(inactivationBlockingDetectionServiceBeanName);
260 
261             boolean foundBlockingRecord = inactivationBlockingDetectionService
262                     .hasABlockingRecord((PersistableBusinessObject) newDataObject, inactivationBlockingMetadata);
263 
264             if (foundBlockingRecord) {
265                 putInactivationBlockingErrorOnPage(maintenanceDocument, inactivationBlockingMetadata);
266             }
267 
268             return !foundBlockingRecord;
269         }
270 
271         return true;
272     }
273 
274     /**
275      * If there is a violation of an InactivationBlockingMetadata, it prints out an appropriate error into the error
276      * map
277      *
278      * @param document
279      * @param inactivationBlockingMetadata
280      */
281     protected void putInactivationBlockingErrorOnPage(MaintenanceDocument document,
282             InactivationBlockingMetadata inactivationBlockingMetadata) {
283         if (!getPersistenceStructureService().hasPrimaryKeyFieldValues(newDataObject)) {
284             throw new RuntimeException("Maintenance document did not have all primary key values filled in.");
285         }
286         Properties parameters = new Properties();
287         parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE,
288                 inactivationBlockingMetadata.getBlockedBusinessObjectClass().getName());
289         parameters
290                 .put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.METHOD_DISPLAY_ALL_INACTIVATION_BLOCKERS);
291 
292         List keys = new ArrayList();
293         if (getPersistenceStructureService().isPersistable(newDataObject.getClass())) {
294             keys = getPersistenceStructureService().listPrimaryKeyFieldNames(newDataObject.getClass());
295         }
296 
297         // build key value url parameters used to retrieve the business object
298         String keyName = null;
299         for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
300             keyName = (String) iter.next();
301 
302             Object keyValue = null;
303             if (keyName != null) {
304                 keyValue = ObjectUtils.getPropertyValue(newDataObject, keyName);
305             }
306 
307             if (keyValue == null) {
308                 keyValue = "";
309             } else if (keyValue instanceof java.sql.Date) { //format the date for passing in url
310                 if (Formatter.findFormatter(keyValue.getClass()) != null) {
311                     Formatter formatter = Formatter.getFormatter(keyValue.getClass());
312                     keyValue = (String) formatter.format(keyValue);
313                 }
314             } else {
315                 keyValue = keyValue.toString();
316             }
317 
318             // Encrypt value if it is a secure field
319             if (getDataObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(
320                     inactivationBlockingMetadata.getBlockedBusinessObjectClass(), keyName)){
321                 try {
322                     keyValue = CoreApiServiceLocator.getEncryptionService().encrypt(keyValue);
323                 } catch (GeneralSecurityException e) {
324                     LOG.error("Exception while trying to encrypted value for inquiry framework.", e);
325                     throw new RuntimeException(e);
326                 }
327             }
328 
329             parameters.put(keyName, keyValue);
330         }
331 
332         String blockingUrl =
333                 UrlFactory.parameterizeUrl(KRADConstants.DISPLAY_ALL_INACTIVATION_BLOCKERS_ACTION, parameters);
334 
335         // post an error about the locked document
336         GlobalVariables.getMessageMap()
337                 .putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INACTIVATION_BLOCKED, blockingUrl);
338     }
339 
340     /**
341      * @see MaintenanceDocumentRule#processApproveDocument(org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent)
342      */
343     @Override
344     public boolean processApproveDocument(ApproveDocumentEvent approveEvent) {
345         MaintenanceDocument maintenanceDocument = (MaintenanceDocument) approveEvent.getDocument();
346 
347         // remove all items from the errorPath temporarily (because it may not
348         // be what we expect, or what we need)
349         clearErrorPath();
350 
351         // setup convenience pointers to the old & new bo
352         setupBaseConvenienceObjects(maintenanceDocument);
353 
354         // apply rules that are common across all maintenance documents, regardless of class
355         processGlobalSaveDocumentBusinessRules(maintenanceDocument);
356 
357         // from here on, it is in a default-success mode, and will approve unless one of the
358         // business rules stop it.
359         boolean success = true;
360 
361         // apply rules that are common across all maintenance documents, regardless of class
362         success &= processGlobalApproveDocumentBusinessRules(maintenanceDocument);
363 
364         // apply rules that are specific to the class of the maintenance document
365         // (if implemented). this will always succeed if not overloaded by the
366         // subclass
367         success &= processCustomApproveDocumentBusinessRules(maintenanceDocument);
368 
369         // return the original set of items to the errorPath, to ensure no impact
370         // on other upstream or downstream items that rely on the errorPath
371         resumeErrorPath();
372 
373         return success;
374     }
375 
376     /**
377      * This method is a convenience method to easily add a Document level error (ie, one not tied to a specific field,
378      * but
379      * applicable to the whole document).
380      *
381      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
382      */
383     protected void putGlobalError(String errorConstant) {
384         if (!errorAlreadyExists(KRADConstants.DOCUMENT_ERRORS, errorConstant)) {
385             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.DOCUMENT_ERRORS, errorConstant);
386         }
387     }
388 
389     /**
390      * This method is a convenience method to easily add a Document level error (ie, one not tied to a specific field,
391      * but
392      * applicable to the whole document).
393      *
394      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
395      * @param parameter - Replacement value for part of the error message.
396      */
397     protected void putGlobalError(String errorConstant, String parameter) {
398         if (!errorAlreadyExists(KRADConstants.DOCUMENT_ERRORS, errorConstant)) {
399             GlobalVariables.getMessageMap()
400                     .putErrorWithoutFullErrorPath(KRADConstants.DOCUMENT_ERRORS, errorConstant, parameter);
401         }
402     }
403 
404     /**
405      * This method is a convenience method to easily add a Document level error (ie, one not tied to a specific field,
406      * but
407      * applicable to the whole document).
408      *
409      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
410      * @param parameters - Array of replacement values for part of the error message.
411      */
412     protected void putGlobalError(String errorConstant, String[] parameters) {
413         if (!errorAlreadyExists(KRADConstants.DOCUMENT_ERRORS, errorConstant)) {
414             GlobalVariables.getMessageMap()
415                     .putErrorWithoutFullErrorPath(KRADConstants.DOCUMENT_ERRORS, errorConstant, parameters);
416         }
417     }
418 
419     /**
420      * This method is a convenience method to add a property-specific error to the global errors list. This method
421      * makes
422      * sure that
423      * the correct prefix is added to the property name so that it will display correctly on maintenance documents.
424      *
425      * @param propertyName - Property name of the element that is associated with the error. Used to mark the field as
426      * errored in
427      * the UI.
428      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
429      */
430     protected void putFieldError(String propertyName, String errorConstant) {
431         if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) {
432             GlobalVariables.getMessageMap()
433                     .putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant);
434         }
435     }
436 
437     /**
438      * This method is a convenience method to add a property-specific error to the global errors list. This method
439      * makes
440      * sure that
441      * the correct prefix is added to the property name so that it will display correctly on maintenance documents.
442      *
443      * @param propertyName - Property name of the element that is associated with the error. Used to mark the field as
444      * errored in
445      * the UI.
446      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
447      * @param parameter - Single parameter value that can be used in the message so that you can display specific
448      * values
449      * to the
450      * user.
451      */
452     protected void putFieldError(String propertyName, String errorConstant, String parameter) {
453         if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) {
454             GlobalVariables.getMessageMap()
455                     .putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant, parameter);
456         }
457     }
458 
459     /**
460      * This method is a convenience method to add a property-specific error to the global errors list. This method
461      * makes
462      * sure that
463      * the correct prefix is added to the property name so that it will display correctly on maintenance documents.
464      *
465      * @param propertyName - Property name of the element that is associated with the error. Used to mark the field as
466      * errored in
467      * the UI.
468      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
469      * @param parameters - Array of strings holding values that can be used in the message so that you can display
470      * specific values
471      * to the user.
472      */
473     protected void putFieldError(String propertyName, String errorConstant, String[] parameters) {
474         if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) {
475             GlobalVariables.getMessageMap()
476                     .putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant, parameters);
477         }
478     }
479 
480     /**
481      * Adds a property-specific error to the global errors list, with the DD short label as the single argument.
482      *
483      * @param propertyName - Property name of the element that is associated with the error. Used to mark the field as
484      * errored in
485      * the UI.
486      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
487      */
488     protected void putFieldErrorWithShortLabel(String propertyName, String errorConstant) {
489         String shortLabel = getDataDictionaryService().getAttributeShortLabel(dataObjectClass, propertyName);
490         putFieldError(propertyName, errorConstant, shortLabel);
491     }
492 
493     /**
494      * This method is a convenience method to add a property-specific document error to the global errors list. This
495      * method makes
496      * sure that the correct prefix is added to the property name so that it will display correctly on maintenance
497      * documents.
498      *
499      * @param propertyName - Property name of the element that is associated with the error. Used to mark the field as
500      * errored in
501      * the UI.
502      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
503      * @param parameter - Single parameter value that can be used in the message so that you can display specific
504      * values
505      * to the
506      * user.
507      */
508     protected void putDocumentError(String propertyName, String errorConstant, String parameter) {
509         if (!errorAlreadyExists(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant)) {
510             GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant, parameter);
511         }
512     }
513 
514     /**
515      * This method is a convenience method to add a property-specific document error to the global errors list. This
516      * method makes
517      * sure that the correct prefix is added to the property name so that it will display correctly on maintenance
518      * documents.
519      *
520      * @param propertyName - Property name of the element that is associated with the error. Used to mark the field as
521      * errored in
522      * the UI.
523      * @param errorConstant - Error Constant that can be mapped to a resource for the actual text message.
524      * @param parameters - Array of String parameters that can be used in the message so that you can display specific
525      * values to the
526      * user.
527      */
528     protected void putDocumentError(String propertyName, String errorConstant, String[] parameters) {
529         GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant, parameters);
530     }
531 
532     /**
533      * Convenience method to determine whether the field already has the message indicated.
534      *
535      * This is useful if you want to suppress duplicate error messages on the same field.
536      *
537      * @param propertyName - propertyName you want to test on
538      * @param errorConstant - errorConstant you want to test
539      * @return returns True if the propertyName indicated already has the errorConstant indicated, false otherwise
540      */
541     protected boolean errorAlreadyExists(String propertyName, String errorConstant) {
542         if (GlobalVariables.getMessageMap().fieldHasMessage(propertyName, errorConstant)) {
543             return true;
544         } else {
545             return false;
546         }
547     }
548 
549     /**
550      * This method specifically doesn't put any prefixes before the error so that the developer can do things specific
551      * to the
552      * globals errors (like newDelegateChangeDocument errors)
553      *
554      * @param propertyName
555      * @param errorConstant
556      */
557     protected void putGlobalsError(String propertyName, String errorConstant) {
558         if (!errorAlreadyExists(propertyName, errorConstant)) {
559             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(propertyName, errorConstant);
560         }
561     }
562 
563     /**
564      * This method specifically doesn't put any prefixes before the error so that the developer can do things specific
565      * to the
566      * globals errors (like newDelegateChangeDocument errors)
567      *
568      * @param propertyName
569      * @param errorConstant
570      * @param parameter
571      */
572     protected void putGlobalsError(String propertyName, String errorConstant, String parameter) {
573         if (!errorAlreadyExists(propertyName, errorConstant)) {
574             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(propertyName, errorConstant, parameter);
575         }
576     }
577 
578     /**
579      * This method is used to deal with error paths that are not what we expect them to be. This method, along with
580      * resumeErrorPath() are used to temporarily clear the errorPath, and then return it to the original state after
581      * the
582      * rule is
583      * executed.
584      *
585      * This method is called at the very beginning of rule enforcement and pulls a copy of the contents of the
586      * errorPath
587      * ArrayList
588      * to a local arrayList for temporary storage.
589      */
590     protected void clearErrorPath() {
591         // add all the items from the global list to the local list
592         priorErrorPath.addAll(GlobalVariables.getMessageMap().getErrorPath());
593 
594         // clear the global list
595         GlobalVariables.getMessageMap().getErrorPath().clear();
596     }
597 
598     /**
599      * This method is used to deal with error paths that are not what we expect them to be. This method, along with
600      * clearErrorPath()
601      * are used to temporarily clear the errorPath, and then return it to the original state after the rule is
602      * executed.
603      *
604      * This method is called at the very end of the rule enforcement, and returns the temporarily stored copy of the
605      * errorPath to
606      * the global errorPath, so that no other classes are interrupted.
607      */
608     protected void resumeErrorPath() {
609         // revert the global errorPath back to what it was when we entered this
610         // class
611         GlobalVariables.getMessageMap().getErrorPath().addAll(priorErrorPath);
612     }
613 
614     /**
615      * Executes the DataDictionary Validation against the document.
616      *
617      * @param document
618      * @return true if it passes DD validation, false otherwise
619      */
620     protected boolean dataDictionaryValidate(MaintenanceDocument document) {
621         LOG.debug("MaintenanceDocument validation beginning");
622 
623         // explicitly put the errorPath that the dictionaryValidationService
624         // requires
625         GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject");
626 
627         // document must have a newMaintainable object
628         Maintainable newMaintainable = document.getNewMaintainableObject();
629         if (newMaintainable == null) {
630             GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject");
631             throw new ValidationException(
632                     "Maintainable object from Maintenance Document '" + document.getDocumentTitle() +
633                             "' is null, unable to proceed.");
634         }
635 
636         // document's newMaintainable must contain an object (ie, not null)
637         Object dataObject = newMaintainable.getDataObject();
638         if (dataObject == null) {
639             GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject.");
640             throw new ValidationException("Maintainable's component business object is null.");
641         }
642 
643         GlobalVariables.getMessageMap().addToErrorPath("dataObject");
644 
645         getDictionaryValidationService().validate(newDataObject);
646 
647         GlobalVariables.getMessageMap().removeFromErrorPath("dataObject");
648 
649         // explicitly remove the errorPath we've added
650         GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject");
651 
652         LOG.debug("MaintenanceDocument validation ending");
653         return true;
654     }
655 
656     /**
657      * This method checks the two major cases that may violate primary key integrity.
658      *
659      * 1. Disallow changing of the primary keys on an EDIT maintenance document. Other fields can be changed, but once
660      * the primary
661      * keys have been set, they are permanent.
662      *
663      * 2. Disallow creating a new object whose primary key values are already present in the system on a CREATE NEW
664      * maintenance
665      * document.
666      *
667      * This method also will add new Errors to the Global Error Map.
668      *
669      * @param document - The Maintenance Document being tested.
670      * @return Returns false if either test failed, otherwise returns true.
671      */
672     protected boolean primaryKeyCheck(MaintenanceDocument document) {
673         // default to success if no failures
674         boolean success = true;
675         Class<?> dataObjectClass = document.getNewMaintainableObject().getDataObjectClass();
676 
677         Object oldBo = document.getOldMaintainableObject().getDataObject();
678         Object newDataObject = document.getNewMaintainableObject().getDataObject();
679 
680         // We dont do primaryKeyChecks on Global Business Object maintenance documents. This is
681         // because it doesnt really make any sense to do so, given the behavior of Globals. When a
682         // Global Document completes, it will update or create a new record for each BO in the list.
683         // As a result, there's no problem with having existing BO records in the system, they will
684         // simply get updated.
685         if (newDataObject instanceof GlobalBusinessObject) {
686             return success;
687         }
688 
689         // fail and complain if the person has changed the primary keys on
690         // an EDIT maintenance document.
691         if (document.isEdit()) {
692             if (!getDataObjectMetaDataService().equalsByPrimaryKeys(oldBo, newDataObject)) {
693                 // add a complaint to the errors
694                 putDocumentError(KRADConstants.DOCUMENT_ERRORS,
695                         RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PRIMARY_KEYS_CHANGED_ON_EDIT,
696                         getHumanReadablePrimaryKeyFieldNames(dataObjectClass));
697                 success &= false;
698             }
699         }
700 
701         // fail and complain if the person has selected a new object with keys that already exist
702         // in the DB.
703         else if (document.isNew()) {
704 
705             // TODO: when/if we have standard support for DO retrieval, do this check for DO's
706             if (newDataObject instanceof PersistableBusinessObject) {
707 
708                 // get a map of the pk field names and values
709                 Map<String, ?> newPkFields = getDataObjectMetaDataService().getPrimaryKeyFieldValues(newDataObject);
710 
711                 // TODO: Good suggestion from Aaron, dont bother checking the DB, if all of the
712                 // objects PK fields dont have values. If any are null or empty, then
713                 // we're done. The current way wont fail, but it will make a wasteful
714                 // DB call that may not be necessary, and we want to minimize these.
715 
716                 // attempt to do a lookup, see if this object already exists by these Primary Keys
717                 PersistableBusinessObject testBo = getBoService()
718                         .findByPrimaryKey(dataObjectClass.asSubclass(PersistableBusinessObject.class), newPkFields);
719 
720                 // if the retrieve was successful, then this object already exists, and we need
721                 // to complain
722                 if (testBo != null) {
723                     putDocumentError(KRADConstants.DOCUMENT_ERRORS,
724                             RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_KEYS_ALREADY_EXIST_ON_CREATE_NEW,
725                             getHumanReadablePrimaryKeyFieldNames(dataObjectClass));
726                     success &= false;
727                 }
728             }
729         }
730 
731         return success;
732     }
733 
734     /**
735      * This method creates a human-readable string of the class' primary key field names, as designated by the
736      * DataDictionary.
737      *
738      * @param dataObjectClass
739      * @return
740      */
741     protected String getHumanReadablePrimaryKeyFieldNames(Class<?> dataObjectClass) {
742         String delim = "";
743         StringBuffer pkFieldNames = new StringBuffer();
744 
745         // get a list of all the primary key field names, walk through them
746         List<String> pkFields = getDataObjectMetaDataService().listPrimaryKeyFieldNames(dataObjectClass);
747         for (Iterator<String> iter = pkFields.iterator(); iter.hasNext(); ) {
748             String pkFieldName = (String) iter.next();
749 
750             // TODO should this be getting labels from the view dictionary
751             // use the DataDictionary service to translate field name into human-readable label
752             String humanReadableFieldName = getDataDictionaryService().getAttributeLabel(dataObjectClass, pkFieldName);
753 
754             // append the next field
755             pkFieldNames.append(delim + humanReadableFieldName);
756 
757             // separate names with commas after the first one
758             if (delim.equalsIgnoreCase("")) {
759                 delim = ", ";
760             }
761         }
762 
763         return pkFieldNames.toString();
764     }
765 
766     /**
767      * This method enforces all business rules that are common to all maintenance documents which must be tested before
768      * doing an
769      * approval.
770      *
771      * It can be overloaded in special cases where a MaintenanceDocument has very special needs that would be contrary
772      * to what is
773      * enforced here.
774      *
775      * @param document - a populated MaintenanceDocument instance
776      * @return true if the document can be approved, false if not
777      */
778     protected boolean processGlobalApproveDocumentBusinessRules(MaintenanceDocument document) {
779         return true;
780     }
781 
782     /**
783      * This method enforces all business rules that are common to all maintenance documents which must be tested before
784      * doing a
785      * route.
786      *
787      * It can be overloaded in special cases where a MaintenanceDocument has very special needs that would be contrary
788      * to what is
789      * enforced here.
790      *
791      * @param document - a populated MaintenanceDocument instance
792      * @return true if the document can be routed, false if not
793      */
794     protected boolean processGlobalRouteDocumentBusinessRules(MaintenanceDocument document) {
795         boolean success = true;
796 
797         // require a document description field
798         success &= checkEmptyDocumentField(
799                 KRADPropertyConstants.DOCUMENT_HEADER + "." + KRADPropertyConstants.DOCUMENT_DESCRIPTION,
800                 document.getDocumentHeader().getDocumentDescription(), "Description");
801 
802         return success;
803     }
804 
805     /**
806      * This method enforces all business rules that are common to all maintenance documents which must be tested before
807      * doing a
808      * save.
809      *
810      * It can be overloaded in special cases where a MaintenanceDocument has very special needs that would be contrary
811      * to what is
812      * enforced here.
813      *
814      * Note that although this method returns a true or false to indicate whether the save should happen or not, this
815      * result may not
816      * be followed by the calling method. In other words, the boolean result will likely be ignored, and the document
817      * saved,
818      * regardless.
819      *
820      * @param document - a populated MaintenanceDocument instance
821      * @return true if all business rules succeed, false if not
822      */
823     protected boolean processGlobalSaveDocumentBusinessRules(MaintenanceDocument document) {
824         // default to success
825         boolean success = true;
826 
827         // do generic checks that impact primary key violations
828         primaryKeyCheck(document);
829 
830         // this is happening only on the processSave, since a Save happens in both the
831         // Route and Save events.
832         this.dataDictionaryValidate(document);
833 
834         return success;
835     }
836 
837     /**
838      * This method should be overridden to provide custom rules for processing document saving
839      *
840      * @param document
841      * @return boolean
842      */
843     protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
844         return true;
845     }
846 
847     /**
848      * This method should be overridden to provide custom rules for processing document routing
849      *
850      * @param document
851      * @return boolean
852      */
853     protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
854         return true;
855     }
856 
857     /**
858      * This method should be overridden to provide custom rules for processing document approval.
859      *
860      * @param document
861      * @return booelan
862      */
863     protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
864         return true;
865     }
866 
867     // Document Validation Helper Methods
868 
869     /**
870      * This method checks to see if the document is in a state that it can be saved without causing exceptions.
871      *
872      * Note that Business Rules are NOT enforced here, only validity checks.
873      *
874      * This method will only return false if the document is in such a state that routing it will cause
875      * RunTimeExceptions.
876      *
877      * @param maintenanceDocument - a populated MaintenaceDocument instance.
878      * @return boolean - returns true unless the object is in an invalid state.
879      */
880     protected boolean isDocumentValidForSave(MaintenanceDocument maintenanceDocument) {
881 
882         boolean success = true;
883 
884         success &= super.isDocumentOverviewValid(maintenanceDocument);
885         success &= validateDocumentStructure((Document) maintenanceDocument);
886         success &= validateMaintenanceDocument(maintenanceDocument);
887         success &= validateGlobalBusinessObjectPersistable(maintenanceDocument);
888         return success;
889     }
890 
891     /**
892      * This method makes sure the document itself is valid, and has the necessary fields populated to be routable.
893      *
894      * This is not a business rules test, rather its a structure test to make sure that the document will not cause
895      * exceptions
896      * before routing.
897      *
898      * @param document - document to be tested
899      * @return false if the document is missing key values, true otherwise
900      */
901     protected boolean validateDocumentStructure(Document document) {
902         boolean success = true;
903 
904         // document must have a populated documentNumber
905         String documentHeaderId = document.getDocumentNumber();
906         if (documentHeaderId == null || StringUtils.isEmpty(documentHeaderId)) {
907             throw new ValidationException("Document has no document number, unable to proceed.");
908         }
909 
910         return success;
911     }
912 
913     /**
914      * This method checks to make sure the document is a valid maintenanceDocument, and has the necessary values
915      * populated such that
916      * it will not cause exceptions in later routing or business rules testing.
917      *
918      * This is not a business rules test.
919      *
920      * @param maintenanceDocument - document to be tested
921      * @return whether maintenance doc passes
922      * @throws ValidationException
923      */
924     protected boolean validateMaintenanceDocument(MaintenanceDocument maintenanceDocument) {
925         boolean success = true;
926         Maintainable newMaintainable = maintenanceDocument.getNewMaintainableObject();
927 
928         // document must have a newMaintainable object
929         if (newMaintainable == null) {
930             throw new ValidationException(
931                     "Maintainable object from Maintenance Document '" + maintenanceDocument.getDocumentTitle() +
932                             "' is null, unable to proceed.");
933         }
934 
935         // document's newMaintainable must contain an object (ie, not null)
936         if (newMaintainable.getDataObject() == null) {
937             throw new ValidationException("Maintainable's component data object is null.");
938         }
939 
940         return success;
941     }
942 
943     /**
944      * This method checks whether this maint doc contains Global Business Objects, and if so, whether the GBOs are in a
945      * persistable
946      * state. This will return false if this method determines that the GBO will cause a SQL Exception when the
947      * document
948      * is
949      * persisted.
950      *
951      * @param document
952      * @return False when the method determines that the contained Global Business Object will cause a SQL Exception,
953      *         and the
954      *         document should not be saved. It will return True otherwise.
955      */
956     protected boolean validateGlobalBusinessObjectPersistable(MaintenanceDocument document) {
957         boolean success = true;
958 
959         if (document.getNewMaintainableObject() == null) {
960             return success;
961         }
962         if (document.getNewMaintainableObject().getDataObject() == null) {
963             return success;
964         }
965         if (!(document.getNewMaintainableObject().getDataObject() instanceof GlobalBusinessObject)) {
966             return success;
967         }
968 
969         PersistableBusinessObject bo = (PersistableBusinessObject) document.getNewMaintainableObject().getDataObject();
970         GlobalBusinessObject gbo = (GlobalBusinessObject) bo;
971         return gbo.isPersistable();
972     }
973 
974     /**
975      * This method tests to make sure the MaintenanceDocument passed in is based on the class you are expecting.
976      *
977      * It does this based on the NewMaintainableObject of the MaintenanceDocument.
978      *
979      * @param document - MaintenanceDocument instance you want to test
980      * @param clazz - class you are expecting the MaintenanceDocument to be based on
981      * @return true if they match, false if not
982      */
983     protected boolean isCorrectMaintenanceClass(MaintenanceDocument document, Class clazz) {
984         // disallow null arguments
985         if (document == null || clazz == null) {
986             throw new IllegalArgumentException("Null arguments were passed in.");
987         }
988 
989         // compare the class names
990         if (clazz.toString().equals(document.getNewMaintainableObject().getDataObjectClass().toString())) {
991             return true;
992         } else {
993             return false;
994         }
995     }
996 
997     /**
998      * This method accepts an object, and attempts to determine whether it is empty by this method's definition.
999      *
1000      * OBJECT RESULT null false empty-string false whitespace false otherwise true
1001      *
1002      * If the result is false, it will add an object field error to the Global Errors.
1003      *
1004      * @param valueToTest - any object to test, usually a String
1005      * @param propertyName - the name of the property being tested
1006      * @return true or false, by the description above
1007      */
1008     protected boolean checkEmptyBOField(String propertyName, Object valueToTest, String parameter) {
1009         boolean success = true;
1010 
1011         success = checkEmptyValue(valueToTest);
1012 
1013         // if failed, then add a field error
1014         if (!success) {
1015             putFieldError(propertyName, RiceKeyConstants.ERROR_REQUIRED, parameter);
1016         }
1017 
1018         return success;
1019     }
1020 
1021     /**
1022      * This method accepts document field (such as , and attempts to determine whether it is empty by this method's
1023      * definition.
1024      *
1025      * OBJECT RESULT null false empty-string false whitespace false otherwise true
1026      *
1027      * If the result is false, it will add document field error to the Global Errors.
1028      *
1029      * @param valueToTest - any object to test, usually a String
1030      * @param propertyName - the name of the property being tested
1031      * @return true or false, by the description above
1032      */
1033     protected boolean checkEmptyDocumentField(String propertyName, Object valueToTest, String parameter) {
1034         boolean success = true;
1035         success = checkEmptyValue(valueToTest);
1036         if (!success) {
1037             putDocumentError(propertyName, RiceKeyConstants.ERROR_REQUIRED, parameter);
1038         }
1039         return success;
1040     }
1041 
1042     /**
1043      * This method accepts document field (such as , and attempts to determine whether it is empty by this method's
1044      * definition.
1045      *
1046      * OBJECT RESULT null false empty-string false whitespace false otherwise true
1047      *
1048      * It will the result as a boolean
1049      *
1050      * @param valueToTest - any object to test, usually a String
1051      */
1052     protected boolean checkEmptyValue(Object valueToTest) {
1053         boolean success = true;
1054 
1055         // if its not a string, only fail if its a null object
1056         if (valueToTest == null) {
1057             success = false;
1058         } else {
1059             // test for null, empty-string, or whitespace if its a string
1060             if (valueToTest instanceof String) {
1061                 if (StringUtils.isBlank((String) valueToTest)) {
1062                     success = false;
1063                 }
1064             }
1065         }
1066 
1067         return success;
1068     }
1069 
1070     /**
1071      * This method is used during debugging to dump the contents of the error map, including the key names. It is not
1072      * used by the
1073      * application in normal circumstances at all.
1074      */
1075     protected void showErrorMap() {
1076         if (GlobalVariables.getMessageMap().hasNoErrors()) {
1077             return;
1078         }
1079 
1080         for (Iterator i = GlobalVariables.getMessageMap().getAllPropertiesAndErrors().iterator(); i.hasNext(); ) {
1081             Map.Entry e = (Map.Entry) i.next();
1082 
1083             AutoPopulatingList errorList = (AutoPopulatingList) e.getValue();
1084             for (Iterator j = errorList.iterator(); j.hasNext(); ) {
1085                 ErrorMessage em = (ErrorMessage) j.next();
1086 
1087                 if (em.getMessageParameters() == null) {
1088                     LOG.error(e.getKey().toString() + " = " + em.getErrorKey());
1089                 } else {
1090                     LOG.error(e.getKey().toString() + " = " + em.getErrorKey() + " : " +
1091                             em.getMessageParameters().toString());
1092                 }
1093             }
1094         }
1095     }
1096 
1097     /**
1098      * @see MaintenanceDocumentRule#setupBaseConvenienceObjects(org.kuali.rice.krad.maintenance.MaintenanceDocument)
1099      */
1100     public void setupBaseConvenienceObjects(MaintenanceDocument document) {
1101         // setup oldAccount convenience objects, make sure all possible sub-objects are populated
1102         oldDataObject = document.getOldMaintainableObject().getDataObject();
1103         if (oldDataObject != null && oldDataObject instanceof PersistableBusinessObject) {
1104             ((PersistableBusinessObject) oldDataObject).refreshNonUpdateableReferences();
1105         }
1106 
1107         // setup newAccount convenience objects, make sure all possible sub-objects are populated
1108         newDataObject = document.getNewMaintainableObject().getDataObject();
1109         if (newDataObject instanceof PersistableBusinessObject) {
1110             ((PersistableBusinessObject) newDataObject).refreshNonUpdateableReferences();
1111         }
1112 
1113         dataObjectClass = document.getNewMaintainableObject().getDataObjectClass();
1114 
1115         // call the setupConvenienceObjects in the subclass, if a subclass exists
1116         setupConvenienceObjects();
1117     }
1118 
1119     public void setupConvenienceObjects() {
1120         // should always be overriden by subclass
1121     }
1122 
1123     /**
1124      * This method checks to make sure that if the foreign-key fields for the given reference attributes have any
1125      * fields filled out,that all fields are filled out.
1126      *
1127      * If any are filled out, but all are not, it will return false and add a global error message about the problem.
1128      *
1129      * @param referenceName - The name of the reference object, whose foreign-key fields must be all-or-none filled
1130      * out.
1131      * @return true if this is the case, false if not
1132      */
1133     protected boolean checkForPartiallyFilledOutReferenceForeignKeys(String referenceName) {
1134         boolean success = true;
1135 
1136         if (newDataObject instanceof PersistableBusinessObject) {
1137             ForeignKeyFieldsPopulationState fkFieldsState;
1138             fkFieldsState = getPersistenceStructureService()
1139                     .getForeignKeyFieldsPopulationState((PersistableBusinessObject) newDataObject, referenceName);
1140 
1141             // determine result
1142             if (fkFieldsState.isAnyFieldsPopulated() && !fkFieldsState.isAllFieldsPopulated()) {
1143                 success = false;
1144 
1145                 // add errors if appropriate
1146 
1147                 // get the full set of foreign-keys
1148                 List fKeys = new ArrayList(getPersistenceStructureService().getForeignKeysForReference(
1149                         newDataObject.getClass().asSubclass(PersistableBusinessObject.class), referenceName).keySet());
1150                 String fKeysReadable = consolidateFieldNames(fKeys, ", ").toString();
1151 
1152                 // walk through the missing fields
1153                 for (Iterator iter = fkFieldsState.getUnpopulatedFieldNames().iterator(); iter.hasNext(); ) {
1154                     String fieldName = (String) iter.next();
1155 
1156                     // get the human-readable name
1157                     String fieldNameReadable = getDataDictionaryService().getAttributeLabel(newDataObject.getClass(), fieldName);
1158 
1159                     // add a field error
1160                     putFieldError(fieldName, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PARTIALLY_FILLED_OUT_REF_FKEYS,
1161                             new String[]{fieldNameReadable, fKeysReadable});
1162                 }
1163             }
1164         }
1165 
1166         return success;
1167     }
1168 
1169     /**
1170      * This method turns a list of field property names, into a delimited string of the human-readable names.
1171      *
1172      * @param fieldNames - List of fieldNames
1173      * @return A filled StringBuffer ready to go in an error message
1174      */
1175     protected StringBuffer consolidateFieldNames(List fieldNames, String delimiter) {
1176         StringBuffer sb = new StringBuffer();
1177 
1178         // setup some vars
1179         boolean firstPass = true;
1180         String delim = "";
1181 
1182         // walk through the list
1183         for (Iterator iter = fieldNames.iterator(); iter.hasNext(); ) {
1184             String fieldName = (String) iter.next();
1185 
1186             // get the human-readable name
1187             // add the new one, with the appropriate delimiter
1188             sb.append(delim + getDataDictionaryService().getAttributeLabel(newDataObject.getClass(), fieldName));
1189 
1190             // after the first item, start using a delimiter
1191             if (firstPass) {
1192                 delim = delimiter;
1193                 firstPass = false;
1194             }
1195         }
1196 
1197         return sb;
1198     }
1199 
1200     /**
1201      * This method translates the passed in field name into a human-readable attribute label.
1202      *
1203      * It assumes the existing newDataObject's class as the class to examine the fieldName for.
1204      *
1205      * @param fieldName The fieldName you want a human-readable label for.
1206      * @return A human-readable label, pulled from the DataDictionary.
1207      */
1208     protected String getFieldLabel(String fieldName) {
1209         return getDataDictionaryService().getAttributeLabel(newDataObject.getClass(), fieldName) + "(" +
1210                 getDataDictionaryService().getAttributeShortLabel(newDataObject.getClass(), fieldName) + ")";
1211     }
1212 
1213     /**
1214      * This method translates the passed in field name into a human-readable attribute label.
1215      *
1216      * It assumes the existing newDataObject's class as the class to examine the fieldName for.
1217      *
1218      * @param dataObjectClass The class to use in combination with the fieldName.
1219      * @param fieldName The fieldName you want a human-readable label for.
1220      * @return A human-readable label, pulled from the DataDictionary.
1221      */
1222     protected String getFieldLabel(Class dataObjectClass, String fieldName) {
1223         return getDataDictionaryService().getAttributeLabel(dataObjectClass, fieldName) + "(" +
1224                 getDataDictionaryService().getAttributeShortLabel(dataObjectClass, fieldName) + ")";
1225     }
1226 
1227     /**
1228      * Gets the newDataObject attribute.
1229      *
1230      * @return Returns the newDataObject.
1231      */
1232     protected final Object getNewDataObject() {
1233         return newDataObject;
1234     }
1235 
1236     protected void setNewDataObject(Object newDataObject) {
1237         this.newDataObject = newDataObject;
1238     }
1239 
1240     /**
1241      * Gets the oldDataObject attribute.
1242      *
1243      * @return Returns the oldDataObject.
1244      */
1245     protected final Object getOldDataObject() {
1246         return oldDataObject;
1247     }
1248 
1249     public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName,
1250             PersistableBusinessObject line) {
1251         return true;
1252     }
1253 
1254     protected final BusinessObjectService getBoService() {
1255         if (boService == null) {
1256             this.boService = KRADServiceLocator.getBusinessObjectService();
1257         }
1258         return boService;
1259     }
1260 
1261     public final void setBoService(BusinessObjectService boService) {
1262         this.boService = boService;
1263     }
1264 
1265     protected final ConfigurationService getConfigService() {
1266         if (configService == null) {
1267             this.configService = KRADServiceLocator.getKualiConfigurationService();
1268         }
1269         return configService;
1270     }
1271 
1272     public final void setConfigService(ConfigurationService configService) {
1273         this.configService = configService;
1274     }
1275 
1276     protected final DataDictionaryService getDdService() {
1277         if (ddService == null) {
1278             this.ddService = KRADServiceLocatorWeb.getDataDictionaryService();
1279         }
1280         return ddService;
1281     }
1282 
1283     public final void setDdService(DataDictionaryService ddService) {
1284         this.ddService = ddService;
1285     }
1286 
1287     protected final DictionaryValidationService getDictionaryValidationService() {
1288         if (dictionaryValidationService == null) {
1289             this.dictionaryValidationService = KRADServiceLocatorWeb.getDictionaryValidationService();
1290         }
1291         return dictionaryValidationService;
1292     }
1293 
1294     public final void setDictionaryValidationService(DictionaryValidationService dictionaryValidationService) {
1295         this.dictionaryValidationService = dictionaryValidationService;
1296     }
1297     public PersonService getPersonService() {
1298         if (personService == null) {
1299             this.personService = KimApiServiceLocator.getPersonService();
1300         }
1301         return personService;
1302     }
1303 
1304     public void setPersonService(PersonService personService) {
1305         this.personService = personService;
1306     }
1307 
1308     public DateTimeService getDateTimeService() {
1309         return CoreApiServiceLocator.getDateTimeService();
1310     }
1311 
1312     protected RoleService getRoleService() {
1313         if (this.roleService == null) {
1314             this.roleService = KimApiServiceLocator.getRoleService();
1315         }
1316         return this.roleService;
1317     }
1318 
1319     protected DataObjectMetaDataService getDataObjectMetaDataService() {
1320         if (dataObjectMetaDataService == null) {
1321             this.dataObjectMetaDataService = KRADServiceLocatorWeb.getDataObjectMetaDataService();
1322         }
1323         return dataObjectMetaDataService;
1324     }
1325 
1326     public void setDataObjectMetaDataService(DataObjectMetaDataService dataObjectMetaDataService) {
1327         this.dataObjectMetaDataService = dataObjectMetaDataService;
1328     }
1329 
1330     protected final PersistenceStructureService getPersistenceStructureService() {
1331         if (persistenceStructureService == null) {
1332             this.persistenceStructureService = KRADServiceLocator.getPersistenceStructureService();
1333         }
1334         return persistenceStructureService;
1335     }
1336 
1337     public final void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
1338         this.persistenceStructureService = persistenceStructureService;
1339     }
1340 
1341     public WorkflowDocumentService getWorkflowDocumentService() {
1342         if (workflowDocumentService == null) {
1343             this.workflowDocumentService = KRADServiceLocatorWeb.getWorkflowDocumentService();
1344         }
1345         return workflowDocumentService;
1346     }
1347 
1348     public void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) {
1349         this.workflowDocumentService = workflowDocumentService;
1350     }
1351 
1352     public DataObjectAuthorizationService getDataObjectAuthorizationService() {
1353         if (dataObjectAuthorizationService == null) {
1354             this.dataObjectAuthorizationService = KRADServiceLocatorWeb.getDataObjectAuthorizationService();
1355         }
1356         return dataObjectAuthorizationService;
1357     }
1358 
1359     public void setDataObjectAuthorizationService(DataObjectAuthorizationService dataObjectAuthorizationService) {
1360         this.dataObjectAuthorizationService = dataObjectAuthorizationService;
1361     }
1362 
1363 }
1364