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