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