use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestClientBuilders method testUpdateCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "compoundKey")
public void testUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
UpdateRequestBuilder<CompoundKey, TestRecord> builder = new UpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord record = new TestRecord().setMessage("foo");
UpdateRequest<TestRecord> request = builder.id(buildCompoundKey()).input(record).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), true);
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.UPDATE, record, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testCompoundKeyBatchingWithoutTypedKeys.
@Test
public void testCompoundKeyBatchingWithoutTypedKeys() {
GetRequestBuilder<CompoundKey, TestRecord> requestBuilder2 = new GetRequestBuilder<CompoundKey, TestRecord>("/", TestRecord.class, _compoundResourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
CompoundKey key = new CompoundKey().append("abc", 1).append("def", 2);
requestBuilder2.id(key);
GetRequest<TestRecord> request2 = requestBuilder2.build();
try {
BatchGetRequestBuilder.batch(request2);
Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
} catch (UnsupportedOperationException exc) {
}
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("ids", Arrays.asList((Object) key));
BatchGetRequest<TestRecord> request4 = new BatchGetRequest<TestRecord>(Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new BatchResponseDecoder<TestRecord>(TestRecord.class), queryParams, Collections.<String, Class<?>>emptyMap(), _compoundResourceSpec, "/", Collections.<String, Object>emptyMap(), RestliRequestOptions.DEFAULT_OPTIONS);
try {
@SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(request4);
BatchGetRequestBuilder.batch(requests);
Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
} catch (UnsupportedOperationException exc) {
}
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestAbstractRequestBuilder method testAssocKeysAreReadOnly.
@Test
public void testAssocKeysAreReadOnly() {
final AbstractRequestBuilder<Object, ?, ?> builder = new DummyAbstractRequestBuilder();
builder.addAssocKey("abc", 5);
builder.addAssocKey("abc2", 6);
CompoundKey compoundKey = builder.buildReadOnlyAssocKey();
Assert.assertTrue(compoundKey.isReadOnly());
}
use of com.linkedin.restli.common.CompoundKey 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.common.CompoundKey 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