Skip to content

Commit

Permalink
server: update enpoint constructors to throw CellBaseServerException,…
Browse files Browse the repository at this point in the history
… #TASK-4976
  • Loading branch information
jtarraga committed Sep 20, 2023
1 parent a62daa2 commit cb8d4f7
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 157 deletions.
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import org.opencb.biodata.models.core.Xref;
import org.opencb.cellbase.core.api.GeneQuery;
import org.opencb.cellbase.core.api.XrefQuery;
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.GeneManager;
import org.opencb.cellbase.lib.managers.XrefManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.cellbase.server.rest.GenericRestWSServer;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -35,7 +34,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.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -60,14 +58,18 @@ public IdWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVersion", value
@ApiParam(name = "dataRelease", value = DATA_RELEASE_DESCRIPTION) @DefaultValue("0") @QueryParam("dataRelease")
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);
if (assembly == null) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}
try {
if (assembly == null) {
assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName();
}

xrefManager = cellBaseManagerFactory.getXrefManager(species, assembly);
geneManager = cellBaseManagerFactory.getGeneManager(species, assembly);
xrefManager = cellBaseManagerFactory.getXrefManager(species, assembly);
geneManager = cellBaseManagerFactory.getGeneManager(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 @@ -21,10 +21,10 @@
import org.opencb.cellbase.core.api.ProteinQuery;
import org.opencb.cellbase.core.api.TranscriptQuery;
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.ProteinManager;
import org.opencb.cellbase.server.exception.CellBaseServerException;
import org.opencb.cellbase.server.rest.GenericRestWSServer;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -33,7 +33,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.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -57,13 +56,17 @@ public ProteinWSServer(@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 {
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();
}

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

@GET
Expand Down
Loading

0 comments on commit cb8d4f7

Please sign in to comment.