Search in sources :

Example 11 with GreetingCriteria

use of com.linkedin.restli.examples.greetings.api.GreetingCriteria 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 12 with GreetingCriteria

use of com.linkedin.restli.examples.greetings.api.GreetingCriteria 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)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)12 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)12 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)10 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)10 Test (org.testng.annotations.Test)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 Batchfinders (com.linkedin.restli.examples.greetings.client.Batchfinders)3 BatchfindersFluentClient (com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient)3 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)3 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)3 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)2 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)2 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)2 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)2 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)2 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 CreateIdEntityStatus (com.linkedin.restli.common.CreateIdEntityStatus)2 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)2