Search in sources :

Example 1 with KeyValueResource

use of com.linkedin.restli.server.resources.KeyValueResource in project rest.li by linkedin.

the class RestLiAnnotationReader method processResource.

/**
   * Processes an annotated resource class, producing a ResourceModel.
   *
   * @param resourceClass annotated resource class
   * @return {@link ResourceModel} for the provided resource class
   */
public static ResourceModel processResource(final Class<?> resourceClass, ResourceModel parentResourceModel) {
    final ResourceModel model;
    checkAnnotation(resourceClass);
    if ((resourceClass.isAnnotationPresent(RestLiCollection.class) || resourceClass.isAnnotationPresent(RestLiAssociation.class))) {
        // If any of these annotations, a subclass of KeyValueResource is expected
        if (!KeyValueResource.class.isAssignableFrom(resourceClass)) {
            throw new RestLiInternalException("Resource class '" + resourceClass.getName() + "' declares RestLi annotation but does not implement " + KeyValueResource.class.getName() + " interface.");
        }
        @SuppressWarnings("unchecked") Class<? extends KeyValueResource<?, ?>> clazz = (Class<? extends KeyValueResource<?, ?>>) resourceClass;
        model = processCollection(clazz, parentResourceModel);
    } else if (resourceClass.isAnnotationPresent(RestLiActions.class)) {
        model = processActions(resourceClass, parentResourceModel);
    } else if (resourceClass.isAnnotationPresent(RestLiSimpleResource.class)) {
        @SuppressWarnings("unchecked") Class<? extends SingleObjectResource<?>> clazz = (Class<? extends SingleObjectResource<?>>) resourceClass;
        model = processSingleObjectResource(clazz, parentResourceModel);
    } else {
        throw new ResourceConfigException("Class '" + resourceClass.getName() + "' must be annotated with a valid @RestLi... annotation");
    }
    if (parentResourceModel != null) {
        parentResourceModel.addSubResource(model.getName(), model);
    }
    if (!model.isActions()) {
        checkRestLiDataAnnotations(resourceClass, (RecordDataSchema) getDataSchema(model.getValueClass(), null));
    }
    addAlternativeKeys(model, resourceClass);
    DataMap annotationsMap = ResourceModelAnnotation.getAnnotationsMap(resourceClass.getAnnotations());
    addDeprecatedAnnotation(annotationsMap, resourceClass);
    model.setCustomAnnotation(annotationsMap);
    return model;
}
Also used : KeyValueResource(com.linkedin.restli.server.resources.KeyValueResource) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException) RestLiActions(com.linkedin.restli.server.annotations.RestLiActions) SingleObjectResource(com.linkedin.restli.server.resources.SingleObjectResource) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) DataMap(com.linkedin.data.DataMap)

Aggregations

DataMap (com.linkedin.data.DataMap)1 RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)1 ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)1 RestLiActions (com.linkedin.restli.server.annotations.RestLiActions)1 KeyValueResource (com.linkedin.restli.server.resources.KeyValueResource)1 SingleObjectResource (com.linkedin.restli.server.resources.SingleObjectResource)1