Search in sources :

Example 11 with GroupMembership

use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.

the class TestGroupsRequestBuilders method requestMembershipsBuilderDataProviderEntityFinderByMember.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProviderEntityFinderByMember")
private static Object[][] requestMembershipsBuilderDataProviderEntityFinderByMember() {
    //Sample URIs:
    //"groupMemberships/memberID=1?q=member"
    //"groupMemberships/(memberID:1)?q=member"
    final Map<String, String> queryParamsMap = new HashMap<String, String>();
    queryParamsMap.put("q", "member");
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groupMemberships/memberID=1", null, queryParamsMap, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groupMemberships/(memberID:1)", null, queryParamsMap, null);
    return new Object[][] { { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails2 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails2 } };
}
Also used : URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) GroupMembershipsBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders) DataProvider(org.testng.annotations.DataProvider)

Example 12 with GroupMembership

use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.

the class TestGroupsRequestBuilders method requestMembershipsBuilderDataProviderEntityFinderByGroup.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProviderEntityFinderByGroup")
private static Object[][] requestMembershipsBuilderDataProviderEntityFinderByGroup() {
    //Sample URIs:
    //"groupMemberships/groupID=1?email=bruce@test.linkedin.com&firstName=Bruce&lastName=Willis&level=MEMBER&q=group&sort=LAST_NAME_ASC"
    //"groupMemberships/(groupID:1)?email=bruce@test.linkedin.com&firstName=Bruce&lastName=Willis&level=MEMBER&q=group&sort=LAST_NAME_ASC"
    final Map<String, String> queryParamsMap = new HashMap<String, String>();
    queryParamsMap.put("email", "bruce@test.linkedin.com");
    queryParamsMap.put("firstName", "Bruce");
    queryParamsMap.put("lastName", "Willis");
    queryParamsMap.put("level", "MEMBER");
    queryParamsMap.put("q", "group");
    queryParamsMap.put("sort", "LAST_NAME_ASC");
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groupMemberships/groupID=1", null, queryParamsMap, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groupMemberships/(groupID:1)", null, queryParamsMap, null);
    return new Object[][] { { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsBuilders()), uriDetails2 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails1 }, { new RootBuilderWrapper<CompoundKey, GroupMembership>(new GroupMembershipsRequestBuilders()), uriDetails2 } };
}
Also used : URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipsRequestBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) GroupMembershipsBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders) DataProvider(org.testng.annotations.DataProvider)

Example 13 with GroupMembership

use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.

the class TestGroupsRequestBuilders method testAssociationEntityUpdate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProviderEntity")
public void testAssociationEntityUpdate(RootBuilderWrapper<CompoundKey, GroupMembership> builders, URIDetails expectedURIDetails) throws IOException, RestException {
    GroupMembership membership = new GroupMembership();
    membership.setLastName("Anderson");
    PatchRequest<GroupMembership> patch = PatchGenerator.diffEmpty(membership);
    GroupMembershipsBuilders.Key key = new GroupMembershipsBuilders.Key().setGroupId(7).setMemberId(1);
    Request<EmptyRecord> request = builders.partialUpdate().id(key).input(patch).build();
    checkRequestBuilder(request, ResourceMethod.PARTIAL_UPDATE, EmptyResponseDecoder.class, expectedURIDetails, patch);
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) GroupMembershipsBuilders(com.linkedin.restli.examples.groups.client.GroupMembershipsBuilders) CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Example 14 with GroupMembership

use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.

the class HashGroupMembershipMgr method search.

@Override
public List<GroupMembership> search(GroupMembershipSearchQuery query) {
    List<GroupMembership> result = new ArrayList<GroupMembership>();
    int counter = 0;
    for (Map.Entry<CompoundKey, GroupMembership> entry : _data.entrySet()) {
        if (query.getStart() > counter) {
            counter++;
            continue;
        }
        if (query.getCount() > 0 && query.getStart() + query.getCount() < counter) {
            break;
        }
        GroupMembership value = entry.getValue();
        boolean match = (query.getGroupID() == GroupMembershipSearchQuery.WILDCARD || query.getGroupID() == value.getGroupID());
        if (query.getFirstName() != null) {
            match = match && query.getFirstName().equals(value.getFirstName());
        }
        if (query.getLastName() != null) {
            match = match && query.getLastName().equals(value.getLastName());
        }
        if (query.getMembershipLevel() != null) {
            match = match && query.getMembershipLevel().equals(value.getMembershipLevel());
        }
        if (match) {
            result.add(value);
        }
        counter++;
    }
    return result;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with GroupMembership

use of com.linkedin.restli.examples.groups.api.GroupMembership in project rest.li by linkedin.

the class GroupMembershipsResource2 method batchUpdate.

@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchPatchRequest<CompoundKey, GroupMembership> patches) {
    Map<CompoundKey, UpdateResponse> results = new HashMap<CompoundKey, UpdateResponse>();
    for (Map.Entry<CompoundKey, PatchRequest<GroupMembership>> entry : patches.getData().entrySet()) {
        CompoundKey key = entry.getKey();
        PatchRequest<GroupMembership> patch = entry.getValue();
        GroupMembership groupMembership = _app.getMembershipMgr().get(key);
        if (groupMembership == null) {
            results.put(key, new UpdateResponse(HttpStatus.S_404_NOT_FOUND));
        } else {
            try {
                PatchApplier.applyPatch(groupMembership, patch);
                _app.getMembershipMgr().save(groupMembership);
                results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
            } catch (DataProcessingException e) {
                results.put(key, new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
            }
        }
    }
    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) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) HashMap(java.util.HashMap) Map(java.util.Map) 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