From d033b344395bedd1c44d4e860d6facd9852d953e Mon Sep 17 00:00:00 2001 From: Fabian Engelniederhammer Date: Tue, 19 Dec 2023 09:47:45 +0100 Subject: [PATCH] fix: set default min proportion See https://github.com/GenSpectrum/LAPIS-SILO/pull/234 --- .../lapis/controller/LapisController.kt | 13 ++++++----- .../request/MutationProportionsRequest.kt | 4 +++- .../lapis/controller/LapisControllerTest.kt | 12 ++++++---- .../request/MutationProportionsRequestTest.kt | 23 +++++++++++++++++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/LapisController.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/LapisController.kt index 1ed0b94fc..ef4649585 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/LapisController.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/LapisController.kt @@ -39,6 +39,7 @@ import org.genspectrum.lapis.openApi.REQUEST_SCHEMA_WITH_MIN_PROPORTION import org.genspectrum.lapis.request.AminoAcidInsertion import org.genspectrum.lapis.request.AminoAcidMutation import org.genspectrum.lapis.request.CommonSequenceFilters +import org.genspectrum.lapis.request.DEFAULT_MIN_PROPORTION import org.genspectrum.lapis.request.Field import org.genspectrum.lapis.request.MutationProportionsRequest import org.genspectrum.lapis.request.NucleotideInsertion @@ -290,7 +291,7 @@ class LapisController( @RequestParam(required = false) @AminoAcidMutations aminoAcidMutations: List?, - @RequestParam minProportion: Double?, + @RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?, @MutationsOrderByFields @RequestParam orderBy: List?, @@ -345,7 +346,7 @@ class LapisController( @RequestParam(required = false) @AminoAcidMutations aminoAcidMutations: List?, - @RequestParam minProportion: Double?, + @RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?, @MutationsOrderByFields @RequestParam orderBy: List?, @@ -394,7 +395,7 @@ class LapisController( @RequestParam(required = false) @AminoAcidMutations aminoAcidMutations: List?, - @RequestParam minProportion: Double?, + @RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?, @MutationsOrderByFields @RequestParam orderBy: List?, @@ -483,7 +484,7 @@ class LapisController( @RequestParam(required = false) @AminoAcidMutations aminoAcidMutations: List?, - @RequestParam minProportion: Double?, + @RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?, @MutationsOrderByFields @RequestParam orderBy: List?, @@ -534,7 +535,7 @@ class LapisController( @RequestParam(required = false) @AminoAcidMutations aminoAcidMutations: List?, - @RequestParam minProportion: Double?, + @RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?, @MutationsOrderByFields @RequestParam orderBy: List?, @@ -583,7 +584,7 @@ class LapisController( @RequestParam(required = false) @AminoAcidMutations aminoAcidMutations: List?, - @RequestParam minProportion: Double?, + @RequestParam(defaultValue = "$DEFAULT_MIN_PROPORTION") minProportion: Double?, @MutationsOrderByFields @RequestParam orderBy: List?, diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/MutationProportionsRequest.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/MutationProportionsRequest.kt index 526d7c994..6bf973cff 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/request/MutationProportionsRequest.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/request/MutationProportionsRequest.kt @@ -10,6 +10,8 @@ import org.genspectrum.lapis.controller.BadRequestException import org.genspectrum.lapis.controller.MIN_PROPORTION_PROPERTY import org.springframework.boot.jackson.JsonComponent +const val DEFAULT_MIN_PROPORTION = 0.05 + data class MutationProportionsRequest( override val sequenceFilters: Map, override val nucleotideMutations: List, @@ -32,7 +34,7 @@ class MutationProportionsRequestDeserializer : JsonDeserializer null + null, is NullNode -> DEFAULT_MIN_PROPORTION is NumericNode -> minProportionNode.doubleValue() else -> throw BadRequestException("minProportion must be a number") diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/LapisControllerTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/LapisControllerTest.kt index fef35029e..98fd4a132 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/LapisControllerTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/LapisControllerTest.kt @@ -3,9 +3,11 @@ package org.genspectrum.lapis.controller import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.IntNode import com.fasterxml.jackson.databind.node.TextNode +import com.fasterxml.jackson.module.kotlin.readValue import com.ninjasquad.springmockk.MockkBean import io.mockk.every import org.genspectrum.lapis.model.SiloQueryModel +import org.genspectrum.lapis.request.DEFAULT_MIN_PROPORTION import org.genspectrum.lapis.request.Field import org.genspectrum.lapis.request.MutationProportionsRequest import org.genspectrum.lapis.request.NucleotideMutation @@ -170,7 +172,7 @@ class LapisControllerTest( @ParameterizedTest(name = "GET {0} without explicit minProportion") @MethodSource("getMutationEndpoints") fun `GET mutations without explicit minProportion`(endpoint: String) { - setupMutationMock(endpoint, null) + setupMutationMock(endpoint, DEFAULT_MIN_PROPORTION) mockMvc.perform(getSample("$endpoint?country=Switzerland")) .andExpect(status().isOk) @@ -196,7 +198,7 @@ class LapisControllerTest( @ParameterizedTest(name = "POST {0} without explicit minProportion") @MethodSource("getMutationEndpoints") fun `POST mutations without explicit minProportion`(endpoint: String) { - setupMutationMock(endpoint, null) + setupMutationMock(endpoint, DEFAULT_MIN_PROPORTION) val request = postSample(endpoint) .content("""{"country": "Switzerland"}""") @@ -245,13 +247,13 @@ class LapisControllerTest( @ParameterizedTest(name = "GET {0} only returns mutation, proportion and count") @MethodSource("getMutationEndpoints") fun `GET mutations only returns mutation, proportion and count`(endpoint: String) { - setupMutationMock(endpoint, null) + setupMutationMock(endpoint, DEFAULT_MIN_PROPORTION) val mvcResult = mockMvc.perform(getSample("$endpoint?country=Switzerland")) .andExpect(status().isOk) .andReturn() - val response = ObjectMapper().readValue(mvcResult.response.contentAsString, Map::class.java) + val response = ObjectMapper().readValue>(mvcResult.response.contentAsString) val data = response["data"] as List<*> val firstDataObject = data[0] as Map<*, *> @@ -261,7 +263,7 @@ class LapisControllerTest( private fun setupMutationMock( endpoint: String, - minProportion: Double?, + minProportion: Double = DEFAULT_MIN_PROPORTION, ) { if (endpoint == "/nucleotideMutations") { every { diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/request/MutationProportionsRequestTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/request/MutationProportionsRequestTest.kt index c6247146f..bede255f4 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/request/MutationProportionsRequestTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/request/MutationProportionsRequestTest.kt @@ -57,6 +57,7 @@ class MutationProportionsRequestTest { emptyList(), emptyList(), emptyList(), + minProportion = DEFAULT_MIN_PROPORTION, ), ), Arguments.of( @@ -71,6 +72,7 @@ class MutationProportionsRequestTest { emptyList(), emptyList(), emptyList(), + minProportion = DEFAULT_MIN_PROPORTION, ), ), Arguments.of( @@ -85,6 +87,7 @@ class MutationProportionsRequestTest { listOf(AminoAcidMutation("S", 501, "Y"), AminoAcidMutation("ORF1b", 12, null)), emptyList(), emptyList(), + minProportion = DEFAULT_MIN_PROPORTION, ), ), Arguments.of( @@ -102,6 +105,7 @@ class MutationProportionsRequestTest { NucleotideInsertion(12, "ABCD", null), ), emptyList(), + minProportion = DEFAULT_MIN_PROPORTION, ), ), Arguments.of( @@ -119,6 +123,7 @@ class MutationProportionsRequestTest { AminoAcidInsertion(501, "S", "Y"), AminoAcidInsertion(12, "ORF1", "ABCD"), ), + minProportion = DEFAULT_MIN_PROPORTION, ), ), Arguments.of( @@ -135,14 +140,28 @@ class MutationProportionsRequestTest { "accessKey": "some access key" } """, - MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList()), + MutationProportionsRequest( + emptyMap(), + emptyList(), + emptyList(), + emptyList(), + emptyList(), + minProportion = DEFAULT_MIN_PROPORTION, + ), ), Arguments.of( """ { } """, - MutationProportionsRequest(emptyMap(), emptyList(), emptyList(), emptyList(), emptyList()), + MutationProportionsRequest( + emptyMap(), + emptyList(), + emptyList(), + emptyList(), + emptyList(), + minProportion = DEFAULT_MIN_PROPORTION, + ), ), )