Search in sources :

Example 51 with CompoundKey

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

the class TestClientBuilders method testUpdateCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "compoundKey")
public void testUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
    UpdateRequestBuilder<CompoundKey, TestRecord> builder = new UpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord record = new TestRecord().setMessage("foo");
    UpdateRequest<TestRecord> request = builder.id(buildCompoundKey()).input(record).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), true);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.UPDATE, record, Collections.<String, String>emptyMap(), null);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 52 with CompoundKey

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

the class BatchGetRequestBuilderTest method testCompoundKeyBatchingWithoutTypedKeys.

@Test
public void testCompoundKeyBatchingWithoutTypedKeys() {
    GetRequestBuilder<CompoundKey, TestRecord> requestBuilder2 = new GetRequestBuilder<CompoundKey, TestRecord>("/", TestRecord.class, _compoundResourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    CompoundKey key = new CompoundKey().append("abc", 1).append("def", 2);
    requestBuilder2.id(key);
    GetRequest<TestRecord> request2 = requestBuilder2.build();
    try {
        BatchGetRequestBuilder.batch(request2);
        Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
    } catch (UnsupportedOperationException exc) {
    }
    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("ids", Arrays.asList((Object) key));
    BatchGetRequest<TestRecord> request4 = new BatchGetRequest<TestRecord>(Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new BatchResponseDecoder<TestRecord>(TestRecord.class), queryParams, Collections.<String, Class<?>>emptyMap(), _compoundResourceSpec, "/", Collections.<String, Object>emptyMap(), RestliRequestOptions.DEFAULT_OPTIONS);
    try {
        @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(request4);
        BatchGetRequestBuilder.batch(requests);
        Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
    } catch (UnsupportedOperationException exc) {
    }
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 53 with CompoundKey

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

the class TestAbstractRequestBuilder method testAssocKeysAreReadOnly.

@Test
public void testAssocKeysAreReadOnly() {
    final AbstractRequestBuilder<Object, ?, ?> builder = new DummyAbstractRequestBuilder();
    builder.addAssocKey("abc", 5);
    builder.addAssocKey("abc2", 6);
    CompoundKey compoundKey = builder.buildReadOnlyAssocKey();
    Assert.assertTrue(compoundKey.isReadOnly());
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Example 54 with CompoundKey

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

the class HashGroupMembershipMgr method search.

@Override
public List<GroupMembership> search(GroupMembershipSearchQuery query) {
    List<GroupMembership> result = new ArrayList<GroupMembership>();
    int counter = 0;
    for (Map.Entry<CompoundKey, GroupMembership> entry : _data.entrySet()) {
        if (query.getStart() > counter) {
            counter++;
            continue;
        }
        if (query.getCount() > 0 && query.getStart() + query.getCount() < counter) {
            break;
        }
        GroupMembership value = entry.getValue();
        boolean match = (query.getGroupID() == GroupMembershipSearchQuery.WILDCARD || query.getGroupID() == value.getGroupID());
        if (query.getFirstName() != null) {
            match = match && query.getFirstName().equals(value.getFirstName());
        }
        if (query.getLastName() != null) {
            match = match && query.getLastName().equals(value.getLastName());
        }
        if (query.getMembershipLevel() != null) {
            match = match && query.getMembershipLevel().equals(value.getMembershipLevel());
        }
        if (match) {
            result.add(value);
        }
        counter++;
    }
    return result;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) HashMap(java.util.HashMap) Map(java.util.Map)

Example 55 with CompoundKey

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

the class GroupMembershipsResource2 method batchUpdate.

@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchPatchRequest<CompoundKey, GroupMembership> patches) {
    Map<CompoundKey, UpdateResponse> results = new HashMap<CompoundKey, UpdateResponse>();
    for (Map.Entry<CompoundKey, PatchRequest<GroupMembership>> entry : patches.getData().entrySet()) {
        CompoundKey key = entry.getKey();
        PatchRequest<GroupMembership> patch = entry.getValue();
        GroupMembership groupMembership = _app.getMembershipMgr().get(key);
        if (groupMembership == null) {
            results.put(key, new UpdateResponse(HttpStatus.S_404_NOT_FOUND));
        } else {
            try {
                PatchApplier.applyPatch(groupMembership, patch);
                _app.getMembershipMgr().save(groupMembership);
                results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
            } catch (DataProcessingException e) {
                results.put(key, new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
            }
        }
    }
    return new BatchUpdateResult<CompoundKey, GroupMembership>(results);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) HashMap(java.util.HashMap) Map(java.util.Map) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Aggregations

CompoundKey (com.linkedin.restli.common.CompoundKey)94 Test (org.testng.annotations.Test)48 HashMap (java.util.HashMap)26 DataProvider (org.testng.annotations.DataProvider)20 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)17 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)16 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)15 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)14 AfterTest (org.testng.annotations.AfterTest)13 BeforeTest (org.testng.annotations.BeforeTest)13 DataMap (com.linkedin.data.DataMap)12 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)12 Key (com.linkedin.restli.server.Key)11 Followed (com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed)10 HashSet (java.util.HashSet)10 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)9 TestRecord (com.linkedin.restli.client.test.TestRecord)9 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)9 AsyncFollowsAssociativeResource (com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource)9 EmptyRecord (com.linkedin.restli.common.EmptyRecord)8