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