Search in sources :

Example 1 with CustomAnnotationContentSchemaMap

use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.

the class ResourceModelEncoder method buildResourceSchema.

/**
 * @param resourceModel {@link ResourceModel} to build the schema for
 * @return {@link ResourceSchema} for the provided resource model
 */
public ResourceSchema buildResourceSchema(final ResourceModel resourceModel) {
    ResourceSchema rootNode = new ResourceSchema();
    switch(resourceModel.getResourceType()) {
        case ACTIONS:
            appendActionsModel(rootNode, resourceModel);
            break;
        case SIMPLE:
            appendSimple(rootNode, resourceModel);
            break;
        default:
            appendCollection(rootNode, resourceModel);
            break;
    }
    final DataMap customAnnotation = resourceModel.getCustomAnnotationData();
    if (!customAnnotation.isEmpty()) {
        rootNode.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
    }
    return rootNode;
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 2 with CustomAnnotationContentSchemaMap

use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.

the class ResourceModelEncoder method createParameters.

@SuppressWarnings("deprecation")
private ParameterSchemaArray createParameters(final ResourceMethodDescriptor resourceMethodDescriptor) {
    ParameterSchemaArray parameterSchemaArray = new ParameterSchemaArray();
    for (Parameter<?> param : resourceMethodDescriptor.getParameters()) {
        // only custom parameters need to be specified in the IDL
        if (!param.isCustom()) {
            continue;
        }
        // assocKeys are listed outside the parameters list
        if (param.getParamType() == Parameter.ParamType.KEY || param.getParamType() == Parameter.ParamType.ASSOC_KEY_PARAM) {
            continue;
        }
        ParameterSchema paramSchema = new ParameterSchema();
        paramSchema.setName(param.getName());
        paramSchema.setType(buildDataSchemaType(param.getType(), param.getDataSchema()));
        final Object defaultValueData = param.getDefaultValueData();
        if (defaultValueData == null && param.isOptional()) {
            paramSchema.setOptional(true);
        } else if (defaultValueData != null) {
            paramSchema.setDefault(defaultValueData.toString());
        }
        String paramDoc = _docsProvider.getParamDoc(resourceMethodDescriptor.getMethod(), param.getName());
        if (paramDoc != null) {
            paramSchema.setDoc(paramDoc);
        }
        final DataMap customAnnotation = param.getCustomAnnotationData();
        if (param.getAnnotations().contains(Deprecated.class)) {
            customAnnotation.put(DEPRECATED_ANNOTATION_NAME, new DataMap());
        }
        if (!customAnnotation.isEmpty()) {
            paramSchema.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
        }
        parameterSchemaArray.add(paramSchema);
    }
    return parameterSchemaArray;
}
Also used : ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 3 with CustomAnnotationContentSchemaMap

use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.

the class ResourceModelEncoder method createFinders.

private FinderSchemaArray createFinders(final ResourceModel resourceModel) {
    FinderSchemaArray findersArray = new FinderSchemaArray();
    List<ResourceMethodDescriptor> resourceMethodDescriptors = resourceModel.getResourceMethodDescriptors();
    Collections.sort(resourceMethodDescriptors, RESOURCE_METHOD_COMPARATOR);
    for (ResourceMethodDescriptor resourceMethodDescriptor : resourceMethodDescriptors) {
        if (ResourceMethod.FINDER.equals(resourceMethodDescriptor.getType())) {
            FinderSchema finder = new FinderSchema();
            finder.setName(resourceMethodDescriptor.getFinderName());
            String doc = _docsProvider.getMethodDoc(resourceMethodDescriptor.getMethod());
            if (doc != null) {
                finder.setDoc(doc);
            }
            ParameterSchemaArray parameters = createParameters(resourceMethodDescriptor);
            if (parameters.size() > 0) {
                finder.setParameters(parameters);
            }
            StringArray assocKeys = createAssocKeyParameters(resourceMethodDescriptor);
            if (assocKeys.size() > 0) {
                finder.setAssocKeys(assocKeys);
            }
            if (resourceMethodDescriptor.getFinderMetadataType() != null) {
                Class<?> metadataType = resourceMethodDescriptor.getFinderMetadataType();
                MetadataSchema metadataSchema = new MetadataSchema();
                metadataSchema.setType(buildDataSchemaType(metadataType));
                finder.setMetadata(metadataSchema);
            }
            final DataMap customAnnotation = resourceMethodDescriptor.getCustomAnnotationData();
            String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(resourceMethodDescriptor.getMethod());
            if (deprecatedDoc != null) {
                customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
            }
            if (!customAnnotation.isEmpty()) {
                finder.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
            }
            if (resourceMethodDescriptor.isPagingSupported()) {
                finder.setPagingSupported(true);
            }
            findersArray.add(finder);
        }
    }
    return findersArray;
}
Also used : StringArray(com.linkedin.data.template.StringArray) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) MetadataSchema(com.linkedin.restli.restspec.MetadataSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) FinderSchema(com.linkedin.restli.restspec.FinderSchema) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 4 with CustomAnnotationContentSchemaMap

use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.

the class ResourceModelEncoder method buildEntitySchema.

private EntitySchema buildEntitySchema(ResourceModel resourceModel) {
    EntitySchema entityNode = new EntitySchema();
    entityNode.setPath(buildPathForEntity(resourceModel));
    if (resourceModel.getResourceLevel() == ResourceLevel.COLLECTION) {
        ActionSchemaArray actions = createActions(resourceModel, ResourceLevel.ENTITY);
        if (actions.size() > 0) {
            entityNode.setActions(actions);
        }
    }
    // subresources
    ResourceSchemaArray subresources = new ResourceSchemaArray();
    for (ResourceModel subResourceModel : resourceModel.getSubResources()) {
        ResourceSchema subresource = new ResourceSchema();
        switch(subResourceModel.getResourceType()) {
            case COLLECTION:
            case ASSOCIATION:
                appendCollection(subresource, subResourceModel);
                break;
            case SIMPLE:
                appendSimple(subresource, subResourceModel);
                break;
            default:
                break;
        }
        final DataMap customAnnotation = subResourceModel.getCustomAnnotationData();
        if (!customAnnotation.isEmpty()) {
            subresource.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
        }
        subresources.add(subresource);
    }
    if (subresources.size() > 0) {
        Collections.sort(subresources, new Comparator<ResourceSchema>() {

            @Override
            public int compare(ResourceSchema resourceSchema, ResourceSchema resourceSchema2) {
                return resourceSchema.getName().compareTo(resourceSchema2.getName());
            }
        });
        entityNode.setSubresources(subresources);
    }
    return entityNode;
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ResourceSchemaArray(com.linkedin.restli.restspec.ResourceSchemaArray) EntitySchema(com.linkedin.restli.restspec.EntitySchema) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 5 with CustomAnnotationContentSchemaMap

use of com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap in project rest.li by linkedin.

the class ResourceModelEncoder method createRestMethods.

private RestMethodSchemaArray createRestMethods(final ResourceModel resourceModel) {
    RestMethodSchemaArray restMethods = new RestMethodSchemaArray();
    ResourceMethod[] crudMethods = { ResourceMethod.CREATE, ResourceMethod.GET, ResourceMethod.UPDATE, ResourceMethod.PARTIAL_UPDATE, ResourceMethod.DELETE, ResourceMethod.BATCH_CREATE, ResourceMethod.BATCH_GET, ResourceMethod.BATCH_UPDATE, ResourceMethod.BATCH_PARTIAL_UPDATE, ResourceMethod.BATCH_DELETE, ResourceMethod.GET_ALL };
    for (ResourceMethod method : crudMethods) {
        ResourceMethodDescriptor descriptor = resourceModel.findMethod(method);
        if (descriptor == null) {
            continue;
        }
        RestMethodSchema restMethod = new RestMethodSchema();
        restMethod.setMethod(method.toString());
        String doc = _docsProvider.getMethodDoc(descriptor.getMethod());
        if (doc != null) {
            restMethod.setDoc(doc);
        }
        ParameterSchemaArray parameters = createParameters(descriptor);
        if (parameters.size() > 0) {
            restMethod.setParameters(parameters);
        }
        final DataMap customAnnotation = descriptor.getCustomAnnotationData();
        String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(descriptor.getMethod());
        if (deprecatedDoc != null) {
            customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
        }
        if (!customAnnotation.isEmpty()) {
            restMethod.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
        }
        if (method == ResourceMethod.GET_ALL) {
            if (descriptor.getCollectionCustomMetadataType() != null) {
                restMethod.setMetadata(createMetadataSchema(descriptor));
            }
            if (descriptor.isPagingSupported()) {
                restMethod.setPagingSupported(true);
            }
        }
        MaxBatchSizeSchema maxBatchSize = descriptor.getMaxBatchSize();
        if (maxBatchSize != null) {
            restMethod.setMaxBatchSize(maxBatchSize);
        }
        appendServiceErrors(restMethod, descriptor.getServiceErrors());
        appendSuccessStatuses(restMethod, descriptor.getSuccessStatuses());
        restMethods.add(restMethod);
    }
    return restMethods;
}
Also used : RestMethodSchemaArray(com.linkedin.restli.restspec.RestMethodSchemaArray) MaxBatchSizeSchema(com.linkedin.restli.restspec.MaxBatchSizeSchema) RestMethodSchema(com.linkedin.restli.restspec.RestMethodSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) ResourceMethod(com.linkedin.restli.common.ResourceMethod) DataMap(com.linkedin.data.DataMap)

Aggregations

DataMap (com.linkedin.data.DataMap)8 CustomAnnotationContentSchemaMap (com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap)8 ParameterSchemaArray (com.linkedin.restli.restspec.ParameterSchemaArray)6 StringArray (com.linkedin.data.template.StringArray)3 BatchFinderSchema (com.linkedin.restli.restspec.BatchFinderSchema)2 FinderSchema (com.linkedin.restli.restspec.FinderSchema)2 MaxBatchSizeSchema (com.linkedin.restli.restspec.MaxBatchSizeSchema)2 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)2 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 ActionSchema (com.linkedin.restli.restspec.ActionSchema)1 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)1 EntitySchema (com.linkedin.restli.restspec.EntitySchema)1 FinderSchemaArray (com.linkedin.restli.restspec.FinderSchemaArray)1 MetadataSchema (com.linkedin.restli.restspec.MetadataSchema)1 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)1 ResourceSchemaArray (com.linkedin.restli.restspec.ResourceSchemaArray)1 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)1 RestMethodSchemaArray (com.linkedin.restli.restspec.RestMethodSchemaArray)1 BatchFinder (com.linkedin.restli.server.annotations.BatchFinder)1