use of com.linkedin.restli.server.annotations.ActionParam 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.ActionParam in project rest.li by linkedin.
the class RestLiAnnotationReader method getParameters.
private static List<Parameter<?>> getParameters(final ResourceModel model, final Method method, final ResourceMethod methodType) {
Set<String> paramNames = new HashSet<String>();
List<Parameter<?>> queryParameters = new ArrayList<Parameter<?>>();
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(AssocKey.class)) {
param = buildAssocKeyParam(model, method, paramAnnotations, paramType, AssocKey.class);
} else if (paramAnnotations.contains(AssocKeyParam.class)) {
param = buildAssocKeyParam(model, method, paramAnnotations, paramType, AssocKeyParam.class);
} else if (paramAnnotations.contains(Context.class)) {
param = buildPagingContextParam(paramAnnotations, paramType, 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(ParSeqContext.class)) {
param = buildParSeqContextParam(method, methodType, idx, paramType, paramAnnotations, ParSeqContext.class);
} else if (paramAnnotations.contains(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(Keys.class)) {
param = buildPathKeysParam(paramAnnotations, paramType, 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 {
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, or @ValidateParam");
}
}
if (param != null) {
validateParameter(method, methodType, paramNames, paramAnnotations, param, paramType);
queryParameters.add(param);
}
}
return queryParameters;
}
Aggregations