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);
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations