org.openmrs.api.handler
Class VoidSaveHandler

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

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

This handler makes sure the when a voided object is saved with the voided bit set to true, the other required values (like dateVoided and voidedBy) are filled in. It also makes sure the voided attributes are cleared out if the voided 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 Voidable, this class is called to handle setting the Voidable.setVoidedBy(User), and Voidable.setDateVoided(Date) if not set already.

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

Since:
1.5
See Also:
RequiredDataAdvice, SaveHandler, RequiredDataAdvice

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

Constructor Detail

VoidSaveHandler

public VoidSaveHandler()
Method Detail

handle

public void handle(Voidable voidableObject,
                   User currentUser,
                   java.util.Date currentDate,
                   java.lang.String notUsed)
This method does not set "voided" to true, but rather only sets the voidedBy/dateVoided if they are null and voided==true.

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

Specified by:
handle in interface RequiredDataHandler<Voidable>
Specified by:
handle in interface SaveHandler<Voidable>
Parameters:
voidableObject - 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 voided bit, not set the voidReason, set voided by, not set voided by if non null, set dateVoided, not set dateVoided if non null, not set the dateVoided if voided is false, set voidReason to null if voided is true, set dateVoided to null if voided is true, set voidedBy to null if voided is true

OpenMRS-1.7.x

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