From 4070b547939aa2f7a1ccc9d69d10d31f15478f36 Mon Sep 17 00:00:00 2001 From: supun Date: Wed, 18 Dec 2024 09:51:27 +0000 Subject: [PATCH 1/5] change find entries by release name --- .../entity/UniProtKBStatisticsEntry.java | 2 +- .../statistics/entity/UniProtRelease.java | 9 +- .../statistics/mapper/StatisticsMapper.java | 4 +- .../UniProtKBStatisticsEntryRepository.java | 8 +- .../repository/UniProtReleaseRepository.java | 5 +- .../service/StatisticsServiceImpl.java | 85 ++++++++++--------- .../src/main/resources/application.properties | 6 +- .../statistics/TestEntityGeneratorUtil.java | 2 +- ...niProtKBStatisticsEntryRepositoryTest.java | 20 ++--- .../service/StatisticsServiceTest.java | 14 +-- 10 files changed, 81 insertions(+), 74 deletions(-) diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java index 0ef284fee..88f2988d2 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java @@ -21,7 +21,7 @@ public class UniProtKBStatisticsEntry { @ManyToOne @JoinColumn(name = "release_name") - private UniProtRelease releaseName; + private UniProtRelease uniprotRelease; @Enumerated(EnumType.STRING) private EntryType entryType; diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java index a0b6bd1f6..8db0366fd 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java @@ -2,9 +2,7 @@ import java.util.Date; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; import lombok.Data; @@ -12,6 +10,9 @@ @Entity @Table(name = "uniprot_release") public class UniProtRelease { - @Id private String id; + @Id private int id; private Date date; + @Enumerated(EnumType.STRING) + private EntryType entryType; + private String name; } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java index 99f4068ff..06eb0cd21 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java @@ -54,8 +54,8 @@ public StatisticsModuleStatisticsAttribute map( public StatisticsModuleStatisticsHistory mapHistory(UniProtKBStatisticsEntry entry) { return StatisticsModuleStatisticsHistoryImpl.builder() .statisticsType(map(entry.getEntryType())) - .releaseName(entry.getReleaseName().getId()) - .releaseDate(entry.getReleaseName().getDate()) + .releaseName(entry.getUniprotRelease().getName()) + .releaseDate(entry.getUniprotRelease().getDate()) .valueCount(entry.getValueCount()) .entryCount(entry.getEntryCount()) .build(); diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java index 794387f91..3eb88e623 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java @@ -15,10 +15,10 @@ @Primary public interface UniProtKBStatisticsEntryRepository extends JpaRepository { - List findAllByReleaseNameAndEntryType( + List findAllByUniprotReleaseAndEntryType( UniProtRelease releaseName, EntryType entryType); - List findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( + List findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( UniProtRelease uniProtRelease, EntryType entryType, Collection statisticsCategory); @@ -28,8 +28,8 @@ List findAllByAttributeNameIgnoreCaseAndEntryType( List findAllByAttributeNameIgnoreCase(String attributeName); - List findAllByReleaseName(UniProtRelease releaseName); + List findAllByUniprotRelease(UniProtRelease uniProtRelease); - List findAllByReleaseNameAndStatisticsCategoryIn( + List findAllByUniprotReleaseAndStatisticsCategoryIn( UniProtRelease releaseName, Collection statisticsCategory); } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java index 22dcdf9b8..b69939f1b 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java @@ -1,5 +1,6 @@ package org.uniprot.api.support.data.statistics.repository; +import java.lang.annotation.ElementType; import java.util.Date; import java.util.Optional; @@ -7,11 +8,13 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import org.uniprot.api.support.data.statistics.entity.EntryType; import org.uniprot.api.support.data.statistics.entity.UniProtRelease; @Repository @Primary public interface UniProtReleaseRepository extends JpaRepository { - @Query("SELECT MAX (ur.date) from UniProtRelease ur where ur.id findPreviousReleaseDate(String currentRelease); + Optional findByNameAndEntryType(String name, EntryType entryType); } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java index df2d44aa4..e57243d20 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java @@ -1,12 +1,5 @@ package org.uniprot.api.support.data.statistics.service; -import static org.uniprot.api.support.data.statistics.entity.EntryType.SWISSPROT; -import static org.uniprot.api.support.data.statistics.entity.EntryType.TREMBL; - -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.uniprot.api.support.data.statistics.entity.*; @@ -17,6 +10,13 @@ import org.uniprot.api.support.data.statistics.repository.UniProtKBStatisticsEntryRepository; import org.uniprot.api.support.data.statistics.repository.UniProtReleaseRepository; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +import static org.uniprot.api.support.data.statistics.entity.EntryType.SWISSPROT; +import static org.uniprot.api.support.data.statistics.entity.EntryType.TREMBL; + @Service public class StatisticsServiceImpl implements StatisticsService { @@ -46,20 +46,7 @@ public StatisticsServiceImpl( @Override public List findAllByVersionAndStatisticTypeAndCategoryIn( String version, String statisticType, Set categories) { - List entries; - if (categories.isEmpty()) { - entries = - statisticsEntryRepository.findAllByReleaseNameAndEntryType( - getRelease(version), - statisticsMapper.map(getStatisticType(statisticType))); - } else { - entries = - statisticsEntryRepository - .findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( - getRelease(version), - statisticsMapper.map(getStatisticType(statisticType)), - getCategories(categories)); - } + List entries = getAllEntriesByVersionAndStatisticTypeAndCategoryIn(version, statisticType, categories); return entries.stream() .collect(Collectors.groupingBy(UniProtKBStatisticsEntry::getStatisticsCategory)) .entrySet() @@ -68,15 +55,6 @@ public List findAllByVersionAndStatisticType .collect(Collectors.toList()); } - private UniProtRelease getRelease(String version) { - return releaseRepository - .findById(version) - .orElseThrow( - () -> - new IllegalArgumentException( - String.format("Invalid Release Version: %s", version))); - } - @Override public List findAllByAttributeAndStatisticType( String attribute, String statisticType) { @@ -98,14 +76,12 @@ public List findAllByAttributeAndStatisticTyp @Override public Collection findAllByVersionAndCategoryIn( String version, Set categories) { - List entries; - if (categories.isEmpty()) { - entries = statisticsEntryRepository.findAllByReleaseName(getRelease(version)); - } else { - entries = - statisticsEntryRepository.findAllByReleaseNameAndStatisticsCategoryIn( - getRelease(version), getCategories(categories)); + List entries = new LinkedList<>(); + + for (StatisticsModuleStatisticsType statisticsType : StatisticsModuleStatisticsType.values()) { + entries.addAll(getAllEntriesByVersionAndStatisticTypeAndCategoryIn(version, statisticsType.name(), categories)); } + return entries.stream() .collect(Collectors.groupingBy(UniProtKBStatisticsEntry::getStatisticsCategory)) .entrySet() @@ -115,6 +91,33 @@ public Collection findAllByVersionAndCategor .collect(Collectors.toList()); } + private List getAllEntriesByVersionAndStatisticTypeAndCategoryIn(String version, String statisticType, Set categories) { + List entries; + StatisticsModuleStatisticsType statisticsModuleStatisticsType = getStatisticType(statisticType); + EntryType entryType = statisticsMapper.map(statisticsModuleStatisticsType); + UniProtRelease release = getRelease(version, entryType); + if (categories.isEmpty()) { + entries = + statisticsEntryRepository.findAllByUniprotRelease(release); + } else { + entries = + statisticsEntryRepository + .findAllByUniprotReleaseAndStatisticsCategoryIn( + release, + getCategories(categories)); + } + return entries; + } + + private UniProtRelease getRelease(String version, EntryType entryType) { + return releaseRepository + .findByNameAndEntryType(version, entryType) + .orElseThrow( + () -> + new IllegalArgumentException( + String.format("Invalid Release Version: %s or entry type: %s", version, entryType))); + } + private Map.Entry> groupEntries( Map.Entry> entry) { List groupedEntries = @@ -143,7 +146,7 @@ private UniProtKBStatisticsEntry mapToSingleEntry( .mapToLong(UniProtKBStatisticsEntry::getEntryCount) .sum()); uniProtKBStatisticsEntry.setDescription(firstEntry.getDescription()); - uniProtKBStatisticsEntry.setReleaseName(firstEntry.getReleaseName()); + uniProtKBStatisticsEntry.setUniprotRelease(firstEntry.getUniprotRelease()); return uniProtKBStatisticsEntry; } @@ -195,7 +198,7 @@ private String prepareQuery(AttributeQuery query, UniProtKBStatisticsEntry entry String result = query.getQuery(); if (result.contains(PREVIOUS_RELEASE_DATE)) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - String currentRelease = entry.getReleaseName().getId(); + String currentRelease = entry.getUniprotRelease().getName(); Date previousReleaseDate = releaseRepository .findPreviousReleaseDate(currentRelease) @@ -214,8 +217,8 @@ private String prepareQuery(AttributeQuery query, UniProtKBStatisticsEntry entry Objects.equals(entryType, SWISSPROT) ? START_QUERY + REVIEWED + "true" + END_QUERY + " AND " : Objects.equals(entryType, TREMBL) - ? START_QUERY + REVIEWED + "false" + END_QUERY + " AND " - : ""; + ? START_QUERY + REVIEWED + "false" + END_QUERY + " AND " + : ""; return prepend + result; } diff --git a/support-data-rest/src/main/resources/application.properties b/support-data-rest/src/main/resources/application.properties index 45a8eb53d..2f2c262d9 100644 --- a/support-data-rest/src/main/resources/application.properties +++ b/support-data-rest/src/main/resources/application.properties @@ -61,6 +61,6 @@ spring.datasource.platform=postgres spring.jpa.hibernate.ddl-auto=update #database -spring.datasource.url= -spring.datasource.username= -spring.datasource.password= \ No newline at end of file +spring.datasource.url=jdbc:postgresql://pgsql-hlvm-024.ebi.ac.uk:5432/unpstspro?currentSchema=uniprot +spring.datasource.username=uniprot +spring.datasource.password=un1pr0t \ No newline at end of file diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java index b691398de..c381b95bc 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java @@ -110,7 +110,7 @@ private static UniProtKBStatisticsEntry createStatisticsEntry(int index) { uniprotkbStatisticsEntry.setValueCount(VALUE_COUNTS[index]); uniprotkbStatisticsEntry.setEntryCount(ENTRY_COUNTS[index]); uniprotkbStatisticsEntry.setDescription(DESCRIPTIONS[index]); - uniprotkbStatisticsEntry.setReleaseName( + uniprotkbStatisticsEntry.setUniProtRelease( Set.of(0, 1, 3, 4, 5).contains(index) ? RELEASES[0] : RELEASES[1]); uniprotkbStatisticsEntry.setEntryType(ENTRY_TYPES[index]); return uniprotkbStatisticsEntry; diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java index 785a59237..c4a1e0b40 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java @@ -48,7 +48,7 @@ void setUp() { @Test void findAllByReleaseNameAndEntryType() { List results = - entryRepository.findAllByReleaseNameAndEntryType(RELEASES[0], SWISSPROT); + entryRepository.findAllByUniprotReleaseAndEntryType(RELEASES[0], SWISSPROT); assertThat( results, @@ -61,7 +61,7 @@ void findAllByReleaseNameAndEntryType() { @Test void findAllByReleaseName() { - List results = entryRepository.findAllByReleaseName(RELEASES[0]); + List results = entryRepository.findAllByUniprotRelease(RELEASES[0]); assertThat( results, @@ -76,14 +76,14 @@ void findAllByReleaseName() { @Test void findAllByReleaseNameAndEntryType_whenNoMatch() { List results = - entryRepository.findAllByReleaseNameAndEntryType(RELEASES[2], TREMBL); + entryRepository.findAllByUniprotReleaseAndEntryType(RELEASES[2], TREMBL); assertThat(results, empty()); } @Test void findAllByReleaseName_whenNoMatch() { - List results = entryRepository.findAllByReleaseName(RELEASES[2]); + List results = entryRepository.findAllByUniprotRelease(RELEASES[2]); assertThat(results, empty()); } @@ -91,7 +91,7 @@ void findAllByReleaseName_whenNoMatch() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn() { List results = - entryRepository.findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( RELEASES[0], SWISSPROT, List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); @@ -105,7 +105,7 @@ void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn() { @Test void findAllByReleaseNameAndStatisticsCategoryIdIn() { List results = - entryRepository.findAllByReleaseNameAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( RELEASES[0], List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); assertThat( @@ -117,7 +117,7 @@ void findAllByReleaseNameAndStatisticsCategoryIdIn() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { List results = - entryRepository.findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( RELEASES[0], SWISSPROT, List.of(STATISTICS_CATEGORIES[0])); assertThat(results, containsInAnyOrder(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); @@ -126,7 +126,7 @@ void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenSingleCategor @Test void findAllByReleaseNameAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { List results = - entryRepository.findAllByReleaseNameAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( RELEASES[0], List.of(STATISTICS_CATEGORIES[0])); assertThat(results, containsInAnyOrder(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); @@ -135,7 +135,7 @@ void findAllByReleaseNameAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenNoCategoryPassed() { List results = - entryRepository.findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( RELEASES[0], SWISSPROT, Collections.emptyList()); assertThat(results, empty()); @@ -144,7 +144,7 @@ void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenNoCategoryPas @Test void findAllByReleaseNameAndStatisticsCategoryIdIn_whenNoCategoryPassed() { List results = - entryRepository.findAllByReleaseNameAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( RELEASES[2], Collections.emptyList()); assertThat(results, empty()); diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java index 9979b3202..6c68bc4ab 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java @@ -148,13 +148,13 @@ private UniProtKBStatisticsEntry getCommonEntry(UniProtKBStatisticsEntry statist entry.setValueCount(statisticsEntry.getValueCount()); entry.setEntryCount(statisticsEntry.getEntryCount()); entry.setDescription(statisticsEntry.getDescription()); - entry.setReleaseName(statisticsEntry.getReleaseName()); + entry.setUniProtRelease(statisticsEntry.getUniProtRelease()); return entry; } @Test void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByReleaseNameAndEntryType( + when(statisticsEntryRepository.findAllByUniprotReleaseAndEntryType( UNI_PROT_RELEASE, ENTRY_TYPE)) .thenReturn( List.of( @@ -177,7 +177,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPass @Test void findAllByVersionAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByReleaseName(UNI_PROT_RELEASE)) + when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE)) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -202,7 +202,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn() { .thenReturn(Optional.of(statisticsCategory0)); when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); - when(statisticsEntryRepository.findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( UNI_PROT_RELEASE, ENTRY_TYPE, Set.of(statisticsCategory0, statisticsCategory1))) @@ -228,7 +228,7 @@ void findAllByVersionAndCategoryIn() { .thenReturn(Optional.of(statisticsCategory0)); when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); - when(statisticsEntryRepository.findAllByReleaseNameAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE, Set.of(statisticsCategory0, statisticsCategory1))) .thenReturn( List.of( @@ -250,7 +250,7 @@ void findAllByVersionAndCategoryIn() { void findAllByVersionAndStatisticTypeAndCategoryIn_whenSingleCategoryIsPassed() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); - when(statisticsEntryRepository.findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( UNI_PROT_RELEASE, ENTRY_TYPE, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); @@ -265,7 +265,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn_whenSingleCategoryIsPassed() void findAllByVersionAndCategoryIn_whenSingleCategoryIsPassed() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); - when(statisticsEntryRepository.findAllByReleaseNameAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); From ae805b0e711f544aefdce3ec0d067a8b96a2b014 Mon Sep 17 00:00:00 2001 From: supun Date: Fri, 20 Dec 2024 06:19:59 +0000 Subject: [PATCH 2/5] test fix --- .../statistics/entity/AttributeQuery.java | 2 +- .../entity/UniProtKBStatisticsEntry.java | 2 +- .../UniProtKBStatisticsEntryRepository.java | 8 ----- .../repository/UniProtReleaseRepository.java | 2 +- .../statistics/TestEntityGeneratorUtil.java | 13 ++++---- .../controller/StatisticsControllerIT.java | 28 ++++++++-------- ...niProtKBStatisticsEntryRepositoryTest.java | 27 ++++------------ .../UniProtReleaseRepositoryTest.java | 4 ++- .../service/StatisticsServiceTest.java | 32 +++++++++++++------ support-data-rest/src/test/resources/init.sql | 32 ++++++++++++------- 10 files changed, 75 insertions(+), 75 deletions(-) diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java index 0a75fb3b9..dab1d9c61 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java @@ -6,7 +6,7 @@ @Data @Entity -@Table(indexes = @Index(columnList = "attributeName, statistics_category_id", unique = true)) +@Table(name = "attribute_query", indexes = @Index(columnList = "attributeName, statistics_category_id", unique = true)) public class AttributeQuery { @Id private Long id; diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java index 88f2988d2..29307d2d1 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java @@ -6,7 +6,7 @@ @Data @Entity -@Table(name = "uniprotkb_statistics_entry") +@Table(name = "uniprotkb_statistics_entry", indexes = @Index(columnList = "release_name")) public class UniProtKBStatisticsEntry { @Id private Long id; private String attributeName; diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java index 3eb88e623..606b34b90 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java @@ -15,14 +15,6 @@ @Primary public interface UniProtKBStatisticsEntryRepository extends JpaRepository { - List findAllByUniprotReleaseAndEntryType( - UniProtRelease releaseName, EntryType entryType); - - List findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( - UniProtRelease uniProtRelease, - EntryType entryType, - Collection statisticsCategory); - List findAllByAttributeNameIgnoreCaseAndEntryType( String attributeName, EntryType entryType); diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java index b69939f1b..062484797 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java @@ -13,7 +13,7 @@ @Repository @Primary -public interface UniProtReleaseRepository extends JpaRepository { +public interface UniProtReleaseRepository extends JpaRepository { @Query("SELECT MAX (ur.date) from UniProtRelease ur where ur.name findPreviousReleaseDate(String currentRelease); Optional findByNameAndEntryType(String name, EntryType entryType); diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java index c381b95bc..7d97d0bec 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java @@ -63,14 +63,15 @@ public class TestEntityGeneratorUtil { }; public static final UniProtRelease[] RELEASES = new UniProtRelease[] { - createRelease(REL_0, DATES[0]), - createRelease(REL_1, DATES[1]), - createRelease(REL_2, DATES[2]) + createRelease(0, REL_0, DATES[0]), + createRelease(1, REL_1, DATES[1]), + createRelease(2, REL_2, DATES[2]) }; - private static UniProtRelease createRelease(String name, Date date) { + private static UniProtRelease createRelease(int id,String name, Date date) { UniProtRelease release = new UniProtRelease(); - release.setId(name); + release.setId(id); + release.setName(name); release.setDate(date); return release; } @@ -110,7 +111,7 @@ private static UniProtKBStatisticsEntry createStatisticsEntry(int index) { uniprotkbStatisticsEntry.setValueCount(VALUE_COUNTS[index]); uniprotkbStatisticsEntry.setEntryCount(ENTRY_COUNTS[index]); uniprotkbStatisticsEntry.setDescription(DESCRIPTIONS[index]); - uniprotkbStatisticsEntry.setUniProtRelease( + uniprotkbStatisticsEntry.setUniprotRelease( Set.of(0, 1, 3, 4, 5).contains(index) ? RELEASES[0] : RELEASES[1]); uniprotkbStatisticsEntry.setEntryType(ENTRY_TYPES[index]); return uniprotkbStatisticsEntry; diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/controller/StatisticsControllerIT.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/controller/StatisticsControllerIT.java index aeba042b6..c4ed9f61f 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/controller/StatisticsControllerIT.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/controller/StatisticsControllerIT.java @@ -39,7 +39,7 @@ static void postgreSQLProperties(DynamicPropertyRegistry registry) { @Test void getByReleaseAndType() throws Exception { this.mockMvc - .perform(get("/statistics/releases/2021_03/reviewed")) + .perform(get("/statistics/releases/2021_02/reviewed")) .andDo(log()) .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(3))) @@ -52,7 +52,7 @@ void getByReleaseAndType() throws Exception { .andExpect( jsonPath( "$.results[0].items[0].query", - is("(reviewed:true) AND (previous_release_date:2021-03-25)"))) + is("(reviewed:true) AND (previous_release_date:2021-01-25)"))) .andExpect(jsonPath("$.results[0].items[0].count", is(329))) .andExpect(jsonPath("$.results[0].items[0].entryCount", is(254))) .andExpect(jsonPath("$.results[1].categoryName", is("TOP_ORGANISM"))) @@ -91,7 +91,7 @@ void getByReleaseAndType() throws Exception { @Test void getByRelease() throws Exception { this.mockMvc - .perform(get("/statistics/releases/2021_03")) + .perform(get("/statistics/releases/2021_02")) .andDo(log()) .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(3))) @@ -104,7 +104,7 @@ void getByRelease() throws Exception { .andExpect( jsonPath( "$.results[0].items[0].query", - is("(previous_release_date:2021-03-25)"))) + is("(previous_release_date:2021-01-25)"))) .andExpect(jsonPath("$.results[0].items[0].count", is(329))) .andExpect(jsonPath("$.results[0].items[0].entryCount", is(254))) .andExpect(jsonPath("$.results[1].categoryName", is("TOP_ORGANISM"))) @@ -137,7 +137,7 @@ void getByRelease() throws Exception { @Test void getByReleaseAndTypeAndSingleCategory() throws Exception { this.mockMvc - .perform(get("/statistics/releases/2021_03/reviewed?categories=EUKARYOTA")) + .perform(get("/statistics/releases/2021_02/reviewed?categories=EUKARYOTA")) .andDo(log()) .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(1))) @@ -165,7 +165,7 @@ void getByReleaseAndTypeAndSingleCategory() throws Exception { @Test void getByReleaseAndSingleCategory() throws Exception { this.mockMvc - .perform(get("/statistics/releases/2021_03?categories=EUKARYOTA")) + .perform(get("/statistics/releases/2021_02?categories=EUKARYOTA")) .andDo(log()) .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(1))) @@ -189,7 +189,7 @@ void getByReleaseAndTypeAndMultipleCategories() throws Exception { this.mockMvc .perform( get( - "/statistics/releases/2021_03/reviewed?categories=EUKARYOTA,TOP_ORGANISM")) + "/statistics/releases/2021_02/reviewed?categories=EUKARYOTA,TOP_ORGANISM")) .andDo(log()) .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(2))) @@ -229,7 +229,7 @@ void getByReleaseAndTypeAndMultipleCategories() throws Exception { @Test void getByReleaseAndMultipleCategories() throws Exception { this.mockMvc - .perform(get("/statistics/releases/2021_03?categories=EUKARYOTA,TOP_ORGANISM")) + .perform(get("/statistics/releases/2021_02?categories=EUKARYOTA,TOP_ORGANISM")) .andDo(log()) .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(2))) @@ -268,8 +268,8 @@ void getAllByAttributeAndStatisticsType() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(1))) .andExpect(jsonPath("$.results[0].statisticsType", is("REVIEWED"))) - .andExpect(jsonPath("$.results[0].releaseName", is("2021_03"))) - .andExpect(jsonPath("$.results[0].releaseDate", is("2021-05-25"))) + .andExpect(jsonPath("$.results[0].releaseName", is("2021_02"))) + .andExpect(jsonPath("$.results[0].releaseDate", is("2021-03-25"))) .andExpect(jsonPath("$.results[0].valueCount", is(35360))) .andExpect(jsonPath("$.results[0].entryCount", is(35360))); } @@ -311,13 +311,13 @@ void getAllByAttributeAndAttributeType_withoutAttributeType() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.results.size()", is(2))) .andExpect(jsonPath("$.results[0].statisticsType", is("REVIEWED"))) - .andExpect(jsonPath("$.results[0].releaseName", is("2021_03"))) - .andExpect(jsonPath("$.results[0].releaseDate", is("2021-05-25"))) + .andExpect(jsonPath("$.results[0].releaseName", is("2021_02"))) + .andExpect(jsonPath("$.results[0].releaseDate", is("2021-03-25"))) .andExpect(jsonPath("$.results[0].valueCount", is(35360))) .andExpect(jsonPath("$.results[0].entryCount", is(35360))) .andExpect(jsonPath("$.results[1].statisticsType", is("UNREVIEWED"))) - .andExpect(jsonPath("$.results[1].releaseName", is("2021_03"))) - .andExpect(jsonPath("$.results[1].releaseDate", is("2021-05-25"))) + .andExpect(jsonPath("$.results[1].releaseName", is("2021_02"))) + .andExpect(jsonPath("$.results[1].releaseDate", is("2021-03-25"))) .andExpect(jsonPath("$.results[1].valueCount", is(12793422))) .andExpect(jsonPath("$.results[1].entryCount", is(12793422))); } diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java index c4a1e0b40..b749dcc39 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java @@ -45,20 +45,6 @@ void setUp() { Arrays.stream(RELEASES).forEach(entityManager::persist); } - @Test - void findAllByReleaseNameAndEntryType() { - List results = - entryRepository.findAllByUniprotReleaseAndEntryType(RELEASES[0], SWISSPROT); - - assertThat( - results, - containsInAnyOrder( - STATISTICS_ENTRIES[0], - STATISTICS_ENTRIES[1], - STATISTICS_ENTRIES[3], - STATISTICS_ENTRIES[4])); - } - @Test void findAllByReleaseName() { List results = entryRepository.findAllByUniprotRelease(RELEASES[0]); @@ -76,7 +62,7 @@ void findAllByReleaseName() { @Test void findAllByReleaseNameAndEntryType_whenNoMatch() { List results = - entryRepository.findAllByUniprotReleaseAndEntryType(RELEASES[2], TREMBL); + entryRepository.findAllByUniprotRelease(RELEASES[2]); assertThat(results, empty()); } @@ -91,9 +77,8 @@ void findAllByReleaseName_whenNoMatch() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn() { List results = - entryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( + entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( RELEASES[0], - SWISSPROT, List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); assertThat( @@ -117,8 +102,8 @@ void findAllByReleaseNameAndStatisticsCategoryIdIn() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { List results = - entryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( - RELEASES[0], SWISSPROT, List.of(STATISTICS_CATEGORIES[0])); + entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + RELEASES[0], List.of(STATISTICS_CATEGORIES[0])); assertThat(results, containsInAnyOrder(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); } @@ -135,8 +120,8 @@ void findAllByReleaseNameAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenNoCategoryPassed() { List results = - entryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( - RELEASES[0], SWISSPROT, Collections.emptyList()); + entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + RELEASES[0], Collections.emptyList()); assertThat(results, empty()); } diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java index 7cf828768..1a1b4b75b 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java @@ -31,7 +31,8 @@ class UniProtReleaseRepositoryTest { @Autowired private TestEntityManager entityManager; @Autowired private UniProtReleaseRepository uniProtReleaseRepository; - private static final String[] IDS = new String[] {"2023_05", "2023_06", "2024_01", "2024_02"}; + private static final int[] IDS = new int[] {0, 1, 2, 3}; + private static final String[] NAMES = new String[] {"2023_05", "2023_06", "2024_01", "2024_02"}; private static final Date[] DATES = new Date[] { Date.from(Instant.ofEpochMilli(100L)), @@ -46,6 +47,7 @@ void setUp() { for (int i = 0; i < 4; i++) { UniProtRelease uniProtRelease = new UniProtRelease(); uniProtRelease.setId(IDS[i]); + uniProtRelease.setName(NAMES[i]); uniProtRelease.setDate(DATES[i]); UNIPROT_RELEASES[i] = uniProtRelease; } diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java index 32595ff90..5d2558b22 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java @@ -4,10 +4,14 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; import static org.uniprot.api.support.data.statistics.TestEntityGeneratorUtil.*; import static org.uniprot.api.support.data.statistics.entity.EntryType.SWISSPROT; +import static org.uniprot.api.support.data.statistics.entity.EntryType.TREMBL; +import static org.uniprot.api.support.data.statistics.model.StatisticsModuleStatisticsType.*; import java.time.Instant; import java.util.*; @@ -34,7 +38,7 @@ class StatisticsServiceTest { private static final String STATISTIC_TYPE = "reviewed"; private static final EntryType ENTRY_TYPE = EntryType.SWISSPROT; private static final StatisticsModuleStatisticsType STATISTIC_TYPE_ENUM = - StatisticsModuleStatisticsType.REVIEWED; + REVIEWED; private static final String VERSION = "version"; private static final UniProtRelease UNI_PROT_RELEASE = new UniProtRelease(); public static final String NAME_0 = "name0"; @@ -92,9 +96,16 @@ void setUp() { .searchField(SEARCH_FIELDS[2]) .build(); lenient().when(statisticsMapper.map(STATISTIC_TYPE_ENUM)).thenReturn(ENTRY_TYPE); + lenient().when(statisticsMapper.map(UNREVIEWED)).thenReturn(TREMBL); lenient() .when(statisticsMapper.map(STATISTICS_ENTRIES[0], QUERIES[0])) .thenReturn(statisticsModuleStatisticsAttribute0); + /* lenient() + .when(statisticsMapper.map(argThat(e->ENTRY_NAMES[0].equals(e.getAttributeName())), same(QUERIES_COMMON[0]))) + .thenReturn(statisticsModuleStatisticsAttribute0); + lenient() + .when(statisticsMapper.map(argThat(e->ENTRY_NAMES[1].equals(e.getAttributeName())), same(QUERIES_COMMON[1]))) + .thenReturn(statisticsModuleStatisticsAttribute0);*/ lenient() .when(statisticsMapper.map(STATISTICS_ENTRIES[1], QUERIES[1])) .thenReturn(statisticsModuleStatisticsAttribute1); @@ -125,8 +136,11 @@ void setUp() { getCommonEntry(STATISTICS_ENTRIES[3]), QUERIES_COMMON[3])) .thenReturn(statisticsModuleStatisticsAttribute3); lenient() - .when(releaseRepository.findById(VERSION)) - .thenReturn(Optional.of(UNI_PROT_RELEASE)); + .when(releaseRepository.findByNameAndEntryType(VERSION, ENTRY_TYPE)) + .thenReturn(Optional.of(UNI_PROT_RELEASE)); + lenient() + .when(releaseRepository.findByNameAndEntryType(VERSION, TREMBL)) + .thenReturn(Optional.of(UNI_PROT_RELEASE)); lenient() .when(attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORIES[1],ENTRY_NAMES[0])) .thenReturn(Optional.of(ATTRIBUTE_QUERIES[0])); @@ -154,14 +168,13 @@ private UniProtKBStatisticsEntry getCommonEntry(UniProtKBStatisticsEntry statist entry.setValueCount(statisticsEntry.getValueCount()); entry.setEntryCount(statisticsEntry.getEntryCount()); entry.setDescription(statisticsEntry.getDescription()); - entry.setUniProtRelease(statisticsEntry.getUniProtRelease()); + entry.setUniprotRelease(statisticsEntry.getUniprotRelease()); return entry; } @Test void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByUniprotReleaseAndEntryType( - UNI_PROT_RELEASE, ENTRY_TYPE)) + when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE)) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -208,9 +221,8 @@ void findAllByVersionAndStatisticTypeAndCategoryIn() { .thenReturn(Optional.of(statisticsCategory0)); when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); - when(statisticsEntryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE, - ENTRY_TYPE, Set.of(statisticsCategory0, statisticsCategory1))) .thenReturn( List.of( @@ -256,8 +268,8 @@ void findAllByVersionAndCategoryIn() { void findAllByVersionAndStatisticTypeAndCategoryIn_whenSingleCategoryIsPassed() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); - when(statisticsEntryRepository.findAllByUniprotReleaseAndEntryTypeAndStatisticsCategoryIn( - UNI_PROT_RELEASE, ENTRY_TYPE, Set.of(statisticsCategory0))) + when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + UNI_PROT_RELEASE, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); Collection results = diff --git a/support-data-rest/src/test/resources/init.sql b/support-data-rest/src/test/resources/init.sql index e5156a97e..e16cc9427 100644 --- a/support-data-rest/src/test/resources/init.sql +++ b/support-data-rest/src/test/resources/init.sql @@ -23,7 +23,7 @@ CREATE TABLE uniprotkb_statistics_entry value_count int8 NULL, entry_count int8 NULL, description varchar NULL, - release_name varchar(32) NOT NULL, + release_name int8 NOT NULL, entry_type varchar(32) NULL, CONSTRAINT uniprotkb_statistics_entry_un UNIQUE (attribute_name, statistics_category_id, release_name, entry_type) ); @@ -34,8 +34,10 @@ ALTER TABLE uniprotkb_statistics_entry CREATE TABLE uniprot_release ( - id varchar(64) PRIMARY KEY, - date date NOT NULL + id int8 PRIMARY KEY, + date date NOT NULL, + entry_type varchar(32) NOT NULL, + name varchar(32) NOT NULL ); ALTER TABLE uniprotkb_statistics_entry @@ -57,26 +59,32 @@ VALUES (45, 'SEQUENCE_AMINO_ACID', 'UNIPROTKB', 'Sequence Amino Acid', 'sf Seque INSERT INTO statistics_category (id, category, db_type, label, search_field) VALUES (52, 'TOP_ORGANISM', 'UNIPROTKB', 'Top Organism', 'sf Organism'); -INSERT INTO uniprot_release (id, date) -VALUES ('2021_02', '2021-03-25'); -INSERT INTO uniprot_release (id, date) -VALUES ('2021_03', '2021-05-25'); +INSERT INTO uniprot_release (id, name, date, entry_type) +VALUES (3, '2021_01', '2021-01-25', 'SWISSPROT'); +INSERT INTO uniprot_release (id, name, date, entry_type) +VALUES (4, '2021_01', '2021-01-25', 'TREMBL'); +INSERT INTO uniprot_release (id, name, date, entry_type) +VALUES (0, '2021_02', '2021-03-25', 'SWISSPROT'); +INSERT INTO uniprot_release (id, name, date, entry_type) +VALUES (1, '2021_02', '2021-03-25', 'TREMBL'); +INSERT INTO uniprot_release (id, name, date, entry_type) +VALUES (2, '2021_03', '2021-05-25', 'SWISSPROT'); INSERT INTO uniprotkb_statistics_entry (id, attribute_name, statistics_category_id, value_count, entry_count, description, release_name, entry_type) -VALUES (47549, 'Fungi', 39, 35360, 35360, null, '2021_03', 'SWISSPROT'); +VALUES (47549, 'Fungi', 39, 35360, 35360, null, 0, 'SWISSPROT'); INSERT INTO uniprotkb_statistics_entry (id, attribute_name, statistics_category_id, value_count, entry_count, description, release_name, entry_type) -VALUES (47550, 'Insecta', 39, 9457, 9457, null, '2021_03', 'SWISSPROT'); +VALUES (47550, 'Insecta', 39, 9457, 9457, null, 0, 'SWISSPROT'); INSERT INTO uniprotkb_statistics_entry (id, attribute_name, statistics_category_id, value_count, entry_count, description, release_name, entry_type) -VALUES (50289, 'Fungi', 39, 12793422, 12793422, null, '2021_03', 'TREMBL'); +VALUES (50289, 'Fungi', 39, 12793422, 12793422, null, 1, 'TREMBL'); INSERT INTO uniprotkb_statistics_entry (id, attribute_name, statistics_category_id, value_count, entry_count, description, release_name, entry_type) -VALUES (47175, 'AMINO_ACID_U', 45, 329, 254, null, '2021_03', 'SWISSPROT'); +VALUES (47175, 'AMINO_ACID_U', 45, 329, 254, null, 0, 'SWISSPROT'); INSERT INTO uniprotkb_statistics_entry (id, attribute_name, statistics_category_id, value_count, entry_count, description, release_name, entry_type) -VALUES (47206, 'Salmonella paratyphi B (strain ATCC BAA-1250 / SPB7)', 52, 716, 716, null, '2021_03', 'SWISSPROT'); +VALUES (47206, 'Salmonella paratyphi B (strain ATCC BAA-1250 / SPB7)', 52, 716, 716, null, 0, 'SWISSPROT'); INSERT INTO attribute_query (id, attribute_name, query, statistics_category_id) VALUES (1,'Fungi','(taxonomy_id:4751)', 39); From 806004b6ed7b4f2e903c5f653db92ce1328a5d10 Mon Sep 17 00:00:00 2001 From: supun Date: Fri, 20 Dec 2024 06:56:48 +0000 Subject: [PATCH 3/5] add date time formatting --- .../statistics/entity/AttributeQuery.java | 4 +- .../statistics/entity/UniProtRelease.java | 4 ++ .../repository/AttributeQueryRepository.java | 3 +- .../repository/UniProtReleaseRepository.java | 2 +- .../service/StatisticsServiceImpl.java | 51 ++++++++------- .../statistics/TestEntityGeneratorUtil.java | 2 +- .../AttributeQueryRepositoryTest.java | 9 ++- ...niProtKBStatisticsEntryRepositoryTest.java | 9 +-- .../UniProtReleaseRepositoryTest.java | 10 +-- .../service/StatisticsServiceTest.java | 65 ++++++++++++------- 10 files changed, 98 insertions(+), 61 deletions(-) diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java index dab1d9c61..8ab7b7024 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/AttributeQuery.java @@ -6,7 +6,9 @@ @Data @Entity -@Table(name = "attribute_query", indexes = @Index(columnList = "attributeName, statistics_category_id", unique = true)) +@Table( + name = "attribute_query", + indexes = @Index(columnList = "attributeName, statistics_category_id", unique = true)) public class AttributeQuery { @Id private Long id; diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java index 8db0366fd..0422a7017 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtRelease.java @@ -11,8 +11,12 @@ @Table(name = "uniprot_release") public class UniProtRelease { @Id private int id; + + @Temporal(TemporalType.DATE) private Date date; + @Enumerated(EnumType.STRING) private EntryType entryType; + private String name; } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepository.java index fe3769ac7..facbf548b 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepository.java @@ -11,5 +11,6 @@ @Repository @Primary public interface AttributeQueryRepository extends JpaRepository { - Optional findByStatisticsCategoryAndAttributeNameIgnoreCase(StatisticsCategory statisticsCategory, String attributeName); + Optional findByStatisticsCategoryAndAttributeNameIgnoreCase( + StatisticsCategory statisticsCategory, String attributeName); } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java index 062484797..685f83ee6 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepository.java @@ -1,6 +1,5 @@ package org.uniprot.api.support.data.statistics.repository; -import java.lang.annotation.ElementType; import java.util.Date; import java.util.Optional; @@ -16,5 +15,6 @@ public interface UniProtReleaseRepository extends JpaRepository { @Query("SELECT MAX (ur.date) from UniProtRelease ur where ur.name findPreviousReleaseDate(String currentRelease); + Optional findByNameAndEntryType(String name, EntryType entryType); } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java index d3d2eaf86..67e9d1556 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java @@ -1,5 +1,12 @@ package org.uniprot.api.support.data.statistics.service; +import static org.uniprot.api.support.data.statistics.entity.EntryType.SWISSPROT; +import static org.uniprot.api.support.data.statistics.entity.EntryType.TREMBL; + +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.uniprot.api.support.data.statistics.entity.*; @@ -10,13 +17,6 @@ import org.uniprot.api.support.data.statistics.repository.UniProtKBStatisticsEntryRepository; import org.uniprot.api.support.data.statistics.repository.UniProtReleaseRepository; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static org.uniprot.api.support.data.statistics.entity.EntryType.SWISSPROT; -import static org.uniprot.api.support.data.statistics.entity.EntryType.TREMBL; - @Service public class StatisticsServiceImpl implements StatisticsService { @@ -46,7 +46,9 @@ public StatisticsServiceImpl( @Override public List findAllByVersionAndStatisticTypeAndCategoryIn( String version, String statisticType, Set categories) { - List entries = getAllEntriesByVersionAndStatisticTypeAndCategoryIn(version, statisticType, categories); + List entries = + getAllEntriesByVersionAndStatisticTypeAndCategoryIn( + version, statisticType, categories); return entries.stream() .collect(Collectors.groupingBy(UniProtKBStatisticsEntry::getStatisticsCategory)) .entrySet() @@ -78,8 +80,11 @@ public Collection findAllByVersionAndCategor String version, Set categories) { List entries = new LinkedList<>(); - for (StatisticsModuleStatisticsType statisticsType : StatisticsModuleStatisticsType.values()) { - entries.addAll(getAllEntriesByVersionAndStatisticTypeAndCategoryIn(version, statisticsType.name(), categories)); + for (StatisticsModuleStatisticsType statisticsType : + StatisticsModuleStatisticsType.values()) { + entries.addAll( + getAllEntriesByVersionAndStatisticTypeAndCategoryIn( + version, statisticsType.name(), categories)); } return entries.stream() @@ -91,20 +96,19 @@ public Collection findAllByVersionAndCategor .collect(Collectors.toList()); } - private List getAllEntriesByVersionAndStatisticTypeAndCategoryIn(String version, String statisticType, Set categories) { + private List getAllEntriesByVersionAndStatisticTypeAndCategoryIn( + String version, String statisticType, Set categories) { List entries; - StatisticsModuleStatisticsType statisticsModuleStatisticsType = getStatisticType(statisticType); + StatisticsModuleStatisticsType statisticsModuleStatisticsType = + getStatisticType(statisticType); EntryType entryType = statisticsMapper.map(statisticsModuleStatisticsType); UniProtRelease release = getRelease(version, entryType); if (categories.isEmpty()) { - entries = - statisticsEntryRepository.findAllByUniprotRelease(release); + entries = statisticsEntryRepository.findAllByUniprotRelease(release); } else { entries = - statisticsEntryRepository - .findAllByUniprotReleaseAndStatisticsCategoryIn( - release, - getCategories(categories)); + statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + release, getCategories(categories)); } return entries; } @@ -115,7 +119,9 @@ private UniProtRelease getRelease(String version, EntryType entryType) { .orElseThrow( () -> new IllegalArgumentException( - String.format("Invalid Release Version: %s or entry type: %s", version, entryType))); + String.format( + "Invalid Release Version: %s or entry type: %s", + version, entryType))); } private Map.Entry> groupEntries( @@ -190,7 +196,8 @@ private Set getCategories(Set categories) { private String getAttributeQuery(UniProtKBStatisticsEntry entry) { Optional attributeQuery = - attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(entry.getStatisticsCategory(),entry.getAttributeName()); + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + entry.getStatisticsCategory(), entry.getAttributeName()); return attributeQuery.map(query -> prepareQuery(query, entry)).orElse(""); } @@ -217,8 +224,8 @@ private String prepareQuery(AttributeQuery query, UniProtKBStatisticsEntry entry Objects.equals(entryType, SWISSPROT) ? START_QUERY + REVIEWED + "true" + END_QUERY + " AND " : Objects.equals(entryType, TREMBL) - ? START_QUERY + REVIEWED + "false" + END_QUERY + " AND " - : ""; + ? START_QUERY + REVIEWED + "false" + END_QUERY + " AND " + : ""; return prepend + result; } diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java index 7d97d0bec..ed9f1abb6 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java @@ -68,7 +68,7 @@ public class TestEntityGeneratorUtil { createRelease(2, REL_2, DATES[2]) }; - private static UniProtRelease createRelease(int id,String name, Date date) { + private static UniProtRelease createRelease(int id, String name, Date date) { UniProtRelease release = new UniProtRelease(); release.setId(id); release.setName(name); diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepositoryTest.java index 6b402f81c..999377c56 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/AttributeQueryRepositoryTest.java @@ -55,7 +55,8 @@ void setUp() { @Test void findByAttributeName_whenExist() { Optional result = - attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORY, ATTRIBUTES[1]); + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORY, ATTRIBUTES[1]); AttributeQuery attributeQuery = result.get(); assertEquals(IDS[1], attributeQuery.getId()); @@ -65,7 +66,8 @@ void findByAttributeName_whenExist() { @Test void findByAttributeName_whenExistAndCaseDiff() { Optional result = - attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORY, ATTRIBUTES[1].toUpperCase()); + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORY, ATTRIBUTES[1].toUpperCase()); AttributeQuery attributeQuery = result.get(); assertEquals(IDS[1], attributeQuery.getId()); @@ -75,7 +77,8 @@ void findByAttributeName_whenExistAndCaseDiff() { @Test void findByAttributeName_whenAbsent() { Optional result = - attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORY, "random"); + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORY, "random"); assertFalse(result.isPresent()); } diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java index b749dcc39..acb29a0e4 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java @@ -47,7 +47,8 @@ void setUp() { @Test void findAllByReleaseName() { - List results = entryRepository.findAllByUniprotRelease(RELEASES[0]); + List results = + entryRepository.findAllByUniprotRelease(RELEASES[0]); assertThat( results, @@ -69,7 +70,8 @@ void findAllByReleaseNameAndEntryType_whenNoMatch() { @Test void findAllByReleaseName_whenNoMatch() { - List results = entryRepository.findAllByUniprotRelease(RELEASES[2]); + List results = + entryRepository.findAllByUniprotRelease(RELEASES[2]); assertThat(results, empty()); } @@ -78,8 +80,7 @@ void findAllByReleaseName_whenNoMatch() { void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn() { List results = entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( - RELEASES[0], - List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); + RELEASES[0], List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); assertThat( results, diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java index 1a1b4b75b..3586b0825 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtReleaseRepositoryTest.java @@ -4,9 +4,11 @@ import java.time.Instant; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.Optional; +import org.apache.commons.lang.time.DateUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -35,10 +37,10 @@ class UniProtReleaseRepositoryTest { private static final String[] NAMES = new String[] {"2023_05", "2023_06", "2024_01", "2024_02"}; private static final Date[] DATES = new Date[] { - Date.from(Instant.ofEpochMilli(100L)), - Date.from(Instant.ofEpochMilli(200L)), - Date.from(Instant.ofEpochMilli(300L)), - Date.from(Instant.ofEpochMilli(400L)) + DateUtils.truncate(Date.from(Instant.ofEpochMilli(100L)), Calendar.DATE), + DateUtils.truncate(Date.from(Instant.ofEpochMilli(200L)), Calendar.DATE), + DateUtils.truncate(Date.from(Instant.ofEpochMilli(300L)), Calendar.DATE), + DateUtils.truncate(Date.from(Instant.ofEpochMilli(400L)), Calendar.DATE) }; private static final UniProtRelease[] UNIPROT_RELEASES = new UniProtRelease[4]; diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java index 5d2558b22..96745983a 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java @@ -4,8 +4,6 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertThrows; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; import static org.uniprot.api.support.data.statistics.TestEntityGeneratorUtil.*; @@ -37,10 +35,24 @@ class StatisticsServiceTest { private static final String STATISTIC_TYPE = "reviewed"; private static final EntryType ENTRY_TYPE = EntryType.SWISSPROT; - private static final StatisticsModuleStatisticsType STATISTIC_TYPE_ENUM = - REVIEWED; + private static final StatisticsModuleStatisticsType STATISTIC_TYPE_ENUM = REVIEWED; private static final String VERSION = "version"; - private static final UniProtRelease UNI_PROT_RELEASE = new UniProtRelease(); + private static final UniProtRelease UNI_PROT_RELEASE_SWISSPROT; + + static { + UniProtRelease uniProtRelease = new UniProtRelease(); + uniProtRelease.setEntryType(ENTRY_TYPE); + UNI_PROT_RELEASE_SWISSPROT = uniProtRelease; + } + + private static final UniProtRelease UNI_PROT_RELEASE_TREMBL; + + static { + UniProtRelease uniProtRelease = new UniProtRelease(); + uniProtRelease.setEntryType(TREMBL); + UNI_PROT_RELEASE_TREMBL = uniProtRelease; + } + public static final String NAME_0 = "name0"; private static final Date PREVIOUS_RELEASE_DATE = Date.from(Instant.ofEpochMilli(1653476723000L)); @@ -100,12 +112,6 @@ void setUp() { lenient() .when(statisticsMapper.map(STATISTICS_ENTRIES[0], QUERIES[0])) .thenReturn(statisticsModuleStatisticsAttribute0); - /* lenient() - .when(statisticsMapper.map(argThat(e->ENTRY_NAMES[0].equals(e.getAttributeName())), same(QUERIES_COMMON[0]))) - .thenReturn(statisticsModuleStatisticsAttribute0); - lenient() - .when(statisticsMapper.map(argThat(e->ENTRY_NAMES[1].equals(e.getAttributeName())), same(QUERIES_COMMON[1]))) - .thenReturn(statisticsModuleStatisticsAttribute0);*/ lenient() .when(statisticsMapper.map(STATISTICS_ENTRIES[1], QUERIES[1])) .thenReturn(statisticsModuleStatisticsAttribute1); @@ -137,24 +143,34 @@ void setUp() { .thenReturn(statisticsModuleStatisticsAttribute3); lenient() .when(releaseRepository.findByNameAndEntryType(VERSION, ENTRY_TYPE)) - .thenReturn(Optional.of(UNI_PROT_RELEASE)); + .thenReturn(Optional.of(UNI_PROT_RELEASE_SWISSPROT)); lenient() .when(releaseRepository.findByNameAndEntryType(VERSION, TREMBL)) - .thenReturn(Optional.of(UNI_PROT_RELEASE)); + .thenReturn(Optional.of(UNI_PROT_RELEASE_TREMBL)); lenient() - .when(attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORIES[1],ENTRY_NAMES[0])) + .when( + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORIES[1], ENTRY_NAMES[0])) .thenReturn(Optional.of(ATTRIBUTE_QUERIES[0])); lenient() - .when(attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORIES[0],ENTRY_NAMES[0])) + .when( + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORIES[0], ENTRY_NAMES[0])) .thenReturn(Optional.of(ATTRIBUTE_QUERIES[0])); lenient() - .when(attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORIES[0], ENTRY_NAMES[1])) + .when( + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORIES[0], ENTRY_NAMES[1])) .thenReturn(Optional.of(ATTRIBUTE_QUERIES[1])); lenient() - .when(attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORIES[2], ENTRY_NAMES[1])) + .when( + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORIES[2], ENTRY_NAMES[1])) .thenReturn(Optional.of(ATTRIBUTE_QUERIES[1])); lenient() - .when(attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase(STATISTICS_CATEGORIES[0], ENTRY_NAMES[5])) + .when( + attributeQueryRepository.findByStatisticsCategoryAndAttributeNameIgnoreCase( + STATISTICS_CATEGORIES[0], ENTRY_NAMES[5])) .thenReturn(Optional.empty()); lenient() .when(releaseRepository.findPreviousReleaseDate(REL_0)) @@ -174,7 +190,7 @@ private UniProtKBStatisticsEntry getCommonEntry(UniProtKBStatisticsEntry statist @Test void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE)) + when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE_SWISSPROT)) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -196,7 +212,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPass @Test void findAllByVersionAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE)) + when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE_SWISSPROT)) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -222,7 +238,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( - UNI_PROT_RELEASE, + UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0, statisticsCategory1))) .thenReturn( List.of( @@ -247,7 +263,8 @@ void findAllByVersionAndCategoryIn() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( - UNI_PROT_RELEASE, Set.of(statisticsCategory0, statisticsCategory1))) + UNI_PROT_RELEASE_SWISSPROT, + Set.of(statisticsCategory0, statisticsCategory1))) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -269,7 +286,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn_whenSingleCategoryIsPassed() when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( - UNI_PROT_RELEASE, Set.of(statisticsCategory0))) + UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); Collection results = @@ -284,7 +301,7 @@ void findAllByVersionAndCategoryIn_whenSingleCategoryIsPassed() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( - UNI_PROT_RELEASE, Set.of(statisticsCategory0))) + UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); Collection results = From 624c1d8b7a81d3a5e905a88f453bfe9fa1492376 Mon Sep 17 00:00:00 2001 From: supun Date: Fri, 20 Dec 2024 06:58:38 +0000 Subject: [PATCH 4/5] make db props empty --- support-data-rest/src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/support-data-rest/src/main/resources/application.properties b/support-data-rest/src/main/resources/application.properties index 2f2c262d9..45a8eb53d 100644 --- a/support-data-rest/src/main/resources/application.properties +++ b/support-data-rest/src/main/resources/application.properties @@ -61,6 +61,6 @@ spring.datasource.platform=postgres spring.jpa.hibernate.ddl-auto=update #database -spring.datasource.url=jdbc:postgresql://pgsql-hlvm-024.ebi.ac.uk:5432/unpstspro?currentSchema=uniprot -spring.datasource.username=uniprot -spring.datasource.password=un1pr0t \ No newline at end of file +spring.datasource.url= +spring.datasource.username= +spring.datasource.password= \ No newline at end of file From 4aaaceda6d237cec9fb5e21140e52938a92361de Mon Sep 17 00:00:00 2001 From: supun Date: Thu, 2 Jan 2025 08:19:10 +0000 Subject: [PATCH 5/5] rename uniProtRelease --- .../entity/UniProtKBStatisticsEntry.java | 2 +- .../statistics/mapper/StatisticsMapper.java | 4 ++-- .../UniProtKBStatisticsEntryRepository.java | 4 ++-- .../service/StatisticsServiceImpl.java | 8 ++++---- .../statistics/TestEntityGeneratorUtil.java | 2 +- ...UniProtKBStatisticsEntryRepositoryTest.java | 18 +++++++++--------- .../service/StatisticsServiceTest.java | 14 +++++++------- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java index 29307d2d1..247a54b30 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/entity/UniProtKBStatisticsEntry.java @@ -21,7 +21,7 @@ public class UniProtKBStatisticsEntry { @ManyToOne @JoinColumn(name = "release_name") - private UniProtRelease uniprotRelease; + private UniProtRelease uniProtRelease; @Enumerated(EnumType.STRING) private EntryType entryType; diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java index 06eb0cd21..14d8b4d45 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/mapper/StatisticsMapper.java @@ -54,8 +54,8 @@ public StatisticsModuleStatisticsAttribute map( public StatisticsModuleStatisticsHistory mapHistory(UniProtKBStatisticsEntry entry) { return StatisticsModuleStatisticsHistoryImpl.builder() .statisticsType(map(entry.getEntryType())) - .releaseName(entry.getUniprotRelease().getName()) - .releaseDate(entry.getUniprotRelease().getDate()) + .releaseName(entry.getUniProtRelease().getName()) + .releaseDate(entry.getUniProtRelease().getDate()) .valueCount(entry.getValueCount()) .entryCount(entry.getEntryCount()) .build(); diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java index 606b34b90..8d83f913f 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepository.java @@ -20,8 +20,8 @@ List findAllByAttributeNameIgnoreCaseAndEntryType( List findAllByAttributeNameIgnoreCase(String attributeName); - List findAllByUniprotRelease(UniProtRelease uniProtRelease); + List findAllByUniProtRelease(UniProtRelease uniProtRelease); - List findAllByUniprotReleaseAndStatisticsCategoryIn( + List findAllByUniProtReleaseAndStatisticsCategoryIn( UniProtRelease releaseName, Collection statisticsCategory); } diff --git a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java index 67e9d1556..24ab44465 100644 --- a/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java +++ b/support-data-rest/src/main/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceImpl.java @@ -104,10 +104,10 @@ private List getAllEntriesByVersionAndStatisticTypeAnd EntryType entryType = statisticsMapper.map(statisticsModuleStatisticsType); UniProtRelease release = getRelease(version, entryType); if (categories.isEmpty()) { - entries = statisticsEntryRepository.findAllByUniprotRelease(release); + entries = statisticsEntryRepository.findAllByUniProtRelease(release); } else { entries = - statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + statisticsEntryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( release, getCategories(categories)); } return entries; @@ -152,7 +152,7 @@ private UniProtKBStatisticsEntry mapToSingleEntry( .mapToLong(UniProtKBStatisticsEntry::getEntryCount) .sum()); uniProtKBStatisticsEntry.setDescription(firstEntry.getDescription()); - uniProtKBStatisticsEntry.setUniprotRelease(firstEntry.getUniprotRelease()); + uniProtKBStatisticsEntry.setUniProtRelease(firstEntry.getUniProtRelease()); return uniProtKBStatisticsEntry; } @@ -205,7 +205,7 @@ private String prepareQuery(AttributeQuery query, UniProtKBStatisticsEntry entry String result = query.getQuery(); if (result.contains(PREVIOUS_RELEASE_DATE)) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - String currentRelease = entry.getUniprotRelease().getName(); + String currentRelease = entry.getUniProtRelease().getName(); Date previousReleaseDate = releaseRepository .findPreviousReleaseDate(currentRelease) diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java index ed9f1abb6..08394f2d2 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/TestEntityGeneratorUtil.java @@ -111,7 +111,7 @@ private static UniProtKBStatisticsEntry createStatisticsEntry(int index) { uniprotkbStatisticsEntry.setValueCount(VALUE_COUNTS[index]); uniprotkbStatisticsEntry.setEntryCount(ENTRY_COUNTS[index]); uniprotkbStatisticsEntry.setDescription(DESCRIPTIONS[index]); - uniprotkbStatisticsEntry.setUniprotRelease( + uniprotkbStatisticsEntry.setUniProtRelease( Set.of(0, 1, 3, 4, 5).contains(index) ? RELEASES[0] : RELEASES[1]); uniprotkbStatisticsEntry.setEntryType(ENTRY_TYPES[index]); return uniprotkbStatisticsEntry; diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java index acb29a0e4..3cee7645f 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/repository/UniProtKBStatisticsEntryRepositoryTest.java @@ -48,7 +48,7 @@ void setUp() { @Test void findAllByReleaseName() { List results = - entryRepository.findAllByUniprotRelease(RELEASES[0]); + entryRepository.findAllByUniProtRelease(RELEASES[0]); assertThat( results, @@ -63,7 +63,7 @@ void findAllByReleaseName() { @Test void findAllByReleaseNameAndEntryType_whenNoMatch() { List results = - entryRepository.findAllByUniprotRelease(RELEASES[2]); + entryRepository.findAllByUniProtRelease(RELEASES[2]); assertThat(results, empty()); } @@ -71,7 +71,7 @@ void findAllByReleaseNameAndEntryType_whenNoMatch() { @Test void findAllByReleaseName_whenNoMatch() { List results = - entryRepository.findAllByUniprotRelease(RELEASES[2]); + entryRepository.findAllByUniProtRelease(RELEASES[2]); assertThat(results, empty()); } @@ -79,7 +79,7 @@ void findAllByReleaseName_whenNoMatch() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn() { List results = - entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + entryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( RELEASES[0], List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); assertThat( @@ -91,7 +91,7 @@ void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn() { @Test void findAllByReleaseNameAndStatisticsCategoryIdIn() { List results = - entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + entryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( RELEASES[0], List.of(STATISTICS_CATEGORIES[0], STATISTICS_CATEGORIES[1])); assertThat( @@ -103,7 +103,7 @@ void findAllByReleaseNameAndStatisticsCategoryIdIn() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { List results = - entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + entryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( RELEASES[0], List.of(STATISTICS_CATEGORIES[0])); assertThat(results, containsInAnyOrder(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); @@ -112,7 +112,7 @@ void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenSingleCategor @Test void findAllByReleaseNameAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { List results = - entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + entryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( RELEASES[0], List.of(STATISTICS_CATEGORIES[0])); assertThat(results, containsInAnyOrder(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); @@ -121,7 +121,7 @@ void findAllByReleaseNameAndStatisticsCategoryIdIn_whenSingleCategoryPassed() { @Test void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenNoCategoryPassed() { List results = - entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + entryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( RELEASES[0], Collections.emptyList()); assertThat(results, empty()); @@ -130,7 +130,7 @@ void findAllByReleaseNameAndEntryTypeAndStatisticsCategoryIdIn_whenNoCategoryPas @Test void findAllByReleaseNameAndStatisticsCategoryIdIn_whenNoCategoryPassed() { List results = - entryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + entryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( RELEASES[2], Collections.emptyList()); assertThat(results, empty()); diff --git a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java index 96745983a..4479eea9b 100644 --- a/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java +++ b/support-data-rest/src/test/java/org/uniprot/api/support/data/statistics/service/StatisticsServiceTest.java @@ -184,13 +184,13 @@ private UniProtKBStatisticsEntry getCommonEntry(UniProtKBStatisticsEntry statist entry.setValueCount(statisticsEntry.getValueCount()); entry.setEntryCount(statisticsEntry.getEntryCount()); entry.setDescription(statisticsEntry.getDescription()); - entry.setUniprotRelease(statisticsEntry.getUniprotRelease()); + entry.setUniProtRelease(statisticsEntry.getUniProtRelease()); return entry; } @Test void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE_SWISSPROT)) + when(statisticsEntryRepository.findAllByUniProtRelease(UNI_PROT_RELEASE_SWISSPROT)) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -212,7 +212,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn_whenEmptyListOfCategoriesPass @Test void findAllByVersionAndCategoryIn_whenEmptyListOfCategoriesPassed() { - when(statisticsEntryRepository.findAllByUniprotRelease(UNI_PROT_RELEASE_SWISSPROT)) + when(statisticsEntryRepository.findAllByUniProtRelease(UNI_PROT_RELEASE_SWISSPROT)) .thenReturn( List.of( STATISTICS_ENTRIES[0], @@ -237,7 +237,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn() { .thenReturn(Optional.of(statisticsCategory0)); when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); - when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0, statisticsCategory1))) .thenReturn( @@ -262,7 +262,7 @@ void findAllByVersionAndCategoryIn() { .thenReturn(Optional.of(statisticsCategory0)); when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_1)) .thenReturn(Optional.of(statisticsCategory1)); - when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0, statisticsCategory1))) .thenReturn( @@ -285,7 +285,7 @@ void findAllByVersionAndCategoryIn() { void findAllByVersionAndStatisticTypeAndCategoryIn_whenSingleCategoryIsPassed() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); - when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1])); @@ -300,7 +300,7 @@ void findAllByVersionAndStatisticTypeAndCategoryIn_whenSingleCategoryIsPassed() void findAllByVersionAndCategoryIn_whenSingleCategoryIsPassed() { when(statisticsCategoryRepository.findByCategoryIgnoreCase(CATEGORY_0)) .thenReturn(Optional.of(statisticsCategory0)); - when(statisticsEntryRepository.findAllByUniprotReleaseAndStatisticsCategoryIn( + when(statisticsEntryRepository.findAllByUniProtReleaseAndStatisticsCategoryIn( UNI_PROT_RELEASE_SWISSPROT, Set.of(statisticsCategory0))) .thenReturn(List.of(STATISTICS_ENTRIES[0], STATISTICS_ENTRIES[1]));