Skip to content

Commit

Permalink
server: set hsapiens as default species, #TASK-5447
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Jan 12, 2024
1 parent 73727ac commit 06327aa
Showing 1 changed file with 10 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
Expand Down Expand Up @@ -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,...)
Expand All @@ -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();
}

Expand Down Expand Up @@ -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 + "'");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 06327aa

Please sign in to comment.