use of com.linkedin.restli.restspec.FinderSchema in project rest.li by linkedin.
the class TestResourceSchemaToResourceSpecTranslator method compareResourceSpecs.
public void compareResourceSpecs(ResourceSpec actual, ResourceSpec expected, RichResourceSchema resourceSchema) {
Assert.assertEquals(actual.getSupportedMethods(), expected.getSupportedMethods());
compareTypes(actual.getKeyType(), expected.getKeyType());
compareTypes(actual.getValueType(), expected.getValueType());
compareComplexKey(actual.getComplexKeyType(), expected.getComplexKeyType());
compareKeyParts(actual.getKeyParts(), expected.getKeyParts());
ActionSchemaArray actions = resourceSchema.getActions();
compareActions(actual, expected, actions);
ActionSchemaArray entityActions = resourceSchema.getEntityActions();
compareActions(actual, expected, entityActions);
FinderSchemaArray finders = resourceSchema.getFinders();
for (FinderSchema finder : finders) {
compareParameters(actual.getRequestMetadata(finder.getName()), expected.getRequestMetadata(finder.getName()));
}
}
use of com.linkedin.restli.restspec.FinderSchema in project rest.li by linkedin.
the class ResourceModelEncoder method createFinders.
private FinderSchemaArray createFinders(final ResourceModel resourceModel) {
FinderSchemaArray findersArray = new FinderSchemaArray();
List<ResourceMethodDescriptor> resourceMethodDescriptors = resourceModel.getResourceMethodDescriptors();
Collections.sort(resourceMethodDescriptors, RESOURCE_METHOD_COMPARATOR);
for (ResourceMethodDescriptor resourceMethodDescriptor : resourceMethodDescriptors) {
if (ResourceMethod.FINDER.equals(resourceMethodDescriptor.getType())) {
FinderSchema finder = new FinderSchema();
finder.setName(resourceMethodDescriptor.getFinderName());
String doc = _docsProvider.getMethodDoc(resourceMethodDescriptor.getMethod());
if (doc != null) {
finder.setDoc(doc);
}
ParameterSchemaArray parameters = createParameters(resourceMethodDescriptor);
if (parameters.size() > 0) {
finder.setParameters(parameters);
}
StringArray assocKeys = createAssocKeyParameters(resourceMethodDescriptor);
if (assocKeys.size() > 0) {
finder.setAssocKeys(assocKeys);
}
if (resourceMethodDescriptor.getFinderMetadataType() != null) {
Class<?> metadataType = resourceMethodDescriptor.getFinderMetadataType();
MetadataSchema metadataSchema = new MetadataSchema();
metadataSchema.setType(buildDataSchemaType(metadataType));
finder.setMetadata(metadataSchema);
}
final DataMap customAnnotation = resourceMethodDescriptor.getCustomAnnotationData();
String deprecatedDoc = _docsProvider.getMethodDeprecatedTag(resourceMethodDescriptor.getMethod());
if (deprecatedDoc != null) {
customAnnotation.put(DEPRECATED_ANNOTATION_NAME, deprecateDocToAnnotationMap(deprecatedDoc));
}
if (!customAnnotation.isEmpty()) {
finder.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
}
if (resourceMethodDescriptor.isPagingSupported()) {
finder.setPagingSupported(true);
}
findersArray.add(finder);
}
}
return findersArray;
}
use of com.linkedin.restli.restspec.FinderSchema 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) {
for (AssocKeySchema assocKeySchema : association.getAssocKeys()) {
String type = assocKeySchema.getType();
recordType(type, foundTypes, typeOrder);
}
if (association.hasFinders()) {
for (FinderSchema restMethodSchema : association.getFinders()) {
findModelsFinder(restMethodSchema, foundTypes, typeOrder);
}
}
if (association.hasMethods()) {
for (RestMethodSchema restMethodSchema : association.getMethods()) {
findModelsMethod(restMethodSchema, foundTypes, typeOrder);
}
}
if (association.hasActions()) {
for (ActionSchema actionSchema : association.getActions()) {
findModelsAction(actionSchema, foundTypes, typeOrder);
}
}
if (association.hasEntity()) {
EntitySchema entitySchema = association.getEntity();
findModelsEntity(entitySchema, foundTypes, typeOrder);
}
}
}
use of com.linkedin.restli.restspec.FinderSchema in project rest.li by linkedin.
the class RequestBuilderSpecGenerator method generateFinders.
private List<RootBuilderMethodSpec> generateFinders(RootBuilderSpec rootBuilderSpec, FinderSchemaArray finderSchemas, String keyClass, String valueClass, String resourceName, List<String> pathKeys, Map<String, String> pathKeyTypes) {
List<RootBuilderMethodSpec> finderSpecList = new ArrayList<RootBuilderMethodSpec>();
if (finderSchemas != null) {
String baseBuilderClass = getBuilderBase(ResourceMethod.FINDER);
for (FinderSchema finder : finderSchemas) {
String finderName = finder.getName();
String builderName = CodeUtil.capitalize(resourceName) + "FindBy" + CodeUtil.capitalize(finderName) + getMethodBuilderSuffix();
FinderBuilderSpec finderBuilderClass = generateFinderRequestBuilder(rootBuilderSpec.getResource(), baseBuilderClass, keyClass, valueClass, builderName, rootBuilderSpec.getNamespace(), finderName, finder);
generatePathKeyBindingMethods(pathKeys, finderBuilderClass, pathKeyTypes);
if (finder.getParameters() != null) {
generateQueryParamBindingMethods(finder.getParameters(), finderBuilderClass);
}
// process custom metadata
if (finder.getMetadata() != null) {
String metadataClass = finder.getMetadata().getType();
ClassTemplateSpec metadataClassSpec = classToTemplateSpec(metadataClass);
finderBuilderClass.setMetadataType(metadataClassSpec);
}
String finderMethod = "findBy" + CodeUtil.capitalize(finderName);
RootBuilderMethodSpec methodSpec = new RootBuilderMethodSpec(finderMethod, finder.getDoc(), finderBuilderClass, rootBuilderSpec);
finderBuilderClass.setRootBuilderMethod(methodSpec);
finderSpecList.add(methodSpec);
}
}
return finderSpecList;
}
use of com.linkedin.restli.restspec.FinderSchema 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);
}
Aggregations