Search in sources :

Example 1 with CreateIdRequestBuilder

use of com.linkedin.restli.client.CreateIdRequestBuilder in project rest.li by linkedin.

the class TestDebugRequestHandlers method createNewGreetingOnTheServer.

private Long createNewGreetingOnTheServer(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Greeting newGreeting = new Greeting().setMessage("New Greeting!").setTone(Tone.FRIENDLY);
    RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilderWrapper = builders.create();
    Long createdId;
    if (createBuilderWrapper.isRestLi2Builder()) {
        Object objBuilder = createBuilderWrapper.getBuilder();
        @SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
        CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(newGreeting).build();
        Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
        createdId = response.getEntity().getId();
    } else {
        Request<EmptyRecord> request = createBuilderWrapper.input(newGreeting).build();
        Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
        @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
        createdId = createResponse.getId();
    }
    return createdId;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) IdResponse(com.linkedin.restli.common.IdResponse) CreateResponse(com.linkedin.restli.client.response.CreateResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) CreateIdRequestBuilder(com.linkedin.restli.client.CreateIdRequestBuilder)

Example 2 with CreateIdRequestBuilder

use of com.linkedin.restli.client.CreateIdRequestBuilder in project rest.li by linkedin.

the class TestGreetingsClient method createBatchTestDataSerially.

/**
 * Creates batch data.
 *
 * @param greetings the greetings that we want to create
 *
 * @return the ids of the created Greetings
 * @throws RemoteInvocationException
 */
private List<Long> createBatchTestDataSerially(RootBuilderWrapper<Long, Greeting> builders, List<Greeting> greetings) throws RemoteInvocationException {
    List<Long> createdIds = new ArrayList<>();
    for (Greeting greeting : greetings) {
        RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilder = builders.create();
        Long createdId;
        if (createBuilder.isRestLi2Builder()) {
            Object objBuilder = createBuilder.getBuilder();
            @SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
            CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(greeting).build();
            Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
            createdId = response.getEntity().getId();
        } else {
            Request<EmptyRecord> request = createBuilder.input(greeting).build();
            Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
            @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
            createdId = createResponse.getId();
        }
        createdIds.add(createdId);
    }
    return createdIds;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) CreateResponse(com.linkedin.restli.client.response.CreateResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ArrayList(java.util.ArrayList) CreateIdRequestBuilder(com.linkedin.restli.client.CreateIdRequestBuilder)

Aggregations

CreateIdRequestBuilder (com.linkedin.restli.client.CreateIdRequestBuilder)2 CreateResponse (com.linkedin.restli.client.response.CreateResponse)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 IdResponse (com.linkedin.restli.common.IdResponse)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)2 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)1 ArrayList (java.util.ArrayList)1