use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class BatchUpdateRequestBuilder method buildReadOnlyBatchUpdateInput.
private CollectionRequest<KeyValueRecord<K, V>> buildReadOnlyBatchUpdateInput(Map<K, V> readOnlyInputEntities) {
try {
DataMap map = new DataMap();
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord<K, V>> input = new CollectionRequest(map, KeyValueRecord.class);
for (Map.Entry<K, V> inputEntityEntry : _updateInputMap.entrySet()) {
K key = getReadOnlyOrCopyKey(inputEntityEntry.getKey());
V entity = getReadOnlyOrCopyDataTemplate(inputEntityEntry.getValue());
readOnlyInputEntities.put(key, entity);
KeyValueRecord<K, V> keyValueRecord = _keyValueRecordFactory.create(key, entity);
keyValueRecord.data().setReadOnly();
input.getElements().add(keyValueRecord);
}
map.setReadOnly();
return input;
} catch (CloneNotSupportedException cloneException) {
throw new IllegalArgumentException("Entity cannot be copied.", cloneException);
}
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class MockBatchEntityResponseFactory method buildDataMap.
private static <K, V extends RecordTemplate> DataMap buildDataMap(Map<K, V> recordTemplates, Map<K, HttpStatus> statuses, Map<K, ErrorResponse> errorResponses, ProtocolVersion version) {
Set<K> mergedKeys = new HashSet<K>();
mergedKeys.addAll(recordTemplates.keySet());
mergedKeys.addAll(statuses.keySet());
mergedKeys.addAll(errorResponses.keySet());
DataMap batchResponseDataMap = new DataMap();
DataMap rawBatchData = new DataMap();
for (K key : mergedKeys) {
DataMap entityResponseData = new DataMap();
RecordTemplate recordTemplate = recordTemplates.get(key);
if (recordTemplate != null) {
entityResponseData.put(EntityResponse.ENTITY, recordTemplate.data());
}
HttpStatus status = statuses.get(key);
if (status != null) {
entityResponseData.put(EntityResponse.STATUS, status.getCode());
}
ErrorResponse errorResponse = errorResponses.get(key);
if (errorResponse != null) {
entityResponseData.put(EntityResponse.ERROR, errorResponse.data());
}
String stringKey = URIParamUtils.encodeKeyForBody(key, false, version);
rawBatchData.put(stringKey, entityResponseData);
}
batchResponseDataMap.put(BatchResponse.RESULTS, rawBatchData);
DataMap rawErrorData = new DataMap();
for (Map.Entry<K, ErrorResponse> errorResponse : errorResponses.entrySet()) {
rawErrorData.put(URIParamUtils.encodeKeyForBody(errorResponse.getKey(), false, version), errorResponse.getValue().data());
}
batchResponseDataMap.put(BatchResponse.ERRORS, rawErrorData);
return batchResponseDataMap;
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class MockBatchEntityResponseFactory method createWithCustomTyperefKey.
/**
* Creates a {@link BatchKVResponse} where the key is a typeref to a custom Java class.
*
* @param keyClass the custom Java class
* @param typerefClass the typeref class (the generated class that extends {@link RecordTemplate})
* @param valueClass class for the value
* @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* @param statuses The HTTP status codes that will be returned as part of {@link EntityResponse}s returned in {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
* @param <K>
* @param <TK>
* @param <V>
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, TK, V extends RecordTemplate> BatchKVResponse<K, EntityResponse<V>> createWithCustomTyperefKey(Class<K> keyClass, Class<TK> typerefClass, Class<V> valueClass, Map<K, V> recordTemplates, Map<K, HttpStatus> statuses, Map<K, ErrorResponse> errorResponses) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
DataMap batchResponseDataMap = buildDataMap(recordTemplates, statuses, errorResponses, version);
return new BatchEntityResponse(batchResponseDataMap, TypeSpec.forClassMaybeNull(typerefClass), TypeSpec.forClassMaybeNull(valueClass), Collections.<String, CompoundKey.TypeInfo>emptyMap(), null, version);
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class MockBatchKVResponseFactory method createWithComplexKey.
/**
* Create a {@link BatchKVResponse} where the key is a {@link ComplexResourceKey}
*
* @param valueClass the value class
* @param keyKeyClass the class of the key part of the {@link ComplexResourceKey}
* @param keyParamsClass the class of the params part of the {@link ComplexResourceKey}
* @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param <V>
* @return
*/
@SuppressWarnings("rawtypes")
public static <KK extends RecordTemplate, KP extends RecordTemplate, V extends RecordTemplate> BatchKVResponse<ComplexResourceKey<KK, KP>, V> createWithComplexKey(Class<V> valueClass, Class<KK> keyKeyClass, Class<KP> keyParamsClass, Map<ComplexResourceKey<KK, KP>, V> recordTemplates, Map<ComplexResourceKey<KK, KP>, ErrorResponse> errorResponses) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
DataMap batchResponseDataMap = buildDataMap(recordTemplates, errorResponses, version);
@SuppressWarnings("unchecked") BatchKVResponse<ComplexResourceKey<KK, KP>, V> response = (BatchKVResponse<ComplexResourceKey<KK, KP>, V>) (Object) new BatchKVResponse<ComplexResourceKey, V>(batchResponseDataMap, ComplexResourceKey.class, valueClass, null, keyKeyClass, keyParamsClass, version);
return response;
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestPatchTreeRecorder method testEmptyPatch.
@Test
public void testEmptyPatch() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
Assert.assertEquals(pc.generatePatchTree().getDataMap(), new DataMap());
}
Aggregations