Search in sources :

Example 1 with AssociationSchema

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

the class TestExamplesGenerator method findFinder.

private static FinderSchema findFinder(ResourceSchema resourceSchema, String finderName) {
    final CollectionSchema collectionSchema = resourceSchema.getCollection();
    if (collectionSchema != null) {
        final FinderSchemaArray finders = collectionSchema.getFinders();
        if (finders != null) {
            for (FinderSchema finderSchema : finders) {
                if (finderSchema.getName().equals(finderName)) {
                    return finderSchema;
                }
            }
        }
    }
    final AssociationSchema associationSchema = resourceSchema.getAssociation();
    if (associationSchema != null) {
        final FinderSchemaArray finders = associationSchema.getFinders();
        if (finders != null) {
            for (FinderSchema finderSchema : finders) {
                if (finderSchema.getName().equals(finderName)) {
                    return finderSchema;
                }
            }
        }
    }
    return null;
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) FinderSchema(com.linkedin.restli.restspec.FinderSchema)

Example 2 with AssociationSchema

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

the class TestExamplesGenerator method findCollectionAction.

private static ActionSchema findCollectionAction(ResourceSchema resourceSchema, String actionName) {
    final CollectionSchema collectionSchema = resourceSchema.getCollection();
    if (collectionSchema != null) {
        final ActionSchemaArray actions = collectionSchema.getActions();
        if (actions != null) {
            for (ActionSchema actionSchema : actions) {
                if (actionSchema.getName().equals(actionName)) {
                    return actionSchema;
                }
            }
        }
    }
    final AssociationSchema associationSchema = resourceSchema.getAssociation();
    if (associationSchema != null) {
        final ActionSchemaArray actions = associationSchema.getActions();
        if (actions != null) {
            for (ActionSchema actionSchema : actions) {
                if (actionSchema.getName().equals(actionName)) {
                    return actionSchema;
                }
            }
        }
    }
    return null;
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 3 with AssociationSchema

use of com.linkedin.restli.restspec.AssociationSchema 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 4 with AssociationSchema

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

the class ResourceModelEncoder method appendCollection.

private void appendCollection(final ResourceSchema resourceSchema, final ResourceModel collectionModel) {
    appendCommon(collectionModel, resourceSchema);
    CollectionSchema collectionSchema = new CollectionSchema();
    //HACK: AssociationSchema and CollectionSchema share many common elements, but have no inheritance
    //relationship.  Here, we construct them both as facades on the same DataMap, which allows
    //us to pass strongly typed CollectionSchema objects around, even when we're dealing with
    //an association.
    AssociationSchema associationSchema = new AssociationSchema(collectionSchema.data());
    if (collectionModel.getKeys().size() == 1) {
        appendIdentifierNode(collectionSchema, collectionModel);
    } else {
        appendKeys(associationSchema, collectionModel);
    }
    appendAlternativeKeys(collectionSchema, collectionModel);
    appendSupportsNodeToCollectionSchema(collectionSchema, collectionModel);
    appendMethodsToCollectionSchema(collectionSchema, collectionModel);
    FinderSchemaArray finders = createFinders(collectionModel);
    if (finders.size() > 0) {
        collectionSchema.setFinders(finders);
    }
    ActionSchemaArray actions = createActions(collectionModel, ResourceLevel.COLLECTION);
    if (actions.size() > 0) {
        collectionSchema.setActions(actions);
    }
    appendEntityToCollectionSchema(collectionSchema, collectionModel);
    switch(collectionModel.getResourceType()) {
        case COLLECTION:
            resourceSchema.setCollection(collectionSchema);
            break;
        case ASSOCIATION:
            resourceSchema.setAssociation(associationSchema);
            break;
        default:
            throw new IllegalArgumentException("unsupported resource type");
    }
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray)

Example 5 with AssociationSchema

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

the class SnapshotGenerator method findModelsAssocation.

private void findModelsAssocation(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    AssociationSchema association = resourceSchema.getAssociation();
    if (association != null) {
        for (AssocKeySchema assocKeySchema : association.getAssocKeys()) {
            String type = assocKeySchema.getType();
            recordType(type, foundTypes, typeOrder);
        }
        if (association.hasFinders()) {
            for (FinderSchema restMethodSchema : association.getFinders()) {
                findModelsFinder(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (association.hasMethods()) {
            for (RestMethodSchema restMethodSchema : association.getMethods()) {
                findModelsMethod(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (association.hasActions()) {
            for (ActionSchema actionSchema : association.getActions()) {
                findModelsAction(actionSchema, foundTypes, typeOrder);
            }
        }
        if (association.hasEntity()) {
            EntitySchema entitySchema = association.getEntity();
            findModelsEntity(entitySchema, foundTypes, typeOrder);
        }
    }
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) RestMethodSchema(com.linkedin.restli.restspec.RestMethodSchema) FinderSchema(com.linkedin.restli.restspec.FinderSchema) EntitySchema(com.linkedin.restli.restspec.EntitySchema) ActionSchema(com.linkedin.restli.restspec.ActionSchema) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema)

Aggregations

AssociationSchema (com.linkedin.restli.restspec.AssociationSchema)9 CollectionSchema (com.linkedin.restli.restspec.CollectionSchema)8 ActionSchema (com.linkedin.restli.restspec.ActionSchema)4 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)3 FinderSchema (com.linkedin.restli.restspec.FinderSchema)3 FinderSchemaArray (com.linkedin.restli.restspec.FinderSchemaArray)3 SimpleSchema (com.linkedin.restli.restspec.SimpleSchema)3 StringArray (com.linkedin.data.template.StringArray)2 ActionsSetSchema (com.linkedin.restli.restspec.ActionsSetSchema)2 AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)2 EntitySchema (com.linkedin.restli.restspec.EntitySchema)2 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)2 RestMethodSchemaArray (com.linkedin.restli.restspec.RestMethodSchemaArray)2 DataList (com.linkedin.data.DataList)1 DataMap (com.linkedin.data.DataMap)1 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 DataSchema (com.linkedin.data.schema.DataSchema)1 DataSchemaTraverse (com.linkedin.data.schema.DataSchemaTraverse)1 MapDataSchema (com.linkedin.data.schema.MapDataSchema)1 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1