Search in sources :

Example 6 with CollectionRequest

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

the class BatchCreateIdEntityRequestBuilder method buildReadOnlyInput.

private CollectionRequest<V> buildReadOnlyInput() {
    try {
        DataMap map = new DataMap();
        CollectionRequest<V> input = new CollectionRequest<V>(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)

Example 7 with CollectionRequest

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

the class BatchCreateIdRequestBuilder method buildReadOnlyInput.

private CollectionRequest<V> buildReadOnlyInput() {
    try {
        DataMap map = new DataMap();
        CollectionRequest<V> input = new CollectionRequest<V>(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)

Example 8 with CollectionRequest

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

the class TestCollectionRequestUtil method testPrimitiveKeySingleEntity.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versions")
public void testPrimitiveKeySingleEntity(ProtocolVersion version) {
    KeyValueRecordFactory<Long, TestRecord> factory = new KeyValueRecordFactory<Long, TestRecord>(Long.class, null, null, null, TestRecord.class);
    TestRecord testRecord = buildTestRecord(1L, "message");
    KeyValueRecord<Long, TestRecord> kvRecord = factory.create(1L, testRecord);
    @SuppressWarnings("rawtypes") CollectionRequest<KeyValueRecord> collectionRequest = new CollectionRequest<KeyValueRecord>(KeyValueRecord.class);
    collectionRequest.getElements().add(kvRecord);
    @SuppressWarnings("unchecked") BatchRequest<TestRecord> batchRequest = CollectionRequestUtil.convertToBatchRequest(collectionRequest, Long.class, null, null, null, TestRecord.class, version);
    Map<String, TestRecord> entities = batchRequest.getEntities();
    Assert.assertEquals(entities.size(), 1);
    Assert.assertEquals(entities.get("1"), testRecord);
}
Also used : KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) CollectionRequest(com.linkedin.restli.common.CollectionRequest) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 9 with CollectionRequest

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

the class TestCollectionRequestUtil method testPrimitiveKeyMultipleEntities.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versions")
public void testPrimitiveKeyMultipleEntities(ProtocolVersion version) {
    @SuppressWarnings("rawtypes") KeyValueRecordFactory<Long, TestRecord> factory = new KeyValueRecordFactory<Long, TestRecord>(Long.class, null, null, null, TestRecord.class);
    @SuppressWarnings("rawtypes") CollectionRequest<KeyValueRecord> collectionRequest = new CollectionRequest<KeyValueRecord>(KeyValueRecord.class);
    Map<Long, TestRecord> inputs = new HashMap<Long, TestRecord>();
    long[] ids = { 1L, 2L, 3L };
    for (long id : ids) {
        TestRecord testRecord = buildTestRecord(id, id + "");
        inputs.put(id, testRecord);
        collectionRequest.getElements().add(factory.create(id, testRecord));
    }
    @SuppressWarnings("unchecked") BatchRequest<TestRecord> batchRequest = CollectionRequestUtil.convertToBatchRequest(collectionRequest, Long.class, null, null, null, TestRecord.class, version);
    Map<String, TestRecord> entities = batchRequest.getEntities();
    Assert.assertEquals(entities.size(), ids.length);
    for (long id : ids) {
        Assert.assertEquals(entities.get(id + ""), inputs.get(id));
    }
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) HashMap(java.util.HashMap) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 10 with CollectionRequest

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

the class TestCollectionRequestUtil method testComplexKeyMultipleEntities.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versions")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testComplexKeyMultipleEntities(ProtocolVersion version) {
    // TestRecord is not keyed by a ComplexResourceKey, but for this test we pretend that it is.
    TestRecord kk1 = buildTestRecord(1, "key key 1");
    TestRecord kp1 = buildTestRecord(2, "key params 1");
    TestRecord kk2 = buildTestRecord(3, "key key 2");
    TestRecord kp2 = buildTestRecord(4, "key params 2");
    ComplexResourceKey<TestRecord, TestRecord> key1 = new ComplexResourceKey<TestRecord, TestRecord>(kk1, kp1);
    ComplexResourceKey<TestRecord, TestRecord> key2 = new ComplexResourceKey<TestRecord, TestRecord>(kk2, kp2);
    ComplexResourceKey[] keys = { key1, key2 };
    KeyValueRecordFactory<ComplexResourceKey, TestRecord> factory = new KeyValueRecordFactory<ComplexResourceKey, TestRecord>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, TestRecord.class);
    CollectionRequest<KeyValueRecord> collectionRequest = new CollectionRequest<KeyValueRecord>(KeyValueRecord.class);
    Map<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> inputs = new HashMap<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>();
    for (ComplexResourceKey key : keys) {
        TestRecord testRecord = buildTestRecord(1L, "foo");
        inputs.put(key, testRecord);
        collectionRequest.getElements().add(factory.create(key, testRecord));
    }
    @SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<TestRecord> batchRequest = CollectionRequestUtil.convertToBatchRequest(collectionRequest, ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, TestRecord.class, version);
    Map<String, TestRecord> entities = batchRequest.getEntities();
    Assert.assertEquals(entities.size(), inputs.size());
    for (ComplexResourceKey key : keys) {
        Assert.assertEquals(entities.get(URIParamUtils.keyToString(key, URLEscaper.Escaping.NO_ESCAPING, null, true, version)), inputs.get(key));
    }
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) HashMap(java.util.HashMap) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Aggregations

CollectionRequest (com.linkedin.restli.common.CollectionRequest)16 DataMap (com.linkedin.data.DataMap)7 TestRecord (com.linkedin.restli.client.test.TestRecord)7 Test (org.testng.annotations.Test)7 KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)6 HashMap (java.util.HashMap)5 KeyValueRecordFactory (com.linkedin.restli.common.KeyValueRecordFactory)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 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)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