use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingSubResourceCollectionBatch.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingSubResourceCollectionBatch")
public void testRoutingSubResourceCollectionBatch(String uri, ProtocolVersion version, String httpMethod, String restliMethod, ResourceMethod method, String methodName, Set<Long> keys) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, RepliesCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
checkResult(uri, version, httpMethod, restliMethod, method, RepliesCollectionResource.class, methodName, true);
checkBatchKeys(uri, version, httpMethod, keys);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiRouting method testActionNestedSimpleRouting.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "actionNestedSimpleRouting")
public void testActionNestedSimpleRouting(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class);
_router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
RestRequest request = createRequest(uri, "POST", version);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
ResourceMethodDescriptor method = _router.process(context);
assertNotNull(method);
assertEquals(method.getActionName(), "new_status_from_location");
assertEquals(method.getType(), ResourceMethod.ACTION);
assertEquals(method.getMethod().getParameterTypes(), new Class<?>[] { String.class });
assertEquals(context.getPathKeys().get("statusID"), Long.valueOf(1));
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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<>();
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;
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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<>();
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.ResourceModel 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<>();
for (ResourceModel resource : rootResources.values()) {
schemaMap.put(resource.getName(), encoder.loadOrBuildResourceSchema(resource));
}
return new ResourceSchemaCollection(schemaMap, rootResources);
}
Aggregations