Skip to content

Commit

Permalink
server: add cypher method to NodeWSServer
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Mar 2, 2018
1 parent 5e3a380 commit dc3a31a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bionetdb-core/src/main/resources/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ databases:
host: "localhost"
port: "7688"
user: "neo4j"
password: "neo4j"
password: "neo4j;"
options: null
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.opencb.bionetdb.server.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.opencb.bionetdb.core.api.NetworkDBAdaptor;
import org.opencb.bionetdb.core.neo4j.Neo4JNetworkDBAdaptor;
import org.opencb.bionetdb.core.network.Node;
import org.opencb.bionetdb.server.exception.DatabaseException;
import org.opencb.bionetdb.server.exception.VersionException;
import org.opencb.commons.datastore.core.QueryResult;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.List;

/**
* Created by imedina on 06/10/15.
*/
@Path("/{version}/node")
@Produces("application/json")
@Api(value = "Node", position = 1, description = "Methods for working with 'nodes'")
public class NodeWSServer extends GenericRestWSServer {

public NodeWSServer(@PathParam("version") String version, @Context UriInfo uriInfo,
Expand All @@ -29,9 +30,9 @@ public NodeWSServer(@PathParam("version") String version, @Context UriInfo uriIn
}

@GET
@Path("/{type}/cc")
@ApiOperation(httpMethod = "GET", value = "Get the object data model")
public Response getModel(@PathParam("type") String type) {
@Path("/{id}/info")
@ApiOperation(httpMethod = "GET", value = "Get Nodes by ID")
public Response getNodesById(@PathParam("id") String type) {
try {
NetworkDBAdaptor networkDBAdaptor = new Neo4JNetworkDBAdaptor(database, bioNetDBConfiguration);
// Query query = new Query("id", physicalEntity);
Expand All @@ -44,4 +45,22 @@ public Response getModel(@PathParam("type") String type) {
}
}

@GET
@Path("/cypher")
@ApiOperation(httpMethod = "GET", value = "Get Nodes by Cypher statement")
public Response getNodesByCypher(@QueryParam("cypher") String cypher) {
try {
NetworkDBAdaptor networkDBAdaptor = new Neo4JNetworkDBAdaptor(database, bioNetDBConfiguration);
List<Node> nodes = networkDBAdaptor.nodeQuery(cypher);
logger.info(cypher);
for (Node node: nodes) {
logger.info(node.toStringEx());
}
QueryResult<Node> queryResult = new QueryResult<>(null, 0, nodes.size(), nodes.size(), null, null, nodes);
networkDBAdaptor.close();
return createOkResponse(queryResult);
} catch (Exception e) {
return createErrorResponse(e);
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<BIONETDB.CATALOG.DB.HOST>localhost</BIONETDB.CATALOG.DB.HOST>
<BIONETDB.CATALOG.DB.PORT>7687</BIONETDB.CATALOG.DB.PORT>
<BIONETDB.CATALOG.DB.USER>neo4j</BIONETDB.CATALOG.DB.USER>
<BIONETDB.CATALOG.DB.PASSWORD></BIONETDB.CATALOG.DB.PASSWORD>
<BIONETDB.CATALOG.DB.PASSWORD>neo4j;</BIONETDB.CATALOG.DB.PASSWORD>
</properties>
</profile>

Expand Down

0 comments on commit dc3a31a

Please sign in to comment.