Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/main/java/org/softwareheritage/graph/App.java
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | private static void startServer(String graphPath, int port, boolean showTimings) | ||||
// By default the traversal is a forward DFS using all edges | // By default the traversal is a forward DFS using all edges | ||||
app.get("/leaves/:src", ctx -> { | app.get("/leaves/:src", ctx -> { | ||||
SwhPID src = new SwhPID(ctx.pathParam("src")); | SwhPID src = new SwhPID(ctx.pathParam("src")); | ||||
String direction = ctx.queryParam("direction", "forward"); | String direction = ctx.queryParam("direction", "forward"); | ||||
String edgesFmt = ctx.queryParam("edges", "*"); | String edgesFmt = ctx.queryParam("edges", "*"); | ||||
Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | ||||
Endpoint.Output output = endpoint.leaves(src); | Endpoint.Output output = endpoint.leaves(new Endpoint.Input(src)); | ||||
ctx.json(formatEndpointOutput(output, showTimings)); | ctx.json(formatEndpointOutput(output, showTimings)); | ||||
}); | }); | ||||
app.get("/neighbors/:src", ctx -> { | app.get("/neighbors/:src", ctx -> { | ||||
SwhPID src = new SwhPID(ctx.pathParam("src")); | SwhPID src = new SwhPID(ctx.pathParam("src")); | ||||
String direction = ctx.queryParam("direction", "forward"); | String direction = ctx.queryParam("direction", "forward"); | ||||
String edgesFmt = ctx.queryParam("edges", "*"); | String edgesFmt = ctx.queryParam("edges", "*"); | ||||
Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | ||||
Endpoint.Output output = endpoint.neighbors(src); | Endpoint.Output output = endpoint.neighbors(new Endpoint.Input(src)); | ||||
ctx.json(formatEndpointOutput(output, showTimings)); | ctx.json(formatEndpointOutput(output, showTimings)); | ||||
}); | }); | ||||
app.get("/visit/nodes/:src", ctx -> { | app.get("/visit/nodes/:src", ctx -> { | ||||
SwhPID src = new SwhPID(ctx.pathParam("src")); | SwhPID src = new SwhPID(ctx.pathParam("src")); | ||||
String direction = ctx.queryParam("direction", "forward"); | String direction = ctx.queryParam("direction", "forward"); | ||||
String edgesFmt = ctx.queryParam("edges", "*"); | String edgesFmt = ctx.queryParam("edges", "*"); | ||||
Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | ||||
Endpoint.Output output = endpoint.visitNodes(src); | Endpoint.Output output = endpoint.visitNodes(new Endpoint.Input(src)); | ||||
ctx.json(formatEndpointOutput(output, showTimings)); | ctx.json(formatEndpointOutput(output, showTimings)); | ||||
}); | }); | ||||
app.get("/visit/paths/:src", ctx -> { | app.get("/visit/paths/:src", ctx -> { | ||||
SwhPID src = new SwhPID(ctx.pathParam("src")); | SwhPID src = new SwhPID(ctx.pathParam("src")); | ||||
String direction = ctx.queryParam("direction", "forward"); | String direction = ctx.queryParam("direction", "forward"); | ||||
String edgesFmt = ctx.queryParam("edges", "*"); | String edgesFmt = ctx.queryParam("edges", "*"); | ||||
Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | ||||
Endpoint.Output output = endpoint.visitPaths(src); | Endpoint.Output output = endpoint.visitPaths(new Endpoint.Input(src)); | ||||
ctx.json(formatEndpointOutput(output, showTimings)); | ctx.json(formatEndpointOutput(output, showTimings)); | ||||
}); | }); | ||||
app.get("/walk/:src/:dst", ctx -> { | app.get("/walk/:src/:dst", ctx -> { | ||||
SwhPID src = new SwhPID(ctx.pathParam("src")); | SwhPID src = new SwhPID(ctx.pathParam("src")); | ||||
String dstFmt = ctx.pathParam("dst"); | String dstFmt = ctx.pathParam("dst"); | ||||
String direction = ctx.queryParam("direction", "forward"); | String direction = ctx.queryParam("direction", "forward"); | ||||
String edgesFmt = ctx.queryParam("edges", "*"); | String edgesFmt = ctx.queryParam("edges", "*"); | ||||
String algorithm = ctx.queryParam("traversal", "dfs"); | String algorithm = ctx.queryParam("traversal", "dfs"); | ||||
Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); | ||||
Endpoint.Output output = endpoint.walk(src, dstFmt, algorithm); | Endpoint.Output output = endpoint.walk(new Endpoint.Input(src, dstFmt, algorithm)); | ||||
ctx.json(formatEndpointOutput(output, showTimings)); | ctx.json(formatEndpointOutput(output, showTimings)); | ||||
}); | }); | ||||
app.exception(IllegalArgumentException.class, (e, ctx) -> { | app.exception(IllegalArgumentException.class, (e, ctx) -> { | ||||
ctx.status(400); | ctx.status(400); | ||||
ctx.result(e.getMessage()); | ctx.result(e.getMessage()); | ||||
}); | }); | ||||
} | } | ||||
Show All 37 Lines |