Search in sources :

Example 1 with ActionSchema

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

the class ResourceSchemaToResourceSpecTranslator method toDynamicRecordMetadata.

private ActionCollectionMetadata toDynamicRecordMetadata(ActionSchemaArray actions, ActionSchemaArray entityActions) {
    Map<String, DynamicRecordMetadata> response = new HashMap<>();
    Map<String, DynamicRecordMetadata> request = new HashMap<>();
    ActionSchemaArray[] actionGroups = new ActionSchemaArray[] { actions, entityActions };
    for (ActionSchemaArray actionGroup : actionGroups) {
        if (actionGroup != null) {
            for (ActionSchema action : actionGroup) {
                ActionMetadata metadata = toActionMetadata(action);
                request.put(metadata._name, metadata._request);
                response.put(metadata._name, metadata._response);
            }
        }
    }
    return new ActionCollectionMetadata(request, response);
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) HashMap(java.util.HashMap) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 2 with ActionSchema

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

the class TestResourceSchemaToResourceSpecTranslator method compareActions.

private void compareActions(ResourceSpec actual, ResourceSpec expected, ActionSchemaArray actions) {
    for (ActionSchema action : actions) {
        ParameterSchemaArray parameters = action.getParameters();
        DynamicRecordMetadata actualRequest = actual.getRequestMetadata(action.getName());
        DynamicRecordMetadata expectedRequest = expected.getRequestMetadata(action.getName());
        if (expectedRequest != null) {
            Assert.assertNotNull(actualRequest);
            Assert.assertEquals(actualRequest.getRecordDataSchema(), expectedRequest.getRecordDataSchema());
            if (parameters != null) {
                for (ParameterSchema parameter : parameters) {
                    compareFieldDef(actualRequest.getFieldDef(parameter.getName()), expectedRequest.getFieldDef(parameter.getName()));
                }
            }
        } else {
            Assert.assertNull(actualRequest);
        }
        compareParameters(actual.getActionResponseMetadata(action.getName()), expected.getActionResponseMetadata(action.getName()));
    }
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 3 with ActionSchema

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

the class JavaRequestBuilderGenerator method responseMetadataMapInit.

private // lets work on this first...
JVar responseMetadataMapInit(// lets work on this first...
JDefinedClass facadeClass, // lets work on this first...
ActionSchemaArray resourceActions, // lets work on this first...
ActionSchemaArray entityActions, // lets work on this first...
JBlock staticInit) {
    final JClass MetadataMapClass = getCodeModel().ref(HashMap.class).narrow(_stringClass, getCodeModel().ref(DynamicRecordMetadata.class));
    final JVar responseMetadataMap = staticInit.decl(MetadataMapClass, "responseMetadataMap").init(JExpr._new(MetadataMapClass));
    // get all actions into a single ActionSchemaArray
    final int resourceActionsSize = resourceActions == null ? 0 : resourceActions.size();
    final int entityActionsSize = entityActions == null ? 0 : entityActions.size();
    final ActionSchemaArray allActionSchema = new ActionSchemaArray(resourceActionsSize + entityActionsSize);
    allActionSchema.addAll(resourceActions == null ? new ActionSchemaArray() : resourceActions);
    allActionSchema.addAll(entityActions == null ? new ActionSchemaArray() : entityActions);
    final String returnName = "value";
    for (ActionSchema actionSchema : allActionSchema) {
        final String methodName = actionSchema.getName();
        final JInvocation returnFieldDefs;
        if (actionSchema.hasReturns()) {
            final JInvocation returnFieldDef = createFieldDef(returnName, actionSchema.getReturns(), facadeClass);
            returnFieldDefs = getCodeModel().ref(Collections.class).staticInvoke("singletonList").arg(returnFieldDef);
        } else {
            returnFieldDefs = getCodeModel().ref(Collections.class).staticInvoke("<FieldDef<?>>emptyList");
        }
        final JInvocation returnMetadata = createMetadata(methodName, returnFieldDefs);
        staticInit.add(responseMetadataMap.invoke("put").arg(methodName).arg(returnMetadata));
    }
    return responseMetadataMap;
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) JClass(com.sun.codemodel.JClass) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) JInvocation(com.sun.codemodel.JInvocation) Collections(java.util.Collections) ActionSchema(com.linkedin.restli.restspec.ActionSchema) JVar(com.sun.codemodel.JVar)

Example 4 with ActionSchema

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

the class RequestBuilderSpecGenerator method generateActions.

private List<RootBuilderMethodSpec> generateActions(RootBuilderSpec rootBuilderSpec, ActionSchemaArray actions, String keyClass, String resourceName, List<String> pathKeys, Map<String, String> pathKeyTypes) {
    List<RootBuilderMethodSpec> actionSpecList = new ArrayList<>();
    if (actions != null) {
        for (ActionSchema action : actions) {
            RootBuilderMethodSpec actionSpec = generateActionMethod(rootBuilderSpec, keyClass, action, resourceName, pathKeys, pathKeyTypes);
            actionSpecList.add(actionSpec);
        }
    }
    return actionSpecList;
}
Also used : RootBuilderMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderMethodSpec) ArrayList(java.util.ArrayList) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 5 with ActionSchema

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

the class SnapshotGenerator method findModelsActionSet.

private void findModelsActionSet(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    ActionsSetSchema actionsSet = resourceSchema.getActionsSet();
    if (actionsSet != null) {
        findErrorDetailTypeModels(actionsSet, foundTypes, typeOrder);
        if (actionsSet.hasActions()) {
            for (ActionSchema actionSchema : actionsSet.getActions()) {
                findModelsAction(actionSchema, foundTypes, typeOrder);
                findErrorDetailTypeModels(actionSchema, foundTypes, typeOrder);
            }
        }
    }
}
Also used : ActionSchema(com.linkedin.restli.restspec.ActionSchema) ActionsSetSchema(com.linkedin.restli.restspec.ActionsSetSchema)

Aggregations

ActionSchema (com.linkedin.restli.restspec.ActionSchema)17 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)6 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)5 BatchFinderSchema (com.linkedin.restli.restspec.BatchFinderSchema)5 FinderSchema (com.linkedin.restli.restspec.FinderSchema)5 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)5 AssociationSchema (com.linkedin.restli.restspec.AssociationSchema)4 CollectionSchema (com.linkedin.restli.restspec.CollectionSchema)4 EntitySchema (com.linkedin.restli.restspec.EntitySchema)4 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)3 ParameterSchemaArray (com.linkedin.restli.restspec.ParameterSchemaArray)3 ArrayList (java.util.ArrayList)3 DataMap (com.linkedin.data.DataMap)2 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 ActionsSetSchema (com.linkedin.restli.restspec.ActionsSetSchema)2 AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)2 IdentifierSchema (com.linkedin.restli.restspec.IdentifierSchema)2 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)2 SimpleSchema (com.linkedin.restli.restspec.SimpleSchema)2 ResourceLevel (com.linkedin.restli.server.ResourceLevel)2