use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class RestLiAnnotationReader method processCollection.
@SuppressWarnings("unchecked")
private static ResourceModel processCollection(final Class<? extends KeyValueResource<?, ?>> collectionResourceClass, ResourceModel parentResourceModel) {
Class<?> keyClass;
Class<? extends RecordTemplate> keyKeyClass = null;
Class<? extends RecordTemplate> keyParamsClass = null;
Class<? extends RecordTemplate> valueClass;
Class<?> complexKeyResourceBase = null;
// type V and the resource key type is ComplexResourceKey<K,P>
if (ComplexKeyResource.class.isAssignableFrom(collectionResourceClass)) {
complexKeyResourceBase = ComplexKeyResource.class;
} else if (ComplexKeyResourceAsync.class.isAssignableFrom(collectionResourceClass)) {
complexKeyResourceBase = ComplexKeyResourceAsync.class;
} else if (ComplexKeyResourceTask.class.isAssignableFrom(collectionResourceClass)) {
complexKeyResourceBase = ComplexKeyResourceTask.class;
} else if (ComplexKeyResourcePromise.class.isAssignableFrom(collectionResourceClass)) {
complexKeyResourceBase = ComplexKeyResourcePromise.class;
}
if (complexKeyResourceBase != null) {
List<Class<?>> kvParams;
if (complexKeyResourceBase.equals(ComplexKeyResource.class)) {
kvParams = ReflectionUtils.getTypeArguments(ComplexKeyResource.class, (Class<? extends ComplexKeyResource<?, ?, ?>>) collectionResourceClass);
} else if (complexKeyResourceBase.equals(ComplexKeyResourceAsync.class)) {
kvParams = ReflectionUtils.getTypeArguments(ComplexKeyResourceAsync.class, (Class<? extends ComplexKeyResourceAsync<?, ?, ?>>) collectionResourceClass);
} else if (complexKeyResourceBase.equals(ComplexKeyResourceTask.class)) {
kvParams = ReflectionUtils.getTypeArguments(ComplexKeyResourceTask.class, (Class<? extends ComplexKeyResourceTask<?, ?, ?>>) collectionResourceClass);
} else {
kvParams = ReflectionUtils.getTypeArguments(ComplexKeyResourcePromise.class, (Class<? extends ComplexKeyResourcePromise<?, ?, ?>>) collectionResourceClass);
}
keyClass = ComplexResourceKey.class;
keyKeyClass = kvParams.get(0).asSubclass(RecordTemplate.class);
keyParamsClass = kvParams.get(1).asSubclass(RecordTemplate.class);
valueClass = kvParams.get(2).asSubclass(RecordTemplate.class);
} else // Otherwise, it's a KeyValueResource, whose parameters are resource key and resource
// value
{
List<Type> actualTypeArguments = ReflectionUtils.getTypeArgumentsParametrized(KeyValueResource.class, collectionResourceClass);
keyClass = ReflectionUtils.getClass(actualTypeArguments.get(0));
if (RecordTemplate.class.isAssignableFrom(keyClass)) {
// ComplexResourceKey
throw new ResourceConfigException("Class '" + collectionResourceClass.getName() + "' should implement 'ComplexKeyResource' as a complex key '" + keyClass.getName() + "' is being used.");
} else if (TyperefInfo.class.isAssignableFrom(keyClass)) {
throw new ResourceConfigException("Typeref '" + keyClass.getName() + "' cannot be key type for class '" + collectionResourceClass.getName() + "'.");
}
if (keyClass.equals(ComplexResourceKey.class)) {
@SuppressWarnings("unchecked") Type[] typeArguments = ((ParameterizedType) actualTypeArguments.get(0)).getActualTypeArguments();
keyKeyClass = ReflectionUtils.getClass(typeArguments[0]).asSubclass(RecordTemplate.class);
keyParamsClass = ReflectionUtils.getClass(typeArguments[1]).asSubclass(RecordTemplate.class);
}
valueClass = ReflectionUtils.getClass(actualTypeArguments.get(1)).asSubclass(RecordTemplate.class);
}
ResourceType resourceType = getResourceType(collectionResourceClass);
RestLiAnnotationData annotationData;
if (collectionResourceClass.isAnnotationPresent(RestLiCollection.class)) {
annotationData = new RestLiAnnotationData(collectionResourceClass.getAnnotation(RestLiCollection.class));
} else if (collectionResourceClass.isAnnotationPresent(RestLiAssociation.class)) {
annotationData = new RestLiAnnotationData(collectionResourceClass.getAnnotation(RestLiAssociation.class));
} else {
throw new ResourceConfigException("No valid annotation on resource class '" + collectionResourceClass.getName() + "'");
}
String name = annotationData.name();
String namespace = annotationData.namespace();
String keyName;
if (annotationData.keyName() == null) {
keyName = name + "Id";
} else {
keyName = annotationData.keyName();
}
Key primaryKey = buildKey(name, keyName, keyClass, annotationData.typerefInfoClass());
Set<Key> keys = new HashSet<Key>();
if (annotationData.keys() == null) {
keys.add(primaryKey);
} else {
keys.addAll(buildKeys(name, annotationData.keys()));
}
Class<?> parentResourceClass = annotationData.parent().equals(RestAnnotations.ROOT.class) ? null : annotationData.parent();
ResourceModel collectionModel = new ResourceModel(primaryKey, keyKeyClass, keyParamsClass, keys, valueClass, collectionResourceClass, parentResourceClass, name, resourceType, namespace);
collectionModel.setParentResourceModel(parentResourceModel);
addResourceMethods(collectionResourceClass, collectionModel);
log.info("Processed collection resource '" + collectionResourceClass.getName() + "'");
return collectionModel;
}
use of com.linkedin.restli.common.ComplexResourceKey in project incubator-gobblin by apache.
the class ThrottlingClientTest method getPermitAllocation.
private PermitAllocation getPermitAllocation(PermitRequest permitRequest, RestClient restClient, PermitsGetRequestBuilder getBuilder) throws Exception {
Request<PermitAllocation> request = getBuilder.id(new ComplexResourceKey<>(permitRequest, new EmptyRecord())).build();
ResponseFuture<PermitAllocation> responseFuture = restClient.sendRequest(request);
Response<PermitAllocation> response = responseFuture.getResponse();
return response.getEntity();
}
use of com.linkedin.restli.common.ComplexResourceKey in project incubator-gobblin by apache.
the class FlowConfigClient method deleteFlowConfig.
/**
* Delete a flow configuration
* @param flowId identifier of flow configuration to delete
* @throws RemoteInvocationException
*/
public void deleteFlowConfig(FlowId flowId) throws RemoteInvocationException {
LOG.debug("deleteFlowConfig with groupName " + flowId.getFlowGroup() + " flowName " + flowId.getFlowName());
DeleteRequest<FlowConfig> deleteRequest = _flowconfigsRequestBuilders.delete().id(new ComplexResourceKey<>(flowId, new EmptyRecord())).build();
ResponseFuture<EmptyRecord> response = _restClient.get().sendRequest(deleteRequest);
response.getResponse();
}
use of com.linkedin.restli.common.ComplexResourceKey in project incubator-gobblin by apache.
the class FlowStatusClient method getFlowStatus.
/**
* Get a flow status
* @param flowStatusId identifier of flow status to get
* @return a {@link FlowStatus} with the flow status
* @throws RemoteInvocationException
*/
public FlowStatus getFlowStatus(FlowStatusId flowStatusId) throws RemoteInvocationException {
LOG.debug("getFlowConfig with groupName " + flowStatusId.getFlowGroup() + " flowName " + flowStatusId.getFlowName());
GetRequest<FlowStatus> getRequest = _flowstatusesRequestBuilders.get().id(new ComplexResourceKey<>(flowStatusId, new EmptyRecord())).build();
Response<FlowStatus> response = _restClient.get().sendRequest(getRequest).getResponse();
return response.getEntity();
}
use of com.linkedin.restli.common.ComplexResourceKey in project incubator-gobblin by apache.
the class JobExecutionInfoResource method batchGet.
@Override
public Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> batchGet(Set<ComplexResourceKey<JobExecutionQuery, EmptyRecord>> keys) {
Map<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> results = Maps.newHashMap();
for (ComplexResourceKey<JobExecutionQuery, EmptyRecord> key : keys) {
JobExecutionQueryResult result = get(key);
if (result != null) {
results.put(key, get(key));
}
}
ResourceContext rc = this.getContext();
rc.setResponseHeader("Access-Control-Allow-Origin", "*");
this.setContext(rc);
return results;
}
Aggregations