Search in sources :

Example 11 with BatchCreateResult

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

the class ValidationDemoResource method batchCreate.

@RestMethod.BatchCreate
public BatchCreateResult<Integer, ValidationDemo> batchCreate(final BatchCreateRequest<Integer, ValidationDemo> entities, @ValidatorParam RestLiDataValidator validator) {
    List<CreateResponse> results = new ArrayList<CreateResponse>();
    int id = 0;
    for (ValidationDemo entity : entities.getInput()) {
        ValidationResult result = validator.validateInput(entity);
        if (result.isValid()) {
            results.add(new CreateResponse(id));
            id++;
        } else {
            results.add(new CreateResponse(new RestLiServiceException(HttpStatus.S_422_UNPROCESSABLE_ENTITY, result.getMessages().toString())));
        }
    }
    return new BatchCreateResult<Integer, ValidationDemo>(results);
}
Also used : RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) CreateResponse(com.linkedin.restli.server.CreateResponse) ArrayList(java.util.ArrayList) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Aggregations

BatchCreateResult (com.linkedin.restli.server.BatchCreateResult)11 Test (org.testng.annotations.Test)8 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)7 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)6 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)6 AfterTest (org.testng.annotations.AfterTest)6 BeforeTest (org.testng.annotations.BeforeTest)6 Callback (com.linkedin.common.callback.Callback)5 HttpStatus (com.linkedin.restli.common.HttpStatus)5 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)5 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)5 CreateResponse (com.linkedin.restli.server.CreateResponse)5 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)5 Status (com.linkedin.restli.server.twitter.TwitterTestDataModels.Status)5 ArrayList (java.util.ArrayList)5 EasyMock.anyObject (org.easymock.EasyMock.anyObject)5 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)4 CustomLong (com.linkedin.restli.server.custom.types.CustomLong)4 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)4 BatchCreateRequest (com.linkedin.restli.server.BatchCreateRequest)3