com.linkedin.restli.common.BatchCreateResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of restli-common Show documentation
Show all versions of restli-common Show documentation
Pegasus is a framework for building robust, scalable service architectures using dynamic discovery and simple asychronous type-checked REST + JSON APIs.
/*
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.common;
import com.linkedin.data.DataList;
import com.linkedin.data.DataMap;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.restli.internal.common.CreateIdStatusDecoder;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/**
* Response for Batch Create Requests. Effectively returns a collection of {@link com.linkedin.restli.common.CreateIdStatus},
* but individual {@link com.linkedin.restli.common.CreateStatus} must be cast to CreateIdStatus to get access to the
* strongly-typed keys.
*
* @author Moira Tagle
*/
public class BatchCreateResponse extends CollectionResponse
{
private final List _collection;
public BatchCreateResponse()
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
{
this(null, null);
}
public BatchCreateResponse(DataMap data, CreateIdStatusDecoder entityDecoder)
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
{
super(data, CreateStatus.class);
_collection = createCollectionFromDecoder(entityDecoder);
}
public BatchCreateResponse(List> elements)
{
super(generateDataMap(elements), CreateStatus.class);
_collection = new ArrayList(elements.size());
for (CreateIdStatus element : elements)
{
_collection.add(element);
}
}
private static DataMap generateDataMap(List extends RecordTemplate> elements)
{
DataMap dataMap = new DataMap();
DataList listElements = new DataList();
for (RecordTemplate recordTemplate : elements)
{
listElements.add(recordTemplate.data());
}
dataMap.put(CollectionResponse.ELEMENTS, listElements);
return dataMap;
}
private CreateStatus decodeValue(DataMap dataMap, CreateIdStatusDecoder entityDecoder)
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
{
return entityDecoder.makeValue(dataMap);
}
private List createCollectionFromDecoder(CreateIdStatusDecoder entityDecoder)
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
{
DataList elements = this.data().getDataList(CollectionResponse.ELEMENTS);
List collection = new ArrayList(elements.size());
for (Object obj : elements)
{
DataMap dataMap = (DataMap) obj;
collection.add(decodeValue(dataMap, entityDecoder));
}
return collection;
}
/**
* @return actually returns a list of {@link com.linkedin.restli.common.CreateIdStatus}
*/
public List getElements()
{
return _collection;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy