Search in sources :

Example 1 with GroupMembership

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;
}
Also used : ArrayList(java.util.ArrayList) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership)

Example 2 with GroupMembership

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership)

Example 3 with GroupMembership

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

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

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);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Aggregations

GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)19 CompoundKey (com.linkedin.restli.common.CompoundKey)15 HashMap (java.util.HashMap)8 GroupMembershipsBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders)7 GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)7 ComplexKeyGroupMembership (com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)6 Test (org.testng.annotations.Test)6 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)4 DataProvider (org.testng.annotations.DataProvider)4 UpdateResponse (com.linkedin.restli.server.UpdateResponse)3 Map (java.util.Map)3 DataProcessingException (com.linkedin.data.transform.DataProcessingException)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2 PatchRequest (com.linkedin.restli.common.PatchRequest)2 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)1