use of com.linkedin.restli.server.annotations.ReturnEntity 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.server.annotations.ReturnEntity in project rest.li by linkedin.
the class CreateGreetingResource method batchCreate.
@ReturnEntity
@RestMethod.BatchCreate
public BatchCreateKVResult<Long, Greeting> batchCreate(BatchCreateRequest<Long, Greeting> entities) {
List<CreateKVResponse<Long, Greeting>> responses = new ArrayList<CreateKVResponse<Long, Greeting>>(entities.getInput().size());
// Maximum number of batch create entity is 3 in this resource. If more than 3 elements are detected, a 400 HTTP exception will be encoded
int quota = 3;
for (Greeting greeting : entities.getInput()) {
if (quota-- <= 0) {
responses.add(new CreateKVResponse<Long, Greeting>(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "exceed quota")));
} else {
responses.add(create(greeting));
}
}
return new BatchCreateKVResult<Long, Greeting>(responses);
}
Aggregations