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
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<OpenmrsObject>> |
recursivelyHandle(Class<H> handlerType,
OpenmrsObject openmrsObject,
String reason)
Convenience method for
recursivelyHandle(Class, OpenmrsObject, User, Date, String, List) . |
static <H extends RequiredDataHandler<OpenmrsObject>> |
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 . |
static <H extends RequiredDataHandler<OpenmrsObject>> |
recursivelyHandle(Class<H> handlerType,
OpenmrsObject openmrsObject,
User currentUser,
Date currentDate,
String other,
Set<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
Should not fail on update method with no arguments
public static <H extends RequiredDataHandler<OpenmrsObject>> void recursivelyHandle(Class<H> handlerType, OpenmrsObject openmrsObject, String reason)
recursivelyHandle(Class, OpenmrsObject, User, Date, String, List)
.
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, List)
public static <H extends RequiredDataHandler<OpenmrsObject>> 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)
public static <H extends RequiredDataHandler<OpenmrsObject>> void recursivelyHandle(Class<H> handlerType, OpenmrsObject openmrsObject, User currentUser, Date currentDate, String other, Set<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)
AllowDirectAccess
annotation.openmrsObject
- the object to get the collection off offield
- the name of the field that is the collectionopenmrsObject
Should get value of given child collection on given field
Should should be able to get annotated private fields
Should throw APIException if getter method not foundprotected static boolean isOpenmrsObjectCollection(Object arg)
arg
- the actual object being passed inprotected static boolean isHandlerMarkedAsDisabled(Class<? extends RequiredDataHandler> handlerType, Field field)
handlerType
- field
- Copyright © 2024 OpenMRS Inc.. All rights reserved.