Search in sources :

Example 16 with ActionSchema

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

the class ResourceModelEncoder method createActions.

private ActionSchemaArray createActions(final ResourceModel resourceModel, final ResourceLevel resourceLevel) {
    List<ResourceMethodDescriptor> resourceMethodDescriptors = resourceModel.getResourceMethodDescriptors();
    Collections.sort(resourceMethodDescriptors, RESOURCE_METHOD_COMPARATOR);
    ActionSchemaArray actionsArray = new ActionSchemaArray();
    for (ResourceMethodDescriptor resourceMethodDescriptor : resourceMethodDescriptors) {
        if (ResourceMethod.ACTION.equals(resourceMethodDescriptor.getType())) {
            // do not apply entity-level actions at collection level or vice-versa
            if (resourceMethodDescriptor.getActionResourceLevel() != resourceLevel) {
                continue;
            }
            ActionSchema action = createActionSchema(resourceMethodDescriptor);
            actionsArray.add(action);
        }
    }
    return actionsArray;
}
Also used : ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 17 with ActionSchema

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

the class JavaRequestBuilderGenerator method methodMetadataMapInit.

private JVar methodMetadataMapInit(JDefinedClass facadeClass, ActionSchemaArray resourceActions, ActionSchemaArray entityActions, JBlock staticInit) {
    // CreateMetadata (only for actions right now)
    final JClass MetadataMapClass = getCodeModel().ref(HashMap.class).narrow(_stringClass, getCodeModel().ref(DynamicRecordMetadata.class));
    final JVar requestMetadataMap = staticInit.decl(MetadataMapClass, "requestMetadataMap").init(JExpr._new(MetadataMapClass));
    final JClass fieldDefListClass = getCodeModel().ref(ArrayList.class).narrow(getCodeModel().ref(FieldDef.class).narrow(getCodeModel().ref(Object.class).wildcard()));
    // 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);
    for (ActionSchema actionSchema : allActionSchema) {
        final String varName = actionSchema.getName() + "Params";
        final JVar currMethodParams = staticInit.decl(fieldDefListClass, varName).init(JExpr._new(fieldDefListClass));
        final ParameterSchemaArray parameters = actionSchema.getParameters();
        for (ParameterSchema parameterSchema : parameters == null ? new ParameterSchemaArray() : parameters) {
            final JInvocation fieldDefParam = createFieldDef(parameterSchema.getName(), parameterSchema.getType(), facadeClass);
            staticInit.add(currMethodParams.invoke("add").arg(fieldDefParam));
        }
        final String methodName = actionSchema.getName();
        final JInvocation newSchema = createMetadata(methodName, currMethodParams);
        staticInit.add(requestMetadataMap.invoke("put").arg(methodName).arg(newSchema));
    }
    return requestMetadataMap;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) JClass(com.sun.codemodel.JClass) ArrayList(java.util.ArrayList) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) JInvocation(com.sun.codemodel.JInvocation) ActionSchema(com.linkedin.restli.restspec.ActionSchema) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) JVar(com.sun.codemodel.JVar)

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