Search in sources :

Example 1 with ReturnEntity

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);
}
Also used : com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) ArrayList(java.util.ArrayList) BatchCreateKVResult(com.linkedin.restli.server.BatchCreateKVResult) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) ReturnEntity(com.linkedin.restli.server.annotations.ReturnEntity)

Example 2 with ReturnEntity

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ArrayList(java.util.ArrayList) BatchCreateKVResult(com.linkedin.restli.server.BatchCreateKVResult) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) ReturnEntity(com.linkedin.restli.server.annotations.ReturnEntity)

Aggregations

BatchCreateKVResult (com.linkedin.restli.server.BatchCreateKVResult)2 CreateKVResponse (com.linkedin.restli.server.CreateKVResponse)2 ReturnEntity (com.linkedin.restli.server.annotations.ReturnEntity)2 ArrayList (java.util.ArrayList)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)1 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)1 com.linkedin.restli.examples.greetings.api.myRecord (com.linkedin.restli.examples.greetings.api.myRecord)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1