Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import edu.berkeley.ground.common.util.IdGenerator;
import edu.berkeley.ground.postgres.dao.core.PostgresEdgeDao;
import edu.berkeley.ground.postgres.dao.core.PostgresEdgeVersionDao;
import edu.berkeley.ground.postgres.util.GroundUtils;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import edu.berkeley.ground.postgres.util.*;
import play.cache.CacheApi;
import play.db.Database;
import play.libs.Json;
Expand All @@ -24,21 +18,27 @@
import play.mvc.Result;
import play.mvc.Results;

import javax.inject.Inject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

public class EdgeController extends Controller {

private CacheApi cache;
private ActorSystem actorSystem;

private PostgresEdgeDao postgresEdgeDao;
private PostgresEdgeVersionDao postgresEdgeVersionDao;
private SharedFileState sharedFileState;

@Inject
final void injectUtils(final CacheApi cache, final Database dbSource, final ActorSystem actorSystem, final IdGenerator idGenerator) {
this.actorSystem = actorSystem;
this.cache = cache;

this.postgresEdgeDao = new PostgresEdgeDao(dbSource, idGenerator);
this.postgresEdgeVersionDao = new PostgresEdgeVersionDao(dbSource, idGenerator);
this.sharedFileState = new SharedFileState(new Tree(new TreeNode("root", "root")));
}

public final CompletionStage<Result> getEdge(final String sourceKey) {
Expand All @@ -60,11 +60,13 @@ public final CompletionStage<Result> getEdge(final String sourceKey) {

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addEdge() {
String currentPath = sharedFileState.getCwd();
return CompletableFuture.supplyAsync(
() -> {
JsonNode json = request().body().asJson();
Edge edge = Json.fromJson(json, Edge.class);

String newName = currentPath + "/" + String.valueOf(json.get("name"));
((ObjectNode) json).put("name", newName);
try {
edge = this.postgresEdgeDao.create(edge);
} catch (GroundException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package edu.berkeley.ground.postgres.controllers;

import akka.actor.ActorSystem;
import edu.berkeley.ground.common.exception.GroundException;
import edu.berkeley.ground.postgres.util.SharedFileState;
import edu.berkeley.ground.postgres.util.Tree;
import edu.berkeley.ground.postgres.util.TreeNode;
import play.cache.CacheApi;
import play.db.Database;

import javax.inject.Inject;

public class FileController {
private CacheApi cache;
private ActorSystem actorSystem;
private String global;
private SharedFileState sharedFileState;


@Inject
final void injectUtils(final CacheApi cache, final Database dbSource, final String global, final String fileLeaf) {
this.actorSystem = actorSystem;
this.cache = cache;
this.global = global;
sharedFileState = new SharedFileState( new Tree(
new TreeNode(global, global))); // represents global directory
}

public SharedFileState getSharedFileState() {
return sharedFileState;
}

public void setCwd(String path) throws GroundException {
sharedFileState.setCwd(path);
}

public String getCwd(String path) {
return sharedFileState.getCwd();
}

public void addFile(String path) {
sharedFileState.addFile(path);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
import edu.berkeley.ground.common.util.IdGenerator;
import edu.berkeley.ground.postgres.dao.core.PostgresGraphDao;
import edu.berkeley.ground.postgres.dao.core.PostgresGraphVersionDao;
import edu.berkeley.ground.postgres.util.GroundUtils;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import edu.berkeley.ground.postgres.util.*;
import play.cache.CacheApi;
import play.db.Database;
import play.libs.Json;
Expand All @@ -35,22 +29,28 @@
import play.mvc.Result;
import play.mvc.Results;

import javax.inject.Inject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

public class GraphController extends Controller {

private CacheApi cache;
private ActorSystem actorSystem;

private PostgresGraphDao postgresGraphDao;
private PostgresGraphVersionDao postgresGraphVersionDao;
private SharedFileState sharedFileState;

@Inject
final void injectUtils(final CacheApi cache, final Database dbSource, final ActorSystem actorSystem, final IdGenerator idGenerator) {
this.actorSystem = actorSystem;
this.cache = cache;

this.postgresGraphDao = new PostgresGraphDao(dbSource, idGenerator);

this.postgresGraphVersionDao = new PostgresGraphVersionDao(dbSource, idGenerator);
this.sharedFileState = new SharedFileState(new Tree(new TreeNode("root", "root")));
}

public final CompletionStage<Result> getGraph(String sourceKey) {
Expand Down Expand Up @@ -88,9 +88,12 @@ public final CompletionStage<Result> getGraphVersion(Long id) {

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraph() {
String currentPath = sharedFileState.getCwd();
return CompletableFuture.supplyAsync(
() -> {
JsonNode json = request().body().asJson();
String newName = currentPath + "/" + String.valueOf(json.get("name"));
((ObjectNode) json).put("name", newName);
Graph graph = Json.fromJson(json, Graph.class);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import edu.berkeley.ground.common.util.IdGenerator;
import edu.berkeley.ground.postgres.dao.usage.PostgresLineageEdgeDao;
import edu.berkeley.ground.postgres.dao.usage.PostgresLineageEdgeVersionDao;
import edu.berkeley.ground.postgres.util.GroundUtils;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import edu.berkeley.ground.postgres.util.*;
import play.cache.CacheApi;
import play.db.Database;
import play.libs.Json;
Expand All @@ -24,13 +18,20 @@
import play.mvc.Result;
import play.mvc.Results;

import javax.inject.Inject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

public class LineageEdgeController extends Controller {

private CacheApi cache;
private ActorSystem actorSystem;

private PostgresLineageEdgeDao postgresLineageEdgeDao;
private PostgresLineageEdgeVersionDao postgresLineageEdgeVersionDao;
private SharedFileState sharedFileState;

@Inject
final void injectUtils(final CacheApi cache, final Database dbSource, final ActorSystem actorSystem, final IdGenerator idGenerator) {
Expand All @@ -39,6 +40,7 @@ final void injectUtils(final CacheApi cache, final Database dbSource, final Acto

this.postgresLineageEdgeDao = new PostgresLineageEdgeDao(dbSource, idGenerator);
this.postgresLineageEdgeVersionDao = new PostgresLineageEdgeVersionDao(dbSource, idGenerator);
this.sharedFileState = new SharedFileState(new Tree(new TreeNode("root", "root")));
}

public final CompletionStage<Result> getLineageEdge(String sourceKey) {
Expand Down Expand Up @@ -77,9 +79,12 @@ public final CompletionStage<Result> getLineageEdgeVersion(Long id) {

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageEdge() {
String currentPath = sharedFileState.getCwd();
return CompletableFuture.supplyAsync(
() -> {
JsonNode json = request().body().asJson();
String newName = currentPath + "/" + String.valueOf(json.get("name"));
((ObjectNode) json).put("name", newName);
LineageEdge lineageEdge = Json.fromJson(json, LineageEdge.class);
try {
lineageEdge = this.postgresLineageEdgeDao.create(lineageEdge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import edu.berkeley.ground.common.util.IdGenerator;
import edu.berkeley.ground.postgres.dao.usage.PostgresLineageGraphDao;
import edu.berkeley.ground.postgres.dao.usage.PostgresLineageGraphVersionDao;
import edu.berkeley.ground.postgres.util.GroundUtils;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import edu.berkeley.ground.postgres.util.*;
import play.cache.CacheApi;
import play.db.Database;
import play.libs.Json;
Expand All @@ -24,13 +18,20 @@
import play.mvc.Result;
import play.mvc.Results;

import javax.inject.Inject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

public class LineageGraphController extends Controller {

private CacheApi cache;
private ActorSystem actorSystem;

private PostgresLineageGraphDao postgresLineageGraphDao;
private PostgresLineageGraphVersionDao postgresLineageGraphVersionDao;
private SharedFileState sharedFileState;

@Inject
final void injectUtils(final CacheApi cache, final Database dbSource,
Expand All @@ -40,6 +41,7 @@ final void injectUtils(final CacheApi cache, final Database dbSource,

this.postgresLineageGraphDao = new PostgresLineageGraphDao(dbSource, idGenerator);
this.postgresLineageGraphVersionDao = new PostgresLineageGraphVersionDao(dbSource, idGenerator);
this.sharedFileState = new SharedFileState(new Tree(new TreeNode("root", "root")));
}

public final CompletionStage<Result> getLineageGraph(String sourceKey) {
Expand Down Expand Up @@ -78,9 +80,12 @@ public final CompletionStage<Result> getLineageGraphVersion(Long id) {

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageGraph() {
String currentPath = sharedFileState.getCwd();
return CompletableFuture.supplyAsync(
() -> {
JsonNode json = request().body().asJson();
String newName = currentPath + "/" + String.valueOf(json.get("name"));
((ObjectNode) json).put("name", newName);
LineageGraph lineageGraph = Json.fromJson(json, LineageGraph.class);
try {
lineageGraph = this.postgresLineageGraphDao.create(lineageGraph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import edu.berkeley.ground.common.util.IdGenerator;
import edu.berkeley.ground.postgres.dao.core.PostgresNodeDao;
import edu.berkeley.ground.postgres.dao.core.PostgresNodeVersionDao;
import edu.berkeley.ground.postgres.util.GroundUtils;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import edu.berkeley.ground.postgres.util.*;
import play.cache.CacheApi;
import play.db.Database;
import play.libs.Json;
Expand All @@ -24,13 +18,20 @@
import play.mvc.Result;
import play.mvc.Results;

import javax.inject.Inject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

public class NodeController extends Controller {

private CacheApi cache;
private ActorSystem actorSystem;

private PostgresNodeDao postgresNodeDao;
private PostgresNodeVersionDao postgresNodeVersionDao;
private SharedFileState sharedFileState;

@Inject
final void injectUtils(final CacheApi cache, final Database dbSource, final ActorSystem actorSystem, final IdGenerator idGenerator) {
Expand All @@ -39,6 +40,7 @@ final void injectUtils(final CacheApi cache, final Database dbSource, final Acto

this.postgresNodeDao = new PostgresNodeDao(dbSource, idGenerator);
this.postgresNodeVersionDao = new PostgresNodeVersionDao(dbSource, idGenerator);
this.sharedFileState = new SharedFileState(new Tree(new TreeNode("root", "root")));
}

public final CompletionStage<Result> getNode(String sourceKey) {
Expand All @@ -60,9 +62,12 @@ public final CompletionStage<Result> getNode(String sourceKey) {

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addNode() {
String currentPath = sharedFileState.getCwd();
return CompletableFuture.supplyAsync(
() -> {
JsonNode json = request().body().asJson();
String newName = currentPath + "/" + String.valueOf(json.get("name"));
((ObjectNode) json).put("name", newName);
Node node = Json.fromJson(json, Node.class);
try {
node = this.postgresNodeDao.create(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
import edu.berkeley.ground.common.util.IdGenerator;
import edu.berkeley.ground.postgres.dao.core.PostgresStructureDao;
import edu.berkeley.ground.postgres.dao.core.PostgresStructureVersionDao;
import edu.berkeley.ground.postgres.util.GroundUtils;
import edu.berkeley.ground.postgres.util.PostgresUtils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import edu.berkeley.ground.postgres.util.*;
import play.cache.CacheApi;
import play.db.Database;
import play.libs.Json;
Expand All @@ -35,13 +29,20 @@
import play.mvc.Result;
import play.mvc.Results;

import javax.inject.Inject;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

public class StructureController extends Controller {

private CacheApi cache;
private ActorSystem actorSystem;

private PostgresStructureDao postgresStructureDao;
private PostgresStructureVersionDao postgresStructureVersionDao;
private SharedFileState sharedFileState;

@Inject
final void injectUtils(final CacheApi cache, final Database dbSource, final ActorSystem actorSystem, final IdGenerator idGenerator) {
Expand All @@ -50,6 +51,7 @@ final void injectUtils(final CacheApi cache, final Database dbSource, final Acto

this.postgresStructureDao = new PostgresStructureDao(dbSource, idGenerator);
this.postgresStructureVersionDao = new PostgresStructureVersionDao(dbSource, idGenerator);
this.sharedFileState = new SharedFileState(new Tree(new TreeNode("root", "root")));
}

public final CompletionStage<Result> getStructure(String sourceKey) {
Expand Down Expand Up @@ -86,9 +88,12 @@ public final CompletionStage<Result> getStructureVersion(Long id) {

@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructure() {
String currentPath = sharedFileState.getCwd();
return CompletableFuture.supplyAsync(
() -> {
JsonNode json = request().body().asJson();
String newName = currentPath + "/" + String.valueOf(json.get("name"));
((ObjectNode) json).put("name", newName);
Structure structure = Json.fromJson(json, Structure.class);

try {
Expand Down
Loading