com.linkedin.restli.test.util.BatchCreateHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of restli-int-test Show documentation
Show all versions of restli-int-test Show documentation
Pegasus is a framework for building robust, scalable service architectures using dynamic discovery and simple asychronous type-checked REST + JSON APIs.
The newest version!
/*
Copyright (c) 2014 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.linkedin.restli.test.util;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.r2.RemoteInvocationException;
import com.linkedin.restli.client.BatchCreateIdRequest;
import com.linkedin.restli.client.BatchCreateIdRequestBuilder;
import com.linkedin.restli.client.BatchCreateRequest;
import com.linkedin.restli.client.BatchCreateRequestBuilder;
import com.linkedin.restli.client.Response;
import com.linkedin.restli.client.RestClient;
import com.linkedin.restli.common.BatchCreateIdResponse;
import com.linkedin.restli.common.CollectionResponse;
import com.linkedin.restli.common.CreateIdStatus;
import com.linkedin.restli.common.CreateStatus;
import java.util.ArrayList;
import java.util.List;
/**
* Functions for dealing with differences between v1 and v2 request builders batchCreate.
* @author Moira Tagle
*/
public class BatchCreateHelper
{
public static List> batchCreate(RestClient restClient, RootBuilderWrapper builders, List entities)
throws RemoteInvocationException
{
RootBuilderWrapper.MethodBuilderWrapper> batchCreateWrapper = builders.batchCreate();
if (batchCreateWrapper.isRestLi2Builder())
{
Object obj = batchCreateWrapper.getBuilder();
@SuppressWarnings("unchecked")
BatchCreateIdRequestBuilder builder = (BatchCreateIdRequestBuilder) obj;
return batchCreateNewBuilders(restClient, builder, entities);
}
else
{
@SuppressWarnings("unchecked")
BatchCreateRequestBuilder builder = (BatchCreateRequestBuilder) batchCreateWrapper.getBuilder();
return batchCreateOldBuilders(restClient, builder, entities);
}
}
private static List> batchCreateOldBuilders(RestClient restClient, BatchCreateRequestBuilder builder, List entities)
throws RemoteInvocationException
{
BatchCreateRequest request = builder.inputs(entities).build();
Response> response = restClient.sendRequest(request).getResponse();
List elements = response.getEntity().getElements();
List> result = new ArrayList>(elements.size());
for (CreateStatus status : elements)
{
@SuppressWarnings("unchecked")
CreateIdStatus createIdStatus = (CreateIdStatus) status;
result.add(createIdStatus);
}
return result;
}
private static List> batchCreateNewBuilders(RestClient restClient, BatchCreateIdRequestBuilder builder, List entities)
throws RemoteInvocationException
{
BatchCreateIdRequest request = builder.inputs(entities).build();
Response> response = restClient.sendRequest(request).getResponse();
return response.getEntity().getElements();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy