Skip to content

Commit

Permalink
view multiplex graphs on graphs.html page
Browse files Browse the repository at this point in the history
  • Loading branch information
MarenHanke committed Dec 22, 2023
1 parent 55cab1d commit 6d9d6c4
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,21 +437,21 @@ public Response createGraph(@DefaultValue("unnamed") @QueryParam("name") String
GraphProcessor processor = new GraphProcessor();
processor.determineGraphTypes(graph);
if (doMakeUndirected) {
for (MultiplexCustomGraph multiplexCustomGraph :graph.getMultiplexCustomGraphs().values()) {
Set<GraphType> graphTypes = multiplexCustomGraph.getTypes();
for (CustomGraph customGraph :graph.getCustomGraphs().values()) {
Set<GraphType> graphTypes = customGraph.getTypes();
if (graphTypes.remove(GraphType.DIRECTED)) {
processor.makeCompatible(multiplexCustomGraph, graphTypes);
processor.makeCompatible(customGraph, graphTypes);
}
}
graph.removeType(GraphType.DIRECTED);
}
try {
for (MultiplexCustomGraph multiplexCustomGraph :graph.getMultiplexCustomGraphs().values()) {
multiplexCustomGraph.setUserName(username);
multiplexCustomGraph.setCreationMethod(log);
multiplexCustomGraph.addType(GraphType.MULTIPLEX_LAYER);
database.storeGraph(multiplexCustomGraph);
graph.addLayerKey(multiplexCustomGraph.getKey());
for (CustomGraph customGraph :graph.getCustomGraphs().values()) {
customGraph.setUserName(username);
customGraph.setCreationMethod(log);
customGraph.addType(GraphType.MULTIPLEX_LAYER);
database.storeGraph(customGraph);
graph.addLayerKey(customGraph.getKey());
}
database.storeGraph(graph);
generalLogger.getLogger().log(Level.INFO, "user " + username + ": import graph " + graph.getKey() + " in format " + graphInputFormatStr);
Expand Down Expand Up @@ -679,7 +679,6 @@ public Response getGraphs(@DefaultValue("0") @QueryParam("firstIndex") String fi
try {
String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName();
List<CustomGraphMeta> queryResults;
List<MultiplexGraphMeta> queryResultsMultiplex;
List<Integer> executionStatusIds = new ArrayList<Integer>();
if (!executionStatusesStr.equals("")) {
try {
Expand Down Expand Up @@ -729,7 +728,6 @@ public Response getGraphs(@DefaultValue("0") @QueryParam("firstIndex") String fi
return requestHandler.writeError(Error.PARAMETER_INVALID, "Length is not valid.");
}
queryResults = database.getGraphMetaDataEfficiently(username, firstIndex, length, executionStatusIds);
queryResultsMultiplex = database.getMultiplexGraphMetaDataEfficiently(username, firstIndex, length, executionStatusIds);
String responseStr;
if (includeMeta) {
responseStr = requestHandler.writeGraphMetasEfficiently(queryResults);
Expand All @@ -743,6 +741,84 @@ public Response getGraphs(@DefaultValue("0") @QueryParam("firstIndex") String fi
}
}

/**
* Returns the ids (or meta information) of multiple graphs.
*
* @param firstIndexStr
* Optional query parameter. The result list index of the
* first id to return. Defaults to 0.
* @param lengthStr
* Optional query parameter. The number of ids to return.
* Defaults to Long.MAX_VALUE.
* @param executionStatusesStr
* Optional query parameter. If set only those graphs are
* returned whose creation method has one of the given
* ExecutionStatus names. Multiple status names are separated
* using the "-" delimiter.
* @return The graphs. Or an error xml.
*/

@GET
@Path("multiplexgraphs")
@Produces(MediaType.TEXT_XML)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized") })
@ApiOperation(tags = {"show"}, value = "Get Multiplexgraphs Info", notes = "Returns the meta information of multiple graphs.")
public Response getMultiplexGraphs(@DefaultValue("0") @QueryParam("firstIndex") String firstIndexStr,
@DefaultValue("") @QueryParam("length") String lengthStr,
@DefaultValue("") @QueryParam("executionStatuses") String executionStatusesStr) {
try {
String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName();
List<MultiplexGraphMeta> queryResults;
List<Integer> executionStatusIds = new ArrayList<Integer>();
if (!executionStatusesStr.equals("")) {
try {
List<String> executionStatusesStrList = requestHandler
.parseQueryMultiParam(executionStatusesStr);
for (String executionStatusStr : executionStatusesStrList) {
ExecutionStatus executionStatus = ExecutionStatus.valueOf(executionStatusStr);
executionStatusIds.add(executionStatus.getId());
}
} catch (Exception e) {
requestHandler.log(Level.WARNING, "user: " + username, e);
return requestHandler.writeError(Error.PARAMETER_INVALID,
"Specified execution status does not exist.");
}
} else {
for (ExecutionStatus executionStatus : ExecutionStatus.values()) {
executionStatusIds.add(executionStatus.getId());
}
}

int firstIndex = 0;
try {
firstIndex = Integer.parseInt(firstIndexStr);
} catch (Exception e) {
requestHandler.log(Level.WARNING, "user: " + username, e);
return requestHandler.writeError(Error.PARAMETER_INVALID, "First index is not valid.");
}

int length = 0;
try {
if (!lengthStr.equals("")) {
length = Integer.parseInt(lengthStr);
}
else {
length = Integer.MAX_VALUE;
}
} catch (Exception e) {
requestHandler.log(Level.WARNING, "user: " + username, e);
return requestHandler.writeError(Error.PARAMETER_INVALID, "Length is not valid.");
}
queryResults = database.getMultiplexGraphMetaDataEfficiently(username, firstIndex, length, executionStatusIds);
String responseStr = requestHandler.writeMultiplexGraphMetasEfficiently(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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import i5.las2peer.services.ocd.adapters.AdapterException;
import i5.las2peer.services.ocd.adapters.Adapters;
import i5.las2peer.services.ocd.graphs.MultiplexCustomGraph;
import i5.las2peer.services.ocd.graphs.CustomGraph;
import i5.las2peer.services.ocd.graphs.MultiplexGraph;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Node;
Expand Down Expand Up @@ -51,11 +51,11 @@ public MultiplexGraph readGraph() throws AdapterException {
while (line.size() == 3) {
//read layer
String layerName = line.get(0);
if (!multiplexGraph.getMultiplexCustomGraphs().containsKey(layerName)) {
multiplexGraph.addLayer(layerName, new MultiplexCustomGraph());
if (!multiplexGraph.getCustomGraphs().containsKey(layerName)) {
multiplexGraph.addLayer(layerName, new CustomGraph());
graphReverseNodeNames.put(layerName, new HashMap<String, Node>());
}
MultiplexCustomGraph graph = multiplexGraph.getMultiplexCustomGraphs().get(layerName);
CustomGraph graph = multiplexGraph.getCustomGraphs().get(layerName);
graph.setName(layerName);
Map<String, Node>reverseNodeNames = graphReverseNodeNames.get(layerName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import i5.las2peer.services.ocd.adapters.AdapterException;
import i5.las2peer.services.ocd.adapters.Adapters;
import i5.las2peer.services.ocd.graphs.MultiplexCustomGraph;
import i5.las2peer.services.ocd.graphs.CustomGraph;
import i5.las2peer.services.ocd.graphs.MultiplexGraph;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Node;
Expand Down Expand Up @@ -54,11 +54,11 @@ public MultiplexGraph readGraph() throws AdapterException {
while(line.size() == 4) {
//read layer
String layerName = line.get(0);
if (!multiplexGraph.getMultiplexCustomGraphs().containsKey(layerName)) {
multiplexGraph.addLayer(layerName, new MultiplexCustomGraph());
if (!multiplexGraph.getCustomGraphs().containsKey(layerName)) {
multiplexGraph.addLayer(layerName, new CustomGraph());
graphReverseNodeNames.put(layerName, new HashMap<String, Node>());
}
MultiplexCustomGraph graph = multiplexGraph.getMultiplexCustomGraphs().get(layerName);
CustomGraph graph = multiplexGraph.getCustomGraphs().get(layerName);
Map<String, Node>reverseNodeNames = graphReverseNodeNames.get(layerName);

//read edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import i5.las2peer.services.ocd.adapters.AdapterException;
import i5.las2peer.services.ocd.graphs.CustomGraphMeta;
import i5.las2peer.services.ocd.graphs.MultiplexGraphMeta;
import i5.las2peer.services.ocd.graphs.GraphType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -83,6 +84,15 @@ public void writeGraph(CustomGraphMeta graphMeta) throws AdapterException {
creationMethodStatus.appendChild(doc.createTextNode(graphMeta.getCreationStatusName()));
creationMethodElt.appendChild(creationMethodStatus);
graphElt.appendChild(creationMethodElt);
/*
* Handle Multiplex Graph Meta
*/
if (graphMeta instanceof MultiplexGraphMeta) {
MultiplexGraphMeta multiplexGraphMeta = (MultiplexGraphMeta) graphMeta;
Element layerCountElt = doc.createElement("LayerCount");
layerCountElt.appendChild(doc.createTextNode(Integer.toString(multiplexGraphMeta.getLayerCount())));
graphElt.appendChild(layerCountElt);
}
/*
* XML output
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public void determineGraphTypes(CustomGraph graph) {
*/
public void determineGraphTypes(MultiplexGraph multiplexGraph) {
multiplexGraph.addType(GraphType.MULTIPLEX);
if (multiplexGraph.getMultiplexCustomGraphs().size() == 0) {
if (multiplexGraph.getCustomGraphs().size() == 0) {
return;
}
for (CustomGraph graph : multiplexGraph.getMultiplexCustomGraphs().values()){
for (CustomGraph graph : multiplexGraph.getCustomGraphs().values()){
determineGraphTypes(graph);
if (graph.isOfType(GraphType.DIRECTED) && !multiplexGraph.isOfType(GraphType.DIRECTED)) {
multiplexGraph.addType(GraphType.DIRECTED);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public class MultiplexGraph {
*/
private List<Cover> covers = new ArrayList<Cover>();

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

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

//////////////////////////////////////////////////////////////////
///////// Constructor
Expand Down Expand Up @@ -260,22 +260,22 @@ public boolean isWeighted() {
return isOfType(GraphType.WEIGHTED);
}

public void addLayer(String layerName, MultiplexCustomGraph multiplexCustomGraph) {
this.mapMultiplexCustomGraphs.put(layerName, multiplexCustomGraph);
public void addLayer(String layerName, CustomGraph customGraph) {
this.mapCustomGraphs.put(layerName, customGraph);
layerCount++;
}

public Map<String, MultiplexCustomGraph> getMultiplexCustomGraphs() {
return mapMultiplexCustomGraphs;
public Map<String, CustomGraph> getCustomGraphs() {
return mapCustomGraphs;
}


//public void setMultiplexCustomGraphs(Map<String, MultiplexCustomGraph> multiplexCustomGraphs) {
// this.mapMultiplexCustomGraphs = multiplexCustomGraphs;
//}
//protected MultiplexCustomGraph getMultiplexCustomGraph(MultiplexCustomGraph multiplexCustomGraph) {
// return mapMultiplexCustomGraphs.get(multiplexCustomGraph.getId());
//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 {
ArangoCollection collection = db.collection(collectionName);
Expand Down
Loading

0 comments on commit 6d9d6c4

Please sign in to comment.