use of com.linkedin.restli.restspec.BatchFinderSchema in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method generateQueryParamBindingMethods.
private void generateQueryParamBindingMethods(JDefinedClass facadeClass, ParameterSchemaArray parameters, JDefinedClass derivedBuilderClass, RecordTemplate methodSchema) {
for (ParameterSchema param : parameters) {
if ("array".equals(param.getType())) {
final JClass paramItemsClass = getJavaBindingType(param.getItems(), facadeClass).valueClass;
final JClass paramClass = getCodeModel().ref(Iterable.class).narrow(paramItemsClass);
generateQueryParamSetMethod(derivedBuilderClass, param, paramClass, paramItemsClass);
generateQueryParamAddMethod(derivedBuilderClass, param, paramItemsClass);
} else {
final DataSchema typeSchema = RestSpecCodec.textToSchema(param.getType(), _schemaResolver);
final JClass paramClass = getJavaBindingType(typeSchema, facadeClass).valueClass;
// since we can not guarantee that SearchCriteraArray is generated
if (!(methodSchema instanceof BatchFinderSchema && ((BatchFinderSchema) methodSchema).getBatchParam().equals(param.getName()))) {
generateQueryParamSetMethod(derivedBuilderClass, param, paramClass, paramClass);
}
// for backwards compatibility, add the method with Iterable<Foo> parameter
if (typeSchema instanceof ArrayDataSchema) {
final DataSchema itemsSchema = ((ArrayDataSchema) typeSchema).getItems();
final JClass paramItemsClass = getJavaBindingType(itemsSchema, facadeClass).valueClass;
final JClass iterableItemsClass = getCodeModel().ref(Iterable.class).narrow(paramItemsClass);
generateQueryParamSetMethod(derivedBuilderClass, param, iterableItemsClass, paramItemsClass);
generateQueryParamAddMethod(derivedBuilderClass, param, paramItemsClass);
}
}
}
}
use of com.linkedin.restli.restspec.BatchFinderSchema in project rest.li by linkedin.
the class SnapshotGenerator method findModelsCollection.
private void findModelsCollection(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
CollectionSchema collection = resourceSchema.getCollection();
if (collection != null) {
IdentifierSchema identifier = collection.getIdentifier();
findModelsIdentifier(identifier, foundTypes, typeOrder);
findErrorDetailTypeModels(collection, foundTypes, typeOrder);
if (collection.hasFinders()) {
for (FinderSchema restMethodSchema : collection.getFinders()) {
findModels(restMethodSchema.getParameters(), restMethodSchema.getMetadata(), foundTypes, typeOrder);
findErrorDetailTypeModels(restMethodSchema, foundTypes, typeOrder);
}
}
if (collection.hasBatchFinders()) {
for (BatchFinderSchema restMethodSchema : collection.getBatchFinders()) {
findModels(restMethodSchema.getParameters(), restMethodSchema.getMetadata(), foundTypes, typeOrder);
findErrorDetailTypeModels(restMethodSchema, foundTypes, typeOrder);
}
}
if (collection.hasMethods()) {
for (RestMethodSchema restMethodSchema : collection.getMethods()) {
findModels(restMethodSchema.getParameters(), restMethodSchema.getMetadata(), foundTypes, typeOrder);
findErrorDetailTypeModels(restMethodSchema, foundTypes, typeOrder);
}
}
if (collection.hasActions()) {
for (ActionSchema actionSchema : collection.getActions()) {
findModelsAction(actionSchema, foundTypes, typeOrder);
findErrorDetailTypeModels(actionSchema, foundTypes, typeOrder);
}
}
if (collection.hasEntity()) {
EntitySchema entity = collection.getEntity();
findModelsEntity(entity, foundTypes, typeOrder);
}
}
}
use of com.linkedin.restli.restspec.BatchFinderSchema in project rest.li by linkedin.
the class SnapshotGenerator method findModelsAssocation.
private void findModelsAssocation(ResourceSchema resourceSchema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
AssociationSchema association = resourceSchema.getAssociation();
if (association != null) {
findErrorDetailTypeModels(association, foundTypes, typeOrder);
for (AssocKeySchema assocKeySchema : association.getAssocKeys()) {
String type = assocKeySchema.getType();
recordType(type, foundTypes, typeOrder);
}
if (association.hasFinders()) {
for (FinderSchema restMethodSchema : association.getFinders()) {
findModels(restMethodSchema.getParameters(), restMethodSchema.getMetadata(), foundTypes, typeOrder);
findErrorDetailTypeModels(restMethodSchema, foundTypes, typeOrder);
}
}
if (association.hasBatchFinders()) {
for (BatchFinderSchema restMethodSchema : association.getBatchFinders()) {
findModels(restMethodSchema.getParameters(), restMethodSchema.getMetadata(), foundTypes, typeOrder);
findErrorDetailTypeModels(restMethodSchema, foundTypes, typeOrder);
}
}
if (association.hasMethods()) {
for (RestMethodSchema restMethodSchema : association.getMethods()) {
findModels(restMethodSchema.getParameters(), restMethodSchema.getMetadata(), foundTypes, typeOrder);
findErrorDetailTypeModels(restMethodSchema, foundTypes, typeOrder);
}
}
if (association.hasActions()) {
for (ActionSchema actionSchema : association.getActions()) {
findModelsAction(actionSchema, foundTypes, typeOrder);
findErrorDetailTypeModels(actionSchema, foundTypes, typeOrder);
}
}
if (association.hasEntity()) {
EntitySchema entitySchema = association.getEntity();
findModelsEntity(entitySchema, foundTypes, typeOrder);
}
}
}
use of com.linkedin.restli.restspec.BatchFinderSchema in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method generateBatchFinders.
private void generateBatchFinders(JDefinedClass facadeClass, JExpression baseUriExpr, BatchFinderSchemaArray batchFinderSchemas, JClass keyClass, JClass valueClass, Map<String, AssocKeyTypeInfo> assocKeys, JVar resourceSpecField, String resourceName, List<String> pathKeys, Map<String, JClass> pathKeyTypes, Map<String, JClass> assocKeyTypes, Map<String, List<String>> pathToAssocKeys, JExpression requestOptionsExpr, String rootPath) throws JClassAlreadyExistsException {
if (batchFinderSchemas != null) {
final JClass baseBuilderClass = getCodeModel().ref(BatchFindRequestBuilderBase.class).narrow(keyClass, valueClass);
for (BatchFinderSchema batchFinder : batchFinderSchemas) {
final String batchFinderName = batchFinder.getName();
final String builderName = CodeUtil.capitalize(resourceName) + "BatchFindBy" + CodeUtil.capitalize(batchFinderName) + METHOD_BUILDER_SUFFIX.get(_version);
JDefinedClass batchFinderBuilderClass = generateDerivedBuilder(baseBuilderClass, valueClass, batchFinderName, builderName, facadeClass.getPackage(), ResourceMethod.BATCH_FINDER, null, rootPath);
final JMethod batchFinderMethod = facadeClass.method(JMod.PUBLIC, batchFinderBuilderClass, "batchFindBy" + CodeUtil.capitalize(batchFinderName));
batchFinderMethod.body()._return(JExpr._new(batchFinderBuilderClass).arg(baseUriExpr).arg(resourceSpecField).arg(requestOptionsExpr));
final Set<String> batchFinderKeys = new TreeSet<>();
if (batchFinder.getAssocKey() != null) {
batchFinderKeys.add(batchFinder.getAssocKey());
}
if (batchFinder.getAssocKeys() != null) {
for (String assocKey : batchFinder.getAssocKeys()) {
batchFinderKeys.add(assocKey);
}
}
generatePathKeyBindingMethods(pathKeys, batchFinderBuilderClass, pathKeyTypes, assocKeyTypes, pathToAssocKeys);
generateAssocKeyBindingMethods(assocKeys, batchFinderBuilderClass, batchFinderKeys);
if (batchFinder.getParameters() != null) {
generateQueryParamBindingMethods(facadeClass, batchFinder.getParameters(), batchFinderBuilderClass, batchFinder);
}
// process the metadata schema file
if (batchFinder.getMetadata() != null) {
final String metadataClass = batchFinder.getMetadata().getType();
getJavaBindingType(metadataClass, facadeClass);
}
generateClassJavadoc(batchFinderBuilderClass, batchFinder);
generateFactoryMethodJavadoc(batchFinderMethod, batchFinder);
}
}
}
use of com.linkedin.restli.restspec.BatchFinderSchema 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<>();
final List<ResourceMethodDocView> finders = new ArrayList<>();
final List<ResourceMethodDocView> batchFinders = new ArrayList<>();
final List<ResourceMethodDocView> actions = new ArrayList<>();
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 BatchFinderSchema) {
BatchFinderSchema batchFinderSchema = (BatchFinderSchema) methodSchema;
capture = generator.batchFinder(batchFinderSchema.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 BatchFinderSchema) {
batchFinders.add(docView);
} else if (methodSchema instanceof ActionSchema) {
actions.add(docView);
}
}
pageModel.put("restMethods", restMethods);
pageModel.put("finders", finders);
pageModel.put("batchFinders", batchFinders);
pageModel.put("actions", actions);
addRelated(resourceSchema, pageModel);
final ServiceErrorGatheringVisitor serviceErrorGatheringVisitor = new ServiceErrorGatheringVisitor();
ResourceSchemaCollection.visitResources(Collections.singletonList(resourceSchema), serviceErrorGatheringVisitor);
pageModel.put("serviceErrors", serviceErrorGatheringVisitor.getServiceErrors());
pageModel.put("resourceLevelServiceErrors", serviceErrorGatheringVisitor.getResourceLevelServiceErrors());
// The following two flags are necessary for conditionally displaying the columns of the REST methods table
pageModel.put("restMethodsHaveSuccessStatuses", serviceErrorGatheringVisitor.doRestMethodsHaveSuccessStatuses());
pageModel.put("restMethodsHaveServiceErrors", serviceErrorGatheringVisitor.doRestMethodsHaveServiceErrors());
pageModel.put("util", new DocumentationTemplateUtil());
_templatingEngine.render("resource/index.vm", pageModel, out);
}
Aggregations