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);
}
}
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()));
}
}
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);
}
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");
}
}
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);
}
Aggregations