From 18eefbd149d15639cada32673216f3dfc7a0558b Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Mon, 28 Oct 2024 23:05:21 +0100 Subject: [PATCH] fix (cli): ./enola -v get --load models/enola.dev/enola.ttl enola:/inline --- ToDo.yaml | 6 ------ java/dev/enola/cli/BUILD | 2 ++ java/dev/enola/cli/CommandWithIRI.java | 29 +++++++++++++++----------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ToDo.yaml b/ToDo.yaml index 5e327b5e3..ca25cd5f7 100644 --- a/ToDo.yaml +++ b/ToDo.yaml @@ -291,12 +291,6 @@ items: - Split Datatype pure-RegExp (with TLC, configurable in Repo) from Java Converter (with DI with @AutoService, fix): tags: [clean] - - Make Rosetta --load multiple inputs instead of --in: &rosettaLoad - - - Unify DocGen into Rosetta: - tags: [ui, docgen, rosetta] - depends: [*rosettaLoad] - - Unify UI with Rosetta: tags: [ui, rosetta] diff --git a/java/dev/enola/cli/BUILD b/java/dev/enola/cli/BUILD index b55c8a785..e2ea9e3c8 100644 --- a/java/dev/enola/cli/BUILD +++ b/java/dev/enola/cli/BUILD @@ -58,6 +58,8 @@ java_binary( "@maven//:com_google_protobuf_protobuf_java", "@maven//:info_picocli_picocli", "@maven//:org_apache_logging_log4j_log4j_to_jul", + "@maven//:org_eclipse_rdf4j_rdf4j_model", + "@maven//:org_eclipse_rdf4j_rdf4j_rio_api", "@maven//:org_jspecify_jspecify", "@maven//:org_slf4j_slf4j_api", "@maven//:org_slf4j_slf4j_jdk14", diff --git a/java/dev/enola/cli/CommandWithIRI.java b/java/dev/enola/cli/CommandWithIRI.java index 816d7fd70..2ec541437 100644 --- a/java/dev/enola/cli/CommandWithIRI.java +++ b/java/dev/enola/cli/CommandWithIRI.java @@ -37,6 +37,9 @@ import dev.enola.thing.proto.Things; import dev.enola.web.EnolaThingProvider; +import org.eclipse.rdf4j.model.util.ModelBuilder; +import org.eclipse.rdf4j.rio.helpers.StatementCollector; + import picocli.CommandLine; import java.io.IOException; @@ -84,21 +87,23 @@ protected final void run(EnolaServiceBlockingStub service) throws Exception { protected abstract void run(EnolaServiceBlockingStub service, String eri) throws Exception; protected void write(Message thing) throws IOException { - if (thing instanceof Thing protoThing) { - if (Format.Turtle.equals(format) || Format.JSONLD.equals(format)) { - var model = new ProtoThingRdfConverter().convert(protoThing); - new RdfWriterConverter().convertIntoOrThrow(model, resource); - return; + if (Format.Turtle.equals(format) || Format.JSONLD.equals(format)) { + var model = new ModelBuilder().build(); + var statementCollector = new StatementCollector(model); + if (thing instanceof Thing protoThing) { + new ProtoThingRdfConverter().convertInto(protoThing, statementCollector); + } else if (thing instanceof Things protoThings) { + for (var protoThing : protoThings.getThingsList()) + new ProtoThingRdfConverter().convertInto(protoThing, statementCollector); } + new RdfWriterConverter().convertIntoOrThrow(model, resource); + return; } - if (thing instanceof Things protoThings) { - if (Format.Graphviz.equals(format)) { - var javaThings = ProtoThings.proto2java(protoThings.getThingsList()); - new GraphvizGenerator(thingMetadataProvider) - .convertIntoOrThrow(javaThings, resource); - return; - } + if (Format.Graphviz.equals(format) && thing instanceof Things protoThings) { + var javaThings = ProtoThings.proto2java(protoThings.getThingsList()); + new GraphvizGenerator(thingMetadataProvider).convertIntoOrThrow(javaThings, resource); + return; } // Otherwise