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