use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.
the class HashGroupMembershipMgr method getByMember.
@Override
public List<GroupMembership> getByMember(int memberID, MembershipLevel level, int start, int count) {
List<GroupMembership> result = new ArrayList<GroupMembership>();
int idx = 0;
for (GroupMembership value : _data.values()) {
if (value.getMemberID().equals(memberID) && value.getMembershipLevel().equals(level)) {
if (idx >= start && idx < start + count) {
result.add(value);
}
++idx;
}
}
return result;
}
use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.
the class HashMapGroupMgr method create.
@Override
public Group create(Group group) {
Integer id = _sequence.incrementAndGet();
group.setId(id);
_data.put(id, group);
GroupMembership m = group.getOwner();
m.setGroupID(id);
_membershipMgr.save(m);
return group;
}
use of com.linkedin.restli.examples.groups.api.GroupMembership 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.examples.groups.api.GroupMembership 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.examples.groups.api.GroupMembership in project rest.li by linkedin.
the class GroupMembershipsResource2 method update.
/**
* @see AssociationResource#update
*/
@Override
public UpdateResponse update(CompoundKey id, PatchRequest<GroupMembership> patch) {
GroupMembership membership = _app.getMembershipMgr().get(id);
try {
PatchApplier.applyPatch(membership, patch);
} catch (DataProcessingException e) {
return new UpdateResponse(S_400_BAD_REQUEST);
}
validate(membership);
// we set groupID, memberID based on the URI
membership.setId(URIParamUtils.encodeKeyForBody(id, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
membership.setGroupID(getContext().getPathKeys().getAsInt(GROUP_ID));
membership.setMemberID(getContext().getPathKeys().getAsInt(MEMBER_ID));
_app.getMembershipMgr().save(membership);
return new UpdateResponse(S_204_NO_CONTENT);
}
Aggregations