Skip to content

Commit c824480

Browse files
author
Cristina Yenyxe Gonzalez Garcia
committed
Merge remote-tracking branch 'origin/feature/web-extjs' into develop
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
2 parents 63e2e5d + d6a4bec commit c824480

File tree

631 files changed

+19280
-1065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

631 files changed

+19280
-1065
lines changed

eva-server/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
<artifactId>jersey-media-multipart</artifactId>
6969
<version>2.7</version>
7070
</dependency>
71-
71+
<dependency>
72+
<groupId>com.wordnik</groupId>
73+
<artifactId>swagger-jersey2-jaxrs_2.11</artifactId>
74+
<version>1.3.10</version>
75+
</dependency>
7276
<dependency>
7377
<groupId>javax.servlet</groupId>
7478
<artifactId>javax.servlet-api</artifactId>

eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/CORSResponseFilter.java renamed to eva-server/src/main/java/uk/ac/ebi/variation/eva/server/CORSResponseFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package uk.ac.ebi.variation.eva.server.ws;
1+
package uk.ac.ebi.variation.eva.server;
22

33
import java.io.IOException;
44

eva-server/src/main/java/uk/ac/ebi/variation/eva/server/EvaWSRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package uk.ac.ebi.variation.eva.server;
22

33
import org.glassfish.jersey.server.ResourceConfig;
4-
import uk.ac.ebi.variation.eva.server.ws.CORSResponseFilter;
54

65
/**
76
* Created by imedina on 01/04/14.
7+
* @author imedina
88
*/
99
public class EvaWSRegistry extends ResourceConfig {
1010

1111
public EvaWSRegistry() {
12-
packages("uk.ac.ebi.variation.eva.server.ws");
12+
// packages("uk.ac.ebi.variation.eva.server.ws");
1313
register(CORSResponseFilter.class);
1414
}
1515

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package uk.ac.ebi.variation.eva.server.exception;
2+
3+
@SuppressWarnings("serial")
4+
public class SpeciesException extends Exception {
5+
6+
public SpeciesException(String msg) {
7+
super(msg);
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package uk.ac.ebi.variation.eva.server.exception;
2+
3+
4+
@SuppressWarnings("serial")
5+
public class VersionException extends Exception {
6+
7+
public VersionException(String msg) {
8+
super(msg);
9+
}
10+
11+
}

eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/EvaWSServer.java

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,47 @@
55
import com.fasterxml.jackson.databind.ObjectWriter;
66
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
77
import com.google.common.base.Splitter;
8-
import java.io.IOException;
98
import java.util.ArrayList;
109
import java.util.Arrays;
1110
import java.util.Collection;
1211
import javax.servlet.http.HttpServletRequest;
13-
import javax.ws.rs.GET;
14-
import javax.ws.rs.Path;
15-
import javax.ws.rs.PathParam;
12+
import javax.ws.rs.*;
1613
import javax.ws.rs.core.*;
14+
15+
import com.wordnik.swagger.annotations.ApiParam;
1716
import org.opencb.biodata.models.feature.Genotype;
1817
import org.opencb.biodata.models.variant.VariantSourceEntry;
1918
import org.opencb.biodata.models.variant.VariantSource;
2019
import org.opencb.biodata.models.variant.stats.VariantStats;
2120
import org.opencb.datastore.core.QueryOptions;
2221
import org.opencb.datastore.core.QueryResponse;
23-
import org.opencb.opencga.lib.auth.IllegalOpenCGACredentialsException;
2422
import org.opencb.opencga.storage.core.variant.io.json.VariantSourceEntryJsonMixin;
2523
import org.opencb.opencga.storage.core.variant.io.json.GenotypeJsonMixin;
2624
import org.opencb.opencga.storage.core.variant.io.json.VariantSourceJsonMixin;
2725
import org.opencb.opencga.storage.core.variant.io.json.VariantStatsJsonMixin;
2826
import org.slf4j.Logger;
2927
import org.slf4j.LoggerFactory;
28+
import uk.ac.ebi.variation.eva.server.exception.SpeciesException;
29+
import uk.ac.ebi.variation.eva.server.exception.VersionException;
3030

3131
/**
3232
* Created by imedina on 01/04/14.
3333
*/
3434
@Path("/{version}")
35-
//@Produces(MediaType.APPLICATION_JSON)
35+
@Produces("application/json")
3636
public class EvaWSServer {
3737

38-
// output content format: txt or text, json, xml, das
39-
protected String outputFormat;
40-
38+
@DefaultValue("")
39+
@PathParam("version")
40+
@ApiParam(name = "version", value = "EVA REST WS version", defaultValue = "v1")
4141
protected String version;
42+
43+
@DefaultValue("Homo sapiens")
44+
@QueryParam("species")
45+
@ApiParam(name = "species", value = "Excluded fields will not be returned. Comma separated JSON paths must be provided",
46+
defaultValue = "hsapiens", allowableValues = "hsapiens,mmusculus")
47+
protected String species;
48+
4249
protected UriInfo uriInfo;
4350
protected HttpServletRequest httpServletRequest;
4451

@@ -47,6 +54,36 @@ public class EvaWSServer {
4754
protected long startTime;
4855
protected long endTime;
4956

57+
@DefaultValue("")
58+
@QueryParam("exclude")
59+
@ApiParam(name = "excluded fields", value = "Excluded fields will not be returned. Comma separated JSON paths must be provided")
60+
protected String exclude;
61+
62+
@DefaultValue("")
63+
@QueryParam("include")
64+
@ApiParam(name = "included fields", value = "Included fields are the only to be returned. Comma separated JSON path must be provided")
65+
protected String include;
66+
67+
@DefaultValue("-1")
68+
@QueryParam("limit")
69+
@ApiParam(name = "limit", value = "Max number of results to be returned. No limit applied when -1 [-1]")
70+
protected int limit;
71+
72+
@DefaultValue("-1")
73+
@QueryParam("skip")
74+
@ApiParam(name = "skip", value = "Number of results to be skipped. No skip applied when -1 [-1]")
75+
protected int skip;
76+
77+
@DefaultValue("false")
78+
@QueryParam("count")
79+
@ApiParam(name = "count", value = "The total number of results is returned [false]")
80+
protected String count;
81+
82+
@DefaultValue("json")
83+
@QueryParam("of")
84+
@ApiParam(name = "Output format", value = "Output format, Protobuf is not yet implemented", defaultValue = "json", allowableValues = "json,pb (Not implemented yet)")
85+
protected String outputFormat;
86+
5087
protected static ObjectMapper jsonObjectMapper;
5188
protected static ObjectWriter jsonObjectWriter;
5289
protected static XmlMapper xmlObjectMapper;
@@ -69,6 +106,7 @@ public class EvaWSServer {
69106
logger.info("EvaWSServer: Initialising attributes inside static block");
70107
}
71108

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

91-
129+
// TODO A properties files may be needed to load valid versions and species
92130
// load properties file
93131
// ResourceBundle databaseConfig =
94132
// ResourceBundle.getBundle("org.bioinfo.infrared.ws.application");
95133
// config = new Config(databaseConfig);
96134

97-
98135
// mediaType = MediaType.valueOf("text/plain");
99136
queryOptions = new QueryOptions();
100137
// logger = new Logger();
101138
// logger.setLevel(Logger.DEBUG_LEVEL);
102139
logger.info("GenericrestWSServer: in 'init' method");
103-
104-
/**
105-
* Check version parameter, must be: v1, v2, ... If 'latest' then is
106-
* converted to appropriate version
107-
*/
108-
// if(version != null && version.equals("latest") &&
109-
// config.getProperty("CELLBASE.LATEST.VERSION") != null) {
110-
// version = config.getProperty("CELLBASE.LATEST.VERSION");
111-
// System.out.println("version init: "+version);
112-
// }
113-
114-
// this code MUST be run before the checking
115-
parseCommonQueryParameters(uriInfo.getQueryParameters());
116140
}
117141

118-
private void parseCommonQueryParameters(MultivaluedMap<String, String> multivaluedMap) {
142+
143+
protected void checkParams() throws VersionException, SpeciesException {
144+
// TODO A Version and Species checker must be implemented
145+
if (version == null || !version.equals("v1")) {
146+
throw new VersionException("Version not valid: '" + version + "'");
147+
}
148+
if (species == null || species.isEmpty()/*|| !isValidSpecies(species)*/) {
149+
throw new SpeciesException("Species not valid: '" + species + "'");
150+
}
151+
152+
MultivaluedMap<String, String> multivaluedMap = uriInfo.getQueryParameters();
153+
queryOptions.put("species", species);
154+
119155
queryOptions.put("metadata", (multivaluedMap.get("metadata") != null) ? multivaluedMap.get("metadata").get(0).equals("true") : true);
120-
queryOptions.put("exclude", (multivaluedMap.get("exclude") != null) ? Splitter.on(",").splitToList(multivaluedMap.get("exclude").get(0)) : null);
121-
queryOptions.put("include", (multivaluedMap.get("include") != null) ? Splitter.on(",").splitToList(multivaluedMap.get("include").get(0)) : null);
122-
queryOptions.put("limit", (multivaluedMap.get("limit") != null) ? multivaluedMap.get("limit").get(0) : -1);
123-
queryOptions.put("skip", (multivaluedMap.get("skip") != null) ? multivaluedMap.get("skip").get(0) : -1);
124-
queryOptions.put("count", (multivaluedMap.get("count") != null) ? Boolean.parseBoolean(multivaluedMap.get("count").get(0)) : false);
125-
126-
outputFormat = (multivaluedMap.get("of") != null) ? multivaluedMap.get("of").get(0) : "json";
127-
// outputCompress = (multivaluedMap.get("outputcompress") != null) ? multivaluedMap.get("outputcompress").get(0) : "false";
156+
queryOptions.put("exclude", (exclude != null && !exclude.equals("")) ? Splitter.on(",").splitToList(exclude) : null);
157+
queryOptions.put("include", (include != null && !include.equals("")) ? Splitter.on(",").splitToList(include) : null);
158+
queryOptions.put("limit", (limit > 0) ? limit : -1);
159+
queryOptions.put("skip", (skip > 0) ? skip : -1);
160+
queryOptions.put("count", (count != null && !count.equals("")) ? Boolean.parseBoolean(count) : false);
161+
162+
outputFormat = (outputFormat != null && !outputFormat.equals("")) ? outputFormat : "json";
128163
}
129-
164+
130165
@GET
131166
@Path("/test")
132167
public Response help() {
133-
return createOkResponse("No help available");
168+
return createOkResponse("No help available yet");
134169
}
135170

136171

eva-server/src/main/java/uk/ac/ebi/variation/eva/server/ws/FilesWSServer.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,66 @@
55
import java.util.Arrays;
66
import javax.naming.NamingException;
77
import javax.servlet.http.HttpServletRequest;
8-
import javax.ws.rs.DefaultValue;
9-
import javax.ws.rs.GET;
10-
import javax.ws.rs.Path;
11-
import javax.ws.rs.PathParam;
12-
import javax.ws.rs.Produces;
13-
import javax.ws.rs.QueryParam;
8+
import javax.ws.rs.*;
149
import javax.ws.rs.core.Context;
15-
import javax.ws.rs.core.MediaType;
1610
import javax.ws.rs.core.Response;
1711
import javax.ws.rs.core.UriInfo;
12+
13+
import com.wordnik.swagger.annotations.Api;
14+
import com.wordnik.swagger.annotations.ApiOperation;
15+
import java.util.logging.Level;
16+
import java.util.logging.Logger;
1817
import org.opencb.opencga.lib.auth.IllegalOpenCGACredentialsException;
1918
import org.opencb.opencga.storage.core.variant.adaptors.VariantSourceDBAdaptor;
2019
import uk.ac.ebi.variation.eva.lib.datastore.DBAdaptorConnector;
2120
import uk.ac.ebi.variation.eva.lib.storage.metadata.VariantSourceEvaproDBAdaptor;
21+
import uk.ac.ebi.variation.eva.server.exception.SpeciesException;
22+
import uk.ac.ebi.variation.eva.server.exception.VersionException;
2223

2324
/**
2425
*
2526
* @author Cristina Yenyxe Gonzalez Garcia <cyenyxe@ebi.ac.uk>
2627
*/
2728
@Path("/{version}/files")
28-
@Produces(MediaType.APPLICATION_JSON)
29+
@Produces("application/json")
30+
@Api(value = "Files", description = "Files RESTful Web Services API")
2931
public class FilesWSServer extends EvaWSServer {
30-
32+
3133
private VariantSourceDBAdaptor variantSourceEvaproDbAdaptor;
3234

33-
public FilesWSServer() throws IllegalOpenCGACredentialsException {
34-
super();
35-
}
3635

37-
public FilesWSServer(@DefaultValue("") @PathParam("version") String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr)
38-
throws NamingException {
36+
public FilesWSServer(@DefaultValue("") @PathParam("version") String version,
37+
@Context UriInfo uriInfo, @Context HttpServletRequest hsr) throws NamingException {
3938
super(version, uriInfo, hsr);
4039
variantSourceEvaproDbAdaptor = new VariantSourceEvaproDBAdaptor();
4140
}
4241

4342
@GET
4443
@Path("/all")
44+
@ApiOperation(httpMethod = "GET", value = "Gets the files of a species")
4545
public Response getFiles(@QueryParam("species") String species)
4646
throws UnknownHostException, IllegalOpenCGACredentialsException, IOException {
47-
if (species != null && !species.isEmpty()) {
48-
queryOptions.put("species", species);
47+
try {
48+
checkParams();
49+
} catch (VersionException | SpeciesException ex) {
50+
return createErrorResponse(ex.toString());
4951
}
52+
5053
VariantSourceDBAdaptor variantSourceMongoDbAdaptor = DBAdaptorConnector.getVariantSourceDBAdaptor(species);
5154
return createOkResponse(variantSourceMongoDbAdaptor.getAllSources(queryOptions));
5255
}
53-
56+
5457
@GET
5558
@Path("/{files}/url")
59+
@ApiOperation(httpMethod = "GET", value = "Gets the URL of a file")
5660
public Response getFileUrl(@PathParam("files") String filenames) {
61+
try {
62+
checkParams();
63+
} catch (VersionException | SpeciesException ex) {
64+
return createErrorResponse(ex.toString());
65+
}
66+
5767
return createOkResponse(variantSourceEvaproDbAdaptor.getSourceDownloadUrlByName(Arrays.asList(filenames.split(","))));
5868
}
59-
69+
6070
}

0 commit comments

Comments
 (0)