Search in sources :

Example 16 with KeyValueRecord

use of com.linkedin.restli.common.KeyValueRecord in project rest.li by linkedin.

the class FluentClientUtils method buildBatchKVInputs.

/**
 * Converts Key -> Value inputs for batch_* requests to a {@link CollectionRequest} as needed by the request classes.
 * @param inputs                Inputs to the batch_* methods.
 * @param keyValueRecordFactory Factory for converting a (key, value) tuple to {@link KeyValueRecord}
 * @param <K>                   Key type
 * @param <V>                   Value type
 */
public static <K, V extends RecordTemplate> CollectionRequest<KeyValueRecord<K, V>> buildBatchKVInputs(Map<K, V> inputs, KeyValueRecordFactory<K, V> keyValueRecordFactory) {
    DataMap map = new DataMap();
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord<K, V>> input = new CollectionRequest(map, KeyValueRecord.class);
    for (Map.Entry<K, V> inputEntry : inputs.entrySet()) {
        K key = inputEntry.getKey();
        V entity = inputEntry.getValue();
        KeyValueRecord<K, V> keyValueRecord = keyValueRecordFactory.create(key, entity);
        keyValueRecord.data().setReadOnly();
        input.getElements().add(keyValueRecord);
    }
    map.setReadOnly();
    return input;
}
Also used : KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) CollectionRequest(com.linkedin.restli.common.CollectionRequest) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Aggregations

KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)16 DataMap (com.linkedin.data.DataMap)11 TestRecord (com.linkedin.restli.client.test.TestRecord)11 Test (org.testng.annotations.Test)11 KeyValueRecordFactory (com.linkedin.restli.common.KeyValueRecordFactory)10 HashMap (java.util.HashMap)10 CollectionRequest (com.linkedin.restli.common.CollectionRequest)8 BatchRequest (com.linkedin.restli.common.BatchRequest)7 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)4 CompoundKey (com.linkedin.restli.common.CompoundKey)4 PatchRequest (com.linkedin.restli.common.PatchRequest)4 Map (java.util.Map)4 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1