OpenMRS Custom Annotations

See also: Java Annotations article

Custom OpenMRS annotations available to core and modules:

@Authorize

This is used on API interface methods to restrict access to the current user (Context.getAuthenticatedUser()) if they don't have a certain privilege.

Parameters

value (default) - An array of Strings

A list of string privilege names to restrict to.
example: @Authorized(OpenmrsConstants.PRIV_VIEW_CONCEPTS) will allow the user to run the method only if they have the privilege
example: @Authorized({OpenmrsConstants.PRIV_VIEW_CONCEPTS, OpenmrsConstants.PRIV_VIEW_CONCEPTS}) will allow the user to run that method if they have either privilege

requireAll - boolean, defaults to false

If true, will require that the user have each privilege defined in the "value" attribute
example: @Authorized(value={OpenmrsConstants.PRIV_VIEW_CONCEPTS, OpenmrsConstants.PRIV_VIEW_CONCEPTS}, requireAll=true) will allow the user to run that method if they have both privilege

@Logging

All methods in the OpenMRS API will log to "info" with their parameter values. (errors go to log.error, and execution time to log.trace).

Use this annotation in order to prevent sensitive parameter values from being logged (UserService.saveUser(user, password)).

Parameters

ignoreAllArgumentValues - boolean, defaults to false

If true, will not print any parameter name or parameter values

ignoredArgumentIndexes - an array of integers

The argument value index to not print. (0-based array)
example: @Logging(ignoredArgumentIndexes={1}) will not print the value of the second argument.

@Handler

This annotation serves as a general mechanism for providing metadata about a class that serves as a 'Handler' for another class or classes.

Spring automatically finds all handlers for a given class and groups them. This way programmers can request them easily and act on them.

See API Save Handlers

Parameters

supports - An array of classes

example: @Handler( supports = { Order.class } ) - means this class can deal with "Order" objects

}