org.kuali.rice.krad.service.impl
Class PessimisticLockServiceImpl

java.lang.Object
  extended by org.kuali.rice.krad.service.impl.PessimisticLockServiceImpl
All Implemented Interfaces:
PessimisticLockService

@Transactional
public class PessimisticLockServiceImpl
extends Object
implements PessimisticLockService

This is a service implementation for pessimistic locking

Author:
Kuali Rice Team (rice.collab@kuali.org)

Constructor Summary
PessimisticLockServiceImpl()
           
 
Method Summary
protected  PessimisticLock createNewPessimisticLock(Document document, Map editMode, Person user)
          This method creates a new PessimisticLock object using the given document and user.
 void delete(String id)
          This method deletes the given lock object
 Map establishLocks(Document document, Map editMode, Person user)
          This implementation will check the given document, editMode map, and user object to verify Pessimistic Locking.
 void establishWorkflowPessimisticLocking(Document document)
          This method creates a new PessimisticLock when Workflow processing requires one
 PessimisticLock generateNewLock(String documentNumber)
          This method will generate a new PessimisticLock object with a 'document' lock descriptor
 PessimisticLock generateNewLock(String documentNumber, Person user)
          This method will generate a new PessimisticLock object with a 'document' lock descriptor
 PessimisticLock generateNewLock(String documentNumber, String lockDescriptor)
          This method will generate a new PessimisticLock object with a lock descriptor of the given parameter
 PessimisticLock generateNewLock(String documentNumber, String lockDescriptor, Person user)
          This method will generate a new PessimisticLock object with a lock descriptor of the given parameter
 BusinessObjectService getBusinessObjectService()
           
 DataDictionaryService getDataDictionaryService()
           
 Set getDocumentActions(Document document, Person user, Set<String> documentActions)
           
protected  Map getEditModeWithEditableModesRemoved(Map currentEditMode)
          This method is used to remove edit modes from the given map that allow the user to edit data on the document.
protected  Map getEntryEditModeReplacementMode(Map.Entry entry)
          This method is used to return values needed to replace the given 'entry type' edit mode Map.Entry with one that will not allow the user to enter data on the document
 PermissionService getPermissionService()
           
 PersonService getPersonService()
           
 List<PessimisticLock> getPessimisticLocksForDocument(String documentNumber)
          This method gets all locks associated with the given document number
protected  Person getWorkflowPessimisticLockOwnerUser()
          This method identifies the user that should be used to create and clear PessimisticLock objects required by Workflow.

The default is the Kuali system user defined by RiceConstants#SYSTEM_USER.
protected  boolean hasPreRouteEditAuthorization(Document document, Person user)
          This method checks to see that the given user has a lock on the document and return true if one is found.
protected  boolean isEntryEditMode(Map.Entry entry)
          This method is used to check if the given Map.Entry is an 'entry type' edit mode and that the value is set to signify that this user has that edit mode available to them
protected  boolean isLockRequiredByUser(Document document, Map editMode, Person user)
          This method is used to check if the given parameters warrant a new lock to be created for the given user.
 boolean isPessimisticLockAdminUser(Person user)
          This method is used to identify who is an admin user for PessimisticLock objects
 void releaseAllLocksForUser(List<PessimisticLock> locks, Person user)
          This method will release all locks in the given list that are owned by the given user
 void releaseAllLocksForUser(List<PessimisticLock> locks, Person user, String lockDescriptor)
          This method will release all locks in the given list that are owned by the given user that have a matching lock descriptor value
 void releaseWorkflowPessimisticLocking(Document document)
          This method releases locks created via the establishWorkflowPessimisticLocking(Document) method for the given document
 PessimisticLock save(PessimisticLock lock)
          This method saves the given lock object
 void setBusinessObjectService(BusinessObjectService businessObjectService)
           
protected  boolean usesPessimisticLocking(Document document)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PessimisticLockServiceImpl

public PessimisticLockServiceImpl()
Method Detail

delete

public void delete(String id)
Description copied from interface: PessimisticLockService
This method deletes the given lock object

Specified by:
delete in interface PessimisticLockService
Parameters:
id - - the id of the lock to delete
See Also:
PessimisticLockService.delete(java.lang.String)

generateNewLock

public PessimisticLock generateNewLock(String documentNumber)
Description copied from interface: PessimisticLockService
This method will generate a new PessimisticLock object with a 'document' lock descriptor

Specified by:
generateNewLock in interface PessimisticLockService
Parameters:
documentNumber - - the document number of the document associated with the new lock
Returns:
the newly generated document descriptor PessimisticLock
See Also:
PessimisticLockService.generateNewLock(String)

generateNewLock

public PessimisticLock generateNewLock(String documentNumber,
                                       String lockDescriptor)
Description copied from interface: PessimisticLockService
This method will generate a new PessimisticLock object with a lock descriptor of the given parameter

Specified by:
generateNewLock in interface PessimisticLockService
Parameters:
documentNumber - - the document number of the document associated with the new lock
lockDescriptor - - the lock descriptor the new PessimisticLock object should contain
Returns:
the newly generated PessimisticLock containing the given lockDescriptor
See Also:
PessimisticLockService.generateNewLock(java.lang.String)

generateNewLock

public PessimisticLock generateNewLock(String documentNumber,
                                       Person user)
Description copied from interface: PessimisticLockService
This method will generate a new PessimisticLock object with a 'document' lock descriptor

Specified by:
generateNewLock in interface PessimisticLockService
Parameters:
documentNumber - - the document number of the document associated with the new lock
user - - the user to set on the new lock being generated
Returns:
the newly generated document descriptor PessimisticLock
See Also:
PessimisticLockService.generateNewLock(java.lang.String, org.kuali.rice.kim.api.identity.Person)

generateNewLock

public PessimisticLock generateNewLock(String documentNumber,
                                       String lockDescriptor,
                                       Person user)
Description copied from interface: PessimisticLockService
This method will generate a new PessimisticLock object with a lock descriptor of the given parameter

Specified by:
generateNewLock in interface PessimisticLockService
Parameters:
documentNumber - - the document number of the document associated with the new lock
lockDescriptor - - the lock descriptor the new PessimisticLock object should contain
user - - the user to set on the new lock being generated
Returns:
the newly generated PessimisticLock containing the given lockDescriptor
See Also:
PessimisticLockService.generateNewLock(java.lang.String, java.lang.String, org.kuali.rice.kim.api.identity.Person)

getPessimisticLocksForDocument

public List<PessimisticLock> getPessimisticLocksForDocument(String documentNumber)
Description copied from interface: PessimisticLockService
This method gets all locks associated with the given document number

Specified by:
getPessimisticLocksForDocument in interface PessimisticLockService
Parameters:
documentNumber - - the document number of the document requiring locks
Returns:
an empty list if no locks are found or the list of PessimisticLock objects found for the given documentNumber
See Also:
PessimisticLockService.getPessimisticLocksForDocument(java.lang.String)

isPessimisticLockAdminUser

public boolean isPessimisticLockAdminUser(Person user)
Description copied from interface: PessimisticLockService
This method is used to identify who is an admin user for PessimisticLock objects

Specified by:
isPessimisticLockAdminUser in interface PessimisticLockService
Parameters:
user - - user to verify as admin
Returns:
true if the given use is an admin user or false if not
See Also:
PessimisticLockService.isPessimisticLockAdminUser(org.kuali.rice.kim.api.identity.Person)

releaseAllLocksForUser

public void releaseAllLocksForUser(List<PessimisticLock> locks,
                                   Person user)
Description copied from interface: PessimisticLockService
This method will release all locks in the given list that are owned by the given user

Specified by:
releaseAllLocksForUser in interface PessimisticLockService
Parameters:
locks - - locks to release if owned by given user
user - - user to check for lock ownership
See Also:
PessimisticLockService.releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.api.identity.Person)

releaseAllLocksForUser

public void releaseAllLocksForUser(List<PessimisticLock> locks,
                                   Person user,
                                   String lockDescriptor)
Description copied from interface: PessimisticLockService
This method will release all locks in the given list that are owned by the given user that have a matching lock descriptor value

Specified by:
releaseAllLocksForUser in interface PessimisticLockService
Parameters:
locks - - locks to release if owned by given user
user - - user to check for lock ownership
lockDescriptor - - lock descriptor value to match locks against
See Also:
PessimisticLockService.releaseAllLocksForUser(java.util.List, org.kuali.rice.kim.api.identity.Person, java.lang.String)

save

public PessimisticLock save(PessimisticLock lock)
Description copied from interface: PessimisticLockService
This method saves the given lock object

Specified by:
save in interface PessimisticLockService
See Also:
PessimisticLockService.save(org.kuali.rice.krad.document.authorization.PessimisticLock)

getBusinessObjectService

public BusinessObjectService getBusinessObjectService()

setBusinessObjectService

public void setBusinessObjectService(BusinessObjectService businessObjectService)

getDocumentActions

public Set getDocumentActions(Document document,
                              Person user,
                              Set<String> documentActions)
Specified by:
getDocumentActions in interface PessimisticLockService
Parameters:
document -
user -
Returns:
Set of actions are permitted the given user on the given document

hasPreRouteEditAuthorization

protected boolean hasPreRouteEditAuthorization(Document document,
                                               Person user)
This method checks to see that the given user has a lock on the document and return true if one is found.

Parameters:
document - - document to check
user - - current user
Returns:
true if the document is using Pessimistic Locking, the user has initiate authorization (see #hasInitiateAuthorization(Document, Person)), and the document has a lock owned by the given user. If the document is not using Pessimistic Locking the value returned will be that returned by #hasInitiateAuthorization(Document, Person).

usesPessimisticLocking

protected boolean usesPessimisticLocking(Document document)

establishWorkflowPessimisticLocking

public void establishWorkflowPessimisticLocking(Document document)
This method creates a new PessimisticLock when Workflow processing requires one

Specified by:
establishWorkflowPessimisticLocking in interface PessimisticLockService
Parameters:
document - - the document to create the lock against and add the lock to
See Also:
org.kuali.rice.krad.document.authorization.DocumentAuthorizer#establishWorkflowPessimisticLocking(org.kuali.rice.krad.document.Document)

releaseWorkflowPessimisticLocking

public void releaseWorkflowPessimisticLocking(Document document)
This method releases locks created via the establishWorkflowPessimisticLocking(Document) method for the given document

Specified by:
releaseWorkflowPessimisticLocking in interface PessimisticLockService
Parameters:
document - - document to release locks from
See Also:
org.kuali.rice.krad.document.authorization.DocumentAuthorizer#releaseWorkflowPessimisticLocking(org.kuali.rice.krad.document.Document)

getWorkflowPessimisticLockOwnerUser

protected Person getWorkflowPessimisticLockOwnerUser()
This method identifies the user that should be used to create and clear PessimisticLock objects required by Workflow.

The default is the Kuali system user defined by RiceConstants#SYSTEM_USER. This method can be overriden by implementing documents if another user is needed.

Returns:
a valid Person object

establishLocks

public Map establishLocks(Document document,
                          Map editMode,
                          Person user)
This implementation will check the given document, editMode map, and user object to verify Pessimistic Locking. If the given edit mode map contains an 'entry type' edit mode then the system will check the locks already in existence on the document. If a valid lock for the given user is found the system will return the given edit mode map. If a valid lock is found but is owned by another user the edit mode map returned will have any 'entry type' edit modes removed. If the given document has no locks and the edit mode map passed in has at least one 'entry type' mode then a new PessimisticLock object will be created and set on the document for the given user.

NOTE: This method is only called if the document uses pessimistic locking as described in the data dictionary file.

Specified by:
establishLocks in interface PessimisticLockService
Parameters:
document - - the document locks are to be established against or by
editMode - - the editMode returned by the method #getEditMode(Document, Person)
user - - the user locks are being established for
Returns:
New map generated by locking logic combined with passed in parameter editMode. Map contains keys AuthorizationConstants.EditMode value (String) which indicates what operations the user is currently allowed to take on that document. This may be a modified list of
See Also:
org.kuali.rice.krad.document.authorization.DocumentAuthorizer#establishLocks(org.kuali.rice.krad.document.Document, java.util.Map, org.kuali.rice.kim.api.identity.Person)

isLockRequiredByUser

protected boolean isLockRequiredByUser(Document document,
                                       Map editMode,
                                       Person user)
This method is used to check if the given parameters warrant a new lock to be created for the given user. This method utilizes the isEntryEditMode(java.util.Map.Entry) method.

Parameters:
document - - document to verify lock creation against
editMode - - edit modes list to check for 'entry type' edit modes
user - - user the lock will be 'owned' by
Returns:
true if the given edit mode map has at least one 'entry type' edit mode... false otherwise

getEditModeWithEditableModesRemoved

protected Map getEditModeWithEditableModesRemoved(Map currentEditMode)
This method is used to remove edit modes from the given map that allow the user to edit data on the document. This method utilizes the isEntryEditMode(java.util.Map.Entry) method to identify if an edit mode is defined as an 'entry type' edit mode. It also uses the getEntryEditModeReplacementMode(java.util.Map.Entry) method to replace any 'entry type' edit modes it finds.

Parameters:
currentEditMode - - current set of edit modes the user has assigned to them
Returns:
an adjusted edit mode map where 'entry type' edit modes have been removed or replaced using the #getEntryEditModeReplacementMode() method

isEntryEditMode

protected boolean isEntryEditMode(Map.Entry entry)
This method is used to check if the given Map.Entry is an 'entry type' edit mode and that the value is set to signify that this user has that edit mode available to them

Parameters:
entry - - the Map.Entry object that contains an edit mode such as the ones returned but #getEditMode(Document, Person)
Returns:
true if the given entry has a key signifying an 'entry type' edit mode and the value is equal to #EDIT_MODE_DEFAULT_TRUE_VALUE... false if not

getEntryEditModeReplacementMode

protected Map getEntryEditModeReplacementMode(Map.Entry entry)
This method is used to return values needed to replace the given 'entry type' edit mode Map.Entry with one that will not allow the user to enter data on the document

Parameters:
entry - - the current 'entry type' edit mode to replace
Returns:
a Map of edit modes that will be used to replace this edit mode (represented by the given entry parameter)

createNewPessimisticLock

protected PessimisticLock createNewPessimisticLock(Document document,
                                                   Map editMode,
                                                   Person user)
This method creates a new PessimisticLock object using the given document and user. If the document's useCustomLockDescriptors() method returns true then the new lock will also have a custom lock descriptor value set to the return value of the document's getCustomLockDescriptor(Person) method.

Parameters:
document - - document to place the lock on
editMode - - current edit modes for given user
user - - user who will 'own' the new lock object
Returns:
the newly created lock object

getPersonService

public PersonService getPersonService()

getDataDictionaryService

public DataDictionaryService getDataDictionaryService()

getPermissionService

public PermissionService getPermissionService()


Copyright © 2005-2011 The Kuali Foundation. All Rights Reserved.