Search in sources :

Example 1 with Empty

use of com.linkedin.restli.examples.greetings.api.Empty in project rest.li by linkedin.

the class ValidationDemoResource method searchValidationDemos.

@BatchFinder(value = "searchValidationDemos", batchParam = "criteria")
public BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> searchValidationDemos(@PagingContextParam PagingContext context, @QueryParam("criteria") ValidationDemoCriteria[] criteria, @ValidatorParam RestLiDataValidator validator) {
    BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> batchFinderResult = new BatchFinderResult<>();
    for (ValidationDemoCriteria currentCriteria : criteria) {
        List<ValidationDemo> validationDemos = new ArrayList<>();
        // Generate entities that are missing stringB fields
        for (int i = 0; i < 3; i++) {
            ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
            union.setMyEnum(myEnum.FOOFOO);
            validationDemos.add(new ValidationDemo().setStringA("valueA").setIntA(currentCriteria.getIntA()).setUnionFieldWithInlineRecord(union));
        }
        // Validate outgoing data
        for (ValidationDemo entity : validationDemos) {
            ValidationResult result = validator.validateOutput(entity);
            check(!result.isValid());
            check(result.getMessages().toString().contains("/stringB :: field is required but not found"));
        }
        // Fix entities
        for (ValidationDemo validationDemo : validationDemos) {
            validationDemo.setStringB("valueB");
        }
        // Validate again
        for (ValidationDemo entity : validationDemos) {
            ValidationResult result = validator.validateOutput(entity);
            check(result.isValid());
        }
        CollectionResult<ValidationDemo, Empty> cr = new CollectionResult<>(validationDemos, validationDemos.size());
        batchFinderResult.putResult(currentCriteria, cr);
    }
    return batchFinderResult;
}
Also used : ArrayList(java.util.ArrayList) BatchFinderResult(com.linkedin.restli.server.BatchFinderResult) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) CollectionResult(com.linkedin.restli.server.CollectionResult) Empty(com.linkedin.restli.examples.greetings.api.Empty) ValidationDemoCriteria(com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder)

Example 2 with Empty

use of com.linkedin.restli.examples.greetings.api.Empty in project rest.li by linkedin.

the class AutomaticValidationDemoResource method searchValidationDemos.

@BatchFinder(value = "searchValidationDemos", batchParam = "criteria")
public BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> searchValidationDemos(@PagingContextParam PagingContext context, @QueryParam("criteria") ValidationDemoCriteria[] criteria) {
    BatchFinderResult<ValidationDemoCriteria, ValidationDemo, Empty> batchFinderResult = new BatchFinderResult<>();
    for (ValidationDemoCriteria currentCriteria : criteria) {
        List<ValidationDemo> validationDemos = new ArrayList<>();
        if (currentCriteria.getIntA() == 1111) {
            // Generate entities that are missing stringB fields
            for (int i = 0; i < 3; i++) {
                ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
                union.setMyEnum(myEnum.FOOFOO);
                validationDemos.add(new ValidationDemo().setStringA("valueA").setIntA(currentCriteria.getIntA()).setUnionFieldWithInlineRecord(union));
            }
        } else if (currentCriteria.getIntA() == 2222) {
            // Generate entities that their stringA field has a value over the length limitation
            for (int i = 0; i < 3; i++) {
                ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
                union.setMyEnum(myEnum.FOOFOO);
                validationDemos.add(new ValidationDemo().setStringA("longLengthValueA").setIntA(currentCriteria.getIntA()).setStringB("valueB").setUnionFieldWithInlineRecord(union));
            }
        } else if (currentCriteria.getIntA() == 3333) {
            // the stringA field has a value over the length limitation and miss stringB fields
            for (int i = 0; i < 3; i++) {
                ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
                union.setMyEnum(myEnum.FOOFOO);
                validationDemos.add(new ValidationDemo().setStringA("longLengthValueA").setIntA(currentCriteria.getIntA()).setUnionFieldWithInlineRecord(union));
            }
        } else if (currentCriteria.getIntA() == 4444) {
            // entities without errors
            for (int i = 0; i < 3; i++) {
                ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
                union.setMyEnum(myEnum.FOOFOO);
                validationDemos.add(new ValidationDemo().setStringA("valueA").setIntA(currentCriteria.getIntA()).setStringB("valueB").setUnionFieldWithInlineRecord(union));
            }
        } else {
            // on errorResponse
            batchFinderResult.putError(currentCriteria, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Fail to find Validation Demo!"));
            continue;
        }
        CollectionResult<ValidationDemo, Empty> cr = new CollectionResult<>(validationDemos, validationDemos.size());
        batchFinderResult.putResult(currentCriteria, cr);
    }
    return batchFinderResult;
}
Also used : ArrayList(java.util.ArrayList) BatchFinderResult(com.linkedin.restli.server.BatchFinderResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) CollectionResult(com.linkedin.restli.server.CollectionResult) Empty(com.linkedin.restli.examples.greetings.api.Empty) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ValidationDemoCriteria(com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria) BatchFinder(com.linkedin.restli.server.annotations.BatchFinder)

Example 3 with Empty

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

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

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

Empty (com.linkedin.restli.examples.greetings.api.Empty)5 BatchFinderResult (com.linkedin.restli.server.BatchFinderResult)5 CollectionResult (com.linkedin.restli.server.CollectionResult)5 BatchFinder (com.linkedin.restli.server.annotations.BatchFinder)5 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)3 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 ArrayList (java.util.ArrayList)2 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 Message (com.linkedin.restli.examples.greetings.api.Message)1 MessageCriteria (com.linkedin.restli.examples.greetings.api.MessageCriteria)1 MaxBatchSize (com.linkedin.restli.server.annotations.MaxBatchSize)1