org.openmrs.api.handler
Class RetireSaveHandler

java.lang.Object
  extended by org.openmrs.api.handler.RetireSaveHandler
All Implemented Interfaces:
RequiredDataHandler<Retireable>, SaveHandler<Retireable>

@Handler(supports=Retireable.class)
public class RetireSaveHandler
extends java.lang.Object
implements SaveHandler<Retireable>

This handler makes sure the when a retired object is saved with the retired bit set to true, the other required values (like dateRetired and retiredBy) are filled in. It also makes sure the retired attributes are cleared out if the retired bit is set to false.

The RequiredDataAdvice class uses AOP around each method in every service to check to see if its a save* method. If it is a save* method, and the object being saved implements Retireable, this class is called to handle setting the Retireable.setRetiredBy(User), and Retireable.setDateRetired(Date) if not set already.

Note: The RequiredDataAdvice class will loop over child collections on this Retireable that are themselves a Retireable and retiredBy/dateRetired are set, but ONLY IF the retired bit was set on them as well. Using the associated retire* method in the service on the parent instance is preferred so that all child objects are indeed retired.

Since:
1.5
See Also:
RequiredDataAdvice, SaveHandler, RequiredDataAdvice

Constructor Summary
RetireSaveHandler()
           
 
Method Summary
 void handle(Retireable retireableObject, User currentUser, java.util.Date currentDate, java.lang.String notUsed)
          This method does not set "retired" to true, but rather only sets the retiredBy/dateRetired if they are null and retired==true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RetireSaveHandler

public RetireSaveHandler()
Method Detail

handle

public void handle(Retireable retireableObject,
                   User currentUser,
                   java.util.Date currentDate,
                   java.lang.String notUsed)
This method does not set "retired" to true, but rather only sets the retiredBy/dateRetired if they are null and retired==true.

If retired is set to false, the retired attributes are cleared nullified.

Specified by:
handle in interface RequiredDataHandler<Retireable>
Specified by:
handle in interface SaveHandler<Retireable>
Parameters:
retireableObject - an OpenmrsObject that needs to have some required data set
currentUser - the user who is saving this object
currentDate - the datetime this object is being saved
notUsed - (optional) would be the second argument in the save method, if exists
See Also:
RequiredDataHandler.handle(org.openmrs.OpenmrsObject, org.openmrs.User, java.util.Date, java.lang.String)
Expected behavior:
not set the retired bit, not set the retireReason, set retired by, not set retired by if non null, set dateRetired, not set dateRetired if non null, not set the dateRetired if retired is false, set retireReason to null if retired is true, set dateRetired to null if retired is true, set retiredBy to null if retired is true

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change