Skip to content

Commit

Permalink
more changes to enable the import
Browse files Browse the repository at this point in the history
  • Loading branch information
MarenHanke committed Dec 4, 2023
1 parent 9b66af7 commit 9b76cda
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,15 @@ 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<GraphType> graphTypes = graph.getTypes();
// if (graphTypes.remove(GraphType.DIRECTED)) {
// processor.makeCompatible(graph, graphTypes);
// }
//}
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");
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


/**
* The common interface of all graph input adapters.
* The common interface of all customgraph input adapters.
* @author Sebastian
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


/**
* The common interface of all graph input adapters.
* The common interface of all multiplexgraph input adapters.
* @author Maren
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -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;

Expand All @@ -84,7 +64,7 @@ public class MultiplexGraph{

private Map<String, CustomGraph> mapCustomGraphs = new HashMap<String, CustomGraph>();

private Map<CustomGraph, String> mapCustomGraphIds = new HashMap<CustomGraph, String>();
//private Map<CustomGraph, String> mapCustomGraphIds = new HashMap<CustomGraph, String>();

//////////////////////////////////////////////////////////////////
///////// Constructor
Expand Down Expand Up @@ -207,14 +187,14 @@ public Map<String, CustomGraph> getCustomGraphs() {
return mapCustomGraphs;
}

public void setCustomGraphs(Map<String, CustomGraph> customGraphs) {
this.mapCustomGraphs = customGraphs;
}
//public void setCustomGraphs(Map<String, CustomGraph> 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
Expand All @@ -223,26 +203,17 @@ 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);
this.key = bd.getKey();

bd = new BaseDocument();

List<CustomNode> nodes = new ArrayList<CustomNode>(this.customNodes.values());
for (CustomNode customNode : nodes) {
customNode.persist(db,createOptions);
List<CustomGraph> layers = new ArrayList<CustomGraph>(this.mapCustomGraphs.values());
for (CustomGraph customGraph : layers) {
customGraph.persist(db, transId);
}


List<CustomEdge> edges = new ArrayList<CustomEdge>(this.customEdges.values());
for (CustomEdge customEdge : edges) {
customEdge.persist(db, createOptions);
}

bd.addAttribute(propertiesColumnName, this.properties);
collection.updateDocument(this.key, bd, updateOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Database {
private ArangoDB arangoDB;
public ArangoDatabase db;

private List<String> collectionNames =new ArrayList<String>(13);
private List<String> collectionNames =new ArrayList<String>(14);


public Database(boolean testDB) {
Expand Down Expand Up @@ -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();
}
}


Expand Down Expand Up @@ -1742,10 +1746,7 @@ public void deleteUserInactivityData(String username, ThreadHandler threadHandle
throw e;
}
}
}



}

public String getTransactionId(Class c, boolean write) {
String [] collections;
Expand Down Expand Up @@ -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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 9b76cda

Please sign in to comment.