use of com.linkedin.restli.internal.server.model.ResourceModelEncoder in project rest.li by linkedin.
the class ResourceSchemaCollection method loadOrCreateResourceSchema.
/**
* For each given {@link ResourceModel}, the classpath is checked for a .restspec.json
* matching the name of the {@link ResourceModel}, if found it is loaded. If a .restspec.json file
* is not found, one is created {@link ResourceSchemaCollection} from specified root {@link ResourceModel}.
* All resources will be recursively traversed to discover subresources.
* Root resources not specified are excluded.
*
* @param rootResources root resources in ResourceModel type
* @return constructed ResourceSchemaCollection
*/
public static ResourceSchemaCollection loadOrCreateResourceSchema(Map<String, ResourceModel> rootResources) {
final ResourceModelEncoder encoder = new ResourceModelEncoder(new NullDocsProvider());
final Map<String, ResourceSchema> schemaMap = new TreeMap<String, ResourceSchema>();
for (ResourceModel resource : rootResources.values()) {
schemaMap.put(resource.getName(), encoder.loadOrBuildResourceSchema(resource));
}
return new ResourceSchemaCollection(schemaMap);
}
use of com.linkedin.restli.internal.server.model.ResourceModelEncoder in project rest.li by linkedin.
the class RestLiSnapshotExporter method generateSnapshotFiles.
private GeneratorResult generateSnapshotFiles(String apiName, String outdir, Map<String, ResourceModel> rootResourceMap, DocsProvider docsProvider) throws IOException {
SnapshotResult result = new SnapshotResult();
final File outdirFile = new File(outdir);
if (!outdirFile.exists()) {
if (!outdirFile.mkdirs()) {
throw new RuntimeException("Output directory '" + outdir + "' could not be created!");
}
}
if (!outdirFile.isDirectory()) {
throw new RuntimeException("Output directory '" + outdir + "' is not a directory");
}
if (!outdirFile.canRead() || !outdirFile.canWrite()) {
throw new RuntimeException("Output directory '" + outdir + "' must be writeable");
}
final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);
final List<ResourceSchema> rootResourceNodes = new ArrayList<ResourceSchema>();
for (Map.Entry<String, ResourceModel> entry : rootResourceMap.entrySet()) {
final ResourceSchema rootResourceNode = encoder.buildResourceSchema(entry.getValue());
rootResourceNodes.add(rootResourceNode);
}
for (ResourceSchema rootResourceNode : rootResourceNodes) {
String fileName = rootResourceNode.getName();
if (rootResourceNode.hasNamespace()) {
final String namespace = rootResourceNode.getNamespace();
fileName = namespace + "." + fileName;
}
if (apiName != null && !apiName.isEmpty()) {
fileName = apiName + "-" + fileName;
}
File writtenFile = writeSnapshotFile(outdirFile, fileName, rootResourceNode);
result.addModifiedFile(writtenFile);
result.addTargetFile(writtenFile);
}
return result;
}
use of com.linkedin.restli.internal.server.model.ResourceModelEncoder in project rest.li by linkedin.
the class RestLiResourceModelExporter method generateIDLFiles.
private GeneratorResult generateIDLFiles(String apiName, String outdir, Map<String, ResourceModel> rootResourceMap, DocsProvider docsProvider) throws IOException {
Result result = new Result();
final File outdirFile = new File(outdir);
if (!outdirFile.exists()) {
if (!outdirFile.mkdirs()) {
throw new RuntimeException("Output directory '" + outdir + "' could not be created!");
}
}
if (!outdirFile.isDirectory()) {
throw new RuntimeException("Output directory '" + outdir + "' is not a directory");
}
if (!outdirFile.canRead() || !outdirFile.canWrite()) {
throw new RuntimeException("Output directory '" + outdir + "' must be writeable");
}
final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);
final List<ResourceSchema> rootResourceNodes = new ArrayList<ResourceSchema>();
for (Entry<String, ResourceModel> entry : rootResourceMap.entrySet()) {
final ResourceSchema rootResourceNode = encoder.buildResourceSchema(entry.getValue());
rootResourceNodes.add(rootResourceNode);
}
for (ResourceSchema rootResourceNode : rootResourceNodes) {
String fileName = rootResourceNode.getName();
if (rootResourceNode.getNamespace() != null) {
final String namespace = rootResourceNode.getNamespace();
fileName = namespace + "." + fileName;
}
if (apiName != null && !apiName.isEmpty()) {
fileName = apiName + "-" + fileName;
}
File writtenFile = writeIDLFile(outdirFile, fileName, rootResourceNode);
result.addModifiedFile(writtenFile);
result.addTargetFile(writtenFile);
}
return result;
}
Aggregations