View Javadoc

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