Search in sources :

Example 1 with Controller

use of eu.okaeri.platform.web.annotation.Controller in project okaeri-platform by OkaeriPoland.

the class RequestHandlerMeta method of.

public static RequestHandlerMeta of(Class<?> parentClass, Method method) {
    Annotation[] handlers = RequestHandlerHelper.findHandlers(method);
    if (handlers.length != 1) {
        throw new IllegalArgumentException("Cannot process method with " + handlers.length + " handler annotations: " + method);
    }
    Annotation handlerAnnotation = handlers[0];
    String path = RequestHandlerHelper.readHandlerPath(handlerAnnotation);
    HandlerType type = RequestHandlerHelper.readHandlerType(handlerAnnotation);
    String[] handlerPermittedRoles = RequestHandlerHelper.readPermittedRoles(handlerAnnotation);
    Parameter[] parameters = method.getParameters();
    int[] contextIndexes = RequestHandlerHelper.readContextIndexes(parameters);
    Map<Integer, PathParamMeta> pathParams = PathParamMeta.of(parameters);
    Controller controller = parentClass.getAnnotation(Controller.class);
    String pathPrefix = controller == null ? "" : controller.path();
    String[] defaultPermittedRoles = controller == null ? new String[] { "ANYONE" } : controller.defaultPermittedRoles();
    String[] permittedRoleNames = handlerPermittedRoles.length > 0 ? handlerPermittedRoles : defaultPermittedRoles;
    SimpleRouteRole[] permittedRoles = Arrays.stream(permittedRoleNames).map(SimpleRouteRole::new).toArray(SimpleRouteRole[]::new);
    return new RequestHandlerMeta(method, pathPrefix + path, type, permittedRoles, contextIndexes, pathParams);
}
Also used : HandlerType(io.javalin.http.HandlerType) Controller(eu.okaeri.platform.web.annotation.Controller) SimpleRouteRole(eu.okaeri.platform.web.meta.role.SimpleRouteRole) Annotation(java.lang.annotation.Annotation) Parameter(java.lang.reflect.Parameter)

Aggregations

Controller (eu.okaeri.platform.web.annotation.Controller)1 SimpleRouteRole (eu.okaeri.platform.web.meta.role.SimpleRouteRole)1 HandlerType (io.javalin.http.HandlerType)1 Annotation (java.lang.annotation.Annotation)1 Parameter (java.lang.reflect.Parameter)1