Search in sources :

Example 6 with ActionSchemaArray

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

the class ResourceSchemaToResourceSpecTranslator method collectionToResourceSpec.

@SuppressWarnings("rawtypes")
private ResourceSpec collectionToResourceSpec(ResourceSchema resourceSchema, CollectionSchema collection) {
    ActionSchemaArray actions = null, entityActions = null;
    StringArray supports = collection.getSupports();
    if (collection.hasActions()) {
        actions = collection.getActions();
    }
    if (collection.getEntity().hasActions()) {
        entityActions = collection.getEntity().getActions();
    }
    String schema = resourceSchema.getSchema();
    IdentifierSchema identifier = collection.getIdentifier();
    if (// in this case we have a "simple" collection resource
    identifier.getParams() == null) {
        DataSchema key = RestSpecCodec.textToSchema(identifier.getType(), _schemaResolver);
        return buildResourceSpec(supports, toTypeSpec(key), null, Collections.<String, Object>emptyMap(), schema, actions, entityActions);
    } else // we have a complex collection resource
    {
        DataSchema keyKeyType = RestSpecCodec.textToSchema(identifier.getType(), _schemaResolver);
        DataSchema keyParamsType = RestSpecCodec.textToSchema(identifier.getParams(), _schemaResolver);
        ComplexKeySpec<?, ?> complexKeyType = toComplexKey(keyKeyType, keyParamsType);
        return buildResourceSpec(supports, new TypeSpec<ComplexResourceKey>(ComplexResourceKey.class, null), complexKeyType, Collections.<String, Object>emptyMap(), schema, actions, entityActions);
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) StringArray(com.linkedin.data.template.StringArray) IdentifierSchema(com.linkedin.restli.restspec.IdentifierSchema) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray)

Example 7 with ActionSchemaArray

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

the class TestResourceSchemaToResourceSpecTranslator method compareResourceSpecs.

public void compareResourceSpecs(ResourceSpec actual, ResourceSpec expected, RichResourceSchema resourceSchema) {
    Assert.assertEquals(actual.getSupportedMethods(), expected.getSupportedMethods());
    compareTypes(actual.getKeyType(), expected.getKeyType());
    compareTypes(actual.getValueType(), expected.getValueType());
    compareComplexKey(actual.getComplexKeyType(), expected.getComplexKeyType());
    compareKeyParts(actual.getKeyParts(), expected.getKeyParts());
    ActionSchemaArray actions = resourceSchema.getActions();
    compareActions(actual, expected, actions);
    ActionSchemaArray entityActions = resourceSchema.getEntityActions();
    compareActions(actual, expected, entityActions);
    FinderSchemaArray finders = resourceSchema.getFinders();
    for (FinderSchema finder : finders) {
        compareParameters(actual.getRequestMetadata(finder.getName()), expected.getRequestMetadata(finder.getName()));
    }
}
Also used : FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) FinderSchema(com.linkedin.restli.restspec.FinderSchema)

Example 8 with ActionSchemaArray

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

the class ResourceModelEncoder method appendSimple.

private void appendSimple(ResourceSchema resourceSchema, ResourceModel resourceModel) {
    appendCommon(resourceModel, resourceSchema);
    SimpleSchema simpleSchema = new SimpleSchema();
    appendSupportsNodeToSimpleSchema(simpleSchema, resourceModel);
    appendMethodsToSimpleSchema(simpleSchema, resourceModel);
    ActionSchemaArray actions = createActions(resourceModel, ResourceLevel.ENTITY);
    if (actions.size() > 0) {
        simpleSchema.setActions(actions);
    }
    appendEntityToSimpleSchema(simpleSchema, resourceModel);
    resourceSchema.setSimple(simpleSchema);
}
Also used : SimpleSchema(com.linkedin.restli.restspec.SimpleSchema) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray)

Example 9 with ActionSchemaArray

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

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

the class ResourceModelEncoder method appendActionsModel.

private void appendActionsModel(final ResourceSchema resourceSchema, final ResourceModel resourceModel) {
    appendCommon(resourceModel, resourceSchema);
    ActionsSetSchema actionsNode = new ActionsSetSchema();
    ActionSchemaArray actions = createActions(resourceModel, ResourceLevel.COLLECTION);
    if (actions.size() > 0) {
        actionsNode.setActions(actions);
    }
    resourceSchema.setActionsSet(actionsNode);
}
Also used : ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ActionsSetSchema(com.linkedin.restli.restspec.ActionsSetSchema)

Aggregations

ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)15 StringArray (com.linkedin.data.template.StringArray)5 ActionSchema (com.linkedin.restli.restspec.ActionSchema)5 HashMap (java.util.HashMap)5 CollectionSchema (com.linkedin.restli.restspec.CollectionSchema)4 FinderSchemaArray (com.linkedin.restli.restspec.FinderSchemaArray)4 DataMap (com.linkedin.data.DataMap)3 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)3 ActionsSetSchema (com.linkedin.restli.restspec.ActionsSetSchema)3 AssociationSchema (com.linkedin.restli.restspec.AssociationSchema)3 ResourceSchemaArray (com.linkedin.restli.restspec.ResourceSchemaArray)3 SimpleSchema (com.linkedin.restli.restspec.SimpleSchema)3 JClass (com.sun.codemodel.JClass)3 JInvocation (com.sun.codemodel.JInvocation)3 JVar (com.sun.codemodel.JVar)3 ArrayList (java.util.ArrayList)3 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)2 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)2 ResourceMethod (com.linkedin.restli.common.ResourceMethod)2 CustomAnnotationContentSchemaMap (com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap)2