Search in sources :

Example 1 with FinderSchema

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

the class ExampleRequestResponseGenerator method finder.

public ExampleRequestResponse finder(String name) {
    FinderSchema finderSchema = _resourceSchema.getFinder(name);
    if (finderSchema == null) {
        throw new IllegalArgumentException("No such finder for resource: " + name);
    }
    RecordDataSchema metadataSchema = null;
    if (finderSchema.hasMetadata()) {
        metadataSchema = (RecordDataSchema) RestSpecCodec.textToSchema(finderSchema.getMetadata().getType(), _schemaResolver);
    }
    return buildRequestResponse(buildFinderRequest(finderSchema), buildFinderResult(metadataSchema), buildResourceMethodDescriptorForFinder(name));
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) FinderSchema(com.linkedin.restli.restspec.FinderSchema)

Example 2 with FinderSchema

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

the class TestExamplesGenerator method findFinder.

private static FinderSchema findFinder(ResourceSchema resourceSchema, String finderName) {
    final CollectionSchema collectionSchema = resourceSchema.getCollection();
    if (collectionSchema != null) {
        final FinderSchemaArray finders = collectionSchema.getFinders();
        if (finders != null) {
            for (FinderSchema finderSchema : finders) {
                if (finderSchema.getName().equals(finderName)) {
                    return finderSchema;
                }
            }
        }
    }
    final AssociationSchema associationSchema = resourceSchema.getAssociation();
    if (associationSchema != null) {
        final FinderSchemaArray finders = associationSchema.getFinders();
        if (finders != null) {
            for (FinderSchema finderSchema : finders) {
                if (finderSchema.getName().equals(finderName)) {
                    return finderSchema;
                }
            }
        }
    }
    return null;
}
Also used : AssociationSchema(com.linkedin.restli.restspec.AssociationSchema) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) FinderSchema(com.linkedin.restli.restspec.FinderSchema)

Example 3 with FinderSchema

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

the class JavaRequestBuilderGenerator method generateFinders.

private void generateFinders(JDefinedClass facadeClass, JExpression baseUriExpr, FinderSchemaArray finderSchemas, JClass keyClass, JClass valueClass, Map<String, AssocKeyTypeInfo> assocKeys, JVar resourceSpecField, String resourceName, List<String> pathKeys, Map<String, JClass> pathKeyTypes, Map<String, JClass> assocKeyTypes, Map<String, List<String>> pathToAssocKeys, JExpression requestOptionsExpr) throws JClassAlreadyExistsException {
    if (finderSchemas != null) {
        final JClass baseBuilderClass = getCodeModel().ref(FindRequestBuilderBase.class).narrow(keyClass, valueClass);
        for (FinderSchema finder : finderSchemas) {
            final String finderName = finder.getName();
            final String builderName = CodeUtil.capitalize(resourceName) + "FindBy" + CodeUtil.capitalize(finderName) + METHOD_BUILDER_SUFFIX.get(_version);
            JDefinedClass finderBuilderClass = generateDerivedBuilder(baseBuilderClass, valueClass, finderName, builderName, facadeClass.getPackage(), ResourceMethod.FINDER, null);
            final JMethod finderMethod = facadeClass.method(JMod.PUBLIC, finderBuilderClass, "findBy" + CodeUtil.capitalize(finderName));
            finderMethod.body()._return(JExpr._new(finderBuilderClass).arg(baseUriExpr).arg(resourceSpecField).arg(requestOptionsExpr));
            final Set<String> finderKeys = new HashSet<String>();
            if (finder.getAssocKey() != null) {
                finderKeys.add(finder.getAssocKey());
            }
            if (finder.getAssocKeys() != null) {
                for (String assocKey : finder.getAssocKeys()) {
                    finderKeys.add(assocKey);
                }
            }
            generatePathKeyBindingMethods(pathKeys, finderBuilderClass, pathKeyTypes, assocKeyTypes, pathToAssocKeys);
            generateAssocKeyBindingMethods(assocKeys, finderBuilderClass, finderKeys);
            if (finder.getParameters() != null) {
                generateQueryParamBindingMethods(facadeClass, finder.getParameters(), finderBuilderClass);
            }
            //process the metadata schema file
            if (finder.getMetadata() != null) {
                final String metadataClass = finder.getMetadata().getType();
                getJavaBindingType(metadataClass, facadeClass);
            }
            generateClassJavadoc(finderBuilderClass, finder);
            generateFactoryMethodJavadoc(finderMethod, finder);
        }
    }
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) FindRequestBuilderBase(com.linkedin.restli.client.base.FindRequestBuilderBase) JClass(com.sun.codemodel.JClass) FinderSchema(com.linkedin.restli.restspec.FinderSchema) JMethod(com.sun.codemodel.JMethod) HashSet(java.util.HashSet)

Example 4 with FinderSchema

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

the class SnapshotGenerator method findModelsCollection.

private void findModelsCollection(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
    CollectionSchema collection = resourceSchema.getCollection();
    if (collection != null) {
        IdentifierSchema identifier = collection.getIdentifier();
        findModelsIdentifier(identifier, foundTypes, typeOrder);
        if (collection.hasFinders()) {
            for (FinderSchema restMethodSchema : collection.getFinders()) {
                findModelsFinder(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (collection.hasMethods()) {
            for (RestMethodSchema restMethodSchema : collection.getMethods()) {
                findModelsMethod(restMethodSchema, foundTypes, typeOrder);
            }
        }
        if (collection.hasActions()) {
            for (ActionSchema actionSchema : collection.getActions()) {
                findModelsAction(actionSchema, foundTypes, typeOrder);
            }
        }
        if (collection.hasEntity()) {
            EntitySchema entity = collection.getEntity();
            findModelsEntity(entity, foundTypes, typeOrder);
        }
    }
}
Also used : CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) IdentifierSchema(com.linkedin.restli.restspec.IdentifierSchema) RestMethodSchema(com.linkedin.restli.restspec.RestMethodSchema) FinderSchema(com.linkedin.restli.restspec.FinderSchema) EntitySchema(com.linkedin.restli.restspec.EntitySchema) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 5 with FinderSchema

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

the class FinderTest method test.

@Test
public void test() throws IOException {
    final String findersFilename = IDLS_DIR + FINDERS_FILE;
    final ResourceSchema findersIdl = _codec.readResourceSchema(new FileInputStream(findersFilename));
    final FinderSchemaArray finders = findersIdl.getCollection().getFinders();
    for (FinderSchema finder : finders) {
        if ("searchWithoutMetadata".equals(finder.getName())) {
            Assert.assertFalse(finder.hasMetadata());
        } else if ("searchWithMetadata".equals(finder.getName())) {
            Assert.assertEquals(finder.getMetadata().getType(), SearchMetadata.class.getName());
        } else if ("basicSearch".equals(finder.getName())) {
            Assert.assertFalse(finder.hasMetadata());
        } else if ("predefinedSearch".equals(finder.getName())) {
            Assert.assertFalse(finder.hasMetadata());
        } else {
            throw new RuntimeException("Unknown finder is added to com.linkedin.restli.examples.greetings.server.FindersResource");
        }
    }
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) FinderSchema(com.linkedin.restli.restspec.FinderSchema) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Aggregations

FinderSchema (com.linkedin.restli.restspec.FinderSchema)11 ActionSchema (com.linkedin.restli.restspec.ActionSchema)4 FinderSchemaArray (com.linkedin.restli.restspec.FinderSchemaArray)4 AssociationSchema (com.linkedin.restli.restspec.AssociationSchema)3 CollectionSchema (com.linkedin.restli.restspec.CollectionSchema)3 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)3 RestMethodSchema (com.linkedin.restli.restspec.RestMethodSchema)3 DataMap (com.linkedin.data.DataMap)2 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)2 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 StringArray (com.linkedin.data.template.StringArray)2 AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)2 EntitySchema (com.linkedin.restli.restspec.EntitySchema)2 IdentifierSchema (com.linkedin.restli.restspec.IdentifierSchema)2 MetadataSchema (com.linkedin.restli.restspec.MetadataSchema)2 ResourceLevel (com.linkedin.restli.server.ResourceLevel)2 ArrayList (java.util.ArrayList)2 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 DataSchema (com.linkedin.data.schema.DataSchema)1 DataSchemaTraverse (com.linkedin.data.schema.DataSchemaTraverse)1