Annotation Interface PredicateRowLevelPolicy


@Target(METHOD) @Retention(RUNTIME) public @interface PredicateRowLevelPolicy
Annotation must be put on a method of an interface that defines a row level role (see RowLevelRole).

Method annotated with PredicateRowLevelPolicy must meet the following requirements:

The input parameter of the RowLevelPredicate must be an instance of the class defined in the entityClass() attribute of the annotation.

RowLevelBiPredicate must be used when you need to use Spring beans in the function. The second parameter of the bi-predicate is ApplicationContext.

Example:

 @RowLevelRole(name = "TestPredicateRoleLevelPolicyRole", code = "TestPredicateRoleLevelPolicyRole")
 public interface TestPredicateRoleLevelPolicyRole {

     @PredicateRowLevelPolicy(entityClass = TestOrder.class,
             actions = {RowLevelPolicyAction.CREATE, RowLevelPolicyAction.UPDATE})
     static RowLevelPredicate<TestOrder> numberStartsWithA() {
         return testOrder -> testOrder.getNumber().startsWith("a");
     }

     @PredicateRowLevelPolicy(entityClass = TestOrder.class,
             actions = {RowLevelPolicyAction.READ})
     default RowLevelBiPredicate<TestOrder, ApplicationContext> numberStartsWithB() {
         return (testOrder, applicationContext) -> {
            CurrentAuthentication currentAuthentication = applicationContext.getBean(CurrentAuthentication.class);
            User currentUser = (User) currentAuthentication.getUser();
            return currentUser.equals(testOrder.getManager());
         }
     }
 }
 
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Entity CRUD operations on which the predicate must be tested
    Entity class on which the predicate must be tested
  • Element Details

    • entityClass

      Class<?> entityClass
      Entity class on which the predicate must be tested
    • actions

      Entity CRUD operations on which the predicate must be tested