Search in sources :

Example 1 with PagingContextParam

use of com.linkedin.restli.server.annotations.PagingContextParam in project rest.li by linkedin.

the class RestLiAnnotationReader method buildPagingContextParam.

@SuppressWarnings("deprecation")
private static Parameter<?> buildPagingContextParam(final AnnotationSet annotations, final Class<?> paramType, final Class<?> paramAnnotationType) {
    if (!paramType.equals(PagingContext.class)) {
        throw new ResourceConfigException("Incorrect data type for param: @" + PagingContextParam.class.getSimpleName() + " or @" + com.linkedin.restli.server.annotations.Context.class.getSimpleName() + " parameter annotation must be of type " + PagingContext.class.getName());
    }
    PagingContext defaultContext = null;
    Parameter.ParamType parameter = null;
    if (paramAnnotationType.equals(PagingContextParam.class)) {
        PagingContextParam pagingContextParam = annotations.get(PagingContextParam.class);
        defaultContext = new PagingContext(pagingContextParam.defaultStart(), pagingContextParam.defaultCount(), false, false);
        parameter = Parameter.ParamType.PAGING_CONTEXT_PARAM;
    } else if (paramAnnotationType.equals(com.linkedin.restli.server.annotations.Context.class)) {
        com.linkedin.restli.server.annotations.Context contextParam = annotations.get(com.linkedin.restli.server.annotations.Context.class);
        defaultContext = new PagingContext(contextParam.defaultStart(), contextParam.defaultCount(), false, false);
        parameter = Parameter.ParamType.CONTEXT;
    } else {
        throw new ResourceConfigException("Param Annotation type must be 'PagingContextParam' or the deprecated 'Context' for PagingContext");
    }
    Optional optional = annotations.get(Optional.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter("", paramType, null, optional != null, defaultContext, parameter, false, annotations);
    return param;
}
Also used : PagingContext(com.linkedin.restli.server.PagingContext) ResourceContext(com.linkedin.restli.server.ResourceContext) Context(com.linkedin.parseq.Context) PagingContextParam(com.linkedin.restli.server.annotations.PagingContextParam) Optional(com.linkedin.restli.server.annotations.Optional) PagingContext(com.linkedin.restli.server.PagingContext) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException)

Example 2 with PagingContextParam

use of com.linkedin.restli.server.annotations.PagingContextParam in project rest.li by linkedin.

the class RestLiAnnotationReader method getParameters.

@SuppressWarnings("deprecation")
private static List<Parameter<?>> getParameters(final ResourceModel model, final Method method, final ResourceMethod methodType) {
    Set<String> paramNames = new HashSet<>();
    List<Parameter<?>> queryParameters = new ArrayList<>();
    Annotation[][] paramsAnnos = method.getParameterAnnotations();
    // Iterate over the method parameters.
    for (int idx = 0; idx < paramsAnnos.length; idx++) {
        AnnotationSet paramAnnotations = new AnnotationSet(paramsAnnos[idx]);
        Class<?> paramType = method.getParameterTypes()[idx];
        Parameter<?> param = getPositionalParameter(model, methodType, idx, paramAnnotations);
        // if no positional definition, look for custom annotated parameters
        if (param == null) {
            if (paramAnnotations.contains(QueryParam.class)) {
                param = buildQueryParam(method, paramAnnotations, paramType);
            } else if (paramAnnotations.contains(ActionParam.class)) {
                param = buildActionParam(method, paramAnnotations, paramType);
            } else if (paramAnnotations.contains(com.linkedin.restli.server.annotations.AssocKey.class)) {
                param = buildAssocKeyParam(model, method, paramAnnotations, paramType, com.linkedin.restli.server.annotations.AssocKey.class);
            } else if (paramAnnotations.contains(AssocKeyParam.class)) {
                param = buildAssocKeyParam(model, method, paramAnnotations, paramType, AssocKeyParam.class);
            } else if (paramAnnotations.contains(com.linkedin.restli.server.annotations.Context.class)) {
                param = buildPagingContextParam(paramAnnotations, paramType, com.linkedin.restli.server.annotations.Context.class);
            } else if (paramAnnotations.contains(PagingContextParam.class)) {
                param = buildPagingContextParam(paramAnnotations, paramType, PagingContextParam.class);
            } else if (paramAnnotations.contains(CallbackParam.class)) {
                param = buildCallbackParam(method, methodType, idx, paramType, paramAnnotations);
            } else if (paramAnnotations.contains(ParSeqContextParam.class)) {
                param = buildParSeqContextParam(method, methodType, idx, paramType, paramAnnotations, ParSeqContextParam.class);
            } else if (paramAnnotations.contains(com.linkedin.restli.server.annotations.ParSeqContext.class)) {
                param = buildParSeqContextParam(method, methodType, idx, paramType, paramAnnotations, com.linkedin.restli.server.annotations.ParSeqContext.class);
            } else if (paramAnnotations.contains(com.linkedin.restli.server.annotations.Projection.class)) {
                param = buildProjectionParam(paramAnnotations, paramType, Parameter.ParamType.PROJECTION);
            } else if (paramAnnotations.contains(ProjectionParam.class)) {
                param = buildProjectionParam(paramAnnotations, paramType, Parameter.ParamType.PROJECTION_PARAM);
            } else if (paramAnnotations.contains(MetadataProjectionParam.class)) {
                param = buildProjectionParam(paramAnnotations, paramType, Parameter.ParamType.METADATA_PROJECTION_PARAM);
            } else if (paramAnnotations.contains(PagingProjectionParam.class)) {
                param = buildProjectionParam(paramAnnotations, paramType, Parameter.ParamType.PAGING_PROJECTION_PARAM);
            } else if (paramAnnotations.contains(com.linkedin.restli.server.annotations.Keys.class)) {
                param = buildPathKeysParam(paramAnnotations, paramType, com.linkedin.restli.server.annotations.Keys.class);
            } else if (paramAnnotations.contains(PathKeysParam.class)) {
                param = buildPathKeysParam(paramAnnotations, paramType, PathKeysParam.class);
            } else if (paramAnnotations.contains(PathKeyParam.class)) {
                param = buildPathKeyParam(model, paramAnnotations, paramType, PathKeyParam.class);
            } else if (paramAnnotations.contains(HeaderParam.class)) {
                param = buildHeaderParam(paramAnnotations, paramType);
            } else if (paramAnnotations.contains(ResourceContextParam.class)) {
                param = buildResourceContextParam(paramAnnotations, paramType);
            } else if (paramAnnotations.contains(ValidatorParam.class)) {
                param = buildValidatorParam(paramAnnotations, paramType);
            } else if (paramAnnotations.contains(RestLiAttachmentsParam.class)) {
                param = buildRestLiAttachmentsParam(paramAnnotations, paramType);
            } else if (paramAnnotations.contains(UnstructuredDataWriterParam.class)) {
                param = buildUnstructuredDataWriterParam(paramAnnotations, paramType);
            } else if (paramAnnotations.contains(UnstructuredDataReactiveReaderParam.class)) {
                param = buildUnstructuredDataReactiveReader(paramAnnotations, paramType);
            } else {
                throw new ResourceConfigException(buildMethodMessage(method) + " must annotate each parameter with @QueryParam, @ActionParam, @AssocKeyParam, @PagingContextParam, " + "@ProjectionParam, @MetadataProjectionParam, @PagingProjectionParam, @PathKeysParam, @PathKeyParam, " + "@HeaderParam, @CallbackParam, @ResourceContext, @ParSeqContextParam, @ValidatorParam, " + "@RestLiAttachmentsParam, @UnstructuredDataWriterParam, @UnstructuredDataReactiveReaderParam, " + "or @ValidateParam");
            }
        }
        if (param != null) {
            validateParameter(method, methodType, paramNames, paramAnnotations, param, paramType);
            queryParameters.add(param);
        }
    }
    return queryParameters;
}
Also used : PagingContextParam(com.linkedin.restli.server.annotations.PagingContextParam) ArrayList(java.util.ArrayList) PathKeyParam(com.linkedin.restli.server.annotations.PathKeyParam) RestLiAttachmentsParam(com.linkedin.restli.server.annotations.RestLiAttachmentsParam) MetadataProjectionParam(com.linkedin.restli.server.annotations.MetadataProjectionParam) HashSet(java.util.HashSet) PagingContext(com.linkedin.restli.server.PagingContext) ResourceContext(com.linkedin.restli.server.ResourceContext) Context(com.linkedin.parseq.Context) ActionParam(com.linkedin.restli.server.annotations.ActionParam) PathKeysParam(com.linkedin.restli.server.annotations.PathKeysParam) PathKeys(com.linkedin.restli.server.PathKeys) AlternativeKeys(com.linkedin.restli.server.annotations.AlternativeKeys) ParSeqContextParam(com.linkedin.restli.server.annotations.ParSeqContextParam) AssocKeyParam(com.linkedin.restli.server.annotations.AssocKeyParam) UnstructuredDataReactiveReaderParam(com.linkedin.restli.server.annotations.UnstructuredDataReactiveReaderParam) ResourceContextParam(com.linkedin.restli.server.annotations.ResourceContextParam) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException)

Aggregations

Context (com.linkedin.parseq.Context)2 PagingContext (com.linkedin.restli.server.PagingContext)2 ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)2 ResourceContext (com.linkedin.restli.server.ResourceContext)2 PagingContextParam (com.linkedin.restli.server.annotations.PagingContextParam)2 PathKeys (com.linkedin.restli.server.PathKeys)1 ActionParam (com.linkedin.restli.server.annotations.ActionParam)1 AlternativeKeys (com.linkedin.restli.server.annotations.AlternativeKeys)1 AssocKeyParam (com.linkedin.restli.server.annotations.AssocKeyParam)1 MetadataProjectionParam (com.linkedin.restli.server.annotations.MetadataProjectionParam)1 Optional (com.linkedin.restli.server.annotations.Optional)1 ParSeqContextParam (com.linkedin.restli.server.annotations.ParSeqContextParam)1 PathKeyParam (com.linkedin.restli.server.annotations.PathKeyParam)1 PathKeysParam (com.linkedin.restli.server.annotations.PathKeysParam)1 ResourceContextParam (com.linkedin.restli.server.annotations.ResourceContextParam)1 RestLiAttachmentsParam (com.linkedin.restli.server.annotations.RestLiAttachmentsParam)1 UnstructuredDataReactiveReaderParam (com.linkedin.restli.server.annotations.UnstructuredDataReactiveReaderParam)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1