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-1063 - Add service end point to provide default locus range for a given species #132

Open
wants to merge 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public String mongoCollectionsAnnotationMetadata() {
return dbCollectionsProperties.getAnnotationMetadata();
}

@Bean
public String mongoCollectionsDefaultLocusRangeMetadata() {
return dbCollectionsProperties.getDefaultLocusRangeMetadata();
}

@Bean
public String mongoCollectionsAnnotations() {
return dbCollectionsProperties.getAnnotations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class DbCollectionsProperties {
@NotNull
private String annotationMetadata;

@Size(min = 1)
@NotNull
private String defaultLocusRangeMetadata;

@Size(min = 1)
@NotNull
private String annotations;
Expand Down Expand Up @@ -67,10 +71,18 @@ public String getAnnotationMetadata() {
return annotationMetadata;
}

public String getDefaultLocusRangeMetadata() {
return defaultLocusRangeMetadata;
}

public void setAnnotationMetadata(String annotationMetadata) {
this.annotationMetadata = annotationMetadata;
}

public void setDefaultLocusRangeMetadata(String defaultLocusRangeMetadata) {
this.defaultLocusRangeMetadata = defaultLocusRangeMetadata;
}

public String getAnnotations() {
return annotations;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2019 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.server.ws;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import uk.ac.ebi.eva.commons.core.models.DefaultLocusRangeMetadata;
import uk.ac.ebi.eva.commons.mongodb.services.DefaultLocusRangeMetadataService;
import uk.ac.ebi.eva.lib.eva_utils.DBAdaptorConnector;
import uk.ac.ebi.eva.lib.eva_utils.MultiMongoDbFactory;
import uk.ac.ebi.eva.lib.utils.QueryResponse;
import uk.ac.ebi.eva.lib.utils.QueryResult;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(value = "/v1/default-locus-range", produces = "application/json")
@Api(tags = {"default-locus-range"})
public class DefaultLocusRangeMetadataWSServer extends EvaWSServer {

@Autowired
private DefaultLocusRangeMetadataService service;

@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public QueryResponse getDefaultLocusRangeMetadata(@RequestParam(name = "species") String species,
HttpServletResponse response) {
if (species.isEmpty()) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return setQueryResponse("Please specify a species");
}

MultiMongoDbFactory.setDatabaseNameForCurrentThread(DBAdaptorConnector.getDBName(species));
List<DefaultLocusRangeMetadata> defaultLocusRangeMetadataList =
service.findAllByOrderByChromosomeAscStartAscEndAsc();
QueryResult<DefaultLocusRangeMetadata> queryResult = buildQueryResult(defaultLocusRangeMetadataList);
return setQueryResponse(queryResult);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2019 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.server.ws;

import org.junit.Before;
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.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import uk.ac.ebi.eva.commons.core.models.DefaultLocusRangeMetadata;
import uk.ac.ebi.eva.commons.mongodb.services.DefaultLocusRangeMetadataService;
import uk.ac.ebi.eva.lib.utils.QueryResponse;
import uk.ac.ebi.eva.lib.utils.QueryResult;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DefaultLocusRangeMetadataWSServerTest {

private List<DefaultLocusRangeMetadata> defaultLocusRangeMetadataList;

@Autowired
private TestRestTemplate restTemplate;

@MockBean
private DefaultLocusRangeMetadataService service;

@Before
public void setUp() throws Exception {
defaultLocusRangeMetadataList = Arrays.asList(new DefaultLocusRangeMetadata("1", 1, 1000000));

given(service.findAllByOrderByChromosomeAscStartAscEndAsc()).willReturn(defaultLocusRangeMetadataList);
}

@Test
public void testDefaultLocusRangeMetadata() {
String url = "/v1/default-locus-range?species=mmusculus_grcm38";
ResponseEntity<QueryResponse<QueryResult<DefaultLocusRangeMetadata>>> response = restTemplate.exchange(
url, HttpMethod.GET, null,
new ParameterizedTypeReference<QueryResponse<QueryResult<DefaultLocusRangeMetadata>>>() {
});
assertEquals(HttpStatus.OK, response.getStatusCode());

QueryResponse<QueryResult<DefaultLocusRangeMetadata>> queryResponse = response.getBody();
assertEquals(1, queryResponse.getResponse().size());

List<DefaultLocusRangeMetadata> results = queryResponse.getResponse().get(0).getResult();
assertEquals(defaultLocusRangeMetadataList.size(), results.size());

for (DefaultLocusRangeMetadata result : results) {
assertTrue(defaultLocusRangeMetadataList.contains(result));
}
}

}
1 change: 1 addition & 0 deletions eva-server/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ spring.data.mongodb.read-preference=
db.collection-names.files=testFiles
db.collection-names.variants=testVariants
db.collection-names.annotation-metadata=testMetadata
db.collection-names.default-locus-range-metadata=testDefaultLocusRange
db.collection-names.annotations=testAnnotations
db.collection-names.features=testFeatures