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