Skip to content

Commit

Permalink
server: implement a REST webservice to query network paths, #29
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Mar 13, 2018
1 parent 8f57405 commit 2ea7533
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.api.NetworkPathIterator;
import org.opencb.bionetdb.core.neo4j.Neo4JNetworkDBAdaptor;
import org.opencb.bionetdb.core.network.NetworkPath;
import org.opencb.bionetdb.server.exception.VersionException;
import org.opencb.commons.datastore.core.QueryResult;

import javax.servlet.http.HttpServletRequest;
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.ArrayList;
import java.util.List;

/**
* Created by jtarraga on 13/03/18.
*/
@Path("/{apiVersion}/path")
@Produces("application/json")
@Api(value = "Path", position = 1, description = "Methods for working with network paths")
public class PathWSServer extends GenericRestWSServer {

public PathWSServer(@PathParam("apiVersion") String apiVersion, @Context UriInfo uriInfo,
@Context HttpServletRequest hsr) throws VersionException {
super(apiVersion, uriInfo, hsr);
}

@GET
@Path("/cypher")
@ApiOperation(httpMethod = "GET", value = "Get network path by Cypher statement")
public Response getNetworkPathByCypher(@QueryParam("cypher") String cypher) {
try {
logger.info(cypher);

NetworkDBAdaptor networkDBAdaptor = new Neo4JNetworkDBAdaptor(database, bioNetDBConfiguration);
NetworkPathIterator iterator = networkDBAdaptor.networkPathIterator(cypher);
List<NetworkPath> networkPaths = new ArrayList<>();
while (iterator.hasNext()) {
NetworkPath networkPath = iterator.next();
networkPaths.add(networkPath);
}
QueryResult<NetworkPath> queryResult = new QueryResult<>(null, 0, networkPaths.size(), networkPaths.size(),
null, null, networkPaths);
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 @@ -217,7 +217,7 @@
<BIONETDB.DB.HOST>localhost</BIONETDB.DB.HOST>
<BIONETDB.DB.PORT>7687</BIONETDB.DB.PORT>
<BIONETDB.DB.USER>neo4j</BIONETDB.DB.USER>
<BIONETDB.DB.PASSWORD>neo4j</BIONETDB.DB.PASSWORD>
<BIONETDB.DB.PASSWORD>neo4j;</BIONETDB.DB.PASSWORD>
</properties>
</profile>

Expand Down

0 comments on commit 2ea7533

Please sign in to comment.