Search in sources :

Example 86 with DataMap

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);
    }
}
Also used : KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) CollectionRequest(com.linkedin.restli.common.CollectionRequest) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 87 with DataMap

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;
}
Also used : HttpStatus(com.linkedin.restli.common.HttpStatus) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) HashSet(java.util.HashSet) DataMap(com.linkedin.data.DataMap) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 88 with DataMap

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);
}
Also used : BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) CompoundKey(com.linkedin.restli.common.CompoundKey) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) DataMap(com.linkedin.data.DataMap)

Example 89 with DataMap

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;
}
Also used : ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) DataMap(com.linkedin.data.DataMap)

Example 90 with DataMap

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());
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

DataMap (com.linkedin.data.DataMap)471 Test (org.testng.annotations.Test)238 DataList (com.linkedin.data.DataList)130 ByteString (com.linkedin.data.ByteString)110 HashMap (java.util.HashMap)56 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)49 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)47 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)46 DataSchema (com.linkedin.data.schema.DataSchema)45 Map (java.util.Map)45 ArrayList (java.util.ArrayList)31 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)23 PathSpec (com.linkedin.data.schema.PathSpec)21 RecordTemplate (com.linkedin.data.template.RecordTemplate)21 DataProvider (org.testng.annotations.DataProvider)20 HashSet (java.util.HashSet)19 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)18 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 IOException (java.io.IOException)18