use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class RestLiRouter method processResourceTree.
private RoutingResult processResourceTree(final ResourceModel resource, final ServerResourceContext context, final Queue<String> remainingPath) {
ResourceModel currentResource = resource;
// iterate through all path segments, simultaneously descending the resource hierarchy
// and parsing path keys where applicable;
// the goal of this loop is to locate the leaf resource, which will be set in
// currentResource, and to parse the necessary information into the context
ResourceLevel currentLevel = currentResource.getResourceLevel();
while (remainingPath.peek() != null) {
String currentPathSegment = remainingPath.poll();
if (currentLevel.equals(ResourceLevel.ENTITY)) {
currentResource = currentResource.getSubResource(parseSubresourceName(currentPathSegment));
currentLevel = currentResource == null ? ResourceLevel.ANY : currentResource.getResourceLevel();
} else {
ResourceModel currentCollectionResource = currentResource;
if (currentResource.getKeys().isEmpty()) {
throw new RoutingException(String.format("Path key not supported on resource '%s' for URI '%s'", currentResource.getName(), context.getRequestURI()), HttpStatus.S_400_BAD_REQUEST.getCode());
} else if (context.getParameters().containsKey(RestConstants.ALT_KEY_PARAM)) {
parseAlternativeKey(currentResource, context, currentPathSegment);
currentLevel = ResourceLevel.ENTITY;
} else if (currentResource.getKeyClass() == ComplexResourceKey.class) {
parseComplexKey(currentResource, context, currentPathSegment);
currentLevel = ResourceLevel.ENTITY;
} else if (currentResource.getKeyClass() == CompoundKey.class) {
CompoundKey compoundKey;
try {
compoundKey = parseCompoundKey(currentCollectionResource, context, currentPathSegment);
} catch (IllegalArgumentException e) {
throw new RoutingException(String.format("Malformed Compound Key: '%s'", currentPathSegment), HttpStatus.S_400_BAD_REQUEST.getCode(), e);
}
if (compoundKey != null && compoundKey.getPartKeys().containsAll(currentResource.getKeyNames())) {
// full match on key parts means that we are targeting a unique entity
currentLevel = ResourceLevel.ENTITY;
}
} else // Must be a simple key then
{
parseSimpleKey(currentResource, context, currentPathSegment);
currentLevel = ResourceLevel.ENTITY;
}
}
if (currentResource == null) {
throw new RoutingException(HttpStatus.S_404_NOT_FOUND.getCode());
}
}
//now we know the key type, look for batch parameter
parseBatchKeysParameter(currentResource, context);
return findMethodDescriptor(currentResource, currentLevel, context);
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class ChainedTyperefResource method batchUpdate.
@Override
public BatchUpdateResult<CompoundKey, Greeting> batchUpdate(BatchUpdateRequest<CompoundKey, Greeting> entities) {
Set<CompoundKey> keys = entities.getData().keySet();
Map<CompoundKey, UpdateResponse> responseMap = new HashMap<CompoundKey, UpdateResponse>();
Map<CompoundKey, RestLiServiceException> errorMap = new HashMap<CompoundKey, RestLiServiceException>();
for (CompoundKey key : keys) {
responseMap.put(key, new UpdateResponse(HttpStatus.S_201_CREATED));
}
return new BatchUpdateResult<CompoundKey, Greeting>(responseMap);
}
use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.
the class TestGroupsRequestBuilders method requestMembershipsBuilderDataProviderEntityFinderByGroupWithOptional.
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBuilderDataProviderEntityFinderByGroupWithOptional")
private static Object[][] requestMembershipsBuilderDataProviderEntityFinderByGroupWithOptional() {
//Sample URIs:
//"groupMemberships/groupID=1?firstName=Bruce&q=group"
//"groupMemberships/(groupID:1)?firstName=Bruce&q=group"
final Map<String, String> queryParamsMap = new HashMap<String, String>();
queryParamsMap.put("firstName", "Bruce");
queryParamsMap.put("q", "group");
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.common.CompoundKey in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method generateKey.
private Object generateKey(ResourceSpec resourceSpec, ResourceSchema resourceSchema, Integer batchIdx) {
if (resourceSpec.getKeyType() == null) {
throw new IllegalArgumentException("Cannot generate key for keyless resource.");
}
switch(toResourceKeyType(resourceSpec.getKeyType().getType())) {
case COMPLEX:
RecordDataSchema keySchema = (RecordDataSchema) resourceSpec.getComplexKeyType().getKeyType().getSchema();
DataMap keyData = (DataMap) _dataGenerator.buildData(postfixBatchIdx(keySchema.getName() + "Key", batchIdx), keySchema);
RecordDataSchema paramsSchema = (RecordDataSchema) resourceSpec.getComplexKeyType().getParamsType().getSchema();
DataMap paramsData = (DataMap) _dataGenerator.buildData(postfixBatchIdx(keySchema.getName() + "Params", batchIdx), paramsSchema);
return new ComplexResourceKey<RecordTemplatePlaceholder, RecordTemplatePlaceholder>(new RecordTemplatePlaceholder(keyData, keySchema), new RecordTemplatePlaceholder(paramsData, paramsSchema));
case COMPOUND:
CompoundKey compoundKey = new CompoundKey();
for (Map.Entry<String, CompoundKey.TypeInfo> keyPart : resourceSpec.getKeyParts().entrySet()) {
String key = keyPart.getKey();
CompoundKey.TypeInfo typeInfo = keyPart.getValue();
compoundKey.append(key, _dataGenerator.buildData(postfixBatchIdx(key, batchIdx), typeInfo.getBinding().getSchema()));
}
return compoundKey;
case PRIMITIVE:
String keyName = resourceSchema.getCollection().getIdentifier().getName();
return _dataGenerator.buildData(postfixBatchIdx(keyName, batchIdx), resourceSpec.getKeyType().getSchema());
case NONE:
return null;
default:
throw new IllegalStateException("Unknown enum value: " + resourceSpec.getKeyType().getType());
}
}
use of com.linkedin.restli.common.CompoundKey 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 } };
}
Aggregations