Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with CompoundKey

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

the class GroupMembershipsResource3 method toGroupMembership.

// This is a hack for the sample resource. So as not to write a separate persistence for this resource,
// convert from and to GroupMembership.
private static GroupMembership toGroupMembership(ComplexKeyGroupMembership complexKeyMembership) {
    GroupMembership groupMembership = new GroupMembership(complexKeyMembership.data());
    GroupMembershipKey complexKey = complexKeyMembership.getId();
    CompoundKey compoundKey = new CompoundKey().append(GROUP_ID, complexKey.getGroupID()).append(MEMBER_ID, complexKey.getMemberID());
    groupMembership.setId(URIParamUtils.encodeKeyForBody(compoundKey, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
    groupMembership.setMemberID(complexKey.getMemberID());
    groupMembership.setGroupID(complexKey.getGroupID());
    return groupMembership;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)

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