Search in sources :

Example 1 with CollectionRequest

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

the class BatchCreateArgumentBuilder method extractRequestData.

@Override
public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request) {
    Class<? extends RecordTemplate> valueClass = ArgumentUtils.getValueClass(routingResult);
    DataMap dataMap = DataMapUtils.readMap(request);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<RecordTemplate> collectionRequest = new CollectionRequest(dataMap, valueClass);
    return new RestLiRequestDataImpl.Builder().batchEntities(collectionRequest.getElements()).build();
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap)

Example 2 with CollectionRequest

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

the class BatchPartialUpdateRequestBuilder method buildReadOnlyInput.

private CollectionRequest<KeyValueRecord<K, PatchRequest<V>>> buildReadOnlyInput() {
    try {
        DataMap map = new DataMap();
        @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord<K, PatchRequest<V>>> input = new CollectionRequest(map, KeyValueRecord.class);
        for (Map.Entry<K, PatchRequest<V>> inputEntityEntry : _partialUpdateInputMap.entrySet()) {
            K key = getReadOnlyOrCopyKey(inputEntityEntry.getKey());
            PatchRequest<V> entity = getReadOnlyOrCopyDataTemplate(inputEntityEntry.getValue());
            KeyValueRecord<K, PatchRequest<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 : CollectionRequest(com.linkedin.restli.common.CollectionRequest) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map)

Example 3 with CollectionRequest

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

the class FluentClientUtils method buildBatchEntityInputs.

/**
 * Converts list of entities for batch_* requests to a {@link CollectionRequest} as needed by the request classes.
 * @param entities   Inputs to the batch_* methods.
 * @param valueClass Entity's class.
 * @param <V>        Value type
 */
public static <V extends RecordTemplate> CollectionRequest<V> buildBatchEntityInputs(List<V> entities, Class<V> valueClass) {
    DataMap map = new DataMap();
    CollectionRequest<V> input = new CollectionRequest<>(map, valueClass);
    for (V entity : entities) {
        input.getElements().add(entity);
    }
    return input;
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) DataMap(com.linkedin.data.DataMap)

Example 4 with CollectionRequest

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

the class BatchKVRequestBuilder method buildReadOnlyInput.

protected <E extends RecordTemplate> CollectionRequest<KeyValueRecord<K, E>> buildReadOnlyInput(Map<K, E> readOnlyInputEntities, Map<K, E> inputMap, KeyValueRecordFactory<K, E> keyValueRecordFactory) {
    try {
        DataMap map = new DataMap();
        @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord<K, E>> input = new CollectionRequest(map, KeyValueRecord.class);
        for (Map.Entry<K, E> inputEntityEntry : inputMap.entrySet()) {
            K key = getReadOnlyOrCopyKey(inputEntityEntry.getKey());
            E entity = getReadOnlyOrCopyDataTemplate(inputEntityEntry.getValue());
            readOnlyInputEntities.put(key, entity);
            KeyValueRecord<K, E> 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) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 5 with CollectionRequest

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

the class BatchCreateRequestBuilder method buildReadOnlyInput.

private CollectionRequest<V> buildReadOnlyInput() {
    try {
        DataMap map = new DataMap();
        CollectionRequest<V> input = new CollectionRequest<>(map, _valueClass);
        for (V entity : _entities) {
            input.getElements().add(getReadOnlyOrCopyDataTemplate(entity));
        }
        map.setReadOnly();
        return input;
    } catch (CloneNotSupportedException cloneException) {
        throw new IllegalArgumentException("Entity cannot be copied.", cloneException);
    }
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) DataMap(com.linkedin.data.DataMap)

Aggregations

CollectionRequest (com.linkedin.restli.common.CollectionRequest)19 DataMap (com.linkedin.data.DataMap)10 KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)8 TestRecord (com.linkedin.restli.client.test.TestRecord)7 Test (org.testng.annotations.Test)7 HashMap (java.util.HashMap)5 KeyValueRecordFactory (com.linkedin.restli.common.KeyValueRecordFactory)4 Map (java.util.Map)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)3 PathSpec (com.linkedin.data.schema.PathSpec)2 CompoundKey (com.linkedin.restli.common.CompoundKey)2 ResourceProperties (com.linkedin.restli.common.ResourceProperties)2 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 PatchRequest (com.linkedin.restli.common.PatchRequest)1 ResourceSpec (com.linkedin.restli.common.ResourceSpec)1 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)1 ResourcePropertiesImpl (com.linkedin.restli.internal.common.ResourcePropertiesImpl)1 RestLiTestAttachmentDataSource (com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource)1 Collection (java.util.Collection)1