From 6dcca7827c1ed3998295af71aad33e96bab09561 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Thu, 14 Sep 2017 12:23:17 +0200 Subject: [PATCH 01/11] Empty classes to build the export --- .../contenttypes/GraphMlWriter.java | 19 +++++++++++++++++ .../serializations/GraphMlSerialization.java | 21 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java create mode 100644 timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java new file mode 100644 index 0000000000..84212d1d0c --- /dev/null +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java @@ -0,0 +1,19 @@ +package nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes; + +import nl.knaw.huygens.timbuctoo.v5.serializable.serializations.GraphMlSerialization; +import javax.ws.rs.Produces; + +@Produces(GraphMlWriter.MIME_TYPE) +public class GraphMlWriter extends SerializerWriter { + + public static final String MIME_TYPE = "text/xml"; + + public GraphMlWriter() { + super(GraphMlSerialization::new); + } + + @Override + public String getMimeType() { + return MIME_TYPE; + } +} diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java new file mode 100644 index 0000000000..d42fe4f9b5 --- /dev/null +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -0,0 +1,21 @@ +package nl.knaw.huygens.timbuctoo.v5.serializable.serializations; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value; +import nl.knaw.huygens.timbuctoo.v5.serializable.serializations.base.CollectionsOfEntitiesSerialization; + +public class GraphMlSerialization extends CollectionsOfEntitiesSerialization { + + // private final CSVPrinter csvPrinter; + + public GraphMlSerialization(OutputStream outputStream) throws IOException { + // csvPrinter = new CSVPrinter(new PrintWriter(outputStream), CSVFormat.EXCEL); + } + + protected void initialize() throws IOException { + } +} From d838a6c6d13a83d2bea8bb42a5fa3badff4ea736 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Mon, 25 Sep 2017 10:55:20 +0200 Subject: [PATCH 02/11] Added writeHeader, writeFooter --- .../serializations/GraphMlSerialization.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index d42fe4f9b5..3011369919 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -11,11 +11,50 @@ public class GraphMlSerialization extends CollectionsOfEntitiesSerialization { // private final CSVPrinter csvPrinter; + private String tableName; + private String columnHeaders; + private List columns; public GraphMlSerialization(OutputStream outputStream) throws IOException { // csvPrinter = new CSVPrinter(new PrintWriter(outputStream), CSVFormat.EXCEL); } - protected void initialize() throws IOException { + protected void initialize(List columnHeaders) throws IOException { + writeHeader(); + this.columnHeaders = ""; + columns = new ArrayList(); + for (String columnHeader : columnHeaders) { + columns.add(columnHeader); + this.columnHeaders += ", " + columnHeader; + this.columnHeaders += ", " + columnHeader + "_type"; + } + this.columnHeaders = this.columnHeaders.substring(2); + } + + protected void setTableName(String tableName) { + this.tableName = tableName; + } + + protected void writeHeader() { + String header = "\n" + + ""; + System.out.println(header); + } + + protected void writeFooter() { + String footer = ""; + System.out.println(footer); + } + + protected void writeRow(List values) throws IOException { + // + // + // + // + // + // } } From 48ec7523a31283631843725ee6429956b642c006 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Wed, 27 Sep 2017 14:39:38 +0200 Subject: [PATCH 03/11] Save in between --- .../serializable/serializations/GraphMlSerialization.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index 3011369919..a858adac3a 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -50,7 +50,13 @@ protected void writeFooter() { } protected void writeRow(List values) throws IOException { - // + System.out.println(""); + int count = 0; + for (Value value: values) { + System.out.println(value); + System.out.println("" + count); + count++; + } // // // From 6aad36424ba2f0b6f72553c744a71cee06bd9403 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Wed, 27 Sep 2017 14:41:01 +0200 Subject: [PATCH 04/11] Save again --- .../serializable/serializations/GraphMlSerialization.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index a858adac3a..59beb964f7 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -57,10 +57,6 @@ protected void writeRow(List values) throws IOException { System.out.println("" + count); count++; } - // - // - // - // - // + System.out.println(""); } } From 04f2506cffabe3bac754ce998c1cdb9d1117cec3 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Wed, 27 Sep 2017 14:50:45 +0200 Subject: [PATCH 05/11] Writes export data as a series of nodes, with the values as data in these nodes --- .../serializations/GraphMlSerialization.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index 59beb964f7..46728d379e 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -14,6 +14,7 @@ public class GraphMlSerialization extends CollectionsOfEntitiesSerialization { private String tableName; private String columnHeaders; private List columns; + private int count = 0; public GraphMlSerialization(OutputStream outputStream) throws IOException { // csvPrinter = new CSVPrinter(new PrintWriter(outputStream), CSVFormat.EXCEL); @@ -42,21 +43,21 @@ protected void writeHeader() { "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n" + "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">"; System.out.println(header); + System.out.println(""); } protected void writeFooter() { + System.out.println(""); String footer = ""; System.out.println(footer); } protected void writeRow(List values) throws IOException { - System.out.println(""); - int count = 0; + System.out.println(""); for (Value value: values) { - System.out.println(value); - System.out.println("" + count); - count++; + System.out.println("" + value.getValue() + ""); } - System.out.println(""); + System.out.println(""); + count++; } } From c6cdcae05db1078fb05f89f165faa1c17e941cab Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Thu, 28 Sep 2017 12:28:14 +0200 Subject: [PATCH 06/11] Improved indention on output --- .../serializations/GraphMlSerialization.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index 46728d379e..dc290a7792 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -39,25 +39,25 @@ protected void setTableName(String tableName) { protected void writeHeader() { String header = "\n" + ""; + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + + " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n" + + " http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">"; System.out.println(header); - System.out.println(""); + System.out.println(" "); } protected void writeFooter() { - System.out.println(""); + System.out.println(" "); String footer = ""; System.out.println(footer); } protected void writeRow(List values) throws IOException { - System.out.println(""); + System.out.println(" "); for (Value value: values) { - System.out.println("" + value.getValue() + ""); + System.out.println(" " + value.getValue() + ""); } - System.out.println(""); + System.out.println(" "); count++; } } From e9730890a05a94d68d6d6e99e31957dc65929407 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Tue, 3 Oct 2017 10:36:53 +0200 Subject: [PATCH 07/11] Added writeEdge --- .../serializable/serializations/GraphMlSerialization.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index dc290a7792..0cf291817d 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -15,6 +15,7 @@ public class GraphMlSerialization extends CollectionsOfEntitiesSerialization { private String columnHeaders; private List columns; private int count = 0; + private int countEdge = 0; public GraphMlSerialization(OutputStream outputStream) throws IOException { // csvPrinter = new CSVPrinter(new PrintWriter(outputStream), CSVFormat.EXCEL); @@ -60,4 +61,10 @@ protected void writeRow(List values) throws IOException { System.out.println(" "); count++; } + + protected void writeEdge(String source, String target) throws IOException { + System.out.println(" "); + countEdge++; + } } From 63cb17df7c4dfea9f6014491b191e5920f882638 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Tue, 10 Oct 2017 15:47:08 +0200 Subject: [PATCH 08/11] Changed mimetype --- .../timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java index 84212d1d0c..9604794681 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/contenttypes/GraphMlWriter.java @@ -6,7 +6,7 @@ @Produces(GraphMlWriter.MIME_TYPE) public class GraphMlWriter extends SerializerWriter { - public static final String MIME_TYPE = "text/xml"; + public static final String MIME_TYPE = "text/graphml"; public GraphMlWriter() { super(GraphMlSerialization::new); From abaf6a2251949f884ce7131c561200c22a328962 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Tue, 10 Oct 2017 15:58:11 +0200 Subject: [PATCH 09/11] Added GraphmlWriter --- .../java/nl/knaw/huygens/timbuctoo/server/TimbuctooV4.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/server/TimbuctooV4.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/server/TimbuctooV4.java index 8800ce62d3..79948b356c 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/server/TimbuctooV4.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/server/TimbuctooV4.java @@ -84,6 +84,7 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository; import nl.knaw.huygens.timbuctoo.v5.dropwizard.DataSetFactoryManager; import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.CsvWriter; +import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.GraphMlWriter; import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.GraphVizWriter; import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.JsonLdWriter; import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.JsonWriter; @@ -282,7 +283,8 @@ public void run(TimbuctooConfiguration configuration, Environment environment) t new CsvWriter(), new JsonLdWriter(), new JsonWriter(), - new GraphVizWriter() + new GraphVizWriter(), + new GraphMlWriter() ); final PaginationArgumentsHelper argHelper = new PaginationArgumentsHelper(configuration.getCollectionFilters()); From df506cc05e570c0caf89d5f2bf15297ce0ee5fdd Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Thu, 12 Oct 2017 14:40:16 +0200 Subject: [PATCH 10/11] Exporting query result for graphml input --- .../serializations/GraphMlSerialization.java | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index 0cf291817d..d9f3c40bed 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -2,40 +2,53 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; -import nl.knaw.huygens.timbuctoo.v5.serializable.dto.Value; +import nl.knaw.huygens.timbuctoo.v5.serializable.SerializableResult; import nl.knaw.huygens.timbuctoo.v5.serializable.serializations.base.CollectionsOfEntitiesSerialization; public class GraphMlSerialization extends CollectionsOfEntitiesSerialization { - // private final CSVPrinter csvPrinter; - private String tableName; - private String columnHeaders; - private List columns; - private int count = 0; - private int countEdge = 0; + private final PrintWriter writer; + private int countEdge = 1; public GraphMlSerialization(OutputStream outputStream) throws IOException { - // csvPrinter = new CSVPrinter(new PrintWriter(outputStream), CSVFormat.EXCEL); + writer = new PrintWriter(outputStream); } - protected void initialize(List columnHeaders) throws IOException { + public void serialize(SerializableResult serializableResult) throws IOException { + super.serialize(serializableResult); + Map entityIds = new HashMap<>(); + AtomicInteger nodeCounter = new AtomicInteger(); writeHeader(); - this.columnHeaders = ""; - columns = new ArrayList(); - for (String columnHeader : columnHeaders) { - columns.add(columnHeader); - this.columnHeaders += ", " + columnHeader; - this.columnHeaders += ", " + columnHeader + "_type"; + for (Map entities : allEntities.values()) { + for (Map.Entry entity : entities.entrySet()) { + Integer nodeId = entityIds.computeIfAbsent(entity.getKey(), k -> nodeCounter.incrementAndGet()); + writer.println(" "); + writer.println(" " + entity.getValue() + ""); + writer.println(" " + entity.getValue() + ""); + writer.println(" "); + for (Map.Entry> relation : entity.getValue().relations.entrySet()) { + for (String otherNodeUri : relation.getValue()) { + Integer otherNodeId = entityIds.computeIfAbsent(otherNodeUri, k -> nodeCounter.incrementAndGet()); + writer.println(" "); + writer.println(" " + relation.getKey() + ""); + writer.println(" "); + countEdge++; + } + } + } } - this.columnHeaders = this.columnHeaders.substring(2); + writeFooter(); + writer.flush(); + writer.close(); } - protected void setTableName(String tableName) { - this.tableName = tableName; - } protected void writeHeader() { String header = "\n" + @@ -43,28 +56,14 @@ protected void writeHeader() { " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\n" + " http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">"; - System.out.println(header); - System.out.println(" "); + writer.println(header); + writer.println(" "); } protected void writeFooter() { - System.out.println(" "); + writer.println(" "); String footer = ""; - System.out.println(footer); + writer.println(footer); } - protected void writeRow(List values) throws IOException { - System.out.println(" "); - for (Value value: values) { - System.out.println(" " + value.getValue() + ""); - } - System.out.println(" "); - count++; - } - - protected void writeEdge(String source, String target) throws IOException { - System.out.println(" "); - countEdge++; - } } From 7be27bac5edaadd838065e6e4f40800af305e4a9 Mon Sep 17 00:00:00 2001 From: Meindert Kroese Date: Thu, 12 Oct 2017 14:46:22 +0200 Subject: [PATCH 11/11] These lables (in node) are more clear --- .../v5/serializable/serializations/GraphMlSerialization.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java index d9f3c40bed..c2d6af1d88 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/GraphMlSerialization.java @@ -30,7 +30,7 @@ public void serialize(SerializableResult serializableResult) throws IOException Integer nodeId = entityIds.computeIfAbsent(entity.getKey(), k -> nodeCounter.incrementAndGet()); writer.println(" "); writer.println(" " + entity.getValue() + ""); - writer.println(" " + entity.getValue() + ""); + writer.println(" " + entity.getKey() + ""); writer.println(" "); for (Map.Entry> relation : entity.getValue().relations.entrySet()) { for (String otherNodeUri : relation.getValue()) {