Skip to content

Commit

Permalink
server: add CellBaseServerException to the endpoints, #TASK-4976
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Sep 14, 2023
1 parent 31e9d98 commit a1157d4
Show file tree
Hide file tree
Showing 24 changed files with 226 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

package org.opencb.cellbase.core.exception;

import javax.ws.rs.WebApplicationException;

public class CellBaseException extends WebApplicationException {
public class CellBaseException extends Exception {

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

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2015-2020 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opencb.cellbase.server.exception;

import javax.ws.rs.WebApplicationException;

@SuppressWarnings("serial")
public class CellBaseServerException extends WebApplicationException {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import org.opencb.cellbase.core.result.CellBaseDataResponse;
import org.opencb.cellbase.server.RestServer;


import javax.servlet.ServletContext;
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.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -43,8 +41,7 @@ public class AdminRestWebService {
private static RestServer server;

public AdminRestWebService(@PathParam("apiVersion") String version, @Context UriInfo uriInfo,
@Context HttpServletRequest httpServletRequest, @Context ServletContext context)
throws IOException {
@Context HttpServletRequest httpServletRequest, @Context ServletContext context) {
// super(version, uriInfo, httpServletRequest, context);
System.out.println("Build AdminWSServer");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.opencb.cellbase.core.ParamConstants;
import org.opencb.cellbase.core.api.FileQuery;
import org.opencb.cellbase.core.api.query.QueryException;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.managers.FileManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
Expand All @@ -48,9 +48,13 @@ public FileWSServer(@PathParam("apiVersion")
@ApiParam(name = "apiVersion", value = ParamConstants.VERSION_DESCRIPTION,
defaultValue = ParamConstants.DEFAULT_VERSION) String apiVersion,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, uriInfo, hsr);
fileManager = cellBaseManagerFactory.getFileManager();
try {
fileManager = cellBaseManagerFactory.getFileManager();
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opencb.cellbase.lib.managers.DataReleaseManager;
import org.opencb.cellbase.lib.managers.MetaManager;
import org.opencb.cellbase.lib.monitor.Monitor;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.commons.datastore.core.Event;
import org.opencb.commons.datastore.core.ObjectMap;
import org.opencb.commons.datastore.core.Query;
Expand Down Expand Up @@ -101,13 +102,13 @@ public class GenericRestWSServer implements IWSServer {
protected static ApiKeyManager apiKeyManager;

public GenericRestWSServer(@PathParam("version") String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
this(version, DONT_CHECK_SPECIES, uriInfo, hsr);
}

public GenericRestWSServer(@PathParam("version") String version, @PathParam("species") String species, @Context UriInfo uriInfo,
@Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {

this.version = version;
this.uriInfo = uriInfo;
Expand All @@ -117,8 +118,8 @@ public GenericRestWSServer(@PathParam("version") String version, @PathParam("spe
try {
init();
initQuery();
} catch (IOException e) {
throw new CellBaseException(e.getMessage());
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

Expand Down Expand Up @@ -183,16 +184,15 @@ private void initQuery() throws CellBaseException {

// Set default API key, if necessary
String apiKey = uriParams.getOrDefault(API_KEY_PARAM, null);
logger.info("Before checking, API key {}", apiKey);
if (StringUtils.isEmpty(apiKey)) {
apiKey = defaultApiKey;
uriParams.put(API_KEY_PARAM, apiKey);
}
logger.info("After checking, API key {}", uriParams.get(API_KEY_PARAM));

// Check limit
checkLimit();

// check version. species is validated later
// Check version (species is validated later)
checkVersion();

// Set default data release if necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.opencb.cellbase.core.utils.SpeciesUtils;
import org.opencb.cellbase.lib.managers.DataReleaseManager;
import org.opencb.cellbase.lib.managers.MetaManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.cellbase.server.rest.clinical.ClinicalWSServer;
import org.opencb.cellbase.server.rest.feature.GeneWSServer;
import org.opencb.cellbase.server.rest.feature.IdWSServer;
Expand Down Expand Up @@ -71,9 +72,13 @@ public MetaWSServer(@PathParam("apiVersion")
@ApiParam(name = "apiVersion", value = ParamConstants.VERSION_DESCRIPTION,
defaultValue = ParamConstants.DEFAULT_VERSION) String apiVersion,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, uriInfo, hsr);
metaManager = cellBaseManagerFactory.getMetaManager();
try {
metaManager = cellBaseManagerFactory.getMetaManager();
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.apache.commons.lang3.StringUtils;
import org.opencb.biodata.models.core.OntologyTerm;
import org.opencb.cellbase.core.api.OntologyQuery;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.utils.SpeciesUtils;
import org.opencb.cellbase.lib.managers.OntologyManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
Expand Down Expand Up @@ -53,17 +53,21 @@ public OntologyWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion",
int dataRelease,
@ApiParam(name = "apiKey", value = API_KEY_DESCRIPTION) @DefaultValue("") @QueryParam("apiKey") String apiKey,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, species, uriInfo, hsr);
List<String> assemblies = uriInfo.getQueryParameters().get("assembly");
if (CollectionUtils.isNotEmpty(assemblies)) {
assembly = assemblies.get(0);
}
if (StringUtils.isEmpty(assembly)) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}
try {
List<String> assemblies = uriInfo.getQueryParameters().get("assembly");
if (CollectionUtils.isNotEmpty(assemblies)) {
assembly = assemblies.get(0);
}
if (StringUtils.isEmpty(assembly)) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}

ontologyManager = cellBaseManagerFactory.getOntologyManager(species, assembly);
ontologyManager = cellBaseManagerFactory.getOntologyManager(species, assembly);
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.opencb.biodata.formats.pubmed.v233jaxb.PubmedArticle;
import org.opencb.cellbase.core.ParamConstants;
import org.opencb.cellbase.core.api.PublicationQuery;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.managers.PublicationManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
Expand All @@ -46,16 +46,20 @@ public class PublicationWSServer extends GenericRestWSServer {
private static final String PONG = "pong";

public PublicationWSServer(@PathParam("apiVersion")
@ApiParam(name = "apiVersion", value = ParamConstants.VERSION_DESCRIPTION,
defaultValue = ParamConstants.DEFAULT_VERSION) String apiVersion,
@ApiParam(name = "apiVersion", value = ParamConstants.VERSION_DESCRIPTION,
defaultValue = ParamConstants.DEFAULT_VERSION) String apiVersion,
@ApiParam(name = "dataRelease", value = DATA_RELEASE_DESCRIPTION) @DefaultValue("0")
@QueryParam("dataRelease") int dataRelease,
@ApiParam(name = "apiKey", value = API_KEY_DESCRIPTION) @DefaultValue("") @QueryParam("apiKey")
String apiKey,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, uriInfo, hsr);
publicationManager = cellBaseManagerFactory.getPublicationManager();
try {
publicationManager = cellBaseManagerFactory.getPublicationManager();
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import io.swagger.annotations.*;
import org.opencb.biodata.models.core.Chromosome;
import org.opencb.cellbase.core.api.GenomeQuery;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.managers.GenomeManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
Expand Down Expand Up @@ -52,10 +52,13 @@ public SpeciesWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion", v
@ApiParam(name = "apiKey", value = API_KEY_DESCRIPTION) @DefaultValue("") @QueryParam("apiKey") String apiKey,
@Context UriInfo uriInfo,
@Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, species, uriInfo, hsr);

genomeManager = cellBaseManagerFactory.getGenomeManager(species, assembly);
try {
genomeManager = cellBaseManagerFactory.getGenomeManager(species, assembly);
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import io.swagger.annotations.*;
import org.opencb.biodata.models.variant.Variant;
import org.opencb.cellbase.core.api.ClinicalVariantQuery;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.utils.SpeciesUtils;
import org.opencb.cellbase.lib.managers.ClinicalManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.cellbase.server.rest.GenericRestWSServer;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -51,13 +51,17 @@ public ClinicalWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion",
int dataRelease,
@ApiParam(name = "apiKey", value = API_KEY_DESCRIPTION) @DefaultValue("") @QueryParam("apiKey") String apiKey,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, species, uriInfo, hsr);
if (assembly == null) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}
try {
if (assembly == null) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}

clinicalManager = cellBaseManagerFactory.getClinicalManager(species, assembly);
clinicalManager = cellBaseManagerFactory.getClinicalManager(species, assembly);
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import io.swagger.annotations.*;
import org.opencb.biodata.models.pharma.PharmaChemical;
import org.opencb.cellbase.core.api.PharmaChemicalQuery;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.utils.SpeciesUtils;
import org.opencb.cellbase.lib.managers.ClinicalManager;
import org.opencb.cellbase.lib.managers.PharmacogenomicsManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.cellbase.server.rest.GenericRestWSServer;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -56,14 +56,18 @@ public PharmacogenomicsWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVe
@ApiParam(name = "apiKey", value = API_KEY_DESCRIPTION) @DefaultValue("") @QueryParam("apiKey")
String apiKey,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws CellBaseException {
throws CellBaseServerException {
super(apiVersion, species, uriInfo, hsr);
if (assembly == null) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}
try {
if (assembly == null) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}

clinicalManager = cellBaseManagerFactory.getClinicalManager(species, assembly);
pharmacogenomicsManager = cellBaseManagerFactory.getPharmacogenomicsManager(species, assembly);
clinicalManager = cellBaseManagerFactory.getClinicalManager(species, assembly);
pharmacogenomicsManager = cellBaseManagerFactory.getPharmacogenomicsManager(species, assembly);
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Loading

0 comments on commit a1157d4

Please sign in to comment.