From 9b76cda0371511a5c615c69c2ef4549413e9b392 Mon Sep 17 00:00:00 2001 From: MarenHanke Date: Mon, 4 Dec 2023 13:24:18 +0100 Subject: [PATCH] more changes to enable the import --- .../las2peer/services/ocd/ServiceClass.java | 15 +++--- .../graphInput/GraphInputAdapter.java | 2 +- .../MultiplexGraphInputAdapter.java | 2 +- .../services/ocd/graphs/CustomGraph.java | 2 +- .../services/ocd/graphs/MultiplexGraph.java | 49 ++++--------------- .../las2peer/services/ocd/utils/Database.java | 16 +++--- .../services/ocd/utils/RequestHandler.java | 31 ++++++++++++ 7 files changed, 63 insertions(+), 54 deletions(-) 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 75fc2fea..5e446cac 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 @@ -600,7 +600,7 @@ public Response createMultiplexGraph(@DefaultValue("unnamed") @QueryParam("name" log.setStatus(ExecutionStatus.COMPLETED); graph.setCreationMethod(log); GraphProcessor processor = new GraphProcessor(); - processor.determineGraphTypes(graph); + //processor.determineGraphTypes(graph); //if (doMakeUndirected) { // Set graphTypes = graph.getTypes(); // if (graphTypes.remove(GraphType.DIRECTED)) { @@ -608,7 +608,7 @@ public Response createMultiplexGraph(@DefaultValue("unnamed") @QueryParam("name" // } //} try { - database.storeGraph(graph); + database.storeMultiplexGraph(graph); generalLogger.getLogger().log(Level.INFO, "user " + username + ": import graph " + graph.getKey() + " in format " + graphInputFormatStr); } catch (Exception e) { return requestHandler.writeError(Error.INTERNAL, "Could not store graph"); @@ -733,12 +733,15 @@ public Response processStoredGraph(@DefaultValue("unnamed") @QueryParam("name") return requestHandler.writeError(Error.INTERNAL, "Internal system error."); } graphFile.delete(); - if (graphInputFormatStr.equals("MULTIPLEX_WEIGHTED_EDGE_LIST" || graphInputFormatStr.equals("MULTIPLEX_UNWEIGHTED_EDGE_LIST")) - return createMultiplexGraph(nameStr, creationTypeStr, graphInputFormatStr, doMakeUndirectedStr, startDateStr, + Response response; + if (graphInputFormatStr.equals("MULTIPLEX_WEIGHTED_EDGE_LIST") || graphInputFormatStr.equals("MULTIPLEX_UNWEIGHTED_EDGE_LIST")){ + response = createMultiplexGraph(nameStr, creationTypeStr, graphInputFormatStr, doMakeUndirectedStr, startDateStr, + endDateStr,involvedUserURIsStr, showUserNamesStr, indexPathStr, filePathStr, contentStr.toString()); + }else{ + response = createGraph(nameStr, creationTypeStr, graphInputFormatStr, doMakeUndirectedStr, startDateStr, endDateStr,involvedUserURIsStr, showUserNamesStr, indexPathStr, filePathStr, contentStr.toString()); } - return createGraph(nameStr, creationTypeStr, graphInputFormatStr, doMakeUndirectedStr, startDateStr, - endDateStr,involvedUserURIsStr, showUserNamesStr, indexPathStr, filePathStr, contentStr.toString()); + return response; } /** diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/GraphInputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/GraphInputAdapter.java index 3bc9062e..80251de7 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/GraphInputAdapter.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/GraphInputAdapter.java @@ -10,7 +10,7 @@ /** - * The common interface of all graph input adapters. + * The common interface of all customgraph input adapters. * @author Sebastian * */ diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/MultiplexGraphInputAdapter.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/MultiplexGraphInputAdapter.java index 31e3634b..596619a4 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/MultiplexGraphInputAdapter.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/adapters/graphInput/MultiplexGraphInputAdapter.java @@ -9,7 +9,7 @@ /** - * The common interface of all graph input adapters. + * The common interface of all multiplexgraph input adapters. * @author Maren * */ diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/CustomGraph.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/CustomGraph.java index 66065d67..93a6cd13 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/CustomGraph.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/graphs/CustomGraph.java @@ -47,7 +47,7 @@ //TODO: Check whether UUIDs work out as unique edge IDs, collision chances should however be extremely low //TODO: Check whether UUIDs work out as unique node IDs, collision chances should however be extremely low. Check whether this could actually replace the current node names. Would however break style with the naming of the other classes. //TODO: Integrate graphstream attributes into persistence or not? -public class CustomGraph extends MultiGraph{ +public class CustomGraph extends MultiGraph { /////////////////// DATABASE COLUMN NAMES 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 3ad62827..1c830789 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,30 +1,10 @@ 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 i5.las2peer.services.ocd.algorithms.utils.Termmatrix; -import i5.las2peer.services.ocd.cooperation.data.simulation.SimulationSeries; -import i5.las2peer.services.ocd.graphs.properties.AbstractProperty; -import i5.las2peer.services.ocd.graphs.properties.GraphProperty; -import org.graphstream.graph.Edge; -import org.graphstream.graph.Node; -import org.graphstream.graph.implementations.AbstractGraph; -import org.graphstream.graph.implementations.AbstractNode; -import org.graphstream.graph.implementations.MultiGraph; -import org.graphstream.graph.implementations.MultiNode; -import org.graphstream.ui.layout.Layout; -import org.graphstream.ui.layout.springbox.implementations.SpringBox; -import org.la4j.matrix.Matrix; -import org.la4j.matrix.sparse.CCSMatrix; - import java.util.*; -import java.util.stream.Stream; - /** * Represents a graph (or network), i.e. the node / edge structure and @@ -34,7 +14,7 @@ * */ -public class MultiplexGraph{ +public class MultiplexGraph { public static final String idColumnName = "ID"; public static final String userColumnName = "USER_NAME"; public static final String nameColumnName = "NAME"; @@ -62,7 +42,7 @@ public class MultiplexGraph{ private String name = ""; /** - * The number of layer of the graph. + * The number of layers of the graph. */ private long layerCount; @@ -84,7 +64,7 @@ public class MultiplexGraph{ private Map mapCustomGraphs = new HashMap(); - private Map mapCustomGraphIds = new HashMap(); + //private Map mapCustomGraphIds = new HashMap(); ////////////////////////////////////////////////////////////////// ///////// Constructor @@ -207,14 +187,14 @@ public Map getCustomGraphs() { return mapCustomGraphs; } - public void setCustomGraphs(Map customGraphs) { - this.mapCustomGraphs = customGraphs; - } + //public void setCustomGraphs(Map customGraphs) { + // this.mapCustomGraphs = customGraphs; + //} //protected CustomGraph getCustomGraph(CustomGraph customgraph) { // return mapCustomGraphs.get(customgraph.getId()); //} - public void persist( ArangoDatabase db, String transId) throws InterruptedException { + public void persist(ArangoDatabase db, String transId) throws InterruptedException { ArangoCollection collection = db.collection(collectionName); BaseDocument bd = new BaseDocument(); //options for the transaction @@ -223,7 +203,6 @@ public void persist( ArangoDatabase db, String transId) throws InterruptedExcept bd.addAttribute(userColumnName, this.userName); bd.addAttribute(nameColumnName, this.name); bd.addAttribute(typesColumnName, this.types); - bd.addAttribute(layerCount, this.layerCount); this.creationMethod.persist(db, createOptions); bd.addAttribute(creationMethodKeyColumnName, this.creationMethod.getKey()); collection.insertDocument(bd, createOptions); @@ -231,18 +210,10 @@ public void persist( ArangoDatabase db, String transId) throws InterruptedExcept bd = new BaseDocument(); - List nodes = new ArrayList(this.customNodes.values()); - for (CustomNode customNode : nodes) { - customNode.persist(db,createOptions); + List layers = new ArrayList(this.mapCustomGraphs.values()); + for (CustomGraph customGraph : layers) { + customGraph.persist(db, transId); } - - - List edges = new ArrayList(this.customEdges.values()); - for (CustomEdge customEdge : edges) { - customEdge.persist(db, createOptions); - } - - bd.addAttribute(propertiesColumnName, this.properties); collection.updateDocument(this.key, bd, updateOptions); } } 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 7a0d7196..a06fd557 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 @@ -67,7 +67,7 @@ public class Database { private ArangoDB arangoDB; public ArangoDatabase db; - private List collectionNames =new ArrayList(13); + private List collectionNames =new ArrayList(14); public Database(boolean testDB) { @@ -182,7 +182,11 @@ public void createCollections() { if(!collection.exists()) { collection.create(); } - + collectionNames.add(MultiplexGraph.collectionName); //13 + collection = db.collection(MultiplexGraph.collectionName); + if(!collection.exists()) { + collection.create(); + } } @@ -1742,10 +1746,7 @@ public void deleteUserInactivityData(String username, ThreadHandler threadHandle throw e; } } - } - - - + } public String getTransactionId(Class c, boolean write) { String [] collections; @@ -1779,6 +1780,9 @@ else if(c == SimulationSeries.class){ else if(c == SimulationSeriesGroup.class){ collections = collectionNames.subList(11,13).toArray(new String[1]); } + //else if(c == MultiplexGraph.class) { + //collections = collectionNames.subList(0, 4).toArray(new String[4]); + //} else { collections = collectionNames.subList(0, 13).toArray(new String[10]); } 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 7535de8a..f8cfc3a6 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 @@ -558,6 +558,20 @@ public String writeId(CustomGraph graph) throws ParserConfigurationException { return writeDoc(doc); } + /** + * Creates an XML document containing the id of a single graph. + * + * @param graph + * The multiplex graph. + * @return The document. + * @throws ParserConfigurationException if parsing failed + */ + public String writeId(MultiplexGraph graph) throws ParserConfigurationException { + Document doc = getDocument(); + doc.appendChild(getIdElt(graph, doc)); + return writeDoc(doc); + } + /** * Creates an XML document containing the id of a single cover. * @@ -973,6 +987,23 @@ protected Node getIdElt(CustomGraph graph, Document doc) { return graphElt; } + /** + * Returns an XML element node representing the id (key) of a multiplex graph. + * + * @param graph + * The multiplex graph. + * @param doc + * The document to create the element node for. + * @return The element node. + */ + protected Node getIdElt(MultiplexGraph graph, Document doc) { + Element graphElt = doc.createElement("Graph"); + Element graphIdElt = doc.createElement("Id"); + graphIdElt.appendChild(doc.createTextNode(graph.getKey())); + graphElt.appendChild(graphIdElt); + return graphElt; + } + /** * Returns an XML element node representing the id of a graph. *