Search in sources :

Example 6 with BatchFinder

use of com.linkedin.restli.server.annotations.BatchFinder in project rest.li by linkedin.

the class BatchFinderResource method searchGreetings.

@BatchFinder(value = "searchGreetings", batchParam = "criteria")
public BatchFinderResult<GreetingCriteria, Greeting, Empty> searchGreetings(@PagingContextParam PagingContext context, @QueryParam("criteria") GreetingCriteria[] criteria, @QueryParam("message") String message) {
    BatchFinderResult<GreetingCriteria, Greeting, Empty> batchFinderResult = new BatchFinderResult<>();
    for (GreetingCriteria currentCriteria : criteria) {
        if (currentCriteria.getId() == 1L) {
            // on success
            CollectionResult<Greeting, Empty> c1 = new CollectionResult<>(Arrays.asList(g1), 1);
            batchFinderResult.putResult(currentCriteria, c1);
        } else if (currentCriteria.getId() == 2L) {
            CollectionResult<Greeting, Empty> c2 = new CollectionResult<>(Arrays.asList(g2), 1);
            batchFinderResult.putResult(currentCriteria, c2);
        } else if (currentCriteria.getId() == 100L) {
            // on error: to construct error response for test
            batchFinderResult.putError(currentCriteria, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Fail to find Greeting!"));
        }
    }
    return batchFinderResult;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResult(com.linkedin.restli.server.CollectionResult) Empty(com.linkedin.restli.examples.greetings.api.Empty) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) BatchFinderResult(com.linkedin.restli.server.BatchFinderResult) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder)

Example 7 with BatchFinder

use of com.linkedin.restli.server.annotations.BatchFinder in project rest.li by linkedin.

the class AssociationsResource method searchMessages.

@BatchFinder(value = "searchMessages", batchParam = "criteria")
public BatchFinderResult<MessageCriteria, Message, Empty> searchMessages(@AssocKeyParam("src") String src, @PagingContextParam PagingContext context, @QueryParam("criteria") MessageCriteria[] criteria) {
    BatchFinderResult<MessageCriteria, Message, Empty> batchFinderResult = new BatchFinderResult<>();
    for (MessageCriteria currentCriteria : criteria) {
        if (currentCriteria.getTone() == Tone.FRIENDLY) {
            // on success
            CollectionResult<Message, Empty> cr = new CollectionResult<>(Arrays.asList(m1, m2), 2);
            batchFinderResult.putResult(currentCriteria, cr);
        } else {
            // on error: to construct error response for test
            batchFinderResult.putError(currentCriteria, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Failed to find message!"));
        }
    }
    return batchFinderResult;
}
Also used : CollectionResult(com.linkedin.restli.server.CollectionResult) Empty(com.linkedin.restli.examples.greetings.api.Empty) Message(com.linkedin.restli.examples.greetings.api.Message) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) MessageCriteria(com.linkedin.restli.examples.greetings.api.MessageCriteria) BatchFinderResult(com.linkedin.restli.server.BatchFinderResult) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder)

Example 8 with BatchFinder

use of com.linkedin.restli.server.annotations.BatchFinder in project rest.li by linkedin.

the class BatchGreetingResource method searchGreetings.

@BatchFinder(value = "searchGreetings", batchParam = "criteria")
@MaxBatchSize(value = 2, validate = true)
public BatchFinderResult<GreetingCriteria, Greeting, Empty> searchGreetings(@QueryParam("criteria") GreetingCriteria[] criteria) {
    BatchFinderResult<GreetingCriteria, Greeting, Empty> batchFinderResult = new BatchFinderResult<>();
    for (GreetingCriteria currentCriteria : criteria) {
        if (currentCriteria.getId() == 1l) {
            CollectionResult<Greeting, Empty> c1 = new CollectionResult<>(Arrays.asList(GREETING_ONE), 1);
            batchFinderResult.putResult(currentCriteria, c1);
        } else if (currentCriteria.getId() == 2l) {
            CollectionResult<Greeting, Empty> c2 = new CollectionResult<>(Arrays.asList(GREETING_TWO), 1);
            batchFinderResult.putResult(currentCriteria, c2);
        }
    }
    return batchFinderResult;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResult(com.linkedin.restli.server.CollectionResult) Empty(com.linkedin.restli.examples.greetings.api.Empty) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) BatchFinderResult(com.linkedin.restli.server.BatchFinderResult) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder) MaxBatchSize(com.linkedin.restli.server.annotations.MaxBatchSize)

Example 9 with BatchFinder

use of com.linkedin.restli.server.annotations.BatchFinder in project rest.li by linkedin.

the class ResourceModelEncoder method createBatchFinderSchema.

private BatchFinderSchema createBatchFinderSchema(ResourceMethodDescriptor resourceMethodDescriptor) {
    BatchFinderSchema batchFinder = new BatchFinderSchema();
    batchFinder.setName(resourceMethodDescriptor.getBatchFinderName());
    String doc = _docsProvider.getMethodDoc(resourceMethodDescriptor.getMethod());
    if (doc != null) {
        batchFinder.setDoc(doc);
    }
    ParameterSchemaArray parameters = createParameters(resourceMethodDescriptor);
    if (parameters.size() > 0) {
        batchFinder.setParameters(parameters);
    }
    StringArray assocKeys = createAssocKeyParameters(resourceMethodDescriptor);
    if (assocKeys.size() > 0) {
        batchFinder.setAssocKeys(assocKeys);
    }
    if (resourceMethodDescriptor.getCollectionCustomMetadataType() != null) {
        batchFinder.setMetadata(createMetadataSchema(resourceMethodDescriptor));
    }
    final DataMap customAnnotation = resourceMethodDescriptor.getCustomAnnotationData();
    String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(resourceMethodDescriptor.getMethod());
    if (deprecatedDoc != null) {
        customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
    }
    if (!customAnnotation.isEmpty()) {
        batchFinder.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
    }
    if (resourceMethodDescriptor.isPagingSupported()) {
        batchFinder.setPagingSupported(true);
    }
    MaxBatchSizeSchema maxBatchSize = resourceMethodDescriptor.getMaxBatchSize();
    if (maxBatchSize != null) {
        batchFinder.setMaxBatchSize(maxBatchSize);
    }
    appendServiceErrors(batchFinder, resourceMethodDescriptor.getServiceErrors());
    appendSuccessStatuses(batchFinder, resourceMethodDescriptor.getSuccessStatuses());
    BatchFinder batchFinderAnnotation = resourceMethodDescriptor.getMethod().getAnnotation(BatchFinder.class);
    batchFinder.setBatchParam(batchFinderAnnotation.batchParam());
    return batchFinder;
}
Also used : StringArray(com.linkedin.data.template.StringArray) MaxBatchSizeSchema(com.linkedin.restli.restspec.MaxBatchSizeSchema) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder) BatchFinderSchema(com.linkedin.restli.restspec.BatchFinderSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Aggregations

BatchFinder (com.linkedin.restli.server.annotations.BatchFinder)9 BatchFinderResult (com.linkedin.restli.server.BatchFinderResult)7 CollectionResult (com.linkedin.restli.server.CollectionResult)6 Empty (com.linkedin.restli.examples.greetings.api.Empty)5 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)4 ArrayList (java.util.ArrayList)3 DataMap (com.linkedin.data.DataMap)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)2 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)2 ValidationDemoCriteria (com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria)2 ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)2 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 StringArray (com.linkedin.data.template.StringArray)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 Photo (com.linkedin.restli.example.Photo)1 PhotoCriteria (com.linkedin.restli.example.PhotoCriteria)1 Message (com.linkedin.restli.examples.greetings.api.Message)1 MessageCriteria (com.linkedin.restli.examples.greetings.api.MessageCriteria)1 BatchFinderSchema (com.linkedin.restli.restspec.BatchFinderSchema)1