Search in sources :

Example 1 with Optional

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

the class RestLiAnnotationReader method buildActionParam.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Parameter buildActionParam(final Method method, final AnnotationSet annotations, final Class<?> paramType) {
    ActionParam actionParam = annotations.get(ActionParam.class);
    Optional optional = annotations.get(Optional.class);
    String paramName = actionParam.value();
    Class<? extends TyperefInfo> typerefInfoClass = actionParam.typeref();
    try {
        Parameter param = new Parameter(paramName, paramType, getDataSchema(paramType, getSchemaFromTyperefInfo(typerefInfoClass)), optional != null, getDefaultValueData(optional), Parameter.ParamType.POST, true, annotations);
        return param;
    } catch (TemplateRuntimeException e) {
        throw new ResourceConfigException("DataSchema for parameter '" + paramName + "' of type " + paramType.getSimpleName() + " on " + buildMethodMessage(method) + "cannot be found; type is invalid or requires typeref", e);
    } catch (Exception e) {
        throw new ResourceConfigException("Typeref for parameter '" + paramName + "' on " + buildMethodMessage(method) + " cannot be instantiated, " + e.getMessage(), e);
    }
}
Also used : ActionParam(com.linkedin.restli.server.annotations.ActionParam) Optional(com.linkedin.restli.server.annotations.Optional) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException)

Example 2 with Optional

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

the class RestLiAnnotationReader method buildAssocKeyParam.

private static Parameter<?> buildAssocKeyParam(final ResourceModel model, final Method method, final AnnotationSet annotations, final Class<?> paramType, final Class<?> paramAnnotationType) {
    Parameter.ParamType parameter = null;
    String assocKeyParamValue = null;
    Class<? extends TyperefInfo> typerefInfoClass = null;
    if (paramAnnotationType.equals(AssocKey.class)) {
        parameter = Parameter.ParamType.KEY;
        assocKeyParamValue = annotations.get(AssocKey.class).value();
        typerefInfoClass = annotations.get(AssocKey.class).typeref();
    } else if (paramAnnotationType.equals(AssocKeyParam.class)) {
        parameter = Parameter.ParamType.ASSOC_KEY_PARAM;
        assocKeyParamValue = annotations.get(AssocKeyParam.class).value();
        typerefInfoClass = annotations.get(AssocKeyParam.class).typeref();
    } else {
        throw new ResourceConfigException("Param Annotation type must be 'AssocKeysParam' or the deprecated 'AssocKey' for AssocKey");
    }
    Optional optional = annotations.get(Optional.class);
    if (!checkAssocKey(model.getKeys(), assocKeyParamValue)) {
        throw new ResourceConfigException("Non-existing assocKey '" + assocKeyParamValue + "' on " + buildMethodMessage(method));
    }
    try {
        @SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter(assocKeyParamValue, paramType, getDataSchema(paramType, getSchemaFromTyperefInfo(typerefInfoClass)), optional != null, getDefaultValueData(optional), parameter, true, annotations);
        return param;
    } catch (TemplateRuntimeException e) {
        throw new ResourceConfigException("DataSchema for assocKey '" + assocKeyParamValue + "' of type " + paramType.getSimpleName() + " on " + buildMethodMessage(method) + "cannot be found; type is invalid or requires typeref", e);
    } catch (Exception e) {
        throw new ResourceConfigException("Typeref for assocKey '" + assocKeyParamValue + "' on " + buildMethodMessage(method) + " cannot be instantiated, " + e.getMessage(), e);
    }
}
Also used : Optional(com.linkedin.restli.server.annotations.Optional) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) AssocKeyParam(com.linkedin.restli.server.annotations.AssocKeyParam) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException)

Example 3 with Optional

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

the class RestLiAnnotationReader method buildPagingContextParam.

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 @" + 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(Context.class)) {
        Context contextParam = annotations.get(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) ParSeqContext(com.linkedin.restli.server.annotations.ParSeqContext) Context(com.linkedin.restli.server.annotations.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 4 with Optional

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

the class RestLiAnnotationReader method buildQueryParam.

private static Parameter<?> buildQueryParam(final Method method, final AnnotationSet annotations, final Class<?> paramType) {
    QueryParam queryParam = annotations.get(QueryParam.class);
    Optional optional = annotations.get(Optional.class);
    String paramName = queryParam.value();
    if (INVALID_CHAR_PATTERN.matcher(paramName).find()) {
        throw new ResourceConfigException("Unsupported character in the parameter name :" + paramName);
    }
    Class<? extends TyperefInfo> typerefInfoClass = queryParam.typeref();
    try {
        @SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter(queryParam.value(), paramType, getDataSchema(paramType, getSchemaFromTyperefInfo(typerefInfoClass)), optional != null, getDefaultValueData(optional), Parameter.ParamType.QUERY, true, annotations);
        return param;
    } catch (TemplateRuntimeException e) {
        throw new ResourceConfigException("DataSchema for parameter '" + paramName + "' of type " + paramType.getSimpleName() + " on " + buildMethodMessage(method) + "cannot be found; type is invalid or requires typeref", e);
    } catch (Exception e) {
        throw new ResourceConfigException("Typeref for parameter '" + paramName + "' on " + buildMethodMessage(method) + " cannot be instantiated, " + e.getMessage(), e);
    }
}
Also used : Optional(com.linkedin.restli.server.annotations.Optional) QueryParam(com.linkedin.restli.server.annotations.QueryParam) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException)

Example 5 with Optional

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

the class RestLiAnnotationReader method buildHeaderParam.

private static Parameter<?> buildHeaderParam(final AnnotationSet annotations, final Class<?> paramType) {
    if (!paramType.equals(String.class)) {
        throw new ResourceConfigException("Incorrect data type for param: @" + HeaderParam.class.getSimpleName() + " parameter annotation must be of type String");
    }
    Optional optional = annotations.get(Optional.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter("", paramType, null, optional != null, "", Parameter.ParamType.HEADER, false, annotations);
    return param;
}
Also used : HeaderParam(com.linkedin.restli.server.annotations.HeaderParam) Optional(com.linkedin.restli.server.annotations.Optional) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException)

Aggregations

ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)7 Optional (com.linkedin.restli.server.annotations.Optional)7 TemplateRuntimeException (com.linkedin.data.template.TemplateRuntimeException)3 RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)3 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 PathKeysImpl (com.linkedin.restli.internal.server.PathKeysImpl)1 PagingContext (com.linkedin.restli.server.PagingContext)1 PathKeys (com.linkedin.restli.server.PathKeys)1 ResourceContext (com.linkedin.restli.server.ResourceContext)1 ActionParam (com.linkedin.restli.server.annotations.ActionParam)1 AssocKeyParam (com.linkedin.restli.server.annotations.AssocKeyParam)1 Context (com.linkedin.restli.server.annotations.Context)1 HeaderParam (com.linkedin.restli.server.annotations.HeaderParam)1 PagingContextParam (com.linkedin.restli.server.annotations.PagingContextParam)1 ParSeqContext (com.linkedin.restli.server.annotations.ParSeqContext)1 PathKeysParam (com.linkedin.restli.server.annotations.PathKeysParam)1 QueryParam (com.linkedin.restli.server.annotations.QueryParam)1