Search in sources :

Example 1 with LoadJsonSchemaResponse

use of com.alibaba.maxgraph.proto.groot.LoadJsonSchemaResponse in project GraphScope by alibaba.

the class MaxTestGraph method loadSchema.

public void loadSchema(LoadGraphWith.GraphData graphData) throws URISyntaxException, IOException {
    String schemaResource = graphData.name().toLowerCase() + ".schema";
    Path path = Paths.get(Thread.currentThread().getContextClassLoader().getResource(schemaResource).toURI());
    String json = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
    CompletableFuture<String> future = new CompletableFuture<>();
    clientService.loadJsonSchema(LoadJsonSchemaRequest.newBuilder().setSchemaJson(json).build(), new StreamObserver<LoadJsonSchemaResponse>() {

        @Override
        public void onNext(LoadJsonSchemaResponse value) {
            future.complete(value.getGraphDef().toString());
        }

        @Override
        public void onError(Throwable t) {
            future.completeExceptionally(t);
        }

        @Override
        public void onCompleted() {
        }
    });
    try {
        String schemaString = future.get();
        logger.info("load json schema: " + schemaString);
    } catch (Exception e) {
        throw new MaxGraphException(e);
    }
}
Also used : Path(java.nio.file.Path) CompletableFuture(java.util.concurrent.CompletableFuture) LoadJsonSchemaResponse(com.alibaba.maxgraph.proto.groot.LoadJsonSchemaResponse) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) URISyntaxException(java.net.URISyntaxException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException)

Aggregations

MaxGraphException (com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)1 LoadJsonSchemaResponse (com.alibaba.maxgraph.proto.groot.LoadJsonSchemaResponse)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 CompletableFuture (java.util.concurrent.CompletableFuture)1