Skip to content

Commit

Permalink
Merge pull request #117 from vsreekanti/master
Browse files Browse the repository at this point in the history
Lineage Edge Adjacency API
  • Loading branch information
vsreekanti authored Sep 4, 2017
2 parents 03cef1b + 1996ac6 commit 62a4aef
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface NodeVersionDao extends RichVersionDao<NodeVersion> {
@Override
NodeVersion retrieveFromDatabase(long id) throws GroundException;

List<Long> retrieveAdjacentLineageEdgeVersion(long startId) throws GroundException;

@Override
default Class<NodeVersion> getType() {
return NodeVersion.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,22 @@ public final CompletionStage<Result> getHistory(String sourceKey) {
.thenApply(Results::ok)
.exceptionally(e -> GroundUtils.handleException(e, request()));
}

public final CompletionStage<Result> getAdjacentLineage(Long id) {
return CompletableFuture.supplyAsync(
() -> {
try {
return this.cache.getOrElse(
"node_version_adj_lineage." + id,
() -> Json.toJson(this.postgresNodeVersionDao.retrieveAdjacentLineageEdgeVersion(id)),
Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
} catch (Exception e) {
throw new CompletionException(e);
}
},
PostgresUtils.getDbSourceHttpContext(actorSystem))
.thenApply(Results::ok)
.exceptionally(e -> GroundUtils.handleException(e, request()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class SqlConstants {

/* Node-specific statements */
public static final String INSERT_NODE_VERSION = "INSERT INTO node_version (id, node_id) VALUES (%d, %d);";
public static final String SELECT_NODE_VERSION_ADJACENT_LINEAGE = "SELECT * FROM lineage_edge_version WHERE from_rich_version_id = %d;";

/* Rich Version-specific statements */
public static final String INSERT_RICH_VERSION_WITH_REFERENCE = "INSERT INTO rich_version (id, structure_version_id, reference) VALUES (%d, %d, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.berkeley.ground.postgres.dao.SqlConstants;
import edu.berkeley.ground.postgres.util.PostgresStatements;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.ArrayList;
import java.util.List;
import play.db.Database;
import play.libs.Json;
Expand Down Expand Up @@ -58,7 +59,7 @@ public PostgresStatements delete(long id) {
@Override
public NodeVersion retrieveFromDatabase(long id) throws GroundException {
String sql = String.format(SqlConstants.SELECT_STAR_BY_ID, "node_version", id);
JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(dbSource, sql));
JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(this.dbSource, sql));

if (json.size() == 0) {
throw new GroundException(ExceptionType.VERSION_NOT_FOUND, this.getType().getSimpleName(), String.format("%d", id));
Expand All @@ -69,4 +70,15 @@ public NodeVersion retrieveFromDatabase(long id) throws GroundException {

return new NodeVersion(id, richVersion, nodeVersion);
}

@Override
public List<Long> retrieveAdjacentLineageEdgeVersion(long startId) throws GroundException {
String sql = String.format(SqlConstants.SELECT_NODE_VERSION_ADJACENT_LINEAGE, startId);
JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(this.dbSource, sql));

List<Long> result = new ArrayList<>();
json.forEach(x -> result.add(x.get("id").asLong()));

return result;
}
}
77 changes: 39 additions & 38 deletions modules/postgres/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,57 @@
# ~~~~

# An example controller showing a sample home page
GET / edu.berkeley.ground.postgres.controllers.HomeController.index
GET / edu.berkeley.ground.postgres.controllers.HomeController.index

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

# edge endpoints
POST /edges edu.berkeley.ground.postgres.controllers.EdgeController.addEdge()
GET /edges/:sourceKey edu.berkeley.ground.postgres.controllers.EdgeController.getEdge(sourceKey: String)
POST /versions/edges edu.berkeley.ground.postgres.controllers.EdgeController.addEdgeVersion()
GET /versions/edges/:id edu.berkeley.ground.postgres.controllers.EdgeController.getEdgeVersion(id: Long)
GET /edges/:sourceKey/latest edu.berkeley.ground.postgres.controllers.EdgeController.getLatest(sourceKey: String)
GET /edges/:sourceKey/history edu.berkeley.ground.postgres.controllers.EdgeController.getHistory(sourceKey: String)
POST /edges edu.berkeley.ground.postgres.controllers.EdgeController.addEdge()
GET /edges/:sourceKey edu.berkeley.ground.postgres.controllers.EdgeController.getEdge(sourceKey: String)
POST /versions/edges edu.berkeley.ground.postgres.controllers.EdgeController.addEdgeVersion()
GET /versions/edges/:id edu.berkeley.ground.postgres.controllers.EdgeController.getEdgeVersion(id: Long)
GET /edges/:sourceKey/latest edu.berkeley.ground.postgres.controllers.EdgeController.getLatest(sourceKey: String)
GET /edges/:sourceKey/history edu.berkeley.ground.postgres.controllers.EdgeController.getHistory(sourceKey: String)

# graph endpoints
POST /graphs edu.berkeley.ground.postgres.controllers.GraphController.addGraph()
GET /graphs/:sourceKey edu.berkeley.ground.postgres.controllers.GraphController.getGraph(sourceKey: String)
POST /versions/graphs edu.berkeley.ground.postgres.controllers.GraphController.addGraphVersion()
GET /versions/graphs/:id edu.berkeley.ground.postgres.controllers.GraphController.getGraphVersion(id: Long)
GET /graphs/:sourceKey/latest edu.berkeley.ground.postgres.controllers.GraphController.getLatest(sourceKey: String)
GET /graphs/:sourceKey/history edu.berkeley.ground.postgres.controllers.GraphController.getHistory(sourceKey: String)
POST /graphs edu.berkeley.ground.postgres.controllers.GraphController.addGraph()
GET /graphs/:sourceKey edu.berkeley.ground.postgres.controllers.GraphController.getGraph(sourceKey: String)
POST /versions/graphs edu.berkeley.ground.postgres.controllers.GraphController.addGraphVersion()
GET /versions/graphs/:id edu.berkeley.ground.postgres.controllers.GraphController.getGraphVersion(id: Long)
GET /graphs/:sourceKey/latest edu.berkeley.ground.postgres.controllers.GraphController.getLatest(sourceKey: String)
GET /graphs/:sourceKey/history edu.berkeley.ground.postgres.controllers.GraphController.getHistory(sourceKey: String)

# lineage edge endpoints
POST /lineage_edges edu.berkeley.ground.postgres.controllers.LineageEdgeController.createLineageEdge()
GET /lineage_edges/:sourceKey edu.berkeley.ground.postgres.controllers.LineageEdgeController.getLineageEdge(sourceKey: String)
POST /versions/lineage_edges edu.berkeley.ground.postgres.controllers.LineageEdgeController.createLineageEdgeVersion()
GET /versions/lineage_edges/:id edu.berkeley.ground.postgres.controllers.LineageEdgeController.getLineageEdgeVersion(id: Long)
GET /lineage_edges/:sourceKey/latest edu.berkeley.ground.postgres.controllers.LineageEdgeController.getLatest(sourceKey: String)
GET /lineage_edges/:sourceKey/history edu.berkeley.ground.postgres.controllers.LineageEdgeController.getHistory(sourceKey: String)
POST /lineage_edges edu.berkeley.ground.postgres.controllers.LineageEdgeController.createLineageEdge()
GET /lineage_edges/:sourceKey edu.berkeley.ground.postgres.controllers.LineageEdgeController.getLineageEdge(sourceKey: String)
POST /versions/lineage_edges edu.berkeley.ground.postgres.controllers.LineageEdgeController.createLineageEdgeVersion()
GET /versions/lineage_edges/:id edu.berkeley.ground.postgres.controllers.LineageEdgeController.getLineageEdgeVersion(id: Long)
GET /lineage_edges/:sourceKey/latest edu.berkeley.ground.postgres.controllers.LineageEdgeController.getLatest(sourceKey: String)
GET /lineage_edges/:sourceKey/history edu.berkeley.ground.postgres.controllers.LineageEdgeController.getHistory(sourceKey: String)

# lineage graph endpoints
POST /lineage_graphs edu.berkeley.ground.postgres.controllers.LineageGraphController.createLineageGraph()
GET /lineage_graphs/:sourceKey edu.berkeley.ground.postgres.controllers.LineageGraphController.getLineageGraph(sourceKey: String)
POST /versions/lineage_graphs edu.berkeley.ground.postgres.controllers.LineageGraphController.createLineageGraphVersion()
GET /versions/lineage_graphs/:id edu.berkeley.ground.postgres.controllers.LineageGraphController.getLineageGraphVersion(id: Long)
GET /lineage_graphs/:sourceKey/latest edu.berkeley.ground.postgres.controllers.LineageGraphController.getLatest(sourceKey: String)
GET /lineage_graphs/:sourceKey/history edu.berkeley.ground.postgres.controllers.LineageGraphController.getHistory(sourceKey: String)
POST /lineage_graphs edu.berkeley.ground.postgres.controllers.LineageGraphController.createLineageGraph()
GET /lineage_graphs/:sourceKey edu.berkeley.ground.postgres.controllers.LineageGraphController.getLineageGraph(sourceKey: String)
POST /versions/lineage_graphs edu.berkeley.ground.postgres.controllers.LineageGraphController.createLineageGraphVersion()
GET /versions/lineage_graphs/:id edu.berkeley.ground.postgres.controllers.LineageGraphController.getLineageGraphVersion(id: Long)
GET /lineage_graphs/:sourceKey/latest edu.berkeley.ground.postgres.controllers.LineageGraphController.getLatest(sourceKey: String)
GET /lineage_graphs/:sourceKey/history edu.berkeley.ground.postgres.controllers.LineageGraphController.getHistory(sourceKey: String)

# node endpoints
POST /nodes edu.berkeley.ground.postgres.controllers.NodeController.addNode()
GET /nodes/:sourceKey edu.berkeley.ground.postgres.controllers.NodeController.getNode(sourceKey: String)
POST /versions/nodes edu.berkeley.ground.postgres.controllers.NodeController.addNodeVersion()
GET /versions/nodes/:id edu.berkeley.ground.postgres.controllers.NodeController.getNodeVersion(id: Long)
GET /nodes/:sourceKey/latest edu.berkeley.ground.postgres.controllers.NodeController.getLatest(sourceKey: String)
GET /nodes/:sourceKey/history edu.berkeley.ground.postgres.controllers.NodeController.getHistory(sourceKey: String)
POST /nodes edu.berkeley.ground.postgres.controllers.NodeController.addNode()
GET /nodes/:sourceKey edu.berkeley.ground.postgres.controllers.NodeController.getNode(sourceKey: String)
POST /versions/nodes edu.berkeley.ground.postgres.controllers.NodeController.addNodeVersion()
GET /versions/nodes/:id edu.berkeley.ground.postgres.controllers.NodeController.getNodeVersion(id: Long)
GET /nodes/:sourceKey/latest edu.berkeley.ground.postgres.controllers.NodeController.getLatest(sourceKey: String)
GET /nodes/:sourceKey/history edu.berkeley.ground.postgres.controllers.NodeController.getHistory(sourceKey: String)
GET /versions/nodes/adjacent/lineage/:id edu.berkeley.ground.postgres.controllers.NodeController.getAdjacentLineage(id: Long)

# structure endpoints
POST /structures edu.berkeley.ground.postgres.controllers.StructureController.addStructure()
GET /structures/:sourceKey edu.berkeley.ground.postgres.controllers.StructureController.getStructure(sourceKey: String)
POST /versions/structures edu.berkeley.ground.postgres.controllers.StructureController.addStructureVersion()
GET /versions/structures/:id edu.berkeley.ground.postgres.controllers.StructureController.getStructureVersion(id: Long)
GET /structures/:sourceKey/latest edu.berkeley.ground.postgres.controllers.StructureController.getLatest(sourceKey: String)
GET /structures/:sourceKey/history edu.berkeley.ground.postgres.controllers.StructureController.getHistory(sourceKey: String)
POST /structures edu.berkeley.ground.postgres.controllers.StructureController.addStructure()
GET /structures/:sourceKey edu.berkeley.ground.postgres.controllers.StructureController.getStructure(sourceKey: String)
POST /versions/structures edu.berkeley.ground.postgres.controllers.StructureController.addStructureVersion()
GET /versions/structures/:id edu.berkeley.ground.postgres.controllers.StructureController.getStructureVersion(id: Long)
GET /structures/:sourceKey/latest edu.berkeley.ground.postgres.controllers.StructureController.getLatest(sourceKey: String)
GET /structures/:sourceKey/history edu.berkeley.ground.postgres.controllers.StructureController.getHistory(sourceKey: String)

0 comments on commit 62a4aef

Please sign in to comment.