Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/web-extjs' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/FilesWSServer.java
	eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/GeneWSServer.java
	eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/RegionWSServer.java
	eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/StudyWSServer.java
	eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/VariantWSServer.java
	eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/ga4gh/GA4GHVariantCallSetWSServer.java
	eva-web/src/js/eva-variant-widget-panel.js
	eva-web/src/js/variant-widget/eva-variant-widget.js
  • Loading branch information
Cristina Yenyxe Gonzalez Garcia committed Mar 2, 2015
2 parents 63e2e5d + d6a4bec commit c824480
Show file tree
Hide file tree
Showing 631 changed files with 19,280 additions and 1,065 deletions.
6 changes: 5 additions & 1 deletion eva-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
<artifactId>jersey-media-multipart</artifactId>
<version>2.7</version>
</dependency>

<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey2-jaxrs_2.11</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.ac.ebi.variation.eva.server.ws;
package uk.ac.ebi.variation.eva.server;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package uk.ac.ebi.variation.eva.server;

import org.glassfish.jersey.server.ResourceConfig;
import uk.ac.ebi.variation.eva.server.ws.CORSResponseFilter;

/**
* Created by imedina on 01/04/14.
* @author imedina
*/
public class EvaWSRegistry extends ResourceConfig {

public EvaWSRegistry() {
packages("uk.ac.ebi.variation.eva.server.ws");
// packages("uk.ac.ebi.variation.eva.server.ws");
register(CORSResponseFilter.class);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.ac.ebi.variation.eva.server.exception;

@SuppressWarnings("serial")
public class SpeciesException extends Exception {

public SpeciesException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.ac.ebi.variation.eva.server.exception;


@SuppressWarnings("serial")
public class VersionException extends Exception {

public VersionException(String msg) {
super(msg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,47 @@
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.google.common.base.Splitter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.*;
import javax.ws.rs.core.*;

import com.wordnik.swagger.annotations.ApiParam;
import org.opencb.biodata.models.feature.Genotype;
import org.opencb.biodata.models.variant.VariantSourceEntry;
import org.opencb.biodata.models.variant.VariantSource;
import org.opencb.biodata.models.variant.stats.VariantStats;
import org.opencb.datastore.core.QueryOptions;
import org.opencb.datastore.core.QueryResponse;
import org.opencb.opencga.lib.auth.IllegalOpenCGACredentialsException;
import org.opencb.opencga.storage.core.variant.io.json.VariantSourceEntryJsonMixin;
import org.opencb.opencga.storage.core.variant.io.json.GenotypeJsonMixin;
import org.opencb.opencga.storage.core.variant.io.json.VariantSourceJsonMixin;
import org.opencb.opencga.storage.core.variant.io.json.VariantStatsJsonMixin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ebi.variation.eva.server.exception.SpeciesException;
import uk.ac.ebi.variation.eva.server.exception.VersionException;

/**
* Created by imedina on 01/04/14.
*/
@Path("/{version}")
//@Produces(MediaType.APPLICATION_JSON)
@Produces("application/json")
public class EvaWSServer {

// output content format: txt or text, json, xml, das
protected String outputFormat;

@DefaultValue("")
@PathParam("version")
@ApiParam(name = "version", value = "EVA REST WS version", defaultValue = "v1")
protected String version;

@DefaultValue("Homo sapiens")
@QueryParam("species")
@ApiParam(name = "species", value = "Excluded fields will not be returned. Comma separated JSON paths must be provided",
defaultValue = "hsapiens", allowableValues = "hsapiens,mmusculus")
protected String species;

protected UriInfo uriInfo;
protected HttpServletRequest httpServletRequest;

Expand All @@ -47,6 +54,36 @@ public class EvaWSServer {
protected long startTime;
protected long endTime;

@DefaultValue("")
@QueryParam("exclude")
@ApiParam(name = "excluded fields", value = "Excluded fields will not be returned. Comma separated JSON paths must be provided")
protected String exclude;

@DefaultValue("")
@QueryParam("include")
@ApiParam(name = "included fields", value = "Included fields are the only to be returned. Comma separated JSON path must be provided")
protected String include;

@DefaultValue("-1")
@QueryParam("limit")
@ApiParam(name = "limit", value = "Max number of results to be returned. No limit applied when -1 [-1]")
protected int limit;

@DefaultValue("-1")
@QueryParam("skip")
@ApiParam(name = "skip", value = "Number of results to be skipped. No skip applied when -1 [-1]")
protected int skip;

@DefaultValue("false")
@QueryParam("count")
@ApiParam(name = "count", value = "The total number of results is returned [false]")
protected String count;

@DefaultValue("json")
@QueryParam("of")
@ApiParam(name = "Output format", value = "Output format, Protobuf is not yet implemented", defaultValue = "json", allowableValues = "json,pb (Not implemented yet)")
protected String outputFormat;

protected static ObjectMapper jsonObjectMapper;
protected static ObjectWriter jsonObjectWriter;
protected static XmlMapper xmlObjectMapper;
Expand All @@ -69,6 +106,7 @@ public class EvaWSServer {
logger.info("EvaWSServer: Initialising attributes inside static block");
}

@Deprecated
public EvaWSServer() {
logger.info("EvaWSServer: in 'constructor'");
}
Expand All @@ -88,49 +126,46 @@ protected void init(String version, UriInfo uriInfo) {
startTime = System.currentTimeMillis();
queryResponse = new QueryResponse();


// TODO A properties files may be needed to load valid versions and species
// load properties file
// ResourceBundle databaseConfig =
// ResourceBundle.getBundle("org.bioinfo.infrared.ws.application");
// config = new Config(databaseConfig);


// mediaType = MediaType.valueOf("text/plain");
queryOptions = new QueryOptions();
// logger = new Logger();
// logger.setLevel(Logger.DEBUG_LEVEL);
logger.info("GenericrestWSServer: in 'init' method");

/**
* Check version parameter, must be: v1, v2, ... If 'latest' then is
* converted to appropriate version
*/
// if(version != null && version.equals("latest") &&
// config.getProperty("CELLBASE.LATEST.VERSION") != null) {
// version = config.getProperty("CELLBASE.LATEST.VERSION");
// System.out.println("version init: "+version);
// }

// this code MUST be run before the checking
parseCommonQueryParameters(uriInfo.getQueryParameters());
}

private void parseCommonQueryParameters(MultivaluedMap<String, String> multivaluedMap) {

protected void checkParams() throws VersionException, SpeciesException {
// TODO A Version and Species checker must be implemented
if (version == null || !version.equals("v1")) {
throw new VersionException("Version not valid: '" + version + "'");
}
if (species == null || species.isEmpty()/*|| !isValidSpecies(species)*/) {
throw new SpeciesException("Species not valid: '" + species + "'");
}

MultivaluedMap<String, String> multivaluedMap = uriInfo.getQueryParameters();
queryOptions.put("species", species);

queryOptions.put("metadata", (multivaluedMap.get("metadata") != null) ? multivaluedMap.get("metadata").get(0).equals("true") : true);
queryOptions.put("exclude", (multivaluedMap.get("exclude") != null) ? Splitter.on(",").splitToList(multivaluedMap.get("exclude").get(0)) : null);
queryOptions.put("include", (multivaluedMap.get("include") != null) ? Splitter.on(",").splitToList(multivaluedMap.get("include").get(0)) : null);
queryOptions.put("limit", (multivaluedMap.get("limit") != null) ? multivaluedMap.get("limit").get(0) : -1);
queryOptions.put("skip", (multivaluedMap.get("skip") != null) ? multivaluedMap.get("skip").get(0) : -1);
queryOptions.put("count", (multivaluedMap.get("count") != null) ? Boolean.parseBoolean(multivaluedMap.get("count").get(0)) : false);

outputFormat = (multivaluedMap.get("of") != null) ? multivaluedMap.get("of").get(0) : "json";
// outputCompress = (multivaluedMap.get("outputcompress") != null) ? multivaluedMap.get("outputcompress").get(0) : "false";
queryOptions.put("exclude", (exclude != null && !exclude.equals("")) ? Splitter.on(",").splitToList(exclude) : null);
queryOptions.put("include", (include != null && !include.equals("")) ? Splitter.on(",").splitToList(include) : null);
queryOptions.put("limit", (limit > 0) ? limit : -1);
queryOptions.put("skip", (skip > 0) ? skip : -1);
queryOptions.put("count", (count != null && !count.equals("")) ? Boolean.parseBoolean(count) : false);

outputFormat = (outputFormat != null && !outputFormat.equals("")) ? outputFormat : "json";
}

@GET
@Path("/test")
public Response help() {
return createOkResponse("No help available");
return createOkResponse("No help available yet");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,66 @@
import java.util.Arrays;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.opencb.opencga.lib.auth.IllegalOpenCGACredentialsException;
import org.opencb.opencga.storage.core.variant.adaptors.VariantSourceDBAdaptor;
import uk.ac.ebi.variation.eva.lib.datastore.DBAdaptorConnector;
import uk.ac.ebi.variation.eva.lib.storage.metadata.VariantSourceEvaproDBAdaptor;
import uk.ac.ebi.variation.eva.server.exception.SpeciesException;
import uk.ac.ebi.variation.eva.server.exception.VersionException;

/**
*
* @author Cristina Yenyxe Gonzalez Garcia <cyenyxe@ebi.ac.uk>
*/
@Path("/{version}/files")
@Produces(MediaType.APPLICATION_JSON)
@Produces("application/json")
@Api(value = "Files", description = "Files RESTful Web Services API")
public class FilesWSServer extends EvaWSServer {

private VariantSourceDBAdaptor variantSourceEvaproDbAdaptor;

public FilesWSServer() throws IllegalOpenCGACredentialsException {
super();
}

public FilesWSServer(@DefaultValue("") @PathParam("version") String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws NamingException {
public FilesWSServer(@DefaultValue("") @PathParam("version") String version,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr) throws NamingException {
super(version, uriInfo, hsr);
variantSourceEvaproDbAdaptor = new VariantSourceEvaproDBAdaptor();
}

@GET
@Path("/all")
@ApiOperation(httpMethod = "GET", value = "Gets the files of a species")
public Response getFiles(@QueryParam("species") String species)
throws UnknownHostException, IllegalOpenCGACredentialsException, IOException {
if (species != null && !species.isEmpty()) {
queryOptions.put("species", species);
try {
checkParams();
} catch (VersionException | SpeciesException ex) {
return createErrorResponse(ex.toString());
}

VariantSourceDBAdaptor variantSourceMongoDbAdaptor = DBAdaptorConnector.getVariantSourceDBAdaptor(species);
return createOkResponse(variantSourceMongoDbAdaptor.getAllSources(queryOptions));
}

@GET
@Path("/{files}/url")
@ApiOperation(httpMethod = "GET", value = "Gets the URL of a file")
public Response getFileUrl(@PathParam("files") String filenames) {
try {
checkParams();
} catch (VersionException | SpeciesException ex) {
return createErrorResponse(ex.toString());
}

return createOkResponse(variantSourceEvaproDbAdaptor.getSourceDownloadUrlByName(Arrays.asList(filenames.split(","))));
}

}
Loading

0 comments on commit c824480

Please sign in to comment.