-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: implement a REST webservice to query network paths, #29
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
bionetdb-server/src/main/java/org/opencb/bionetdb/server/rest/PathWSServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters