use of com.linkedin.restli.restspec.RestMethodSchema in project rest.li by linkedin.
the class TestExamplesGenerator method findRestMethod.
private static RestMethodSchema findRestMethod(ResourceSchema resourceSchema, ResourceMethod method) {
RestMethodSchemaArray methods = null;
RestMethodSchema methodResult = null;
final CollectionSchema collectionSchema = resourceSchema.getCollection();
if (collectionSchema != null) {
methods = collectionSchema.getMethods();
}
final AssociationSchema associationSchema = resourceSchema.getAssociation();
if (associationSchema != null) {
methods = associationSchema.getMethods();
}
final SimpleSchema simpleSchema = resourceSchema.getSimple();
if (simpleSchema != null) {
methods = simpleSchema.getMethods();
}
if (methods != null) {
for (RestMethodSchema restMethodSchema : methods) {
if (restMethodSchema.getMethod().equalsIgnoreCase(method.name())) {
methodResult = restMethodSchema;
break;
}
}
}
return methodResult;
}
use of com.linkedin.restli.restspec.RestMethodSchema in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method generateBasicMethods.
@SuppressWarnings("deprecation")
private void generateBasicMethods(JDefinedClass facadeClass, JExpression baseUriExpr, JClass keyClass, JClass valueClass, Set<ResourceMethod> supportedMethods, RestMethodSchemaArray restMethods, JVar resourceSpecField, String resourceName, List<String> pathKeys, Map<String, JClass> pathKeyTypes, Map<String, JClass> assocKeyTypes, Map<String, List<String>> pathToAssocKeys, JExpression requestOptionsExpr, DataMap annotations) throws JClassAlreadyExistsException {
final Map<ResourceMethod, RestMethodSchema> schemaMap = new HashMap<ResourceMethod, RestMethodSchema>();
if (restMethods != null) {
for (RestMethodSchema restMethod : restMethods) {
schemaMap.put(ResourceMethod.fromString(restMethod.getMethod()), restMethod);
}
}
final Map<ResourceMethod, Class<?>> crudBuilderClasses = new HashMap<ResourceMethod, Class<?>>();
if (_version == RestliVersion.RESTLI_2_0_0) {
crudBuilderClasses.put(ResourceMethod.CREATE, CreateIdRequestBuilderBase.class);
} else {
// we use fully qualified class name to avoid importing the deprecated class
// so far in Java there is no way to suppress deprecation warning for import
crudBuilderClasses.put(ResourceMethod.CREATE, com.linkedin.restli.client.base.CreateRequestBuilderBase.class);
}
crudBuilderClasses.put(ResourceMethod.GET, GetRequestBuilderBase.class);
crudBuilderClasses.put(ResourceMethod.UPDATE, UpdateRequestBuilderBase.class);
crudBuilderClasses.put(ResourceMethod.PARTIAL_UPDATE, PartialUpdateRequestBuilderBase.class);
crudBuilderClasses.put(ResourceMethod.DELETE, DeleteRequestBuilderBase.class);
if (_version == RestliVersion.RESTLI_2_0_0) {
crudBuilderClasses.put(ResourceMethod.BATCH_CREATE, BatchCreateIdRequestBuilderBase.class);
} else {
// we use fully qualified class name to avoid importing the deprecated class
// so far in Java there is no way to suppress deprecation warning for import
crudBuilderClasses.put(ResourceMethod.BATCH_CREATE, com.linkedin.restli.client.base.BatchCreateRequestBuilderBase.class);
}
crudBuilderClasses.put(ResourceMethod.BATCH_UPDATE, BatchUpdateRequestBuilderBase.class);
crudBuilderClasses.put(ResourceMethod.BATCH_PARTIAL_UPDATE, BatchPartialUpdateRequestBuilderBase.class);
crudBuilderClasses.put(ResourceMethod.BATCH_DELETE, BatchDeleteRequestBuilderBase.class);
crudBuilderClasses.put(ResourceMethod.GET_ALL, GetAllRequestBuilderBase.class);
if (_version == RestliVersion.RESTLI_2_0_0) {
crudBuilderClasses.put(ResourceMethod.BATCH_GET, BatchGetEntityRequestBuilderBase.class);
} else {
// we use fully qualified class name to avoid importing the deprecated class
// so far in Java there is no way to suppress deprecation warning for import
crudBuilderClasses.put(ResourceMethod.BATCH_GET, com.linkedin.restli.client.base.BatchGetRequestBuilderBase.class);
}
for (Map.Entry<ResourceMethod, Class<?>> entry : crudBuilderClasses.entrySet()) {
final ResourceMethod method = entry.getKey();
final Class<?> refModel = entry.getValue();
if (supportedMethods.contains(method)) {
final String methodName = RestLiToolsUtils.normalizeUnderscores(method.toString());
final RestMethodSchema schema = schemaMap.get(method);
generateDerivedBuilderAndJavaDoc(facadeClass, baseUriExpr, keyClass, valueClass, resourceSpecField, resourceName, pathKeys, pathKeyTypes, assocKeyTypes, pathToAssocKeys, requestOptionsExpr, annotations, method, refModel, methodName, schema);
if ((method == ResourceMethod.CREATE || method == ResourceMethod.BATCH_CREATE) && schema != null && schema.getAnnotations() != null && schema.getAnnotations().containsKey("returnEntity")) {
Class<?> newBuildClass = methodName.equals("create") ? CreateIdEntityRequestBuilderBase.class : BatchCreateIdEntityRequestBuilderBase.class;
String requestName = methodName.equals("create") ? "createAndGet" : "batchCreateAndGet";
generateDerivedBuilderAndJavaDoc(facadeClass, baseUriExpr, keyClass, valueClass, resourceSpecField, resourceName, pathKeys, pathKeyTypes, assocKeyTypes, pathToAssocKeys, requestOptionsExpr, annotations, method, newBuildClass, requestName, schema);
}
}
}
}
use of com.linkedin.restli.restspec.RestMethodSchema in project rest.li by linkedin.
the class RequestBuilderSpecGenerator method generateBasicMethods.
@SuppressWarnings("deprecation")
private List<RootBuilderMethodSpec> generateBasicMethods(RootBuilderSpec rootBuilderSpec, String keyClass, String valueClass, Set<ResourceMethod> supportedMethods, RestMethodSchemaArray restMethods, String resourceName, List<String> pathKeys, Map<String, String> pathKeyTypes) {
final Map<ResourceMethod, RestMethodSchema> schemaMap = new HashMap<ResourceMethod, RestMethodSchema>();
if (restMethods != null) {
for (RestMethodSchema restMethod : restMethods) {
schemaMap.put(ResourceMethod.fromString(restMethod.getMethod()), restMethod);
}
}
List<RootBuilderMethodSpec> methodSpecList = new ArrayList<RootBuilderMethodSpec>();
for (Map.Entry<ResourceMethod, String> entry : _builderBaseMap.entrySet()) {
ResourceMethod method = entry.getKey();
if (supportedMethods.contains(method)) {
String methodName = RestLiToolsUtils.normalizeUnderscores(method.toString());
final RestMethodSchema schema = schemaMap.get(method);
RestMethodBuilderSpec requestBuilder = generateRestMethodRequestBuilder(rootBuilderSpec.getResource(), entry.getValue(), keyClass, valueClass, resourceName + RestLiToolsUtils.nameCapsCase(methodName) + getMethodBuilderSuffix(), rootBuilderSpec.getNamespace(), schema);
generatePathKeyBindingMethods(pathKeys, requestBuilder, pathKeyTypes);
if (schema != null && schema.hasParameters()) {
this.generateQueryParamBindingMethods(schema.getParameters(), requestBuilder);
}
RootBuilderMethodSpec methodSpec = new RootBuilderMethodSpec(RestLiToolsUtils.nameCamelCase(methodName), schema.getDoc(), requestBuilder, rootBuilderSpec);
requestBuilder.setRootBuilderMethod(methodSpec);
methodSpecList.add(methodSpec);
}
}
return methodSpecList;
}
use of com.linkedin.restli.restspec.RestMethodSchema in project rest.li by linkedin.
the class RestLiHTMLDocumentationRenderer method renderResource.
@Override
public void renderResource(String resourceName, OutputStream out) {
final ResourceSchema resourceSchema = _resourceSchemas.getResource(resourceName);
final List<ResourceSchema> parentResources = _resourceSchemas.getParentResources(resourceSchema);
ExampleRequestResponseGenerator generator = new ExampleRequestResponseGenerator(parentResources, resourceSchema, _schemaResolver);
if (resourceSchema == null) {
throw new RoutingException(String.format("Resource \"%s\" does not exist", resourceName), HttpStatus.S_404_NOT_FOUND.getCode());
}
final Map<String, Object> pageModel = createPageModel();
pageModel.put("resource", resourceSchema);
pageModel.put("resourceName", resourceName);
pageModel.put("resourceFullName", ResourceSchemaUtil.getFullName(resourceSchema));
pageModel.put("resourceType", getResourceType(resourceSchema));
pageModel.put("subResources", _resourceSchemas.getSubResources(resourceSchema));
final List<ResourceMethodDocView> restMethods = new ArrayList<ResourceMethodDocView>();
final List<ResourceMethodDocView> finders = new ArrayList<ResourceMethodDocView>();
final List<ResourceMethodDocView> actions = new ArrayList<ResourceMethodDocView>();
final MethodGatheringResourceSchemaVisitor visitor = new MethodGatheringResourceSchemaVisitor(resourceName);
ResourceSchemaCollection.visitResources(_resourceSchemas.getResources().values(), visitor);
for (RecordTemplate methodSchema : visitor.getAllMethods()) {
final ExampleRequestResponse capture;
if (methodSchema instanceof RestMethodSchema) {
RestMethodSchema restMethodSchema = (RestMethodSchema) methodSchema;
capture = generator.method(ResourceMethod.valueOf(restMethodSchema.getMethod().toUpperCase()));
} else if (methodSchema instanceof FinderSchema) {
FinderSchema finderMethodSchema = (FinderSchema) methodSchema;
capture = generator.finder(finderMethodSchema.getName());
} else if (methodSchema instanceof ActionSchema) {
ActionSchema actionMethodSchema = (ActionSchema) methodSchema;
final ResourceLevel resourceLevel = (visitor.getCollectionActions().contains(methodSchema) ? ResourceLevel.COLLECTION : ResourceLevel.ENTITY);
capture = generator.action(actionMethodSchema.getName(), resourceLevel);
} else {
capture = null;
}
String requestEntity = null;
String responseEntity = null;
if (capture != null) {
try {
DataMap entityMap;
if (capture.getRequest().getEntity().length() > 0) {
entityMap = DataMapUtils.readMap(capture.getRequest());
requestEntity = new String(_codec.mapToBytes(entityMap));
}
if (capture.getResponse() != null && capture.getResponse().getEntity() != null && capture.getResponse().getEntity().length() > 0) {
entityMap = DataMapUtils.readMap(capture.getResponse());
responseEntity = new String(_codec.mapToBytes(entityMap));
}
} catch (IOException e) {
throw new RestLiInternalException(e);
}
}
final ResourceMethodDocView docView = new ResourceMethodDocView(methodSchema, capture, getDoc(methodSchema, resourceSchema.hasSimple()), requestEntity, responseEntity);
if (methodSchema instanceof RestMethodSchema) {
restMethods.add(docView);
} else if (methodSchema instanceof FinderSchema) {
finders.add(docView);
} else if (methodSchema instanceof ActionSchema) {
actions.add(docView);
}
}
pageModel.put("restMethods", restMethods);
pageModel.put("finders", finders);
pageModel.put("actions", actions);
addRelated(resourceSchema, pageModel);
_templatingEngine.render("resource.vm", pageModel, out);
}
use of com.linkedin.restli.restspec.RestMethodSchema in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method addParams.
private void addParams(RestfulRequestBuilder<?, ?, ?> builder, ResourceMethod method) {
RestMethodSchema methodSchema = _resourceSchema.getMethod(method.toString().toLowerCase());
ParameterSchemaArray parameters = methodSchema.getParameters();
addParams(builder, parameters);
}
Aggregations