Skip to content

Commit

Permalink
server: fix endpoint /versions by returning the sources from the inpu…
Browse files Browse the repository at this point in the history
…t data release, #TASK-5704
  • Loading branch information
jtarraga committed Mar 28, 2024
1 parent d4416aa commit e5bfdab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public Type type() {
public static final String VERSION_DESCRIPTION = "API version, e.g.: " + DEFAULT_VERSION;

public static final String DATA_RELEASE_PARAM = "dataRelease";
public static final String DATA_RELEASE_DESCRIPTION = "Data release. To use the default data release, set this to 0. To get the list"
+ " of available data release, please call the endpoint 'meta/dataReleases'";
public static final String DATA_RELEASE_DESCRIPTION = "Data release. To get the list of available data release, please call the"
+ " endpoint 'meta/dataReleases'";

public static final String API_KEY_PARAM = "apiKey";
public static final String API_KEY_DESCRIPTION = "API key to allow access to licensed/restricted data sources such as"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.models.DataReleaseSource;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.utils.SpeciesUtils;
import org.opencb.cellbase.lib.managers.DataReleaseManager;
Expand Down Expand Up @@ -56,6 +57,9 @@
import java.text.SimpleDateFormat;
import java.util.*;

import static org.opencb.cellbase.lib.EtlCommons.COSMIC_DATA;
import static org.opencb.cellbase.lib.EtlCommons.HGMD_DATA;

/**
* Created by imedina on 04/08/15.
*/
Expand Down Expand Up @@ -84,26 +88,42 @@ public MetaWSServer(@PathParam("apiVersion")
@GET
@Path("/{species}/versions")
@ApiOperation(httpMethod = "GET", value = "Returns source version metadata, including source urls from which "
+ "data files were downloaded.", response = DownloadProperties.class, responseContainer = "QueryResponse")
+ "data files were downloaded.", response = DataReleaseSource.class, responseContainer = "QueryResponse")
public Response getVersion(@PathParam("species")
@ApiParam(name = "species", value = ParamConstants.SPECIES_DESCRIPTION,
defaultValue = ParamConstants.DEFAULT_SPECIES, required = true) String species,
@ApiParam(name = "assembly", value = ParamConstants.ASSEMBLY_DESCRIPTION,
defaultValue = ParamConstants.DEFAULT_ASSEMBLY) @QueryParam("assembly") String assembly) {
defaultValue = ParamConstants.DEFAULT_ASSEMBLY) @QueryParam("assembly") String assembly,
@ApiParam(name = "dataRelease", value = ParamConstants.DATA_RELEASE_DESCRIPTION) @QueryParam("dataRelease")
int dataRelease) {
try {
long dbTimeStart;
dbTimeStart = System.currentTimeMillis();
if (StringUtils.isEmpty(assembly)) {
SpeciesConfiguration.Assembly assemblyObject = SpeciesUtils.getDefaultAssembly(cellBaseConfiguration, species);
if (assemblyObject != null) {
assembly = assemblyObject.getName();
}
}
if (!SpeciesUtils.validateSpeciesAndAssembly(cellBaseConfiguration, species, assembly)) {
return createErrorResponse("getVersion", "Invalid species: '" + species + "' or assembly: '"
return createErrorResponse("/versions", "Invalid species: '" + species + "' or assembly: '"
+ assembly + "'");
}
logger.error("species " + species);
CellBaseDataResult queryResult = metaManager.getVersions(species, assembly);
return createOkResponse(queryResult);
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly);
DataRelease dr = dataReleaseManager.get(dataRelease);
if (dr == null) {
return createErrorResponse("/versions", "Could not find data release '" + dataRelease + "'");
}
// Remove some sources
List<DataReleaseSource> sources = new ArrayList<>();
for (DataReleaseSource source : dr.getSources()) {
if (!COSMIC_DATA.equalsIgnoreCase(source.getName()) && !HGMD_DATA.equalsIgnoreCase(source.getName())) {
sources.add(source);
}
}
int dbTime = Long.valueOf(System.currentTimeMillis() - dbTimeStart).intValue();
return createOkResponse(new CellBaseDataResult<>("versions", dbTime, Collections.emptyList(), sources.size(), sources,
sources.size()));
} catch (CellBaseException e) {
return createErrorResponse(e);
}
Expand Down Expand Up @@ -135,7 +155,7 @@ public Response getDataRelease(@PathParam("species")
}
}
if (!SpeciesUtils.validateSpeciesAndAssembly(cellBaseConfiguration, species, assembly)) {
return createErrorResponse("getVersion", "Invalid species: '" + species + "' or assembly: '"
return createErrorResponse("/dataReleases", "Invalid species: '" + species + "' or assembly: '"
+ assembly + "'");
}
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly);
Expand Down

0 comments on commit e5bfdab

Please sign in to comment.