public class RequiredDataAdvice extends 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 List<String> |
fieldAccess |
Constructor and Description |
---|
RequiredDataAdvice() |
Modifier and Type | Method and Description |
---|---|
void |
before(Method method,
Object[] args,
Object target) |
protected static Collection<OpenmrsObject> |
getChildCollection(OpenmrsObject openmrsObject,
Field field)
This method gets a child attribute off of an OpenmrsObject.
|
protected static boolean |
isHandlerMarkedAsDisabled(Class<? extends RequiredDataHandler> handlerType,
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(Object arg)
|
static <H extends RequiredDataHandler> |
recursivelyHandle(Class<H> handlerType,
OpenmrsObject openmrsObject,
String reason)
Convenience method for
#recursivelyHandle(Class, OpenmrsObject, User, Date, String) . |
static <H extends RequiredDataHandler> |
recursivelyHandle(Class<H> handlerType,
OpenmrsObject openmrsObject,
User currentUser,
Date currentDate,
String other,
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(Method method, Object[] args, Object target) throws Throwable
before
in interface org.springframework.aop.MethodBeforeAdvice
Throwable
MethodBeforeAdvice.before(java.lang.reflect.Method,
java.lang.Object[], java.lang.Object)
public static <H extends RequiredDataHandler> void recursivelyHandle(Class<H> handlerType, OpenmrsObject openmrsObject, 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(Class<H> handlerType, OpenmrsObject openmrsObject, User currentUser, Date currentDate, String other, 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 Collection<OpenmrsObject> getChildCollection(OpenmrsObject openmrsObject, 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(Object arg)
arg
- the actual object being passed inprotected static boolean isHandlerMarkedAsDisabled(Class<? extends RequiredDataHandler> handlerType, Field field)
handlerType
- field
- Copyright © 2018 OpenMRS LLC.. All Rights Reserved.