use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class GroupMembershipsResource3 method create.
/** @see com.linkedin.restli.server.resources.ComplexKeyResourceTemplate#create(com.linkedin.data.template.RecordTemplate) */
@Override
public CreateResponse create(ComplexKeyGroupMembership groupMembership) {
// object
if (!groupMembership.getId().hasMemberID() || !groupMembership.getId().hasGroupID()) {
throw new RestLiServiceException(S_400_BAD_REQUEST, "groupID and memberID fields must be set while creating a ComplexKeyGroupMembership.");
}
GroupMembershipKey groupMembershipKey = new GroupMembershipKey();
groupMembershipKey.setMemberID(groupMembership.getId().getMemberID());
groupMembershipKey.setGroupID(groupMembership.getId().getGroupID());
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexResourceKey = new ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>(groupMembershipKey, new GroupMembershipParam());
groupMembership.setId(complexResourceKey.getKey());
_app.getMembershipMgr().save(toGroupMembership(groupMembership));
return new CreateResponse(complexResourceKey, HttpStatus.S_201_CREATED);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class GroupMembershipsResource3 method batchGet.
/**
* @see GroupMembershipsResource2#batchGet(Set)
*/
@Override
public BatchResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> batchGet(Set<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>> ids) {
Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> result = new HashMap<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership>(ids.size());
Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, RestLiServiceException> errors = new HashMap<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, RestLiServiceException>();
Iterator<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>> iterator = ids.iterator();
while (iterator.hasNext()) {
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> key = iterator.next();
ComplexKeyGroupMembership membership = fromGroupMembership(_app.getMembershipMgr().get(complexKeyToCompoundKey(key)));
if (membership != null) {
result.put(key, membership);
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership>(result, errors);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestComplexArrayResource method testGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGet(RootBuilderWrapper<ComplexResourceKey<ComplexArray, ComplexArray>, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
// all array are singletons with single element
LongArray singleton = new LongArray();
singleton.add(1L);
ComplexArray next = new ComplexArray().setArray(singleton);
ComplexArray key = new ComplexArray().setArray(singleton).setNext(next);
ComplexArray params = new ComplexArray().setArray(singleton).setNext(next);
ComplexResourceKey<ComplexArray, ComplexArray> complexKey = new ComplexResourceKey<ComplexArray, ComplexArray>(key, params);
Request<Greeting> request = builders.get().id(complexKey).build();
getClient().sendRequest(request).getResponse().getEntity();
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestGroupsClient method testComplexKeyBatchCreateGetUpdateDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexBuilderDataProvider")
public void testComplexKeyBatchCreateGetUpdateDelete(ProtocolVersion version, RootBuilderWrapper<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> builders) throws RemoteInvocationException {
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey1 = buildComplexKey(1, 1, 10, "String1");
ComplexKeyGroupMembership groupMembership1 = buildComplexKeyGroupMembership(complexKey1.getKey(), "alfred@test.linkedin.com", "alfred", "hitchcock");
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey2 = buildComplexKey(2, 1, 20, "String2");
ComplexKeyGroupMembership groupMembership2 = buildComplexKeyGroupMembership(complexKey2.getKey(), "bruce@test.linkedin.com", "bruce", "willis");
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey3 = buildComplexKey(3, 1, 30, "String3");
ComplexKeyGroupMembership groupMembership3 = buildComplexKeyGroupMembership(complexKey3.getKey(), "carole@test.linkedin.com", "carole", "bouquet");
Request<CollectionResponse<CreateStatus>> createRequest = builders.batchCreate().input(groupMembership1).input(groupMembership2).input(groupMembership3).build();
Response<CollectionResponse<CreateStatus>> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertEquals(createResponse.getStatus(), 200);
final RestliRequestOptions requestOptions = builders.getRequestOptions();
@SuppressWarnings("unchecked") Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>>> request = new GroupMembershipsComplexRequestBuilders(requestOptions).batchGet().ids(complexKey1, complexKey2, complexKey3).fields(GroupMembership.fields().contactEmail()).build();
BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity();
Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> results = groupMemberships.getResults();
ComplexKeyGroupMembership groupMembership1_ = results.get(complexKey1).getEntity();
ComplexKeyGroupMembership groupMembership2_ = results.get(complexKey2).getEntity();
ComplexKeyGroupMembership groupMembership3_ = results.get(complexKey3).getEntity();
Assert.assertNotNull(groupMembership1_);
Assert.assertEquals(groupMembership1_.getContactEmail(), "alfred@test.linkedin.com");
Assert.assertNotNull(groupMembership2_);
Assert.assertEquals(groupMembership2_.getContactEmail(), "bruce@test.linkedin.com");
Assert.assertNotNull(groupMembership3_);
Assert.assertEquals(groupMembership3_.getContactEmail(), "carole@test.linkedin.com");
// Update and verify
groupMembership1.setContactEmail("alfred+@test.linkedin.com");
groupMembership2.setContactEmail("bruce+@test.linkedin.com");
groupMembership3.setContactEmail("carole+@test.linkedin.com");
Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, UpdateStatus>> updateRequest = builders.batchUpdate().input(complexKey1, groupMembership1).input(complexKey2, groupMembership2).input(complexKey3, groupMembership3).build();
int status = getClient().sendRequest(updateRequest).getResponse().getStatus();
Assert.assertEquals(status, 200);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class MockBatchEntityResponseFactory method createWithComplexKey.
/**
* Create a {@link BatchKVResponse} where the key is a {@link ComplexResourceKey}
*
* @param valueClass the value class
* @param keyKeyClass the class of the key part of the {@link ComplexResourceKey}
* @param keyParamsClass the class of the params part of the {@link ComplexResourceKey}
* @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param statuses The HTTP status codes that will be returned as part of {@link EntityResponse}s
* returned in {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param <V>
* @return
*/
@SuppressWarnings("rawtypes")
public static <KK extends RecordTemplate, KP extends RecordTemplate, V extends RecordTemplate> BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>> createWithComplexKey(Class<V> valueClass, Class<KK> keyKeyClass, Class<KP> keyParamsClass, Map<ComplexResourceKey<KK, KP>, V> recordTemplates, Map<ComplexResourceKey<KK, KP>, HttpStatus> statuses, Map<ComplexResourceKey<KK, KP>, ErrorResponse> errorResponses) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
DataMap batchResponseDataMap = buildDataMap(recordTemplates, statuses, errorResponses, version);
@SuppressWarnings("unchecked") BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>> response = (BatchKVResponse<ComplexResourceKey<KK, KP>, EntityResponse<V>>) (Object) new BatchEntityResponse<ComplexResourceKey, V>(batchResponseDataMap, new TypeSpec<ComplexResourceKey>(ComplexResourceKey.class), TypeSpec.forClassMaybeNull(valueClass), null, ComplexKeySpec.forClassesMaybeNull(keyKeyClass, keyParamsClass), version);
return response;
}
Aggregations