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 } };
}
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();
}
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;
}
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);
}
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);
}
Aggregations