Search in sources :

Example 1 with EntitySchema

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

the class TestExamplesGenerator method findEntityAction.

private static ActionSchema findEntityAction(ResourceSchema resourceSchema, String actionName) {
    ActionSchema actionSchema;
    final CollectionSchema collectionSchema = resourceSchema.getCollection();
    if (collectionSchema != null) {
        final EntitySchema entity = collectionSchema.getEntity();
        if (entity != null) {
            actionSchema = findActionInEntity(entity, actionName);
            if (actionSchema != null) {
                return actionSchema;
            }
        }
    }
    final AssociationSchema associationSchema = resourceSchema.getAssociation();
    if (associationSchema != null) {
        final EntitySchema entity = associationSchema.getEntity();
        if (entity != null) {
            actionSchema = findActionInEntity(entity, actionName);
            if (actionSchema != null) {
                return actionSchema;
            }
        }
    }
    return null;
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) EntitySchema(com.linkedin.restli.restspec.EntitySchema) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 2 with EntitySchema

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

the class SnapshotGenerator method findModelsCollection.

private void findModelsCollection(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    CollectionSchema collection = resourceSchema.getCollection();
    if (collection != null) {
        IdentifierSchema identifier = collection.getIdentifier();
        findModelsIdentifier(identifier, foundTypes, typeOrder);
        if (collection.hasFinders()) {
            for (FinderSchema restMethodSchema : collection.getFinders()) {
                findModelsFinder(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (collection.hasMethods()) {
            for (RestMethodSchema restMethodSchema : collection.getMethods()) {
                findModelsMethod(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (collection.hasActions()) {
            for (ActionSchema actionSchema : collection.getActions()) {
                findModelsAction(actionSchema, foundTypes, typeOrder);
            }
        }
        if (collection.hasEntity()) {
            EntitySchema entity = collection.getEntity();
            findModelsEntity(entity, foundTypes, typeOrder);
        }
    }
}
Also used : CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) IdentifierSchema(com.linkedin.restli.restspec.IdentifierSchema) RestMethodSchema(com.linkedin.restli.restspec.RestMethodSchema) FinderSchema(com.linkedin.restli.restspec.FinderSchema) EntitySchema(com.linkedin.restli.restspec.EntitySchema) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 3 with EntitySchema

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

the class ResourceModelEncoder method appendEntityToSimpleSchema.

private void appendEntityToSimpleSchema(final SimpleSchema simpleSchema, final ResourceModel resourceModel) {
    EntitySchema entityNode = buildEntitySchema(resourceModel);
    simpleSchema.setEntity(entityNode);
}
Also used : EntitySchema(com.linkedin.restli.restspec.EntitySchema)

Example 4 with EntitySchema

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

the class ResourceModelEncoder method appendEntityToCollectionSchema.

private void appendEntityToCollectionSchema(final CollectionSchema collectionSchema, final ResourceModel resourceModel) {
    EntitySchema entityNode = buildEntitySchema(resourceModel);
    collectionSchema.setEntity(entityNode);
}
Also used : EntitySchema(com.linkedin.restli.restspec.EntitySchema)

Example 5 with EntitySchema

use of com.linkedin.restli.restspec.EntitySchema 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

EntitySchema (com.linkedin.restli.restspec.EntitySchema)7 ActionSchema (com.linkedin.restli.restspec.ActionSchema)4 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)3 AssociationSchema (com.linkedin.restli.restspec.AssociationSchema)2 CollectionSchema (com.linkedin.restli.restspec.CollectionSchema)2 FinderSchema (com.linkedin.restli.restspec.FinderSchema)2 DataMap (com.linkedin.data.DataMap)1 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)1 AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)1 CustomAnnotationContentSchemaMap (com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap)1 IdentifierSchema (com.linkedin.restli.restspec.IdentifierSchema)1 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)1 ResourceSchemaArray (com.linkedin.restli.restspec.ResourceSchemaArray)1 SimpleSchema (com.linkedin.restli.restspec.SimpleSchema)1