|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openmrs.aop.RequiredDataAdvice
public class RequiredDataAdvice
This class provides the AOP around each save, (un)void, and (un)retire method in the service
layer so that the required data (like creator, dateChanged, dateVoided, etc) can be set
automatically and the developer doesn't have to worry about doing it explicitly in the service
impl method.
See /metadata/api/spring/applicationContext-service.xml for the mapping of this bean.
For an Openmrs Service to use this AOP advice class and take advantage of its automatic variable
setting, it must have "<ref local="requiredDataInterceptor"/>" in its "preInterceptors".
By default, this should take care of any child collections on the object being acted on. Any
child collection of OpenmrsObject
s will get "handled" (i.e., void data set up, save data
set up, or retire data set up, etc) by the same handler type that the parent object was handled
with.
To add a new action to happen for a save* method, create a new class that extends
RequiredDataHandler
. Add any unique code that needs to be done automatically
before the save. See ConceptNameSaveHandler
as an example. (The code should be
unique because all other SaveHandler
s will still be called in addition to
your new handler.) Be sure to add the Handler
annotation (like
"@Handler(supports=YourPojoThatHasUniqueSaveNeeds.class)") to your class so that it is picked up
by Spring automatically.
To add a new action for a void* or retire* method, extend the VoidHandler
/
RetireHandler
class and override the handle method. Do not call super, because that code
would then be run twice because both handlers are registered. Be sure to add the
Handler
annotation (like
"@Handler(supports=YourPojoThatHasUniqueSaveNeeds.class)") to your class so that it is picked up
by Spring automatically.
RequiredDataHandler
,
SaveHandler
,
VoidHandler
Field Summary | |
---|---|
protected static java.util.List<java.lang.String> |
fieldAccess
|
Constructor Summary | |
---|---|
RequiredDataAdvice()
|
Method Summary | ||
---|---|---|
void |
before(java.lang.reflect.Method method,
java.lang.Object[] args,
java.lang.Object target)
|
|
protected static java.util.Collection<OpenmrsObject> |
getChildCollection(OpenmrsObject openmrsObject,
java.lang.reflect.Field field)
This method gets a child attribute off of an OpenmrsObject. |
|
protected static boolean |
isOpenmrsObjectCollection(java.lang.Object arg)
Checks the given Class to see if it A) is a Collection /Set /
List , and B) contains OpenmrsObject s |
|
static
|
recursivelyHandle(java.lang.Class<H> handlerType,
OpenmrsObject openmrsObject,
java.lang.String reason)
Convenience method for #recursivelyHandle(Class, OpenmrsObject, User, Date, String) . |
|
static
|
recursivelyHandle(java.lang.Class<H> handlerType,
OpenmrsObject openmrsObject,
User currentUser,
java.util.Date currentDate,
java.lang.String other,
java.util.List<OpenmrsObject> alreadyHandled)
This loops over all declared collections on the given object and all declared collections on parent objects to use the given handlerType . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.util.List<java.lang.String> fieldAccess
Constructor Detail |
---|
public RequiredDataAdvice()
Method Detail |
---|
public void before(java.lang.reflect.Method method, java.lang.Object[] args, java.lang.Object target) throws java.lang.Throwable
before
in interface org.springframework.aop.MethodBeforeAdvice
java.lang.Throwable
MethodBeforeAdvice.before(java.lang.reflect.Method,
java.lang.Object[], java.lang.Object)
public static <H extends RequiredDataHandler> void recursivelyHandle(java.lang.Class<H> handlerType, OpenmrsObject openmrsObject, java.lang.String reason)
#recursivelyHandle(Class, OpenmrsObject, User, Date, String)
.
Calls that method with the current user and the current Date.
H
- the type of Handler to get (should extend RequiredDataHandler
)handlerType
- the type of Handler to get (should extend RequiredDataHandler
)openmrsObject
- the object that is being acted uponreason
- an optional second argument that was passed to the service method (usually a
void/retire reason)#recursivelyHandle(Class, OpenmrsObject, User, Date, String)
public static <H extends RequiredDataHandler> void recursivelyHandle(java.lang.Class<H> handlerType, OpenmrsObject openmrsObject, User currentUser, java.util.Date currentDate, java.lang.String other, java.util.List<OpenmrsObject> alreadyHandled)
handlerType
.
H
- the type of Handler to get (should extend RequiredDataHandler
)handlerType
- the type of Handler to get (should extend RequiredDataHandler
)openmrsObject
- the object that is being acted uponcurrentUser
- the current user to set recursively on the objectcurrentDate
- the date to set recursively on the objectother
- an optional second argument that was passed to the service method (usually a
void/retire reason)alreadyHandled
- an optional list of objects that have already been handled and should
not be processed again. this is intended to prevent infinite recursion when
handling collection properties.HandlerUtil.getHandlersForType(Class, Class)
protected static java.util.Collection<OpenmrsObject> getChildCollection(OpenmrsObject openmrsObject, java.lang.reflect.Field field)
fieldAccess
list.
openmrsObject
- the object to get the collection off offield
- the name of the field that is the collection
openmrsObject
protected static boolean isOpenmrsObjectCollection(java.lang.Object arg)
Class
to see if it A) is a Collection
/Set
/
List
, and B) contains OpenmrsObject
s
arg
- the actual object being passed in
|
OpenMRS-1.7.x | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |