From 06327aa2de2967f854802a2523901980f62e352c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20T=C3=A1rraga=20Gim=C3=A9nez?= Date: Fri, 12 Jan 2024 15:08:03 +0100 Subject: [PATCH] server: set hsapiens as default species, #TASK-5447 --- .../server/rest/GenericRestWSServer.java | 50 ++++--------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java index e6263d4bc..ed21eac32 100755 --- a/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java +++ b/cellbase-server/src/main/java/org/opencb/cellbase/server/rest/GenericRestWSServer.java @@ -97,16 +97,13 @@ public class GenericRestWSServer implements IWSServer { protected static org.opencb.cellbase.lib.monitor.Monitor monitor; private static final String ERROR = "error"; private static final String OK = "ok"; - // this webservice has no species or assembly, do not validate - private static final String DONT_CHECK_SPECIES = "do not validate species"; - private static final String DONT_CHECK_ASSEMBLY = "do not validate assembly"; protected static String defaultApiKey; protected static ApiKeyManager apiKeyManager; public GenericRestWSServer(@PathParam("version") String version, @Context UriInfo uriInfo, @Context HttpServletRequest hsr) throws CellBaseServerException { - this(version, DONT_CHECK_SPECIES, DONT_CHECK_ASSEMBLY, uriInfo, hsr); + this(version, "hsapiens", null, uriInfo, hsr); } public GenericRestWSServer(@PathParam("version") String version, @PathParam("species") String species, @@ -121,11 +118,13 @@ public GenericRestWSServer(@PathParam("version") String version, @PathParam("spe this.assembly = assembly; try { - if (this.assembly == null && !DONT_CHECK_SPECIES.equals(species)) { - this.assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species).getName(); + init(); + + if (this.assembly == null) { + // Default assembly depends on the CellBaseConfiguration (so it has to be already initialized) + this.assembly = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, this.species).getName(); } - init(); initQuery(); } catch (Exception e) { throw new CellBaseServerException(e.getMessage()); @@ -205,15 +204,10 @@ private void initQuery() throws CellBaseException { checkVersion(); // Set default data release if necessary - if (!DONT_CHECK_SPECIES.equals(species) && defaultDataRelease == null) { - // As the assembly may not be presented in the query, we have to be sure to get it from the CellBase configuration - assembly = SpeciesUtils.getSpecies(cellBaseConfiguration, this.species, assembly).getAssembly(); - - if (!DONT_CHECK_ASSEMBLY.equals(assembly) && StringUtils.isNotEmpty(assembly)) { - DataReleaseManager releaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly); - // getDefault launches an exception if no data release is found for that CellBase version - defaultDataRelease = releaseManager.getDefault(version); - } + if (defaultDataRelease == null) { + DataReleaseManager releaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly); + // getDefault launches an exception if no data release is found for that CellBase version + defaultDataRelease = releaseManager.getDefault(version); } // Check API key (expiration date, quota,...) @@ -237,10 +231,6 @@ protected int getDataRelease() throws CellBaseException { } } // If no data release is present in the query, then use the default data release - if (!DONT_CHECK_SPECIES.equals(species)) { - logger.info("No data release present in query: using the default data release '" + defaultDataRelease + "' for CellBase version" - + " '" + version + "'"); - } return defaultDataRelease.getRelease(); } @@ -284,11 +274,6 @@ private void checkVersion() throws CellBaseException { throw new CellBaseException("Version not valid: '" + version + "'"); } -// System.out.println("*************************************"); -// System.out.println("cellBaseConfiguration = " + cellBaseConfiguration); -// System.out.println("cellBaseConfiguration.getVersion() = " + cellBaseConfiguration.getVersion()); -// System.out.println("version = " + version); -// System.out.println("*************************************"); if (!uriInfo.getPath().contains("health") && !version.startsWith(cellBaseConfiguration.getVersion())) { logger.error("URL version '{}' does not match configuration '{}'", this.version, cellBaseConfiguration.getVersion()); throw new CellBaseException("URL version not valid: '" + version + "'"); @@ -450,23 +435,8 @@ protected Response createOkResponse(Object obj) { return jsonResponse; } -// protected Response createOkResponse(Object obj, MediaType mediaType) { -// return buildResponse(Response.ok(obj, mediaType)); -// } -// -// protected Response createOkResponse(Object obj, MediaType mediaType, String fileName) { -// return buildResponse(Response.ok(obj, mediaType).header("content-disposition", "attachment; filename =" + fileName)); -// } -// -// protected Response createStringResponse(String str) { -// return buildResponse(Response.ok(str)); -// } - protected Response createJsonResponse(CellBaseDataResponse queryResponse) { try { -// if (CollectionUtils.isNotEmpty(queryResponse.getResponses()) && queryResponse.getResponses().get(0) != null) { -// System.out.println("queryResponse.getResponses().get(0).toString() = " + queryResponse.getResponses().get(0).toString()); -// } String value = jsonObjectWriter.writeValueAsString(queryResponse); ResponseBuilder ok = Response.ok(value, MediaType.APPLICATION_JSON_TYPE.withCharset("utf-8")); Response response = buildResponse(ok);