Search in sources :

Example 6 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)

Aggregations

DataMap (com.linkedin.data.DataMap)6 CustomAnnotationContentSchemaMap (com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap)6 ParameterSchemaArray (com.linkedin.restli.restspec.ParameterSchemaArray)4 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)2 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)2 StringArray (com.linkedin.data.template.StringArray)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 ActionSchema (com.linkedin.restli.restspec.ActionSchema)1 EntitySchema (com.linkedin.restli.restspec.EntitySchema)1 FinderSchema (com.linkedin.restli.restspec.FinderSchema)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