Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-2217 Improve release api #143

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ stages:

variables:
WS_ARTIFACT_PATH: eva-server/target/eva-$ENVIRONMENT_NAME.war
WS_RS_RELEASE_ARTIFACT_PATH: eva-release/target/eva-release-$ENVIRONMENT_NAME.war
MAVEN_SETTINGS: maven-settings.xml
URL_MAVEN_SETTINGS: https://api.github.com/repos/EBIvariation/configuration/contents/eva-maven-settings.xml
MEDIA_TYPE: application/vnd.github.raw
Expand All @@ -16,7 +17,7 @@ test:
- mongo:4.0.18
script:
# Gitlab exposes services under their own hostnames. So test host should be "mongo" instead of "localhost".
- mvn clean test --projects 'eva-lib,eva-server' -Deva.mongo.host.test=mongo
- mvn clean test --projects 'eva-lib,eva-server,eva-release' -Deva.mongo.host.test=mongo
only:
- master
- tags
Expand All @@ -34,11 +35,13 @@ test:
script:
- mvn package --projects 'eva-lib,eva-server' --settings $MAVEN_SETTINGS -P $MAVEN_PROFILE -DskipTests -Dtimestamp=$DATETIME
- cp eva-server/target/eva-*.war $WS_ARTIFACT_PATH
- cp eva-release/target/eva-release-*.war $WS_RS_RELEASE_ARTIFACT_PATH
after_script:
- rm $MAVEN_SETTINGS
artifacts:
paths:
- $WS_ARTIFACT_PATH
- $WS_RS_RELEASE_ARTIFACT_PATH

package-internal:
extends: .package
Expand Down Expand Up @@ -74,6 +77,7 @@ package-production:
- DATETIME=$(date +%Y-%m-%dT%H-%M-%S)
- apk add --update curl
- curl -u $TOMCAT_USER:$TOMCAT_PASSWORD -T "$WS_ARTIFACT_PATH" "http://$TOMCAT_HOST/manager/text/deploy?update=true&path=/eva&version=$DATETIME" | grep "OK - Deployed application"
- curl -u $TOMCAT_USER:$TOMCAT_PASSWORD -T "$WS_RS_RELEASE_ARTIFACT_PATH" "http://$TOMCAT_HOST/manager/text/deploy?update=true&path=/eva/webservices/release&version=$DATETIME" | grep "OK - Deployed application"

deploy-tomcat-internal:
extends: .deploy-tomcat
Expand Down
4 changes: 4 additions & 0 deletions eva-release/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<artifactId>springfox-swagger2</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ebi.eva.release;
package uk.ac.ebi.eva.release.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -47,8 +47,8 @@ private ApiInfo getApiInfo() {
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.title("EVA RS Release API")
.description(
"API to retrieve information about clustered variant identifiers (usually called RefSNP or RS)" +
"released by the EVA")
"API to retrieve information about clustered variant identifiers (usually called RefSNP or " +
"RS) released by the EVA")
.version("0.1")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package uk.ac.ebi.eva.release.controllers;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -24,7 +25,6 @@
import uk.ac.ebi.eva.release.models.ReleaseInfo;
import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository;

import javax.websocket.server.PathParam;
import java.util.Collections;

@RestController
Expand All @@ -40,6 +40,7 @@ public ReleaseInfoController(ReleaseInfoRepository releaseInfoRepository) {

@GetMapping
public Iterable<ReleaseInfo> getReleaseInfo(
@ApiParam(value = "Version of the RS Release, e.g.: 2")
@RequestParam(name = "releaseVersion", required = false) Integer releaseVersion) {
if (releaseVersion != null) {
return Collections.singleton(releaseInfoRepository.findById(releaseVersion).get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package uk.ac.ebi.eva.release.controllers;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -37,13 +38,16 @@ public ReleaseStatsController(ReleaseStatsService releaseStatsService) {

@GetMapping("/per-species")
public Iterable<ReleaseStatsPerSpeciesDto> getReleaseStatsPerSpecies(
@ApiParam(value = "Version of the RS Release, e.g.: 2")
@RequestParam(name = "releaseVersion", required = false) Integer releaseVersion,
@ApiParam(value = "Flag to indicate if unmapped variants should be excluded from statistics")
@RequestParam(name = "excludeUnmappedOnly", required = false) boolean excludeUnmappedOnly) {
return releaseStatsService.getReleaseStatsPerSpecies(releaseVersion, excludeUnmappedOnly);
}

@GetMapping("/per-species/new")
public Iterable<ReleaseStatsPerSpeciesDto> getSpeciesWithNewRsIds(
@ApiParam(value = "Version of the RS Release, e.g.: 2")
@RequestParam(name = "releaseVersion") Integer releaseVersion) {
return releaseStatsService.getSpeciesWithNewRsIds(releaseVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package uk.ac.ebi.eva.release.repositories;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -27,17 +28,21 @@ public interface ReleaseStatsPerSpeciesRepository extends CrudRepository<Release

Iterable<ReleaseStatsPerSpecies> findAllByReleaseVersion(int releaseVersion);

//All release data excluding rows with only unmapped data
Iterable<ReleaseStatsPerSpecies> findByCurrentRsNotAndMultiMappedRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan(
long currentRs, long multiMappedRs, long mergedRs, long deprecatedRs, long mergedDeprecatedRs,
long unmappedRs);

//Data by release version excluding rows with only unmapped data
Iterable<ReleaseStatsPerSpecies> findByReleaseVersionAndCurrentRsNotAndMultiMappedRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan(
int releaseVersion, long currentRs, long multiMappedRs, long mergedRs, long deprecatedRs,
long mergedDeprecatedRs, long unmappedRs);

Iterable<ReleaseStatsPerSpecies> findByNewCurrentRsGreaterThan(long currentRs);

Iterable<ReleaseStatsPerSpecies> findByReleaseVersionAndNewCurrentRsGreaterThan(int releaseVersion, long currentRs);
//All released species stats excluding the unmapped only
@Query(value = "select * from release_rs_statistics_per_species " +
"where not (current_rs = 0 and multi_mapped_rs = 0 and merged_rs = 0 and deprecated_rs = 0 " +
"and merged_deprecated_rs = 0 and unmapped_rs > 0)", nativeQuery=true)
Iterable<ReleaseStatsPerSpecies> getAllExcludingUnmappedOnly();

//Species stats by release version excluding the unmapped only
@Query(value = "select * from release_rs_statistics_per_species " +
"where release_version = ?1 and not (current_rs = 0 and multi_mapped_rs = 0 and merged_rs = 0 " +
"and deprecated_rs = 0 and merged_deprecated_rs = 0 and unmapped_rs > 0)", nativeQuery=true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor the query string for getAllExcludingUnmappedOnly into a variable and just add a release_version condition for this method?

Iterable<ReleaseStatsPerSpecies> getAllByVersionExcludingUnmappedOnly(int releaseVersion);

//Species that introduced new variants in specified release
@Query(value = "select * from release_rs_statistics_per_species where release_version = ?1 " +
"and (new_current_rs > 0 or new_merged_rs > 0 or new_deprecated_rs > 0 or new_merged_deprecated_rs > 0 " +
"or new_unmapped_rs > 0)", nativeQuery=true)
Iterable<ReleaseStatsPerSpecies> getSpeciesWithVariantsInRelease(int releaseVersion);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,20 @@ public Iterable<ReleaseStatsPerSpeciesDto> getReleaseStatsPerSpecies(Integer rel
Iterable<ReleaseStatsPerSpecies> releaseData;
if (releaseVersion != null) {
if (excludeUnmappedOnly) {
releaseData = getReleaseDataByVersionExcludingUnmappedOnly(releaseVersion);
releaseData = releaseStatsPerSpeciesRepository.getAllByVersionExcludingUnmappedOnly(releaseVersion);
} else {
releaseData = releaseStatsPerSpeciesRepository.findAllByReleaseVersion(releaseVersion);
}
} else {
if (excludeUnmappedOnly) {
releaseData = getReleaseDataExcludingUnmappedOnly();
releaseData = releaseStatsPerSpeciesRepository.getAllExcludingUnmappedOnly();
} else {
releaseData = releaseStatsPerSpeciesRepository.findAll();
}
}
return toDto(releaseData);
}

private Iterable<ReleaseStatsPerSpecies> getReleaseDataByVersionExcludingUnmappedOnly(Integer releaseVersion) {
return releaseStatsPerSpeciesRepository
.findByReleaseVersionAndCurrentRsNotAndMultiMappedRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan(
releaseVersion, 0, 0, 0, 0, 0, 0);
}

private Iterable<ReleaseStatsPerSpecies> getReleaseDataExcludingUnmappedOnly() {
return releaseStatsPerSpeciesRepository
.findByCurrentRsNotAndMultiMappedRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan(
0, 0, 0, 0, 0, 0);
}

private Iterable<ReleaseStatsPerSpeciesDto> toDto(Iterable<ReleaseStatsPerSpecies> releaseStatsPerSpecies) {
List<ReleaseStatsPerSpeciesDto> releaseStatsPerSpeciesDtos = new ArrayList();
for (ReleaseStatsPerSpecies species : releaseStatsPerSpecies) {
Expand Down Expand Up @@ -105,11 +93,6 @@ private ReleaseStatsPerSpeciesDto toDto(ReleaseStatsPerSpecies releaseStatsPerSp
}

public Iterable<ReleaseStatsPerSpeciesDto> getSpeciesWithNewRsIds(Integer releaseVersion) {
if (releaseVersion != null) {
return toDto(releaseStatsPerSpeciesRepository
.findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L));
} else {
return toDto(releaseStatsPerSpeciesRepository.findByNewCurrentRsGreaterThan(0L));
}
return toDto(releaseStatsPerSpeciesRepository.getSpeciesWithVariantsInRelease(releaseVersion));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2020 EMBL - European Bioinformatics Institute
*
* 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 uk.ac.ebi.eva.release.controllers;

import org.assertj.core.util.IterableUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import uk.ac.ebi.eva.release.Application;
import uk.ac.ebi.eva.release.models.ReleaseInfo;

import static org.junit.Assert.assertEquals;

@SpringBootTest(classes = Application.class)
@RunWith(SpringRunner.class)
public class ReleaseInfoControllerTest {

@Autowired
private ReleaseInfoController releaseInfoController;

@Test
public void getOneReleaseInfo() {
int releaseVersion = 1;
Iterable<ReleaseInfo> releaseInfo = releaseInfoController.getReleaseInfo(releaseVersion);
assertEquals(releaseVersion, releaseInfo.iterator().next().getReleaseVersion());
}

@Test
public void getAllReleasesInfo() {
Integer releaseVersion = null;
Iterable<ReleaseInfo> releaseInfo = releaseInfoController.getReleaseInfo(releaseVersion);
assertEquals(2, IterableUtil.sizeOf(releaseInfo));
}

@Test
public void getLatestReleaseInfo() {
int latestReleaseVersion = 2;
ReleaseInfo latestReleaseInfo = releaseInfoController.getLatestReleaseInfo();
assertEquals(latestReleaseVersion, latestReleaseInfo.getReleaseVersion());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020 EMBL - European Bioinformatics Institute
*
* 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 uk.ac.ebi.eva.release.controllers;

import org.assertj.core.util.IterableUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import uk.ac.ebi.eva.release.Application;
import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesDto;

import static org.junit.Assert.assertEquals;

@SpringBootTest(classes = Application.class)
@RunWith(SpringRunner.class)
public class ReleaseStatsControllerTest {

@Autowired
private ReleaseStatsController releaseStatsController;

@Test
public void getAllSpeciesStats() {
int totalNumberOfRecords = 417;
Iterable<ReleaseStatsPerSpeciesDto> allRecords = releaseStatsController.getReleaseStatsPerSpecies(null, false);
assertEquals(totalNumberOfRecords, IterableUtil.sizeOf(allRecords));
}

@Test
public void getStatsByReleaseVersion() {
int speciesInRelease2 = 218;
Iterable<ReleaseStatsPerSpeciesDto> allRecords = releaseStatsController.getReleaseStatsPerSpecies(2, false);
assertEquals(speciesInRelease2, IterableUtil.sizeOf(allRecords));
}

@Test
public void getStatsByReleaseVersionNoUnmapped() {
int speciesInRelease1ExcludingUnmapped = 58;
Iterable<ReleaseStatsPerSpeciesDto> release1 = releaseStatsController.getReleaseStatsPerSpecies(1, true);
assertEquals(speciesInRelease1ExcludingUnmapped, IterableUtil.sizeOf(release1));

int speciesInRelease2ExcludingUnmapped = 79;
Iterable<ReleaseStatsPerSpeciesDto> release2 = releaseStatsController.getReleaseStatsPerSpecies(2, true);
assertEquals(speciesInRelease2ExcludingUnmapped, IterableUtil.sizeOf(release2));
}

@Test
public void getStatsForNewVariantsOnlyInSpecificRelease() {
int numberOfSpeciesWithNewVariantsRelease1 = 199;
Iterable<ReleaseStatsPerSpeciesDto> Release1 = releaseStatsController.getSpeciesWithNewRsIds(1);
assertEquals(numberOfSpeciesWithNewVariantsRelease1, IterableUtil.sizeOf(Release1));

int numberOfSpeciesWithNewVariantsRelease2 = 29;
Iterable<ReleaseStatsPerSpeciesDto> Release2 = releaseStatsController.getSpeciesWithNewRsIds(2);
assertEquals(numberOfSpeciesWithNewVariantsRelease2, IterableUtil.sizeOf(Release2));
}
}
10 changes: 10 additions & 0 deletions eva-release/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spring.datasource.driver-class-name=org.hsqldb.jdbcDriver
spring.datasource.url=jdbc:hsqldb:mem:db;sql.syntax_pgs=true;DB_CLOSE_DELAY=-1
spring.datasource.username=SA
spring.datasource.password=

spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

# See https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes#bean-overriding
spring.main.allow-bean-definition-overriding=true
Loading