Skip to content

Commit

Permalink
Merge pull request #668 from opencb/TASK-4976-5.4.x
Browse files Browse the repository at this point in the history
TASK-4976 Fix error handling when an exception raises in the CellBase Rest server constructors
  • Loading branch information
jtarraga authored Oct 2, 2023
2 parents 7965af5 + 6a578ea commit 8902508
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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;

public class CellBaseServerException extends WebApplicationException {
public CellBaseServerException(String msg) {
super(msg);
}
}
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 QueryException, IOException, 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 @@ -28,7 +28,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.opencb.cellbase.core.ParamConstants;
import org.opencb.cellbase.core.api.query.QueryException;
import org.opencb.cellbase.core.config.CellBaseConfiguration;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.models.DataRelease;
Expand All @@ -38,6 +37,7 @@
import org.opencb.cellbase.lib.managers.CellBaseManagerFactory;
import org.opencb.cellbase.lib.managers.DataReleaseManager;
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 @@ -96,21 +96,25 @@ public class GenericRestWSServer implements IWSServer {
private static final String DONT_CHECK_SPECIES = "do not validate species";

public GenericRestWSServer(@PathParam("version") String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws QueryException, IOException, 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 QueryException, IOException, CellBaseException {
throws CellBaseServerException {

this.version = version;
this.uriInfo = uriInfo;
this.httpServletRequest = hsr;
this.species = species;

init();
initQuery();
try {
init();
initQuery();
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

private void init() throws IOException, CellBaseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.opencb.cellbase.core.ParamConstants;
import org.opencb.cellbase.core.api.query.QueryException;
import org.opencb.cellbase.core.common.GitRepositoryState;
import org.opencb.cellbase.core.config.DownloadProperties;
import org.opencb.cellbase.core.config.SpeciesConfiguration;
import org.opencb.cellbase.core.config.SpeciesProperties;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.token.DataAccessTokenManager;
import org.opencb.cellbase.core.token.DataAccessTokenSources;
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.core.token.DataAccessTokenManager;
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 All @@ -49,7 +49,6 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.text.DateFormat;
Expand All @@ -72,9 +71,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 QueryException, IOException, 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,19 +21,17 @@
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.api.query.QueryException;
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.*;
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 java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -56,17 +54,21 @@ public OntologyWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion",
@ApiParam(name = "token", value = DATA_ACCESS_TOKEN_DESCRIPTION) @DefaultValue("") @QueryParam("token")
String token,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws QueryException, IOException, 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,17 +20,15 @@
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.api.query.QueryException;
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.*;
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.Map;

import static org.opencb.cellbase.core.ParamConstants.*;
Expand All @@ -55,9 +53,13 @@ public PublicationWSServer(@PathParam("apiVersion")
@ApiParam(name = "token", value = DATA_ACCESS_TOKEN_DESCRIPTION) @DefaultValue("") @QueryParam("token")
String token,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws QueryException, IOException, 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,18 +19,16 @@
import io.swagger.annotations.*;
import org.opencb.biodata.models.core.Chromosome;
import org.opencb.cellbase.core.api.GenomeQuery;
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.GenomeManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;

import javax.servlet.http.HttpServletRequest;
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 java.io.IOException;

import static org.opencb.cellbase.core.ParamConstants.*;

Expand All @@ -54,10 +52,13 @@ public SpeciesWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion", v
@ApiParam(name = "token", value = DATA_ACCESS_TOKEN_DESCRIPTION) @DefaultValue("") @QueryParam("token")
String token,
@Context UriInfo uriInfo,
@Context HttpServletRequest hsr) throws QueryException, IOException, CellBaseException {
@Context HttpServletRequest hsr) 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,11 +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.api.query.QueryException;
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 All @@ -32,7 +31,6 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;

import static org.opencb.cellbase.core.ParamConstants.*;

Expand All @@ -56,13 +54,17 @@ public ClinicalWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion",
@ApiParam(name = "token", value = DATA_ACCESS_TOKEN_DESCRIPTION) @DefaultValue("") @QueryParam("token")
String token,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr)
throws QueryException, IOException, 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 @@ -30,11 +30,13 @@
import org.opencb.cellbase.core.api.TranscriptQuery;
import org.opencb.cellbase.core.api.VariantQuery;
import org.opencb.cellbase.core.api.query.LogicalList;
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.core.utils.SpeciesUtils;
import org.opencb.cellbase.lib.managers.*;
import org.opencb.cellbase.lib.managers.GeneManager;
import org.opencb.cellbase.lib.managers.ProteinManager;
import org.opencb.cellbase.lib.managers.TranscriptManager;
import org.opencb.cellbase.lib.managers.VariantManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.cellbase.server.rest.GenericRestWSServer;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -43,7 +45,6 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.*;

Expand Down Expand Up @@ -71,21 +72,24 @@ public GeneWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion", valu
int dataRelease,
@ApiParam(name = "token", value = DATA_ACCESS_TOKEN_DESCRIPTION) @DefaultValue("") @QueryParam("token")
String token,
@Context UriInfo uriInfo, @Context HttpServletRequest hsr) throws QueryException, IOException,
CellBaseException {
@Context UriInfo uriInfo, @Context HttpServletRequest hsr) 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();
}

geneManager = cellBaseManagerFactory.getGeneManager(species, assembly);
transcriptManager = cellBaseManagerFactory.getTranscriptManager(species, assembly);
variantManager = cellBaseManagerFactory.getVariantManager(species, assembly);
proteinManager = cellBaseManagerFactory.getProteinManager(species, assembly);
geneManager = cellBaseManagerFactory.getGeneManager(species, assembly);
transcriptManager = cellBaseManagerFactory.getTranscriptManager(species, assembly);
variantManager = cellBaseManagerFactory.getVariantManager(species, assembly);
proteinManager = cellBaseManagerFactory.getProteinManager(species, assembly);
} catch (Exception e) {
throw new CellBaseServerException(e.getMessage());
}
}

@GET
Expand Down
Loading

0 comments on commit 8902508

Please sign in to comment.