use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class TestRestLiValidationFromClient method testPartialUpdateFailure.
@Test(dataProvider = "providePartialUpdateFailureData")
public void testPartialUpdateFailure(Object builder, String patch, String errorMessage) {
PatchRequest<ValidationDemo> patchRequest = PatchBuilder.buildPatchFromString(patch);
ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).partialUpdate().validateInput(patchRequest);
Assert.assertEquals(result.isValid(), false);
Assert.assertEquals(result.getMessages().toString(), errorMessage);
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class AutomaticValidationDemoResource method batchUpdate.
@RestMethod.BatchUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchUpdateRequest<Integer, ValidationDemo> entities) {
Map<Integer, UpdateResponse> results = new HashMap<Integer, UpdateResponse>();
Map<Integer, RestLiServiceException> errors = new HashMap<Integer, RestLiServiceException>();
for (Map.Entry<Integer, ValidationDemo> entry : entities.getData().entrySet()) {
Integer key = entry.getKey();
ValidationDemo entity = entry.getValue();
results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
}
return new BatchUpdateResult<Integer, ValidationDemo>(results, errors);
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class AutomaticValidationDemoResource method get.
@RestMethod.Get
public ValidationDemo get(final Integer key) {
if (key == 0) {
throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST);
}
// Generate an entity that does not conform to the data schema
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyEnum(myEnum.BARBAR);
ValidationDemo validationDemo = new ValidationDemo().setStringA("stringA is readOnly").setUnionFieldWithInlineRecord(union);
return validationDemo;
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo in project rest.li by linkedin.
the class AutomaticValidationDemoResource method batchCreate.
@RestMethod.BatchCreate
@ReturnEntity
public BatchCreateKVResult<Integer, ValidationDemo> batchCreate(final BatchCreateRequest<Integer, ValidationDemo> entities) {
List<CreateKVResponse<Integer, ValidationDemo>> results = new ArrayList<CreateKVResponse<Integer, ValidationDemo>>();
int id = 0;
for (ValidationDemo entity : entities.getInput()) {
ValidationDemo returnEntity;
if (entity.getStringB().equals("b1")) {
// Missing union field.
returnEntity = new ValidationDemo().setStringA("a").setStringB("b");
} else if (entity.getStringB().equals("b2")) {
// Missing foo1 in myRecord.
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyRecord(new myRecord().setFoo2(2));
returnEntity = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(unionField);
} else {
returnEntity = _validReturnEntity;
}
results.add(new CreateKVResponse<Integer, ValidationDemo>(id, returnEntity));
id++;
}
return new BatchCreateKVResult<Integer, ValidationDemo>(results);
}
use of com.linkedin.restli.examples.greetings.api.ValidationDemo 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);
}
Aggregations