From 8c0f82bb2dd3208aff295c90e2c145139d1f1612 Mon Sep 17 00:00:00 2001 From: Gaofei Zhao <15748980+dippindots@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:08:44 -0400 Subject: [PATCH] Address sonorcloud issues --- .../helper/StudyViewFilterHelper.java | 4 ++-- .../StudyViewMyBatisRepository.java | 14 +++----------- .../web/columnar/BasicDataBinner.java | 18 ++++-------------- .../StudyViewMapperClinicalDataCountTest.java | 4 ---- 4 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/cbioportal/persistence/helper/StudyViewFilterHelper.java b/src/main/java/org/cbioportal/persistence/helper/StudyViewFilterHelper.java index dbc3e53de1c..c94600c57d8 100644 --- a/src/main/java/org/cbioportal/persistence/helper/StudyViewFilterHelper.java +++ b/src/main/java/org/cbioportal/persistence/helper/StudyViewFilterHelper.java @@ -11,7 +11,7 @@ import org.springframework.lang.Nullable; import java.util.ArrayList; -import java.util.HashMap; +import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -24,7 +24,7 @@ public static StudyViewFilterHelper build(@Nullable StudyViewFilter studyViewFil studyViewFilter = new StudyViewFilter(); } if (Objects.isNull(genericAssayProfilesMap)) { - genericAssayProfilesMap = new HashMap<>(); + genericAssayProfilesMap = new EnumMap<>(DataSource.class); } if (Objects.isNull(customDataSamples)) { customDataSamples = new ArrayList<>(); diff --git a/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java b/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java index c73877f45d1..41687281c5d 100644 --- a/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java +++ b/src/main/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMyBatisRepository.java @@ -37,8 +37,7 @@ public class StudyViewMyBatisRepository implements StudyViewRepository { private Map> clinicalAttributesMap = new EnumMap<>(DataSource.class); private Map> genericAssayProfilesMap = new EnumMap<>(DataSource.class); - - + private static final List FILTERED_CLINICAL_ATTR_VALUES = Collections.emptyList(); private final StudyViewMapper mapper; @@ -217,11 +216,11 @@ public List getGenomicDataBinCounts(StudyViewFilterContext st public List getGenericAssayDataBinCounts(StudyViewFilterContext studyViewFilterContext, List attributeIds) { return mapper.getGenericAssayDataBinCounts(createStudyViewFilterHelper(studyViewFilterContext), attributeIds); } - + private void buildClinicalAttributeNameMap() { clinicalAttributesMap = this.getClinicalAttributes() .stream() - .collect(Collectors.groupingBy(ca -> ca.getPatientAttribute() ? DataSource.PATIENT : DataSource.SAMPLE)); + .collect(Collectors.groupingBy(ca -> ca.getPatientAttribute().booleanValue() ? DataSource.PATIENT : DataSource.SAMPLE)); } private void buildGenericAssayProfilesMap() { @@ -229,13 +228,6 @@ private void buildGenericAssayProfilesMap() { .stream() .collect(Collectors.groupingBy(ca -> ca.getPatientLevel().booleanValue() ? DataSource.PATIENT : DataSource.SAMPLE)); } - - private Map> getClinicalAttributeNameMap() { - if (clinicalAttributesMap.isEmpty()) { - buildClinicalAttributeNameMap(); - } - return clinicalAttributesMap; - } private Map> getGenericAssayProfilesMap() { if (genericAssayProfilesMap.isEmpty()) { diff --git a/src/main/java/org/cbioportal/web/columnar/BasicDataBinner.java b/src/main/java/org/cbioportal/web/columnar/BasicDataBinner.java index 495b815be8a..d6978e35a5e 100644 --- a/src/main/java/org/cbioportal/web/columnar/BasicDataBinner.java +++ b/src/main/java/org/cbioportal/web/columnar/BasicDataBinner.java @@ -152,28 +152,20 @@ public void removeSelfFromFilter(S dataBinFilter, StudyViewFilter studyViewFilter) { switch (dataBinFilter) { - case ClinicalDataBinFilter clinicalDataBinFilter -> { - if (studyViewFilter.getClinicalDataFilters() != null) { + case ClinicalDataBinFilter clinicalDataBinFilter when studyViewFilter.getClinicalDataFilters() != null -> studyViewFilter.getClinicalDataFilters().removeIf(f -> f.getAttributeId().equals(clinicalDataBinFilter.getAttributeId())); - } - } - case GenomicDataBinFilter genomicDataBinFilter -> { - if (studyViewFilter.getGenomicDataFilters() != null) { + case GenomicDataBinFilter genomicDataBinFilter when studyViewFilter.getGenomicDataFilters() != null -> studyViewFilter.getGenomicDataFilters().removeIf(f -> f.getHugoGeneSymbol().equals(genomicDataBinFilter.getHugoGeneSymbol()) && f.getProfileType().equals(genomicDataBinFilter.getProfileType()) ); - } - } - case GenericAssayDataBinFilter genericAssayDataBinFilter -> { - if (studyViewFilter.getGenericAssayDataFilters() != null) { + case GenericAssayDataBinFilter genericAssayDataBinFilter when studyViewFilter.getGenericAssayDataFilters() != null -> studyViewFilter.getGenericAssayDataFilters().removeIf(f -> f.getStableId().equals(genericAssayDataBinFilter.getStableId()) && f.getProfileType().equals(genericAssayDataBinFilter.getProfileType()) ); - } - } default -> { + // Do not remove any filters } } } @@ -223,7 +215,6 @@ private List calculateStaticData for (T dataBinFilter : dataBinFilters) { // if there is data for requested attribute - // TODO: consider if this is correct to passing in a empty map if (attributeDatatypeMap.isEmpty() || attributeDatatypeMap.containsKey(getDataBinFilterUniqueKey(dataBinFilter))) { List dataBins = dataBinner .calculateClinicalDataBins( @@ -252,7 +243,6 @@ private List calculateDynamicDat for (T dataBinFilter : dataBinFilters) { // if there is data for requested attribute - // TODO: consider if this is correct to passing in a empty map if (attributeDatatypeMap.isEmpty() || attributeDatatypeMap.containsKey(getDataBinFilterUniqueKey(dataBinFilter))) { List dataBins = dataBinner .calculateDataBins( diff --git a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java index ae16aedb97f..8013aa5f6a2 100644 --- a/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java +++ b/src/test/java/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapperClinicalDataCountTest.java @@ -1,8 +1,6 @@ package org.cbioportal.persistence.mybatisclickhouse; -import org.cbioportal.model.ClinicalAttribute; import org.cbioportal.model.ClinicalDataCount; -import org.cbioportal.persistence.enums.DataSource; import org.cbioportal.persistence.helper.StudyViewFilterHelper; import org.cbioportal.persistence.mybatisclickhouse.config.MyBatisConfig; import org.cbioportal.web.parameter.ClinicalDataFilter; @@ -20,9 +18,7 @@ import java.math.BigDecimal; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static org.junit.Assert.assertEquals;