Search in sources :

Example 1 with ParameterSchemaArray

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

the class SnapshotGenerator method findModelsFinder.

private void findModelsFinder(FinderSchema finderSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    ParameterSchemaArray parameters = finderSchema.getParameters();
    if (parameters != null) {
        for (ParameterSchema parameterSchema : parameters) {
            findModelsParameter(parameterSchema, foundTypes, typeOrder);
        }
    }
    MetadataSchema metadata = finderSchema.getMetadata();
    if (metadata != null) {
        String type = metadata.getType();
        recordType(type, foundTypes, typeOrder);
    }
}
Also used : MetadataSchema(com.linkedin.restli.restspec.MetadataSchema) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray)

Example 2 with ParameterSchemaArray

use of com.linkedin.restli.restspec.ParameterSchemaArray 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 ParameterSchemaArray

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

the class ResourceModelEncoder method createParameters.

@SuppressWarnings("deprecation")
private ParameterSchemaArray createParameters(final ResourceMethodDescriptor resourceMethodDescriptor) {
    ParameterSchemaArray parameterSchemaArray = new ParameterSchemaArray();
    for (Parameter<?> param : resourceMethodDescriptor.getParameters()) {
        // only custom parameters need to be specified in the IDL
        if (!param.isCustom()) {
            continue;
        }
        // assocKeys are listed outside the parameters list
        if (param.getParamType() == Parameter.ParamType.KEY || param.getParamType() == Parameter.ParamType.ASSOC_KEY_PARAM) {
            continue;
        }
        ParameterSchema paramSchema = new ParameterSchema();
        paramSchema.setName(param.getName());
        paramSchema.setType(buildDataSchemaType(param.getType(), param.getDataSchema()));
        final Object defaultValueData = param.getDefaultValueData();
        if (defaultValueData == null && param.isOptional()) {
            paramSchema.setOptional(true);
        } else if (defaultValueData != null) {
            paramSchema.setDefault(defaultValueData.toString());
        }
        String paramDoc = _docsProvider.getParamDoc(resourceMethodDescriptor.getMethod(), param.getName());
        if (paramDoc != null) {
            paramSchema.setDoc(paramDoc);
        }
        final DataMap customAnnotation = param.getCustomAnnotationData();
        if (param.getAnnotations().contains(Deprecated.class)) {
            customAnnotation.put(DEPRECATED_ANNOTATION_NAME, new DataMap());
        }
        if (!customAnnotation.isEmpty()) {
            paramSchema.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
        }
        parameterSchemaArray.add(paramSchema);
    }
    return parameterSchemaArray;
}
Also used : ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 4 with ParameterSchemaArray

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

the class ResourceModelEncoder method createFinders.

private FinderSchemaArray createFinders(final ResourceModel resourceModel) {
    FinderSchemaArray findersArray = new FinderSchemaArray();
    List<ResourceMethodDescriptor> resourceMethodDescriptors = resourceModel.getResourceMethodDescriptors();
    Collections.sort(resourceMethodDescriptors, RESOURCE_METHOD_COMPARATOR);
    for (ResourceMethodDescriptor resourceMethodDescriptor : resourceMethodDescriptors) {
        if (ResourceMethod.FINDER.equals(resourceMethodDescriptor.getType())) {
            FinderSchema finder = new FinderSchema();
            finder.setName(resourceMethodDescriptor.getFinderName());
            String doc = _docsProvider.getMethodDoc(resourceMethodDescriptor.getMethod());
            if (doc != null) {
                finder.setDoc(doc);
            }
            ParameterSchemaArray parameters = createParameters(resourceMethodDescriptor);
            if (parameters.size() > 0) {
                finder.setParameters(parameters);
            }
            StringArray assocKeys = createAssocKeyParameters(resourceMethodDescriptor);
            if (assocKeys.size() > 0) {
                finder.setAssocKeys(assocKeys);
            }
            if (resourceMethodDescriptor.getFinderMetadataType() != null) {
                Class<?> metadataType = resourceMethodDescriptor.getFinderMetadataType();
                MetadataSchema metadataSchema = new MetadataSchema();
                metadataSchema.setType(buildDataSchemaType(metadataType));
                finder.setMetadata(metadataSchema);
            }
            final DataMap customAnnotation = resourceMethodDescriptor.getCustomAnnotationData();
            String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(resourceMethodDescriptor.getMethod());
            if (deprecatedDoc != null) {
                customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
            }
            if (!customAnnotation.isEmpty()) {
                finder.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
            }
            if (resourceMethodDescriptor.isPagingSupported()) {
                finder.setPagingSupported(true);
            }
            findersArray.add(finder);
        }
    }
    return findersArray;
}
Also used : StringArray(com.linkedin.data.template.StringArray) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) MetadataSchema(com.linkedin.restli.restspec.MetadataSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) FinderSchema(com.linkedin.restli.restspec.FinderSchema) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 5 with ParameterSchemaArray

use of com.linkedin.restli.restspec.ParameterSchemaArray 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

ParameterSchemaArray (com.linkedin.restli.restspec.ParameterSchemaArray)10 DataMap (com.linkedin.data.DataMap)6 CustomAnnotationContentSchemaMap (com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap)6 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)4 StringArray (com.linkedin.data.template.StringArray)3 ActionSchema (com.linkedin.restli.restspec.ActionSchema)3 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)2 BatchFinderSchema (com.linkedin.restli.restspec.BatchFinderSchema)2 FinderSchema (com.linkedin.restli.restspec.FinderSchema)2 MaxBatchSizeSchema (com.linkedin.restli.restspec.MaxBatchSizeSchema)2 MetadataSchema (com.linkedin.restli.restspec.MetadataSchema)2 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)2 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)1 FinderSchemaArray (com.linkedin.restli.restspec.FinderSchemaArray)1 RestMethodSchemaArray (com.linkedin.restli.restspec.RestMethodSchemaArray)1 BatchFinder (com.linkedin.restli.server.annotations.BatchFinder)1 JClass (com.sun.codemodel.JClass)1 JInvocation (com.sun.codemodel.JInvocation)1 JVar (com.sun.codemodel.JVar)1