@Test public void testTrueUserAndOperationExpression() throws Exception { @Entity @Include class Book { @Id private long id; @ReadPermission(expression = "True User Check AND In Memory Check") private String title; } EntityDictionary dictionary = new EntityDictionary(checkMappings); dictionary.bindEntity(Book.class); RequestScope scope = mock(RequestScope.class); assertFalse(CanPaginateVisitor.canPaginate(Book.class, dictionary, scope)); }
public static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope) { CanPaginateVisitor visitor = new CanPaginateVisitor(dictionary, scope); Class<? extends Annotation> annotationClass = ReadPermission.class; ParseTree classPermissions = dictionary.getPermissionsForClass(resourceClass, annotationClass); PaginationStatus canPaginateClass = PaginationStatus.CAN_PAGINATE; if (classPermissions != null) { canPaginateClass = visitor.visit(classPermissions); } List<String> fields = dictionary.getAllFields(resourceClass); String resourceName = dictionary.getJsonAliasFor(resourceClass); Set<String> requestedFields = scope.getSparseFields().getOrDefault(resourceName, Collections.EMPTY_SET); boolean canPaginate = true; for (String field : fields) { if (! requestedFields.isEmpty() && ! requestedFields.contains(field)) { continue; } PaginationStatus canPaginateField = canPaginateClass; ParseTree fieldPermissions = dictionary.getPermissionsForField(resourceClass, field, annotationClass); if (fieldPermissions != null) { canPaginateField = visitor.visit(fieldPermissions); } if (canPaginateField == PaginationStatus.USER_CHECK_TRUE) { return true; } if (canPaginateField == PaginationStatus.CANNOT_PAGINATE) { canPaginate = false; } } return canPaginate; }
CanPaginateVisitor extends ExpressionBaseVisitor<CanPaginateVisitor.PaginationStatus> implements CheckInstantiator { public static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope) { CanPaginateVisitor visitor = new CanPaginateVisitor(dictionary, scope); Class<? extends Annotation> annotationClass = ReadPermission.class; ParseTree classPermissions = dictionary.getPermissionsForClass(resourceClass, annotationClass); PaginationStatus canPaginateClass = PaginationStatus.CAN_PAGINATE; if (classPermissions != null) { canPaginateClass = visitor.visit(classPermissions); } List<String> fields = dictionary.getAllFields(resourceClass); String resourceName = dictionary.getJsonAliasFor(resourceClass); Set<String> requestedFields = scope.getSparseFields().getOrDefault(resourceName, Collections.EMPTY_SET); boolean canPaginate = true; for (String field : fields) { if (! requestedFields.isEmpty() && ! requestedFields.contains(field)) { continue; } PaginationStatus canPaginateField = canPaginateClass; ParseTree fieldPermissions = dictionary.getPermissionsForField(resourceClass, field, annotationClass); if (fieldPermissions != null) { canPaginateField = visitor.visit(fieldPermissions); } if (canPaginateField == PaginationStatus.USER_CHECK_TRUE) { return true; } if (canPaginateField == PaginationStatus.CANNOT_PAGINATE) { canPaginate = false; } } return canPaginate; } }
CanPaginateVisitor extends ExpressionBaseVisitor<CanPaginateVisitor.PaginationStatus> implements CheckInstantiator { public static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope) { CanPaginateVisitor visitor = new CanPaginateVisitor(dictionary, scope); Class<? extends Annotation> annotationClass = ReadPermission.class; ParseTree classPermissions = dictionary.getPermissionsForClass(resourceClass, annotationClass); PaginationStatus canPaginateClass = PaginationStatus.CAN_PAGINATE; if (classPermissions != null) { canPaginateClass = visitor.visit(classPermissions); } List<String> fields = dictionary.getAllFields(resourceClass); String resourceName = dictionary.getJsonAliasFor(resourceClass); Set<String> requestedFields = scope.getSparseFields().getOrDefault(resourceName, Collections.EMPTY_SET); boolean canPaginate = true; for (String field : fields) { if (! requestedFields.isEmpty() && ! requestedFields.contains(field)) { continue; } PaginationStatus canPaginateField = canPaginateClass; ParseTree fieldPermissions = dictionary.getPermissionsForField(resourceClass, field, annotationClass); if (fieldPermissions != null) { canPaginateField = visitor.visit(fieldPermissions); } if (canPaginateField == PaginationStatus.USER_CHECK_TRUE) { return true; } if (canPaginateField == PaginationStatus.CANNOT_PAGINATE) { canPaginate = false; } } return canPaginate; } CanPaginateVisitor(EntityDictionary dictionary, RequestScope scope); }
CanPaginateVisitor extends ExpressionBaseVisitor<CanPaginateVisitor.PaginationStatus> implements CheckInstantiator { public static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope) { CanPaginateVisitor visitor = new CanPaginateVisitor(dictionary, scope); Class<? extends Annotation> annotationClass = ReadPermission.class; ParseTree classPermissions = dictionary.getPermissionsForClass(resourceClass, annotationClass); PaginationStatus canPaginateClass = PaginationStatus.CAN_PAGINATE; if (classPermissions != null) { canPaginateClass = visitor.visit(classPermissions); } List<String> fields = dictionary.getAllFields(resourceClass); String resourceName = dictionary.getJsonAliasFor(resourceClass); Set<String> requestedFields = scope.getSparseFields().getOrDefault(resourceName, Collections.EMPTY_SET); boolean canPaginate = true; for (String field : fields) { if (! requestedFields.isEmpty() && ! requestedFields.contains(field)) { continue; } PaginationStatus canPaginateField = canPaginateClass; ParseTree fieldPermissions = dictionary.getPermissionsForField(resourceClass, field, annotationClass); if (fieldPermissions != null) { canPaginateField = visitor.visit(fieldPermissions); } if (canPaginateField == PaginationStatus.USER_CHECK_TRUE) { return true; } if (canPaginateField == PaginationStatus.CANNOT_PAGINATE) { canPaginate = false; } } return canPaginate; } CanPaginateVisitor(EntityDictionary dictionary, RequestScope scope); @Override PaginationStatus visitNOT(ExpressionParser.NOTContext ctx); @Override PaginationStatus visitOR(ExpressionParser.ORContext ctx); @Override PaginationStatus visitAND(ExpressionParser.ANDContext ctx); @Override PaginationStatus visitPAREN(ExpressionParser.PARENContext ctx); @Override PaginationStatus visitPermissionClass(ExpressionParser.PermissionClassContext ctx); static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope); }
CanPaginateVisitor extends ExpressionBaseVisitor<CanPaginateVisitor.PaginationStatus> implements CheckInstantiator { public static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope) { CanPaginateVisitor visitor = new CanPaginateVisitor(dictionary, scope); Class<? extends Annotation> annotationClass = ReadPermission.class; ParseTree classPermissions = dictionary.getPermissionsForClass(resourceClass, annotationClass); PaginationStatus canPaginateClass = PaginationStatus.CAN_PAGINATE; if (classPermissions != null) { canPaginateClass = visitor.visit(classPermissions); } List<String> fields = dictionary.getAllFields(resourceClass); String resourceName = dictionary.getJsonAliasFor(resourceClass); Set<String> requestedFields = scope.getSparseFields().getOrDefault(resourceName, Collections.EMPTY_SET); boolean canPaginate = true; for (String field : fields) { if (! requestedFields.isEmpty() && ! requestedFields.contains(field)) { continue; } PaginationStatus canPaginateField = canPaginateClass; ParseTree fieldPermissions = dictionary.getPermissionsForField(resourceClass, field, annotationClass); if (fieldPermissions != null) { canPaginateField = visitor.visit(fieldPermissions); } if (canPaginateField == PaginationStatus.USER_CHECK_TRUE) { return true; } if (canPaginateField == PaginationStatus.CANNOT_PAGINATE) { canPaginate = false; } } return canPaginate; } CanPaginateVisitor(EntityDictionary dictionary, RequestScope scope); @Override PaginationStatus visitNOT(ExpressionParser.NOTContext ctx); @Override PaginationStatus visitOR(ExpressionParser.ORContext ctx); @Override PaginationStatus visitAND(ExpressionParser.ANDContext ctx); @Override PaginationStatus visitPAREN(ExpressionParser.PARENContext ctx); @Override PaginationStatus visitPermissionClass(ExpressionParser.PermissionClassContext ctx); static boolean canPaginate(Class<?> resourceClass, EntityDictionary dictionary, RequestScope scope);  }