From 849a1ae9ec2192265930419bd3cd835873a01798 Mon Sep 17 00:00:00 2001 From: MarenHanke Date: Tue, 9 Jan 2024 19:13:09 +0100 Subject: [PATCH] added output adapter so view multiplex graph on multiplexgraph.html analog zu customgraphs on graph.html --- .../las2peer/services/ocd/ServiceClass.java | 71 ++++++++++++++- .../AbstractMultiplexGraphOutputAdapter.java | 12 +++ .../graphOutput/CommonGraphOutputAdapter.java | 23 +++++ .../graphOutput/GraphOutputAdapter.java | 2 +- .../GraphOutputAdapterFactory.java | 4 +- .../graphOutput/GraphOutputFormat.java | 12 ++- .../MetaXmlMultiplexGraphOutputAdapter.java | 89 +++++++++++++++++++ .../MultiplexGraphOutputAdapter.java | 23 +++++ .../services/ocd/graphs/MultiplexGraph.java | 49 +++++++++- .../las2peer/services/ocd/utils/Database.java | 80 ++++++++++++++++- .../services/ocd/utils/RequestHandler.java | 27 +++++- time_seed.dat | 2 +- 12 files changed, 380 insertions(+), 14 deletions(-) create mode 100644 rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/AbstractMultiplexGraphOutputAdapter.java create mode 100644 rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/CommonGraphOutputAdapter.java create mode 100644 rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MetaXmlMultiplexGraphOutputAdapter.java create mode 100644 rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MultiplexGraphOutputAdapter.java diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java index 9ea48921..6132ad90 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java @@ -757,7 +757,6 @@ public Response getGraphs(@DefaultValue("0") @QueryParam("firstIndex") String fi * using the "-" delimiter. * @return The graphs. Or an error xml. */ - @GET @Path("multiplexgraphs") @Produces(MediaType.TEXT_XML) @@ -819,6 +818,31 @@ public Response getMultiplexGraphs(@DefaultValue("0") @QueryParam("firstIndex") } } + /** + * Returns the ids (or meta information) of multiple graphs. + * + * @param keyMultiplexStr key of the multiplex graph we want to get the customgraph layers of + * @return The graphs. Or an error xml. + */ + @GET + @Path("multiplexlayers") + @Produces(MediaType.TEXT_XML) + @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), + @ApiResponse(code = 401, message = "Unauthorized") }) + @ApiOperation(tags = {"show"}, value = "Get Infos of a MultiplexGraphs layers/CustomGraphs", notes = "Returns the meta information of the layers of a multiplexgraph.") + public Response getLayersOfMultiplexGraph(@DefaultValue("0") @QueryParam("keyMultiplex") String keyMultiplexStr) { + try { + String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName(); + List queryResults; + queryResults = database.getMultiplexGraphMetaDataOfLayersEfficiently(username, keyMultiplexStr); + String responseStr = requestHandler.writeGraphMetasEfficiently(queryResults); + return Response.ok(responseStr).build(); + } catch (Exception e) { + requestHandler.log(Level.SEVERE, "", e); + return requestHandler.writeError(Error.INTERNAL, "Internal system error."); + } + } + /** * Returns a graph in a specified output format. * @@ -864,6 +888,51 @@ public Response getGraph(@DefaultValue("GRAPH_ML") @QueryParam("outputFormat") S } + /** + * Returns a graph in a specified output format. + * + * @param graphIdStr + * The graph id. + * @param graphOutputFormatStr + * The name of the graph output format. + * @return The graph output. Or an error xml. + */ + @GET + @Produces(MediaType.TEXT_PLAIN) + @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), + @ApiResponse(code = 401, message = "Unauthorized") }) + @Path("multiplexgraphs/{graphId}") + @ApiOperation(tags = {"export"}, value = "Export Graph", notes = "Returns a graph in a specified output format.") + public Response getMultiplexGraph(@DefaultValue("GRAPH_ML") @QueryParam("outputFormat") String graphOutputFormatStr, + @PathParam("graphId") String graphIdStr) { + try { + + String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName(); + GraphOutputFormat format; + try { + + format = GraphOutputFormat.valueOf(graphOutputFormatStr); + } catch (Exception e) { + requestHandler.log(Level.WARNING, "user: " + username, e); + return requestHandler.writeError(Error.PARAMETER_INVALID, + "Specified graph output format does not exist."); + } + + MultiplexGraph graph = database.getMultiplexGraph(username, graphIdStr); //done + + if (graph == null) + return requestHandler.writeError(Error.PARAMETER_INVALID, + "Graph does not exist: graph key " + graphIdStr); //done + + generalLogger.getLogger().log(Level.INFO, "user " + username + ": get cover " + graphIdStr + " in format " + graphOutputFormatStr ); + return Response.ok(requestHandler.writeMultiplexGraph(graph, format)).build(); + } catch (Exception e) { + requestHandler.log(Level.SEVERE, "", e); + return requestHandler.writeError(Error.INTERNAL, "Internal system error."); + } + + } + /** * Deletes a graph. All covers based on the graph are removed as well. * If a benchmark is currently calculating the graph the execution is diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/AbstractMultiplexGraphOutputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/AbstractMultiplexGraphOutputAdapter.java new file mode 100644 index 00000000..d1ec4408 --- /dev/null +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/AbstractMultiplexGraphOutputAdapter.java @@ -0,0 +1,12 @@ +package i5.las2peer.services.ocd.adapters.graphOutput; + +import i5.las2peer.services.ocd.adapters.AbstractOutputAdapter; + +/** + * An abstract class for graph output adapters. + * @author Sebastian + * + */ +public abstract class AbstractMultiplexGraphOutputAdapter extends AbstractOutputAdapter implements MultiplexGraphOutputAdapter { + +} diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/CommonGraphOutputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/CommonGraphOutputAdapter.java new file mode 100644 index 00000000..45ffe04b --- /dev/null +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/CommonGraphOutputAdapter.java @@ -0,0 +1,23 @@ +package i5.las2peer.services.ocd.adapters.graphOutput; + +import i5.las2peer.services.ocd.adapters.AdapterException; +import i5.las2peer.services.ocd.adapters.InputAdapter; +import i5.las2peer.services.ocd.adapters.OutputAdapter; +import i5.las2peer.services.ocd.graphs.MultiplexGraph; + +import java.text.ParseException; +import java.util.Map; + +/** + * The common interface of all graph output adapters. + * @author Sebastian + * + */ +public interface CommonGraphOutputAdapter extends OutputAdapter { + + /** + * Writes a graph and closes the writer. + * @throws AdapterException if the adapter failed + */ + public void writeGraph(T graph) throws AdapterException; +} diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapter.java index 6dbc5906..7da74eb3 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapter.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapter.java @@ -9,7 +9,7 @@ * @author Sebastian * */ -public interface GraphOutputAdapter extends OutputAdapter { +public interface GraphOutputAdapter extends CommonGraphOutputAdapter { /** * Writes a graph and closes the writer. diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapterFactory.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapterFactory.java index 02c4b073..6e66675c 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapterFactory.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputAdapterFactory.java @@ -7,10 +7,10 @@ * @author Sebastian * */ -public class GraphOutputAdapterFactory implements SimpleFactory{ +public class GraphOutputAdapterFactory implements SimpleFactory{ @Override - public GraphOutputAdapter getInstance(GraphOutputFormat outputFormat) throws InstantiationException, IllegalAccessException { + public CommonGraphOutputAdapter getInstance(GraphOutputFormat outputFormat) throws InstantiationException, IllegalAccessException { return outputFormat.getAdapterClass().newInstance(); } diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputFormat.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputFormat.java index 4e0a0773..335c4372 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputFormat.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/GraphOutputFormat.java @@ -32,11 +32,15 @@ public enum GraphOutputFormat implements EnumDisplayNames{ /** * Format corresponding to the PropertiesXMLGraphOutputAdapter. */ - PROPERTIES_XML ("Properties XML", PropertiesXmlGraphOutputAdapter.class, 3); + PROPERTIES_XML ("Properties XML", PropertiesXmlGraphOutputAdapter.class, 3), + /** + * Format corresponding to the MetaXmlMultiplexGraphOutputAdapter. + */ + MULTIPLEX_META_XML ("Multiplex Meta XML", MetaXmlMultiplexGraphOutputAdapter.class, 4);; /** * The adapter class corresponding to the format. */ - private final Class adapterClass; + private final Class adapterClass; /** * Reserved for persistence or other purposes. @@ -53,7 +57,7 @@ public enum GraphOutputFormat implements EnumDisplayNames{ * @param adapterClass Defines the adapterClass attribute. * @param id Defines the id attribute. */ - private GraphOutputFormat(String displayName, Class adapterClass, int id) { + private GraphOutputFormat(String displayName, Class adapterClass, int id) { this.displayName = displayName; this.adapterClass = adapterClass; this.id = id; @@ -63,7 +67,7 @@ private GraphOutputFormat(String displayName, Class getAdapterClass() { + protected Class getAdapterClass() { return this.adapterClass; } diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MetaXmlMultiplexGraphOutputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MetaXmlMultiplexGraphOutputAdapter.java new file mode 100644 index 00000000..59438a20 --- /dev/null +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MetaXmlMultiplexGraphOutputAdapter.java @@ -0,0 +1,89 @@ +package i5.las2peer.services.ocd.adapters.graphOutput; + +import i5.las2peer.services.ocd.adapters.AdapterException; +import i5.las2peer.services.ocd.graphs.MultiplexGraph; +import i5.las2peer.services.ocd.graphs.GraphType; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +/** + * A graph output adapter for the meta XML format. + * The output contains meta information about the graph in XML format, but not the actual graph structure or other node or edge related meta data. + * @author Sebastian + * + */ +public class MetaXmlMultiplexGraphOutputAdapter extends AbstractMultiplexGraphOutputAdapter { + + @Override + public void writeGraph(MultiplexGraph graph) throws AdapterException { + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + try { + DocumentBuilder builder = builderFactory.newDocumentBuilder(); + Document doc = builder.newDocument(); + Element graphElt = doc.createElement("Graph"); + doc.appendChild(graphElt); + /* + * Basic Attributes + */ + Element graphIdElt = doc.createElement("Id"); + graphIdElt.appendChild(doc.createTextNode(graph.getKey())); + graphElt.appendChild(graphIdElt); + Element graphNameElt = doc.createElement("Name"); + graphNameElt.appendChild(doc.createTextNode(graph.getName())); + graphElt.appendChild(graphNameElt); + Element graphNodeCountElt = doc.createElement("NodeCount"); + graphNodeCountElt.appendChild(doc.createTextNode(Integer.toString(graph.getNodeCount()))); + graphElt.appendChild(graphNodeCountElt); + Element graphEdgeCountElt = doc.createElement("EdgeCount"); + graphEdgeCountElt.appendChild(doc.createTextNode(Integer.toString(graph.getEdgeCount()))); + graphElt.appendChild(graphEdgeCountElt); + Element graphLayerCountElt = doc.createElement("LayerCount"); + graphLayerCountElt.appendChild(doc.createTextNode(Integer.toString(graph.getLayerCount()))); + graphElt.appendChild(graphLayerCountElt); + /* + * Graph Types + */ + Element typesElt = doc.createElement("Types"); + for(GraphType type : graph.getTypes()) { + Element typeElt = doc.createElement("Type"); + typeElt.appendChild(doc.createTextNode(type.name())); + typeElt.setAttribute("displayName", type.getDisplayName()); + typesElt.appendChild(typeElt); + } + graphElt.appendChild(typesElt); + /* + * Creation Method + */ + Element creationMethodElt = doc.createElement("CreationMethod"); + Element creationMethodTypeElt = doc.createElement("Type"); + creationMethodTypeElt.appendChild(doc.createTextNode(graph.getCreationMethod().getType().name())); + creationMethodTypeElt.setAttribute("displayName", graph.getCreationMethod().getType().getDisplayName()); + creationMethodElt.appendChild(creationMethodTypeElt); + Element creationMethodStatus = doc.createElement("Status"); + creationMethodStatus.appendChild(doc.createTextNode(graph.getCreationMethod().getStatus().name())); + creationMethodElt.appendChild(creationMethodStatus); + graphElt.appendChild(creationMethodElt); + /* + * XML output + */ + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + DOMSource domSource = new DOMSource(doc); + StreamResult streamResult = new StreamResult(this.writer); + transformer.transform(domSource, streamResult); + } + catch(Exception e) { + throw new AdapterException(e); + } + } + +} diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MultiplexGraphOutputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MultiplexGraphOutputAdapter.java new file mode 100644 index 00000000..9d3f3270 --- /dev/null +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/MultiplexGraphOutputAdapter.java @@ -0,0 +1,23 @@ +package i5.las2peer.services.ocd.adapters.graphOutput; + +import i5.las2peer.services.ocd.adapters.AdapterException; +import i5.las2peer.services.ocd.adapters.OutputAdapter; +import i5.las2peer.services.ocd.adapters.graphInput.CommonGraphInputAdapter; +import i5.las2peer.services.ocd.graphs.CustomGraph; +import i5.las2peer.services.ocd.graphs.MultiplexGraph; + +/** + * The common interface of all graph output adapters. + * @author Sebastian + * + */ +public interface MultiplexGraphOutputAdapter extends CommonGraphOutputAdapter { + + /** + * Writes a graph and closes the writer. + * @param graph The graph to write. + * @throws AdapterException if the adapter failed + */ + public void writeGraph(MultiplexGraph graph) throws AdapterException; + +} diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/MultiplexGraph.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/MultiplexGraph.java index 32012a15..de3b1fdd 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/MultiplexGraph.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/MultiplexGraph.java @@ -1,9 +1,13 @@ package i5.las2peer.services.ocd.graphs; import com.arangodb.ArangoCollection; +import com.arangodb.ArangoCursor; import com.arangodb.ArangoDatabase; import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.BaseEdgeDocument; import com.arangodb.model.*; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.util.*; /** @@ -34,6 +38,11 @@ public class MultiplexGraph { */ private String key = ""; + /** + * System generated persistence id. + */ + private long id; + /** * The name of the user owning the graph. */ @@ -162,7 +171,7 @@ public GraphCreationLog getCreationMethod() { * * @return The number of nodes. */ - public long getNodeCount(){return this.graphNodeCount;} + public int getNodeCount(){return (int)this.graphNodeCount;} /** * Getter for the number of nodes. @@ -175,7 +184,7 @@ public GraphCreationLog getCreationMethod() { * * @return The number of edges. */ - public long getEdgeCount(){return this.graphEdgeCount;} + public int getEdgeCount(){return (int)this.graphEdgeCount;} /** * Getter for the number of edges. * @@ -277,6 +286,42 @@ protected CustomGraph getCustomGraph(CustomGraph customGraph) { return mapCustomGraphs.get(customGraph.getId()); } + public static MultiplexGraph load(String key, ArangoDatabase db, String transId) { + MultiplexGraph graph = null; + ArangoCollection collection = db.collection(collectionName); + DocumentReadOptions readOpt = new DocumentReadOptions().streamTransactionId(transId); + AqlQueryOptions queryOpt = new AqlQueryOptions().streamTransactionId(transId); + BaseDocument bd = collection.getDocument(key, BaseDocument.class, readOpt); + + if (bd != null) { + graph = new MultiplexGraph(); + ObjectMapper om = new ObjectMapper(); + Object objId = bd.getAttribute(idColumnName); + if(objId!= null) { + graph.id = Long.parseLong(objId.toString()); + } + graph.key = key; + graph.userName = bd.getAttribute(userColumnName).toString(); + //graph.path = bd.getAttribute(pathColumnName).toString(); + graph.name = bd.getAttribute(nameColumnName).toString(); + Object objTypes = bd.getAttribute(typesColumnName); + graph.types = om.convertValue(objTypes, Set.class); + //Object objProperties = bd.getAttribute(propertiesColumnName); + //graph.properties = om.convertValue(objProperties, List.class); + String creationMethodKey = bd.getAttribute(creationMethodKeyColumnName).toString(); + graph.graphNodeCount = om.convertValue(bd.getAttribute(nodeCountColumnName), Long.class); + graph.graphEdgeCount = om.convertValue(bd.getAttribute(edgeCountColumnName), Long.class); + graph.layerCount = om.convertValue(bd.getAttribute(layerCountColumnName), Integer.class); + graph.creationMethod = GraphCreationLog.load(creationMethodKey, db, readOpt); + Object objLayerKeys = bd.getAttribute(layerKeysColumnName); + graph.layerKeys = om.convertValue(objLayerKeys, List.class); + } + else { + System.out.println("Empty Graph document"); + System.out.println(" DB name: " + db.dbName().get()); + } + return graph; + } public void persist(ArangoDatabase db, String transId) throws InterruptedException { ArangoCollection collection = db.collection(collectionName); BaseDocument bd = new BaseDocument(); diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java index 3ff3cdba..88443774 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java @@ -285,6 +285,19 @@ private CustomGraph getGraph(String key) { } return graph; } + + private MultiplexGraph getMultiplexGraph(String key) { + String transId = getTransactionId(MultiplexGraph.class, false); + MultiplexGraph graph; + try { + graph = MultiplexGraph.load(key, db, transId); + db.commitStreamTransaction(transId); + }catch(Exception e) { + db.abortStreamTransaction(transId); + throw e; + } + return graph; + } /** * Returns a persisted CustomGraph if it has the right username @@ -308,6 +321,29 @@ else if(!username.equals(g.getUserName())) { return g; } + + /** + * Returns a persisted CustomGraph if it has the right username + * + * @param username + * owner of the graph + * @param key + * key of the graph + * @return the found CustomGraph instance or null if the CustomGraph does not exists or the username is wrong + */ + public MultiplexGraph getMultiplexGraph(String username, String key) { + MultiplexGraph g = getMultiplexGraph(key); + + if (g == null) { + logger.log(Level.WARNING, "user: " + username + " Graph does not exist: graph key " + key); + } + else if(!username.equals(g.getUserName())) { + logger.log(Level.WARNING, "user: " + username + " is not allowed to use Graph: " + key + " with user: " + g.getUserName()); + g = null; + } + + return g; + } /** * Return all graphs of a user @@ -385,7 +421,49 @@ public ArrayList getGraphMetaDataEfficiently(String username, i db.abortStreamTransaction(transId); e.printStackTrace(); } - System.out.println("customGraphMetas getGraphMetaDataEfficiently: " + customGraphMetas); + return customGraphMetas; + } + /** + * Return specified graphs' meta information of a user using an efficient approach. This approach only necessary + * metadata about graphs. E.g. no information about nodes/edges (other than their count) is loaded. + * + * @param username + * the users username + * @param key + * the key of the multiplex graph the customgraphs belong to as layers + * @return the list of graphs + */ + public ArrayList getMultiplexGraphMetaDataOfLayersEfficiently(String username, String key){ + System.out.println("key in database:" + key); + String transId = getTransactionId(MultiplexGraph.class, false); + ObjectMapper objectMapper = new ObjectMapper(); // needed to instantiate CustomGraphMeta from JSON + ArrayList customGraphMetas = new ArrayList(); + + try { + AqlQueryOptions queryOpt = new AqlQueryOptions().streamTransactionId(transId); + String queryStr = "FOR g IN " + CustomGraph.collectionName + " FOR gcl IN " + GraphCreationLog.collectionName + " FOR mg IN " + MultiplexGraph.collectionName + + " FILTER g." + CustomGraph.userColumnName + " == @username AND gcl._key == g." + CustomGraph.creationMethodKeyColumnName + + " AND mg._key == \"" + key + "\" AND g._key IN mg." + MultiplexGraph.layerKeysColumnName + + " AND 8 IN g." + CustomGraph.typesColumnName + + " RETURN "+ + "{\"key\" : g._key," + + "\"userName\" : g." + CustomGraph.userColumnName + "," + + "\"name\" : g." + CustomGraph.nameColumnName + "," + + "\"nodeCount\" : g." + CustomGraph.nodeCountColumnName + "," + + "\"edgeCount\" : g." + CustomGraph.edgeCountColumnName + "," + + "\"types\" : g." + CustomGraph.typesColumnName + "," + + "\"creationTypeId\" : gcl." + GraphCreationLog.typeColumnName + "," + + "\"creationStatusId\" : gcl." + GraphCreationLog.statusIdColumnName + "}"; + Map bindVars = Collections.singletonMap("username",username); + ArangoCursor customGraphMetaJson = db.query(queryStr, bindVars, queryOpt, String.class); + while(customGraphMetaJson.hasNext()) { + customGraphMetas.add(objectMapper.readValue(customGraphMetaJson.next(), CustomGraphMeta.class)); + } + db.commitStreamTransaction(transId); + }catch(Exception e) { + db.abortStreamTransaction(transId); + e.printStackTrace(); + } return customGraphMetas; } diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/RequestHandler.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/RequestHandler.java index 33b709a6..a0f3f029 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/RequestHandler.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/RequestHandler.java @@ -17,7 +17,8 @@ import i5.las2peer.services.ocd.adapters.graphInput.CommonGraphInputAdapter; import i5.las2peer.services.ocd.adapters.graphInput.GraphInputAdapterFactory; import i5.las2peer.services.ocd.adapters.graphInput.GraphInputFormat; -import i5.las2peer.services.ocd.adapters.graphOutput.GraphOutputAdapter; +import i5.las2peer.services.ocd.adapters.graphOutput.CommonGraphOutputAdapter; +import i5.las2peer.services.ocd.adapters.graphOutput.MultiplexGraphOutputAdapter; import i5.las2peer.services.ocd.adapters.graphOutput.GraphOutputAdapterFactory; import i5.las2peer.services.ocd.adapters.graphOutput.GraphOutputFormat; import i5.las2peer.services.ocd.adapters.metaOutput.*; @@ -654,13 +655,35 @@ public String writeId(OcdMetricLog metricLog) throws ParserConfigurationExceptio */ public String writeGraph(CustomGraph graph, GraphOutputFormat outputFormat) throws AdapterException, InstantiationException, IllegalAccessException { - GraphOutputAdapter adapter = graphOutputAdapterFactory.getInstance(outputFormat); + CommonGraphOutputAdapter adapter = graphOutputAdapterFactory.getInstance(outputFormat); Writer writer = new StringWriter(); adapter.setWriter(writer); adapter.writeGraph(graph); return writer.toString(); } + /** + * Creates a graph output in a specified format. + * + * @param graph + * The graph. + * @param outputFormat + * The format. + * @return The graph output. + * @throws AdapterException if adapter failed + * @throws InstantiationException if instantiation failed + * @throws IllegalAccessException if an illegal access occurred on the instance + */ + public String writeMultiplexGraph(MultiplexGraph graph, GraphOutputFormat outputFormat) + throws AdapterException, InstantiationException, IllegalAccessException { + CommonGraphOutputAdapter adapter = graphOutputAdapterFactory.getInstance(outputFormat); + Writer writer = new StringWriter(); + adapter.setWriter(writer); + adapter.writeGraph(graph); + return writer.toString(); + } + + /** * Creates a graph output in a MetaXml format. This method uses efficient approach. * Only necessary information is loaded (e.g. no node/edge info) diff --git a/time_seed.dat b/time_seed.dat index 9c76bbc6..6db8c249 100644 --- a/time_seed.dat +++ b/time_seed.dat @@ -1 +1 @@ -21112707 \ No newline at end of file +21113040 \ No newline at end of file