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