public class RequiredDataAdvice
extends java.lang.Object
implements org.springframework.aop.MethodBeforeAdvice
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.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.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
Modifier and Type | Field and Description |
---|---|
protected static java.util.List<java.lang.String> |
fieldAccess |
Constructor and Description |
---|
RequiredDataAdvice() |
Modifier and Type | Method and Description |
---|---|
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 |
isHandlerMarkedAsDisabled(java.lang.Class<? extends RequiredDataHandler> handlerType,
java.lang.reflect.Field field)
Checks if the given field is annotated with a @DisableHandler annotation to specify
that the given handlerType should be disabled
|
protected static boolean |
isOpenmrsObjectCollection(java.lang.Object arg)
|
static <H extends RequiredDataHandler> |
recursivelyHandle(java.lang.Class<H> handlerType,
OpenmrsObject openmrsObject,
java.lang.String reason)
Convenience method for
#recursivelyHandle(Class, OpenmrsObject, User, Date, String) . |
static <H extends RequiredDataHandler> |
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 . |
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 collectionopenmrsObject
protected static boolean isOpenmrsObjectCollection(java.lang.Object arg)
arg
- the actual object being passed inprotected static boolean isHandlerMarkedAsDisabled(java.lang.Class<? extends RequiredDataHandler> handlerType, java.lang.reflect.Field field)
handlerType
- field
- Copyright © 2018 OpenMRS Inc.. All Rights Reserved.