Coverage Report - org.kuali.rice.kns.service.impl.PessimisticLockServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PessimisticLockServiceImpl
0%
0/151
0%
0/102
3.143
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.HashSet;
 21  
 import java.util.Iterator;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 import java.util.Set;
 25  
 
 26  
 import org.apache.commons.lang.StringUtils;
 27  
 import org.kuali.rice.core.util.RiceConstants;
 28  
 import org.kuali.rice.kim.api.services.IdentityManagementService;
 29  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 30  
 import org.kuali.rice.kim.bo.Person;
 31  
 import org.kuali.rice.kim.service.PersonService;
 32  
 import org.kuali.rice.kim.util.KimConstants.PermissionNames;
 33  
 import org.kuali.rice.kns.authorization.AuthorizationConstants;
 34  
 import org.kuali.rice.kns.document.Document;
 35  
 import org.kuali.rice.kns.document.authorization.PessimisticLock;
 36  
 import org.kuali.rice.kns.exception.AuthorizationException;
 37  
 import org.kuali.rice.kns.exception.PessimisticLockingException;
 38  
 import org.kuali.rice.kns.service.*;
 39  
 import org.kuali.rice.kns.util.GlobalVariables;
 40  
 import org.kuali.rice.kns.util.KNSConstants;
 41  
 import org.kuali.rice.kns.util.KNSPropertyConstants;
 42  
 import org.kuali.rice.kns.util.ObjectUtils;
 43  
 import org.springframework.transaction.annotation.Transactional;
 44  
 
 45  
 /**
 46  
  * This is a service implementation for pessimistic locking
 47  
  *
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  *
 50  
  */
 51  
 @Transactional
 52  0
 public class PessimisticLockServiceImpl implements PessimisticLockService {
 53  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PessimisticLockServiceImpl.class);
 54  
 
 55  
     private PersonService personService;
 56  
     private BusinessObjectService businessObjectService;
 57  
     private DataDictionaryService dataDictionaryService;
 58  
     private IdentityManagementService identityManagementService;
 59  
 
 60  
     /**
 61  
      * @see org.kuali.rice.kns.service.PessimisticLockService#delete(java.lang.String)
 62  
      */
 63  
     public void delete(String id) {
 64  0
         if (StringUtils.isBlank(id)) {
 65  0
             throw new IllegalArgumentException("An invalid blank id was passed to delete a Pessimistic Lock.");
 66  
         }
 67  0
         Map<String,Object> primaryKeys = new HashMap<String,Object>();
 68  0
         primaryKeys.put(KNSPropertyConstants.ID, Long.valueOf(id));
 69  0
         PessimisticLock lock = (PessimisticLock) getBusinessObjectService().findByPrimaryKey(PessimisticLock.class, primaryKeys);
 70  0
         if (ObjectUtils.isNull(lock)) {
 71  0
             throw new IllegalArgumentException("Pessimistic Lock with id " + id + " cannot be found in the database.");
 72  
         }
 73  0
         Person user = GlobalVariables.getUserSession().getPerson();
 74  0
         if ( (!lock.isOwnedByUser(user)) && (!isPessimisticLockAdminUser(user)) ) {
 75  0
             throw new AuthorizationException(user.getName(),"delete", "Pessimistick Lock (id " + id + ")");
 76  
         }
 77  0
         delete(lock);
 78  0
     }
 79  
 
 80  
     private void delete(PessimisticLock lock) {
 81  0
             if ( LOG.isDebugEnabled() ) {
 82  0
                     LOG.debug("Deleting lock: " + lock);
 83  
             }
 84  0
         getBusinessObjectService().delete(lock);
 85  0
     }
 86  
 
 87  
     /**
 88  
      * @see org.kuali.rice.kns.service.PessimisticLockService#generateNewLock(String)
 89  
      */
 90  
     public PessimisticLock generateNewLock(String documentNumber) {
 91  0
         return generateNewLock(documentNumber, GlobalVariables.getUserSession().getPerson());
 92  
     }
 93  
 
 94  
     /**
 95  
      * @see org.kuali.rice.kns.service.PessimisticLockService#generateNewLock(java.lang.String)
 96  
      */
 97  
     public PessimisticLock generateNewLock(String documentNumber, String lockDescriptor) {
 98  0
         return generateNewLock(documentNumber, lockDescriptor, GlobalVariables.getUserSession().getPerson());
 99  
     }
 100  
 
 101  
     /**
 102  
      * @see org.kuali.rice.kns.service.PessimisticLockService#generateNewLock(java.lang.String, org.kuali.rice.kim.bo.Person)
 103  
      */
 104  
     public PessimisticLock generateNewLock(String documentNumber, Person user) {
 105  0
         return generateNewLock(documentNumber, PessimisticLock.DEFAULT_LOCK_DESCRIPTOR, user);
 106  
     }
 107  
 
 108  
     /**
 109  
      * @see org.kuali.rice.kns.service.PessimisticLockService#generateNewLock(java.lang.String, java.lang.String, org.kuali.rice.kim.bo.Person)
 110  
      */
 111  
     public PessimisticLock generateNewLock(String documentNumber, String lockDescriptor, Person user) {
 112  0
         PessimisticLock lock = new PessimisticLock(documentNumber, lockDescriptor, user);
 113  0
         lock = save(lock);
 114  0
         if ( LOG.isDebugEnabled() ) {
 115  0
                 LOG.debug("Generated new lock: " + lock);
 116  
         }
 117  0
         return lock;
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see org.kuali.rice.kns.service.PessimisticLockService#getPessimisticLocksForDocument(java.lang.String)
 122  
      */
 123  
     @SuppressWarnings("unchecked")
 124  
     public List<PessimisticLock> getPessimisticLocksForDocument(String documentNumber) {
 125  0
         Map fieldValues = new HashMap();
 126  0
         fieldValues.put(KNSPropertyConstants.DOCUMENT_NUMBER, documentNumber);
 127  0
         return (List<PessimisticLock>) getBusinessObjectService().findMatching(PessimisticLock.class, fieldValues);
 128  
     }
 129  
 
 130  
     /**
 131  
      * @see org.kuali.rice.kns.service.PessimisticLockService#isPessimisticLockAdminUser(org.kuali.rice.kim.bo.Person)
 132  
      */
 133  
     public boolean isPessimisticLockAdminUser(Person user) {
 134  0
             return getIdentityManagementService().isAuthorized( user.getPrincipalId(), KNSConstants.KNS_NAMESPACE, PermissionNames.ADMIN_PESSIMISTIC_LOCKING, null, null );
 135  
     }
 136  
 
 137  
     /**
 138  
      * @see org.kuali.rice.kns.service.PessimisticLockService#releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.bo.Person)
 139  
      */
 140  
     public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user) {
 141  0
         for (Iterator<PessimisticLock> iterator = locks.iterator(); iterator.hasNext();) {
 142  0
             PessimisticLock lock = (PessimisticLock) iterator.next();
 143  0
             if (lock.isOwnedByUser(user)) {
 144  0
                 delete(lock);
 145  
             }
 146  0
         }
 147  0
     }
 148  
 
 149  
     /**
 150  
      * @see org.kuali.rice.kns.service.PessimisticLockService#releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.bo.Person, java.lang.String)
 151  
      */
 152  
     public void releaseAllLocksForUser(List<PessimisticLock> locks, Person user, String lockDescriptor) {
 153  0
         for (Iterator<PessimisticLock> iterator = locks.iterator(); iterator.hasNext();) {
 154  0
             PessimisticLock lock = (PessimisticLock) iterator.next();
 155  0
             if ( (lock.isOwnedByUser(user)) && (lockDescriptor.equals(lock.getLockDescriptor())) ) {
 156  0
                 delete(lock);
 157  
             }
 158  0
         }
 159  0
     }
 160  
 
 161  
     /**
 162  
      * @see org.kuali.rice.kns.service.PessimisticLockService#save(org.kuali.rice.kns.document.authorization.PessimisticLock)
 163  
      */
 164  
     public PessimisticLock save(PessimisticLock lock) {
 165  0
             if ( LOG.isDebugEnabled() ) {
 166  0
                     LOG.debug("Saving lock: " + lock);
 167  
             }
 168  0
         return (PessimisticLock)getBusinessObjectService().save(lock);
 169  
     }
 170  
 
 171  
     public BusinessObjectService getBusinessObjectService() {
 172  0
         return this.businessObjectService;
 173  
     }
 174  
 
 175  
     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 176  0
         this.businessObjectService = businessObjectService;
 177  0
     }
 178  
 
 179  
     /**
 180  
      * @param document
 181  
      * @param user
 182  
      * @return Set of actions are permitted the given user on the given document
 183  
      */
 184  
     public Set getDocumentActions(Document document, Person user, Set<String> documentActions){
 185  0
             if(documentActions.contains(KNSConstants.KUALI_ACTION_CAN_CANCEL) && !hasPreRouteEditAuthorization(document, user) ){
 186  0
                     documentActions.remove(KNSConstants.KUALI_ACTION_CAN_CANCEL);
 187  
             }
 188  0
             if(documentActions.contains(KNSConstants.KUALI_ACTION_CAN_SAVE)  && !hasPreRouteEditAuthorization(document, user)){
 189  0
                     documentActions.remove(KNSConstants.KUALI_ACTION_CAN_SAVE);
 190  
             }
 191  0
         if(documentActions.contains(KNSConstants.KUALI_ACTION_CAN_ROUTE) && !hasPreRouteEditAuthorization(document, user)){
 192  0
                 documentActions.remove(KNSConstants.KUALI_ACTION_CAN_ROUTE);
 193  
         }
 194  0
         if (documentActions.contains(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE) && !hasPreRouteEditAuthorization(document, user)){
 195  0
                 documentActions.remove(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
 196  
         }
 197  0
             return documentActions;
 198  
     }
 199  
 
 200  
 
 201  
     /**
 202  
      * This method checks to see that the given user has a lock on the document and return true if one is found.
 203  
      *
 204  
      * @param document - document to check
 205  
      * @param user - current user
 206  
      * @return true if the document is using Pessimistic Locking, the user has initiate authorization (see
 207  
      *         {@link #hasInitiateAuthorization(Document, Person)}), and the document has a lock owned by the given
 208  
      *         user. If the document is not using Pessimistic Locking the value returned will be that returned by
 209  
      *         {@link #hasInitiateAuthorization(Document, Person)}.
 210  
      */
 211  
     protected boolean hasPreRouteEditAuthorization(Document document, Person user) {
 212  0
             if (document.getPessimisticLocks().isEmpty()) {
 213  0
                     return true;
 214  
             }
 215  0
             for (Iterator iterator = document.getPessimisticLocks().iterator(); iterator.hasNext();) {
 216  0
                     PessimisticLock lock = (PessimisticLock) iterator.next();
 217  0
                     if (lock.isOwnedByUser(user)) {
 218  0
                             return true;
 219  
             }
 220  0
         }
 221  0
         return false;
 222  
     }
 223  
 
 224  
 
 225  
     protected boolean usesPessimisticLocking(Document document) {
 226  0
         return getDataDictionaryService().getDataDictionary().getDocumentEntry(document.getClass().getName()).getUsePessimisticLocking();
 227  
     }
 228  
 
 229  
 
 230  
     /**
 231  
      * This method creates a new {@link PessimisticLock} when Workflow processing requires one
 232  
      *
 233  
      * @param document - the document to create the lock against and add the lock to
 234  
      * @see org.kuali.rice.kns.document.authorization.DocumentAuthorizer#establishWorkflowPessimisticLocking(org.kuali.rice.kns.document.Document)
 235  
      */
 236  
     public void establishWorkflowPessimisticLocking(Document document) {
 237  0
         PessimisticLock lock = createNewPessimisticLock(document, new HashMap(), getWorkflowPessimisticLockOwnerUser());
 238  0
         document.addPessimisticLock(lock);
 239  0
     }
 240  
 
 241  
     /**
 242  
      * This method releases locks created via the {@link #establishWorkflowPessimisticLocking(Document)} method for the given document
 243  
      *
 244  
      * @param document - document to release locks from
 245  
      * @see org.kuali.rice.kns.document.authorization.DocumentAuthorizer#releaseWorkflowPessimisticLocking(org.kuali.rice.kns.document.Document)
 246  
      */
 247  
     public void releaseWorkflowPessimisticLocking(Document document) {
 248  0
         releaseAllLocksForUser(document.getPessimisticLocks(), getWorkflowPessimisticLockOwnerUser());
 249  0
         document.refreshPessimisticLocks();
 250  0
     }
 251  
 
 252  
     /**
 253  
      * This method identifies the user that should be used to create and clear {@link PessimisticLock} objects required by
 254  
      * Workflow.<br>
 255  
      * <br>
 256  
      * The default is the Kuali system user defined by {@link RiceConstants#SYSTEM_USER}. This method can be overriden by
 257  
      * implementing documents if another user is needed.
 258  
      *
 259  
      * @return a valid {@link Person} object
 260  
      */
 261  
     protected Person getWorkflowPessimisticLockOwnerUser() {
 262  0
         String networkId = KNSConstants.SYSTEM_USER;
 263  0
         return getPersonService().getPersonByPrincipalName(networkId);
 264  
     }
 265  
 
 266  
     /**
 267  
      * This implementation will check the given document, editMode map, and user object to verify Pessimistic Locking. If the
 268  
      * given edit mode map contains an 'entry type' edit mode then the system will check the locks already in existence on
 269  
      * the document. If a valid lock for the given user is found the system will return the given edit mode map. If a valid
 270  
      * lock is found but is owned by another user the edit mode map returned will have any 'entry type' edit modes removed. If the
 271  
      * given document has no locks and the edit mode map passed in has at least one 'entry type' mode then a new
 272  
      * {@link PessimisticLock} object will be created and set on the document for the given user.<br>
 273  
      * <br>
 274  
      * NOTE: This method is only called if the document uses pessimistic locking as described in the data dictionary file.
 275  
      *
 276  
      * @see org.kuali.rice.kns.document.authorization.DocumentAuthorizer#establishLocks(org.kuali.rice.kns.document.Document,
 277  
      *      java.util.Map, org.kuali.rice.kim.bo.Person)
 278  
      */
 279  
     public Map establishLocks(Document document, Map editMode, Person user) {
 280  0
         Map editModeMap = new HashMap();
 281  
         // givenUserLockDescriptors is a list of lock descriptors currently held on the document by the given user
 282  0
         List<String> givenUserLockDescriptors = new ArrayList<String>();
 283  
         // lockDescriptorUsers is a map with lock descriptors as keys and users other than the given user who hold a lock of each descriptor
 284  0
         Map<String,Set<Person>> lockDescriptorUsers = new HashMap<String,Set<Person>>();
 285  
 
 286  
         // build the givenUserLockDescriptors set and the lockDescriptorUsers map
 287  0
         for (PessimisticLock lock : document.getPessimisticLocks()) {
 288  0
             if (lock.isOwnedByUser(user)) {
 289  
                 // lock is owned by given user
 290  0
                 givenUserLockDescriptors.add(lock.getLockDescriptor());
 291  
             } else {
 292  
                 // lock is not owned by the given user
 293  0
                 if (!lockDescriptorUsers.containsKey(lock.getLockDescriptor())) {
 294  0
                     lockDescriptorUsers.put(lock.getLockDescriptor(), new HashSet<Person>());
 295  
                 }
 296  0
                 ((Set<Person>) lockDescriptorUsers.get(lock.getLockDescriptor())).add(lock.getOwnedByUser());
 297  
             }
 298  
         }
 299  
 
 300  
         // verify that no locks held by current user exist for any other user
 301  0
         for (String givenUserLockDescriptor : givenUserLockDescriptors) {
 302  0
             if ( (lockDescriptorUsers.containsKey(givenUserLockDescriptor)) && (lockDescriptorUsers.get(givenUserLockDescriptor).size() > 0) ) {
 303  0
                 Set<Person> users = lockDescriptorUsers.get(givenUserLockDescriptor);
 304  0
                 if ( (users.size() != 1) || (!getWorkflowPessimisticLockOwnerUser().getPrincipalId().equals(users.iterator().next().getPrincipalId())) ) {
 305  0
                     String descriptorText = (document.useCustomLockDescriptors()) ? " using lock descriptor '" + givenUserLockDescriptor + "'" : "";
 306  0
                     String errorMsg = "Found an invalid lock status on document number " + document.getDocumentNumber() + "with current user and other user both having locks" + descriptorText + " concurrently";
 307  0
                     LOG.debug(errorMsg);
 308  0
                     throw new PessimisticLockingException(errorMsg);
 309  
                 }
 310  0
             }
 311  
         }
 312  
 
 313  
         // check to see if the given user has any locks in the system at all
 314  0
         if (givenUserLockDescriptors.isEmpty()) {
 315  
             // given user has no locks... check for other user locks
 316  0
             if (lockDescriptorUsers.isEmpty()) {
 317  
                 // no other user has any locks... set up locks for given user if user has edit privileges
 318  0
                 if (isLockRequiredByUser(document, editMode, user)) {
 319  0
                     document.addPessimisticLock(createNewPessimisticLock(document, editMode, user));
 320  
                 }
 321  0
                 editModeMap.putAll(editMode);
 322  
             } else {
 323  
                 // at least one other user has at least one other lock... adjust edit mode for read only
 324  0
                 if (document.useCustomLockDescriptors()) {
 325  
                     // check to see if the custom lock descriptor is already in use
 326  0
                     String customLockDescriptor = document.getCustomLockDescriptor(user);
 327  0
                     if (lockDescriptorUsers.containsKey(customLockDescriptor)) {
 328  
                         // at least one other user has this descriptor locked... remove editable edit modes
 329  0
                         editModeMap = getEditModeWithEditableModesRemoved(editMode);
 330  
                     } else {
 331  
                         // no other user has a lock with this descriptor
 332  0
                         if (isLockRequiredByUser(document, editMode, user)) {
 333  0
                             document.addPessimisticLock(createNewPessimisticLock(document, editMode, user));
 334  
                         }
 335  0
                         editModeMap.putAll(editMode);
 336  
                     }
 337  0
                 } else {
 338  0
                     editModeMap = getEditModeWithEditableModesRemoved(editMode);
 339  
                 }
 340  
             }
 341  
         } else {
 342  
             // given user already has at least one lock descriptor
 343  0
             if (document.useCustomLockDescriptors()) {
 344  
                 // get the custom lock descriptor and check to see if if the given user has a lock with that descriptor
 345  0
                 String customLockDescriptor = document.getCustomLockDescriptor(user);
 346  0
                 if (givenUserLockDescriptors.contains(customLockDescriptor)) {
 347  
                     // user already has lock that is required
 348  0
                     editModeMap.putAll(editMode);
 349  
                 } else {
 350  
                     // user does not have lock for descriptor required
 351  0
                     if (lockDescriptorUsers.containsKey(customLockDescriptor)) {
 352  
                         // another user has the lock descriptor that the given user requires... disallow lock and alter edit modes to have read only
 353  0
                         editModeMap = getEditModeWithEditableModesRemoved(editMode);
 354  
                     } else {
 355  
                         // no other user has a lock with this descriptor... check if this user needs a lock
 356  0
                         if (isLockRequiredByUser(document, editMode, user)) {
 357  0
                             document.addPessimisticLock(createNewPessimisticLock(document, editMode, user));
 358  
                         }
 359  0
                         editModeMap.putAll(editMode);
 360  
                     }
 361  
                 }
 362  0
             } else {
 363  
                 // user already has lock and no descriptors are being used... use the existing edit modes
 364  0
                 editModeMap.putAll(editMode);
 365  
             }
 366  
         }
 367  
 
 368  0
         return editModeMap;
 369  
     }
 370  
 
 371  
     /**
 372  
      * This method is used to check if the given parameters warrant a new lock to be created for the given user. This method
 373  
      * utilizes the {@link #isEntryEditMode(java.util.Map.Entry)} method.
 374  
      *
 375  
      * @param document -
 376  
      *            document to verify lock creation against
 377  
      * @param editMode -
 378  
      *            edit modes list to check for 'entry type' edit modes
 379  
      * @param user -
 380  
      *            user the lock will be 'owned' by
 381  
      * @return true if the given edit mode map has at least one 'entry type' edit mode... false otherwise
 382  
      */
 383  
     protected boolean isLockRequiredByUser(Document document, Map editMode, Person user) {
 384  
         // check for entry edit mode
 385  0
         for (Iterator iterator = editMode.entrySet().iterator(); iterator.hasNext();) {
 386  0
             Map.Entry entry = (Map.Entry) iterator.next();
 387  0
             if (isEntryEditMode(entry)) {
 388  0
                 return true;
 389  
             }
 390  0
         }
 391  0
         return false;
 392  
     }
 393  
 
 394  
    /**
 395  
      * This method is used to remove edit modes from the given map that allow the user to edit data on the document. This
 396  
      * method utilizes the {@link #isEntryEditMode(java.util.Map.Entry)} method to identify if an edit mode is defined as an
 397  
      * 'entry type' edit mode. It also uses the {@link #getEntryEditModeReplacementMode(java.util.Map.Entry)} method to replace
 398  
      * any 'entry type' edit modes it finds.
 399  
      *
 400  
      * @param currentEditMode -
 401  
      *            current set of edit modes the user has assigned to them
 402  
      * @return an adjusted edit mode map where 'entry type' edit modes have been removed or replaced using the
 403  
      *         {@link #getEntryEditModeReplacementMode()} method
 404  
      */
 405  
     protected Map getEditModeWithEditableModesRemoved(Map currentEditMode) {
 406  0
         Map editModeMap = new HashMap();
 407  0
         for (Iterator iterator = currentEditMode.entrySet().iterator(); iterator.hasNext();) {
 408  0
             Map.Entry entry = (Map.Entry) iterator.next();
 409  0
             if (isEntryEditMode(entry)) {
 410  0
                 editModeMap.putAll(getEntryEditModeReplacementMode(entry));
 411  
             } else {
 412  0
                 editModeMap.put(entry.getKey(), entry.getValue());
 413  
             }
 414  0
         }
 415  0
         return editModeMap;
 416  
     }
 417  
 
 418  
     /**
 419  
      * This method is used to check if the given {@link Map.Entry} is an 'entry type' edit mode and that the value is set to
 420  
      * signify that this user has that edit mode available to them
 421  
      *
 422  
      * @param entry -
 423  
      *            the {@link Map.Entry} object that contains an edit mode such as the ones returned but
 424  
      *            {@link #getEditMode(Document, Person)}
 425  
      * @return true if the given entry has a key signifying an 'entry type' edit mode and the value is equal to
 426  
      *         {@link #EDIT_MODE_DEFAULT_TRUE_VALUE}... false if not
 427  
      */
 428  
     protected boolean isEntryEditMode(Map.Entry entry) {
 429  
             // check for FULL_ENTRY edit mode set to default true value
 430  0
             if (AuthorizationConstants.EditMode.FULL_ENTRY.equals(entry.getKey())) {
 431  0
                     String fullEntryEditModeValue = (String)entry.getValue();           
 432  0
                     return ( StringUtils.equalsIgnoreCase(KNSConstants.KUALI_DEFAULT_TRUE_VALUE, fullEntryEditModeValue) );             
 433  
             }
 434  0
             return false;
 435  
     }
 436  
 
 437  
     /**
 438  
      * This method is used to return values needed to replace the given 'entry type' edit mode {@link Map.Entry} with one that will not allow the user to enter data on the document
 439  
      *
 440  
      * @param entry - the current 'entry type' edit mode to replace
 441  
      * @return a Map of edit modes that will be used to replace this edit mode (represented by the given entry parameter)
 442  
      */
 443  
     protected Map getEntryEditModeReplacementMode(Map.Entry entry) {
 444  0
         Map editMode = new HashMap();
 445  0
         editMode.put(AuthorizationConstants.EditMode.VIEW_ONLY, KNSConstants.KUALI_DEFAULT_TRUE_VALUE);
 446  0
         return editMode;
 447  
     }
 448  
 
 449  
     /**
 450  
      * This method creates a new {@link PessimisticLock} object using the given document and user. If the document's
 451  
      * useCustomLockDescriptors() method returns true then the new lock will also have a custom lock descriptor
 452  
      * value set to the return value of the document's getCustomLockDescriptor(Person) method.
 453  
      *
 454  
      * @param document -
 455  
      *            document to place the lock on
 456  
      * @param editMode -
 457  
      *            current edit modes for given user
 458  
      * @param user -
 459  
      *            user who will 'own' the new lock object
 460  
      * @return the newly created lock object
 461  
      */
 462  
     protected PessimisticLock createNewPessimisticLock(Document document, Map editMode, Person user) {
 463  0
         if (document.useCustomLockDescriptors()) {
 464  0
             return generateNewLock(document.getDocumentNumber(), document.getCustomLockDescriptor(user), user);
 465  
         } else {
 466  0
             return generateNewLock(document.getDocumentNumber(), user);
 467  
         }
 468  
     }
 469  
 
 470  
     public PersonService getPersonService() {
 471  0
         if ( personService == null ) {
 472  0
             personService = KimApiServiceLocator.getPersonService();
 473  
         }
 474  0
         return personService;
 475  
     }
 476  
 
 477  
         public DataDictionaryService getDataDictionaryService() {
 478  0
         if ( dataDictionaryService == null ) {
 479  0
                 dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService();
 480  
         }
 481  0
                 return dataDictionaryService;
 482  
         }
 483  
 
 484  
         public IdentityManagementService getIdentityManagementService() {
 485  0
         if ( identityManagementService == null ) {
 486  0
                 identityManagementService = KimApiServiceLocator.getIdentityManagementService();
 487  
         }
 488  0
                 return identityManagementService;
 489  
         }
 490  
 
 491  
 
 492  
 
 493  
 }
 494