Search in sources :

Example 31 with CompoundKey

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

the class TestRestLiRouting method nKeyAssociationRoutingBatch.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "nKeyAssociationRoutingBatch")
public Object[][] nKeyAssociationRoutingBatch() {
    CompoundKey key1 = new CompoundKey();
    key1.append("foo", "1,1").append("bar", "1:2");
    CompoundKey key2 = new CompoundKey();
    key2.append("foo", "2,1").append("bar", "2;2");
    Set<CompoundKey> keys = new HashSet<CompoundKey>();
    keys.add(key1);
    keys.add(key2);
    return new Object[][] { { "/test?ids=bar%3D1%253A2%26foo%3D1%252C1&ids=bar%3D2%253B2%26foo%3D2%252C1", AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "GET", ResourceMethod.BATCH_GET, "batchGet", keys }, { "/test?ids=List((bar:1%3A2,foo:1%2C1),(bar:2;2,foo:2%2C1))", AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "GET", ResourceMethod.BATCH_GET, "batchGet", keys } };
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) HashSet(java.util.HashSet) DataProvider(org.testng.annotations.DataProvider)

Example 32 with CompoundKey

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

the class ExampleRequestResponseGenerator method buildFinderRequest.

private FindRequest<RecordTemplatePlaceholder> buildFinderRequest(FinderSchema finderSchema) {
    FindRequestBuilder<Object, RecordTemplatePlaceholder> finder = new FindRequestBuilder<Object, RecordTemplatePlaceholder>(_uriTemplate, RecordTemplatePlaceholder.class, _resourceSpec, _requestOptions);
    finder.name(finderSchema.getName());
    if (finderSchema.hasAssocKeys()) {
        CompoundKey key = (CompoundKey) generateKey();
        for (String partKey : finderSchema.getAssocKeys()) {
            finder.assocKey(partKey, key.getPart(partKey));
        }
    } else if (// why do we have a separate field for the singular form?  assocKeys and assocKey.
    finderSchema.hasAssocKey()) {
        String partKey = finderSchema.getAssocKey();
        CompoundKey key = (CompoundKey) generateKey();
        finder.assocKey(partKey, key.getPart(partKey));
    }
    if (finderSchema.hasParameters() && !finderSchema.getParameters().isEmpty()) {
        addParams(finder, finderSchema.getParameters());
    }
    addPathKeys(finder);
    return finder.build();
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) FindRequestBuilder(com.linkedin.restli.client.FindRequestBuilder)

Example 33 with CompoundKey

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

the class HashGroupMembershipMgr method save.

@Override
public GroupMembership save(GroupMembership membership) {
    int groupID = membership.getGroupID();
    int memberID = membership.getMemberID();
    CompoundKey key = buildKey(groupID, memberID);
    membership.setId(URIParamUtils.encodeKeyForBody(key, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
    _data.put(key, membership);
    return membership;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey)

Example 34 with CompoundKey

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

the class GroupMembershipsResource2 method batchGet.

/**
  * @see GroupMembershipsResource2#batchGet(Set)
  */
@Override
public BatchResult<CompoundKey, GroupMembership> batchGet(Set<CompoundKey> ids) {
    Map<CompoundKey, GroupMembership> result = new HashMap<CompoundKey, GroupMembership>(ids.size());
    Map<CompoundKey, RestLiServiceException> errors = new HashMap<CompoundKey, RestLiServiceException>();
    Iterator<CompoundKey> iterator = ids.iterator();
    while (iterator.hasNext()) {
        CompoundKey key = iterator.next();
        GroupMembership membership = _app.getMembershipMgr().get(key);
        if (membership != null) {
            result.put(key, membership);
        } else {
            errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
        }
    }
    return new BatchResult<CompoundKey, GroupMembership>(result, errors);
}
Also used : RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) BatchResult(com.linkedin.restli.server.BatchResult)

Example 35 with CompoundKey

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

the class GroupMembershipsResource2 method batchUpdate.

/** @see com.linkedin.restli.server.resources.AssociationResourceTemplate#batchUpdate(com.linkedin.restli.server.BatchUpdateRequest) */
@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchUpdateRequest<CompoundKey, GroupMembership> entities) {
    Map<CompoundKey, UpdateResponse> results = new HashMap<CompoundKey, UpdateResponse>();
    for (Map.Entry<CompoundKey, GroupMembership> entry : entities.getData().entrySet()) {
        CompoundKey id = entry.getKey();
        GroupMembership membership = entry.getValue();
        membership.setId(URIParamUtils.encodeKeyForBody(id, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
        membership.setGroupID(((Integer) id.getPart(GROUP_ID)));
        membership.setMemberID(((Integer) id.getPart(MEMBER_ID)));
        _app.getMembershipMgr().save(membership);
        results.put(id, new UpdateResponse(S_204_NO_CONTENT));
    }
    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) HashMap(java.util.HashMap) Map(java.util.Map)

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