From b942d60bfe8c17d6db84e639c7d5934236ea196b Mon Sep 17 00:00:00 2001 From: tcezard Date: Thu, 14 Mar 2024 10:44:05 +0000 Subject: [PATCH 01/12] initial version of the v2 endpoints --- .../controllers/ReleaseStatsv2Controller.java | 63 +++++ .../dto/ReleaseStatsPerAssemblyV2Dto.java | 202 +++++++++++++ .../dto/ReleaseStatsPerSpeciesV2Dto.java | 265 ++++++++++++++++++ .../models/ReleaseStatsPerAssemblyView.java | 104 +++++++ .../models/ReleaseStatsPerAssemblyViewPK.java | 83 ++++++ .../models/ReleaseStatsPerTaxonomyView.java | 118 ++++++++ .../models/ReleaseStatsPerTaxonomyViewPK.java | 83 ++++++ ...ReleaseStatsPerAssemblyViewRepository.java | 32 +++ ...ReleaseStatsPerTaxonomyViewRepository.java | 32 +++ .../services/ReleaseStatsServicev2.java | 127 +++++++++ 10 files changed, 1109 insertions(+) create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java new file mode 100644 index 00000000..27f15c37 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java @@ -0,0 +1,63 @@ +/* + * Copyright 2020 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.controllers; + +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyDto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesDto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; +import uk.ac.ebi.eva.release.services.ReleaseStatsServicev2; + +@RestController +@RequestMapping(value = "/v1/stats2", produces = "application/json") +@Api(tags = {"RS Release Statistics"}) +public class ReleaseStatsv2Controller { + + private final ReleaseStatsServicev2 releaseStatsService; + + public ReleaseStatsv2Controller(ReleaseStatsServicev2 releaseStatsService) { + this.releaseStatsService = releaseStatsService; + } + + @GetMapping("/per-species") + public Iterable getReleaseStatsPerSpecies( + @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion, + @RequestParam(name = "excludeUnmappedOnly", required = false) boolean excludeUnmappedOnly) { + return releaseStatsService.getReleaseStatsPerSpecies(releaseVersion); + } + +// @GetMapping("/per-species/new") +// public Iterable getSpeciesWithNewRsIds( +// @RequestParam(name = "releaseVersion") Integer releaseVersion) { +// return releaseStatsService.getSpeciesWithNewRsIds(releaseVersion); +// } +// +// @GetMapping("/per-assembly") +// public Iterable getReleaseStatsPerAssemblies( +// @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion) { +// return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion); +// } +// +// @GetMapping("/per-assembly/new") +// public Iterable getAssembliesWithNewRsIds( +// @RequestParam(name = "releaseVersion") Integer releaseVersion) { +// return releaseStatsService.getReleaseStatsPerAssemblyWithNewRsIds(releaseVersion); +// } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java new file mode 100644 index 00000000..3e8dd85a --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java @@ -0,0 +1,202 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.dto; + +import javax.persistence.Id; +import java.util.Objects; + +public class ReleaseStatsPerAssemblyV2Dto { + + @Id + private String assemblyAccession; + + @Id + private int releaseVersion; + + private int[] taxonomyIds; + + private String releaseFolder; + + private Long currentRs; + + private Long mergedRs; + + private Long deprecatedRs; + + private Long mergedDeprecatedRs; + + private Long newCurrentRs; + + private Long newMergedRs; + + private Long newDeprecatedRs; + + private Long newMergedDeprecatedRs; + + private String releaseLink; + + private String taxonomyLink; + + public ReleaseStatsPerAssemblyV2Dto() { + } + + public int[] getTaxonomyIds() { + return taxonomyIds; + } + + public void setTaxonomyId(int[] taxonomyIds) { + this.taxonomyIds = taxonomyIds; + } + + public String getAssemblyAccession() { + return assemblyAccession; + } + + public void setAssemblyAccession(String assemblyAccession) { + this.assemblyAccession = assemblyAccession; + } + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + public String getReleaseFolder() { + return releaseFolder; + } + + public void setReleaseFolder(String releaseFolder) { + this.releaseFolder = releaseFolder; + } + + public Long getCurrentRs() { + return currentRs; + } + + public void setCurrentRs(Long currentRs) { + this.currentRs = currentRs; + } + + public Long getMergedRs() { + return mergedRs; + } + + public void setMergedRs(Long mergedRs) { + this.mergedRs = mergedRs; + } + + public Long getDeprecatedRs() { + return deprecatedRs; + } + + public void setDeprecatedRs(Long deprecatedRs) { + this.deprecatedRs = deprecatedRs; + } + + public Long getMergedDeprecatedRs() { + return mergedDeprecatedRs; + } + + public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { + this.mergedDeprecatedRs = mergedDeprecatedRs; + } + + public Long getNewCurrentRs() { + return newCurrentRs; + } + + public void setNewCurrentRs(Long newCurrentRs) { + this.newCurrentRs = newCurrentRs; + } + + public Long getNewMergedRs() { + return newMergedRs; + } + + public void setNewMergedRs(Long newMergedRs) { + this.newMergedRs = newMergedRs; + } + + public Long getNewDeprecatedRs() { + return newDeprecatedRs; + } + + public void setNewDeprecatedRs(Long newDeprecatedRs) { + this.newDeprecatedRs = newDeprecatedRs; + } + + public Long getNewMergedDeprecatedRs() { + return newMergedDeprecatedRs; + } + + public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { + this.newMergedDeprecatedRs = newMergedDeprecatedRs; + } + + public String getReleaseLink() { + return releaseLink; + } + + public void setReleaseLink(String releaseLink) { + this.releaseLink = releaseLink; + } + + public String getTaxonomyLink() { + return taxonomyLink; + } + + public void setTaxonomyLink(String taxonomyLink) { + this.taxonomyLink = taxonomyLink; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerAssemblyV2Dto that = (ReleaseStatsPerAssemblyV2Dto) o; + return releaseVersion == that.releaseVersion && + Objects.equals(assemblyAccession, that.assemblyAccession); + } + + @Override + public int hashCode() { + return Objects.hash(assemblyAccession, releaseVersion); + } + + @Override + public String toString() { + return "ReleaseStatsPerAssemblyDto{" + + "assemblyAccession='" + assemblyAccession + '\'' + + ", releaseVersion=" + releaseVersion + + ", taxonomyIds=" + taxonomyIds + + ", releaseFolder='" + releaseFolder + '\'' + + ", currentRs=" + currentRs + + ", mergedRs=" + mergedRs + + ", deprecatedRs=" + deprecatedRs + + ", mergedDeprecatedRs=" + mergedDeprecatedRs + + ", newCurrentRs=" + newCurrentRs + + ", newMergedRs=" + newMergedRs + + ", newDeprecatedRs=" + newDeprecatedRs + + ", newMergedDeprecatedRs=" + newMergedDeprecatedRs + + ", releaseLink='" + releaseLink + '\'' + + ", taxonomyLink='" + taxonomyLink + '\'' + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java new file mode 100644 index 00000000..8b4ce8d6 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java @@ -0,0 +1,265 @@ +/* + * Copyright 2020 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.dto; + +import javax.persistence.Id; +import java.util.Objects; + +public class ReleaseStatsPerSpeciesV2Dto { + + @Id + private int taxonomyId; + + @Id + private int releaseVersion; + + private String releaseFolder; + + private Long currentRs; + + private Long multiMappedRs; + + private Long mergedRs; + + private Long deprecatedRs; + + private Long mergedDeprecatedRs; + + private Long unmappedRs; + + private Long newCurrentRs; + + private Long newMultiMappedRs; + + private Long newMergedRs; + + private Long newDeprecatedRs; + + private Long newMergedDeprecatedRs; + + private Long newUnmappedRs; + + private String releaseLink; + + private String taxonomyLink; + + private String scientificName; + + public ReleaseStatsPerSpeciesV2Dto() { + } + + public int getTaxonomyId() { + return taxonomyId; + } + + public void setTaxonomyId(int taxonomyId) { + this.taxonomyId = taxonomyId; + } + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + public String getScientificName() { + return scientificName; + } + + public void setScientificName(String scientificName) { + this.scientificName = scientificName; + } + + public String getReleaseFolder() { + return releaseFolder; + } + + public void setReleaseFolder(String releaseFolder) { + this.releaseFolder = releaseFolder; + } + + public Long getCurrentRs() { + return currentRs; + } + + public void setCurrentRs(Long currentRs) { + this.currentRs = currentRs; + } + + public Long getMultiMappedRs() { + return multiMappedRs; + } + + public void setMultiMappedRs(Long multiMappedRs) { + this.multiMappedRs = multiMappedRs; + } + + public Long getMergedRs() { + return mergedRs; + } + + public void setMergedRs(Long mergedRs) { + this.mergedRs = mergedRs; + } + + public Long getDeprecatedRs() { + return deprecatedRs; + } + + public void setDeprecatedRs(Long deprecatedRs) { + this.deprecatedRs = deprecatedRs; + } + + public Long getMergedDeprecatedRs() { + return mergedDeprecatedRs; + } + + public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { + this.mergedDeprecatedRs = mergedDeprecatedRs; + } + + public Long getUnmappedRs() { + return unmappedRs; + } + + public void setUnmappedRs(Long unmappedRs) { + this.unmappedRs = unmappedRs; + } + + public Long getNewCurrentRs() { + return newCurrentRs; + } + + public void setNewCurrentRs(Long newCurrentRs) { + this.newCurrentRs = newCurrentRs; + } + + public Long getNewMultiMappedRs() { + return newMultiMappedRs; + } + + public void setNewMultiMappedRs(Long newMultiMappedRs) { + this.newMultiMappedRs = newMultiMappedRs; + } + + public Long getNewMergedRs() { + return newMergedRs; + } + + public void setNewMergedRs(Long newMergedRs) { + this.newMergedRs = newMergedRs; + } + + public Long getNewDeprecatedRs() { + return newDeprecatedRs; + } + + public void setNewDeprecatedRs(Long newDeprecatedRs) { + this.newDeprecatedRs = newDeprecatedRs; + } + + public Long getNewMergedDeprecatedRs() { + return newMergedDeprecatedRs; + } + + public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { + this.newMergedDeprecatedRs = newMergedDeprecatedRs; + } + + public Long getNewUnmappedRs() { + return newUnmappedRs; + } + + public void setNewUnmappedRs(Long newUnmappedRs) { + this.newUnmappedRs = newUnmappedRs; + } + + public String getReleaseLink() { + return releaseLink; + } + + public void setReleaseLink(String releaseLink) { + this.releaseLink = releaseLink; + } + + public String getTaxonomyLink() { + return taxonomyLink; + } + + public void setTaxonomyLink(String taxonomyLink) { + this.taxonomyLink = taxonomyLink; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerSpeciesV2Dto that = (ReleaseStatsPerSpeciesV2Dto) o; + return taxonomyId == that.taxonomyId && + releaseVersion == that.releaseVersion && + Objects.equals(scientificName, that.scientificName) && + Objects.equals(releaseFolder, that.releaseFolder) && + Objects.equals(currentRs, that.currentRs) && + Objects.equals(multiMappedRs, that.multiMappedRs) && + Objects.equals(mergedRs, that.mergedRs) && + Objects.equals(deprecatedRs, that.deprecatedRs) && + Objects.equals(mergedDeprecatedRs, that.mergedDeprecatedRs) && + Objects.equals(unmappedRs, that.unmappedRs) && + Objects.equals(newCurrentRs, that.newCurrentRs) && + Objects.equals(newMultiMappedRs, that.newMultiMappedRs) && + Objects.equals(newMergedRs, that.newMergedRs) && + Objects.equals(newDeprecatedRs, that.newDeprecatedRs) && + Objects.equals(newMergedDeprecatedRs, that.newMergedDeprecatedRs) && + Objects.equals(newUnmappedRs, that.newUnmappedRs) && + Objects.equals(releaseLink, that.releaseLink) && + Objects.equals(taxonomyLink, that.taxonomyLink); + } + + @Override + public int hashCode() { + return Objects.hash(taxonomyId, releaseVersion, scientificName, releaseFolder, currentRs, multiMappedRs, + mergedRs, + deprecatedRs, mergedDeprecatedRs, unmappedRs, newCurrentRs, newMultiMappedRs, newMergedRs, + newDeprecatedRs, newMergedDeprecatedRs, newUnmappedRs, releaseLink, + taxonomyLink); + } + + @Override + public String toString() { + return "ReleaseStatsPerSpeciesDto{" + + "taxonomyId=" + taxonomyId + + ", releaseVersion=" + releaseVersion + + ", scientificName='" + scientificName + '\'' + + ", releaseFolder='" + releaseFolder + '\'' + + ", currentRs=" + currentRs + + ", multiMappedRs=" + multiMappedRs + + ", mergedRs=" + mergedRs + + ", deprecatedRs=" + deprecatedRs + + ", mergedDeprecatedRs=" + mergedDeprecatedRs + + ", unmappedRs=" + unmappedRs + + ", newCurrentRs=" + newCurrentRs + + ", newMultiMappedRs=" + newMultiMappedRs + + ", newMergedRs=" + newMergedRs + + ", newDeprecatedRs=" + newDeprecatedRs + + ", newMergedDeprecatedRs=" + newMergedDeprecatedRs + + ", newUnmappedRs=" + newUnmappedRs + + ", releaseLink='" + releaseLink + '\'' + + ", taxonomyLink='" + taxonomyLink + '\'' + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java new file mode 100644 index 00000000..fba7a715 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java @@ -0,0 +1,104 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import org.hibernate.annotations.Type; + +import javax.persistence.*; +import java.util.Objects; + +@Entity +@IdClass(ReleaseStatsPerAssemblyViewPK.class) +@Table(name = "release_rs_count_per_assembly_accession") +public class ReleaseStatsPerAssemblyView { + + + @Id + private String assemblyAccession; + + @Id + private int releaseVersion; + + private int[] taxonomyIds; + + private String rsType; + + private Long count; + + @Column(name="new") + private Long newAddition; + + public ReleaseStatsPerAssemblyView() { + } + + public int[] getTaxonomyIds() { + return taxonomyIds; + } + + public void setTaxonomyIds(int[] taxonomyIds) { + this.taxonomyIds = taxonomyIds; + } + + public String getAssemblyAccession() { + return assemblyAccession; + } + + public void setAssemblyAccession(String assemblyAccession) { + this.assemblyAccession = assemblyAccession; + } + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + + public String getRsType() { + return rsType; + } + + public void setRsType(String rsType) { + this.rsType = rsType; + } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerAssemblyView assembly = (ReleaseStatsPerAssemblyView) o; + return releaseVersion == assembly.releaseVersion && + Objects.equals(assemblyAccession, assembly.assemblyAccession) && + Objects.equals(rsType, assembly.rsType); + } + + @Override + public int hashCode() { + return Objects.hash(assemblyAccession, releaseVersion, rsType); + } + + @Override + public String toString() { + return "ReleaseStatsPerAssembly{" + + ", assemblyAccession='" + assemblyAccession + '\'' + + ", releaseVersion=" + releaseVersion + + ", rsType='" + rsType + '\'' + + ", count=" + count + + ", new=" + newAddition + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java new file mode 100644 index 00000000..bc37c443 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java @@ -0,0 +1,83 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; +import java.util.Objects; + +public class ReleaseStatsPerAssemblyViewPK implements Serializable { + + + private String assemblyAccession; + + private int releaseVersion; + + private String rsType; + + public ReleaseStatsPerAssemblyViewPK() { + } + + public String getAssemblyAccession() { + return assemblyAccession; + } + + public void setAssemblyAccession(String assemblyAccession) { + this.assemblyAccession = assemblyAccession; + } + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + public String getRsType() { + return rsType; + } + + public void setRsType(String rsType) { + this.rsType = rsType; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerAssemblyViewPK assembly = (ReleaseStatsPerAssemblyViewPK) o; + return releaseVersion == assembly.releaseVersion && + Objects.equals(assemblyAccession, assembly.assemblyAccession) && + Objects.equals(rsType, assembly.rsType); + } + + @Override + public int hashCode() { + return Objects.hash(assemblyAccession, releaseVersion, rsType); + } + + @Override + public String toString() { + return "ReleaseStatsPerAssembly{" + + ", assemblyAccession='" + assemblyAccession + '\'' + + ", releaseVersion=" + releaseVersion + + ", rsType='" + rsType + '\'' + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java new file mode 100644 index 00000000..46342a2b --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java @@ -0,0 +1,118 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import javax.persistence.*; +import java.util.Objects; + +@Entity +@IdClass(ReleaseStatsPerTaxonomyViewPK.class) +@Table(name = "release_rs_count_per_taxonomy_id") +public class ReleaseStatsPerTaxonomyView { + + @Id + private int taxonomyId; + + @Id + private int releaseVersion; + + private String[] assemblyAccessions; + + private String rsType; + + private Long count; + + @Column(name="new") + private Long newAddition; + + public ReleaseStatsPerTaxonomyView() { + } + + public int getTaxonomyId() { + return taxonomyId; + } + + public void setTaxonomyId(int taxonomyId) { + this.taxonomyId = taxonomyId; + } + + public String[] getAssemblyAccessions() { + return assemblyAccessions; + } + + public void setAssemblyAccessions(String[] assemblyAccessions) { + this.assemblyAccessions = assemblyAccessions; + } + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + + public String getRsType() { + return rsType; + } + + public void setRsType(String rsType) { + this.rsType = rsType; + } + + public Long getCount() { + return count; + } + + public void setCount(Long count) { + this.count = count; + } + + public Long getNewAddition() { + return newAddition; + } + + public void setNewAddition(Long newAddition) { + this.newAddition = newAddition; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerTaxonomyView taxonomy = (ReleaseStatsPerTaxonomyView) o; + return releaseVersion == taxonomy.releaseVersion && + Objects.equals(taxonomyId, taxonomy.taxonomyId) && + Objects.equals(rsType, taxonomy.rsType); + } + + @Override + public int hashCode() { + return Objects.hash(taxonomyId, releaseVersion, rsType); + } + + @Override + public String toString() { + return "ReleaseStatsPerAssembly{" + + ", taxonomyId=" + taxonomyId + + ", releaseVersion=" + releaseVersion + + ", rsType='" + rsType + '\'' + + ", count=" + count + + ", new=" + newAddition + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java new file mode 100644 index 00000000..ed479472 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java @@ -0,0 +1,83 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.Table; +import java.io.Serializable; +import java.util.Objects; + +public class ReleaseStatsPerTaxonomyViewPK implements Serializable { + + private int taxonomyId; + + private int releaseVersion; + + private String rsType; + + public ReleaseStatsPerTaxonomyViewPK() { + } + + public int getTaxonomyId() { + return taxonomyId; + } + + public void setTaxonomyId(int taxonomyId) { + this.taxonomyId = taxonomyId; + } + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + + public String getRsType() { + return rsType; + } + + public void setRsType(String rsType) { + this.rsType = rsType; + } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerTaxonomyViewPK taxonomy = (ReleaseStatsPerTaxonomyViewPK) o; + return releaseVersion == taxonomy.releaseVersion && + Objects.equals(taxonomyId, taxonomy.taxonomyId) && + Objects.equals(rsType, taxonomy.rsType); + } + + @Override + public int hashCode() { + return Objects.hash(taxonomyId, releaseVersion, rsType); + } + + @Override + public String toString() { + return "ReleaseStatsPerAssembly{" + + ", taxonomyId=" + taxonomyId + + ", releaseVersion=" + releaseVersion + + ", rsType='" + rsType + '\'' + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java new file mode 100644 index 00000000..a7d009d0 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java @@ -0,0 +1,32 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.repositories; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyPK; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyView; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyViewPK; + +@Repository +public interface ReleaseStatsPerAssemblyViewRepository extends CrudRepository { + + Iterable findAllByReleaseVersion(int releaseVersion); + + +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java new file mode 100644 index 00000000..a997332c --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.repositories; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerSpecies; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerSpeciesPK; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyView; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyViewPK; + +@Repository +public interface ReleaseStatsPerTaxonomyViewRepository extends CrudRepository { + + Iterable findAllByReleaseVersion(int releaseVersion); + + +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java new file mode 100644 index 00000000..2177210d --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java @@ -0,0 +1,127 @@ +/* + * Copyright 2020 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.services; + +import org.springframework.stereotype.Service; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; +import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerAssemblyMapper; +import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerSpeciesMapper; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyView; +import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerAssemblyViewRepository; +import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerTaxonomyViewRepository; + +import java.util.HashMap; + +@Service +public class ReleaseStatsServicev2 { + + private final ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository; + + private final ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository; + + private final ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper; + + private final ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper; + + public ReleaseStatsServicev2(ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository, + ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository, + ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper, + ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper) { + this.releaseStatsPerTaxonomyRepository = releaseStatsPerTaxonomyRepository; + this.releaseStatsPerAssemblyRepository = releaseStatsPerAssemblyRepository; + this.releaseStatsPerSpeciesMapper = releaseStatsPerSpeciesMapper; + this.releaseStatsPerAssemblyMapper = releaseStatsPerAssemblyMapper; + } + + public Iterable getReleaseStatsPerSpecies(Integer releaseVersion) { + Iterable releaseData; + releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); + HashMap keyToDto= new HashMap<>(); + for (ReleaseStatsPerTaxonomyView viewData : releaseData){ + String key = viewData.getTaxonomyId() + "_" + viewData.getReleaseVersion(); + if (! keyToDto.containsKey(key)){ + keyToDto.put(key, new ReleaseStatsPerSpeciesV2Dto()); + } + ReleaseStatsPerSpeciesV2Dto dto = keyToDto.get(key); + dto.setTaxonomyId(viewData.getTaxonomyId()); + dto.setReleaseVersion(viewData.getReleaseVersion()); + switch (viewData.getRsType()){ + case "current": + dto.setCurrentRs(viewData.getCount()); + dto.setNewCurrentRs(viewData.getNewAddition()); + break; + case "deprecated": + dto.setDeprecatedRs(viewData.getCount()); + dto.setNewDeprecatedRs(viewData.getNewAddition()); + break; + case "merged": + dto.setMergedRs(viewData.getCount()); + dto.setNewMergedRs(viewData.getNewAddition()); + break; + case "merged_deprecated": + dto.setMergedDeprecatedRs(viewData.getCount()); + dto.setNewMergedDeprecatedRs(viewData.getNewAddition()); + break; + case "multimap": + dto.setMultiMappedRs(viewData.getCount()); + dto.setNewMultiMappedRs(viewData.getNewAddition()); + break; + case "unmapped": + dto.setUnmappedRs(viewData.getCount()); + dto.setNewUnmappedRs(viewData.getNewAddition()); + break; + } + } + return keyToDto.values(); + } + + private Iterable getReleaseDataByVersionExcludingUnmappedOnly(Integer releaseVersion) { + return getReleaseStatsPerSpecies(releaseVersion); + } + + private Iterable getReleaseDataExcludingUnmappedOnly() { + return getReleaseStatsPerSpecies(null); + } + +// public Iterable getSpeciesWithNewRsIds(Integer releaseVersion) { +// if (releaseVersion != null) { +// return releaseStatsPerSpeciesMapper.toDto(releaseStatsPerSpeciesRepository +// .findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L)); +// } else { +// return releaseStatsPerSpeciesMapper.toDto(releaseStatsPerSpeciesRepository.findByNewCurrentRsGreaterThan(0L)); +// } +// } +// +// public Iterable getReleaseStatsPerAssembly(Integer releaseVersion) { +// Iterable releaseData; +// if (releaseVersion != null) { +// releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); +// } else { +// releaseData = releaseStatsPerAssemblyRepository.findAll(); +// } +// return releaseStatsPerAssemblyMapper.toDto(releaseData); +// } +// +// public Iterable getReleaseStatsPerAssemblyWithNewRsIds(Integer releaseVersion) { +// if (releaseVersion != null) { +// return releaseStatsPerAssemblyMapper.toDto( +// releaseStatsPerAssemblyRepository.findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L)); +// } else { +// return releaseStatsPerAssemblyMapper.toDto( +// releaseStatsPerAssemblyRepository.findByNewCurrentRsGreaterThan(0L)); +// } +// } +} From 4f01662f11ffc2de8ef175a750e50deac0ec0293 Mon Sep 17 00:00:00 2001 From: tcezard Date: Sun, 17 Mar 2024 22:48:01 +0000 Subject: [PATCH 02/12] v2 endpoints for both Assembly and taxonomy --- .../controllers/ReleaseInfoController.java | 1 - .../controllers/ReleaseStatsv2Controller.java | 43 ++-- .../dto/ReleaseStatsPerAssemblyV2Dto.java | 126 +---------- .../dto/ReleaseStatsPerSpeciesV2Dto.java | 177 ++------------- .../eva/release/dto/ReleaseStatsPerV2Dto.java | 213 ++++++++++++++++++ .../models/ReleaseStatsPerAssemblyView.java | 61 +++-- .../models/ReleaseStatsPerTaxonomyView.java | 57 +++-- .../eva/release/models/ReleaseStatsView.java | 39 ++++ .../services/ReleaseStatsServicev2.java | 173 ++++++++------ .../src/main/resources/application.properties | 2 +- 10 files changed, 491 insertions(+), 401 deletions(-) create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseInfoController.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseInfoController.java index 3b4633fa..8818a7e9 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseInfoController.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseInfoController.java @@ -24,7 +24,6 @@ import uk.ac.ebi.eva.release.models.ReleaseInfo; import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; -import javax.websocket.server.PathParam; import java.util.Collections; @RestController diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java index 27f15c37..dc9771e5 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java @@ -20,8 +20,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyDto; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesDto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; import uk.ac.ebi.eva.release.services.ReleaseStatsServicev2; @@ -40,24 +39,28 @@ public ReleaseStatsv2Controller(ReleaseStatsServicev2 releaseStatsService) { public Iterable getReleaseStatsPerSpecies( @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion, @RequestParam(name = "excludeUnmappedOnly", required = false) boolean excludeUnmappedOnly) { - return releaseStatsService.getReleaseStatsPerSpecies(releaseVersion); + if (releaseVersion != null) { + return releaseStatsService.getReleaseStatsPerSpecies(releaseVersion, excludeUnmappedOnly); + }else{ + return releaseStatsService.getReleaseStatsPerSpecies(excludeUnmappedOnly); + } } -// @GetMapping("/per-species/new") -// public Iterable getSpeciesWithNewRsIds( -// @RequestParam(name = "releaseVersion") Integer releaseVersion) { -// return releaseStatsService.getSpeciesWithNewRsIds(releaseVersion); -// } -// -// @GetMapping("/per-assembly") -// public Iterable getReleaseStatsPerAssemblies( -// @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion) { -// return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion); -// } -// -// @GetMapping("/per-assembly/new") -// public Iterable getAssembliesWithNewRsIds( -// @RequestParam(name = "releaseVersion") Integer releaseVersion) { -// return releaseStatsService.getReleaseStatsPerAssemblyWithNewRsIds(releaseVersion); -// } + @GetMapping("/per-species/new") + public Iterable getSpeciesWithNewRsIds( + @RequestParam(name = "releaseVersion") Integer releaseVersion) { + return releaseStatsService.getSpeciesWithNewRsIds(releaseVersion); + } + + @GetMapping("/per-assembly") + public Iterable getReleaseStatsPerAssemblies( + @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion) { + return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion, false); + } + + @GetMapping("/per-assembly/new") + public Iterable getAssembliesWithNewRsIds( + @RequestParam(name = "releaseVersion") Integer releaseVersion) { + return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion, true); + } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java index 3e8dd85a..52b669ce 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java @@ -18,7 +18,7 @@ import javax.persistence.Id; import java.util.Objects; -public class ReleaseStatsPerAssemblyV2Dto { +public class ReleaseStatsPerAssemblyV2Dto extends ReleaseStatsPerV2Dto { @Id private String assemblyAccession; @@ -28,24 +28,6 @@ public class ReleaseStatsPerAssemblyV2Dto { private int[] taxonomyIds; - private String releaseFolder; - - private Long currentRs; - - private Long mergedRs; - - private Long deprecatedRs; - - private Long mergedDeprecatedRs; - - private Long newCurrentRs; - - private Long newMergedRs; - - private Long newDeprecatedRs; - - private Long newMergedDeprecatedRs; - private String releaseLink; private String taxonomyLink; @@ -69,94 +51,6 @@ public void setAssemblyAccession(String assemblyAccession) { this.assemblyAccession = assemblyAccession; } - public int getReleaseVersion() { - return releaseVersion; - } - - public void setReleaseVersion(int releaseVersion) { - this.releaseVersion = releaseVersion; - } - - public String getReleaseFolder() { - return releaseFolder; - } - - public void setReleaseFolder(String releaseFolder) { - this.releaseFolder = releaseFolder; - } - - public Long getCurrentRs() { - return currentRs; - } - - public void setCurrentRs(Long currentRs) { - this.currentRs = currentRs; - } - - public Long getMergedRs() { - return mergedRs; - } - - public void setMergedRs(Long mergedRs) { - this.mergedRs = mergedRs; - } - - public Long getDeprecatedRs() { - return deprecatedRs; - } - - public void setDeprecatedRs(Long deprecatedRs) { - this.deprecatedRs = deprecatedRs; - } - - public Long getMergedDeprecatedRs() { - return mergedDeprecatedRs; - } - - public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { - this.mergedDeprecatedRs = mergedDeprecatedRs; - } - - public Long getNewCurrentRs() { - return newCurrentRs; - } - - public void setNewCurrentRs(Long newCurrentRs) { - this.newCurrentRs = newCurrentRs; - } - - public Long getNewMergedRs() { - return newMergedRs; - } - - public void setNewMergedRs(Long newMergedRs) { - this.newMergedRs = newMergedRs; - } - - public Long getNewDeprecatedRs() { - return newDeprecatedRs; - } - - public void setNewDeprecatedRs(Long newDeprecatedRs) { - this.newDeprecatedRs = newDeprecatedRs; - } - - public Long getNewMergedDeprecatedRs() { - return newMergedDeprecatedRs; - } - - public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { - this.newMergedDeprecatedRs = newMergedDeprecatedRs; - } - - public String getReleaseLink() { - return releaseLink; - } - - public void setReleaseLink(String releaseLink) { - this.releaseLink = releaseLink; - } - public String getTaxonomyLink() { return taxonomyLink; } @@ -187,14 +81,16 @@ public String toString() { ", releaseVersion=" + releaseVersion + ", taxonomyIds=" + taxonomyIds + ", releaseFolder='" + releaseFolder + '\'' + - ", currentRs=" + currentRs + - ", mergedRs=" + mergedRs + - ", deprecatedRs=" + deprecatedRs + - ", mergedDeprecatedRs=" + mergedDeprecatedRs + - ", newCurrentRs=" + newCurrentRs + - ", newMergedRs=" + newMergedRs + - ", newDeprecatedRs=" + newDeprecatedRs + - ", newMergedDeprecatedRs=" + newMergedDeprecatedRs + + ", currentRs=" + getCurrentRs() + + ", multiMappedRs=" + getMultiMappedRs() + + ", mergedRs=" + getMergedRs() + + ", deprecatedRs=" + getDeprecatedRs() + + ", mergedDeprecatedRs=" + getMergedDeprecatedRs() + + ", newCurrentRs=" + getNewCurrentRs() + + ", newMultiMappedRs=" + getNewMultiMappedRs() + + ", newMergedRs=" + getNewMergedRs() + + ", newDeprecatedRs=" + getNewDeprecatedRs() + + ", newMergedDeprecatedRs=" + getNewMergedDeprecatedRs() + ", releaseLink='" + releaseLink + '\'' + ", taxonomyLink='" + taxonomyLink + '\'' + '}'; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java index 8b4ce8d6..ed252a17 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java @@ -18,42 +18,11 @@ import javax.persistence.Id; import java.util.Objects; -public class ReleaseStatsPerSpeciesV2Dto { +public class ReleaseStatsPerSpeciesV2Dto extends ReleaseStatsPerV2Dto { @Id private int taxonomyId; - @Id - private int releaseVersion; - - private String releaseFolder; - - private Long currentRs; - - private Long multiMappedRs; - - private Long mergedRs; - - private Long deprecatedRs; - - private Long mergedDeprecatedRs; - - private Long unmappedRs; - - private Long newCurrentRs; - - private Long newMultiMappedRs; - - private Long newMergedRs; - - private Long newDeprecatedRs; - - private Long newMergedDeprecatedRs; - - private Long newUnmappedRs; - - private String releaseLink; - private String taxonomyLink; private String scientificName; @@ -69,14 +38,6 @@ public void setTaxonomyId(int taxonomyId) { this.taxonomyId = taxonomyId; } - public int getReleaseVersion() { - return releaseVersion; - } - - public void setReleaseVersion(int releaseVersion) { - this.releaseVersion = releaseVersion; - } - public String getScientificName() { return scientificName; } @@ -85,118 +46,6 @@ public void setScientificName(String scientificName) { this.scientificName = scientificName; } - public String getReleaseFolder() { - return releaseFolder; - } - - public void setReleaseFolder(String releaseFolder) { - this.releaseFolder = releaseFolder; - } - - public Long getCurrentRs() { - return currentRs; - } - - public void setCurrentRs(Long currentRs) { - this.currentRs = currentRs; - } - - public Long getMultiMappedRs() { - return multiMappedRs; - } - - public void setMultiMappedRs(Long multiMappedRs) { - this.multiMappedRs = multiMappedRs; - } - - public Long getMergedRs() { - return mergedRs; - } - - public void setMergedRs(Long mergedRs) { - this.mergedRs = mergedRs; - } - - public Long getDeprecatedRs() { - return deprecatedRs; - } - - public void setDeprecatedRs(Long deprecatedRs) { - this.deprecatedRs = deprecatedRs; - } - - public Long getMergedDeprecatedRs() { - return mergedDeprecatedRs; - } - - public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { - this.mergedDeprecatedRs = mergedDeprecatedRs; - } - - public Long getUnmappedRs() { - return unmappedRs; - } - - public void setUnmappedRs(Long unmappedRs) { - this.unmappedRs = unmappedRs; - } - - public Long getNewCurrentRs() { - return newCurrentRs; - } - - public void setNewCurrentRs(Long newCurrentRs) { - this.newCurrentRs = newCurrentRs; - } - - public Long getNewMultiMappedRs() { - return newMultiMappedRs; - } - - public void setNewMultiMappedRs(Long newMultiMappedRs) { - this.newMultiMappedRs = newMultiMappedRs; - } - - public Long getNewMergedRs() { - return newMergedRs; - } - - public void setNewMergedRs(Long newMergedRs) { - this.newMergedRs = newMergedRs; - } - - public Long getNewDeprecatedRs() { - return newDeprecatedRs; - } - - public void setNewDeprecatedRs(Long newDeprecatedRs) { - this.newDeprecatedRs = newDeprecatedRs; - } - - public Long getNewMergedDeprecatedRs() { - return newMergedDeprecatedRs; - } - - public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { - this.newMergedDeprecatedRs = newMergedDeprecatedRs; - } - - public Long getNewUnmappedRs() { - return newUnmappedRs; - } - - public void setNewUnmappedRs(Long newUnmappedRs) { - this.newUnmappedRs = newUnmappedRs; - } - - public String getReleaseLink() { - return releaseLink; - } - - public void setReleaseLink(String releaseLink) { - this.releaseLink = releaseLink; - } - public String getTaxonomyLink() { return taxonomyLink; } @@ -246,18 +95,18 @@ public String toString() { ", releaseVersion=" + releaseVersion + ", scientificName='" + scientificName + '\'' + ", releaseFolder='" + releaseFolder + '\'' + - ", currentRs=" + currentRs + - ", multiMappedRs=" + multiMappedRs + - ", mergedRs=" + mergedRs + - ", deprecatedRs=" + deprecatedRs + - ", mergedDeprecatedRs=" + mergedDeprecatedRs + - ", unmappedRs=" + unmappedRs + - ", newCurrentRs=" + newCurrentRs + - ", newMultiMappedRs=" + newMultiMappedRs + - ", newMergedRs=" + newMergedRs + - ", newDeprecatedRs=" + newDeprecatedRs + - ", newMergedDeprecatedRs=" + newMergedDeprecatedRs + - ", newUnmappedRs=" + newUnmappedRs + + ", currentRs=" + getCurrentRs() + + ", multiMappedRs=" + getMultiMappedRs() + + ", mergedRs=" + getMergedRs() + + ", deprecatedRs=" + getDeprecatedRs() + + ", mergedDeprecatedRs=" + getMergedDeprecatedRs() + + ", unmappedRs=" + getUnmappedRs() + + ", newCurrentRs=" + getNewCurrentRs() + + ", newMultiMappedRs=" + getNewMultiMappedRs() + + ", newMergedRs=" + getNewMergedRs() + + ", newDeprecatedRs=" + getNewDeprecatedRs() + + ", newMergedDeprecatedRs=" + getNewMergedDeprecatedRs() + + ", newUnmappedRs=" + getNewUnmappedRs() + ", releaseLink='" + releaseLink + '\'' + ", taxonomyLink='" + taxonomyLink + '\'' + '}'; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java new file mode 100644 index 00000000..6b06d6df --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java @@ -0,0 +1,213 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.dto; + +import javax.persistence.Id; +import java.util.Objects; + +public abstract class ReleaseStatsPerV2Dto { + + protected int releaseVersion; + + protected String releaseFolder; + + protected Long currentRs; + + protected Long mergedRs; + + protected Long deprecatedRs; + + protected Long mergedDeprecatedRs; + + protected Long newCurrentRs; + + protected Long newMergedRs; + + protected Long newDeprecatedRs; + + protected Long newMergedDeprecatedRs; + + protected Long multiMappedRs; + + protected Long newMultiMappedRs; + + protected Long unmappedRs; + + protected Long newUnmappedRs; + + protected String releaseLink; + + public ReleaseStatsPerV2Dto() { + } + + + public int getReleaseVersion() { + return releaseVersion; + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseVersion = releaseVersion; + } + + public String getReleaseFolder() { + return releaseFolder; + } + + public void setReleaseFolder(String releaseFolder) { + this.releaseFolder = releaseFolder; + } + + public Long getCurrentRs() { + + if (currentRs == null){ + return new Long(0); + } + return currentRs; + } + + public void setCurrentRs(Long currentRs) { + this.currentRs = currentRs; + } + + public Long getMergedRs() { + if (mergedRs == null){ + return new Long(0); + } + return mergedRs; + } + + public void setMergedRs(Long mergedRs) { + this.mergedRs = mergedRs; + } + + public Long getDeprecatedRs() { + if (deprecatedRs == null){ + return new Long(0); + } + return deprecatedRs; + } + + public void setDeprecatedRs(Long deprecatedRs) { + this.deprecatedRs = deprecatedRs; + } + + public Long getMergedDeprecatedRs() { + if (mergedDeprecatedRs == null){ + return new Long(0); + } + return mergedDeprecatedRs; + } + + public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { + this.mergedDeprecatedRs = mergedDeprecatedRs; + } + + public Long getNewCurrentRs() { + if (newCurrentRs == null){ + return new Long(0); + } + return newCurrentRs; + } + + public void setNewCurrentRs(Long newCurrentRs) { + this.newCurrentRs = newCurrentRs; + } + + public Long getNewMergedRs() { + if (newMergedRs == null){ + return new Long(0); + } + return newMergedRs; + } + + public void setNewMergedRs(Long newMergedRs) { + this.newMergedRs = newMergedRs; + } + + public Long getNewDeprecatedRs() { + if (newDeprecatedRs == null){ + return new Long(0); + } + return newDeprecatedRs; + } + + public void setNewDeprecatedRs(Long newDeprecatedRs) { + this.newDeprecatedRs = newDeprecatedRs; + } + + public Long getNewMergedDeprecatedRs() { + if (newMergedDeprecatedRs == null){ + return new Long(0); + } + return newMergedDeprecatedRs; + } + + public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { + this.newMergedDeprecatedRs = newMergedDeprecatedRs; + } + public Long getMultiMappedRs() { + if (multiMappedRs == null){ + return new Long(0); + } + return multiMappedRs; + } + + public void setMultiMappedRs(Long multiMappedRs) { + this.multiMappedRs = multiMappedRs; + } + + public Long getNewMultiMappedRs() { + if (newMultiMappedRs == null){ + return new Long(0); + } + return newMultiMappedRs; + } + + public void setNewMultiMappedRs(Long newMultiMappedRs) { + this.newMultiMappedRs = newMultiMappedRs; + } + + public Long getUnmappedRs() { + if (unmappedRs == null){ + return new Long(0); + } + return unmappedRs; + } + + public void setUnmappedRs(Long unmappedRs) { + this.unmappedRs = unmappedRs; + } + + public Long getNewUnmappedRs() { + if (newUnmappedRs == null){ + return new Long(0); + } + return newUnmappedRs; + } + + public void setNewUnmappedRs(Long newUnmappedRs) { + this.newUnmappedRs = newUnmappedRs; + } + + public String getReleaseLink() { + return releaseLink; + } + + public void setReleaseLink(String releaseLink) { + this.releaseLink = releaseLink; + } + +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java index fba7a715..8ee0d6e3 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java @@ -22,35 +22,32 @@ @Entity @IdClass(ReleaseStatsPerAssemblyViewPK.class) -@Table(name = "release_rs_count_per_assembly_accession") -public class ReleaseStatsPerAssemblyView { - - - @Id - private String assemblyAccession; +@Table(name = "release_rs_count_per_assembly") +public class ReleaseStatsPerAssemblyView implements ReleaseStatsView { @Id private int releaseVersion; - - private int[] taxonomyIds; + @Id + private String assemblyAccession; private String rsType; +// private int[] taxonomyIds; + private Long count; @Column(name="new") - private Long newAddition; - + protected Long newAddition; public ReleaseStatsPerAssemblyView() { } - public int[] getTaxonomyIds() { - return taxonomyIds; - } - - public void setTaxonomyIds(int[] taxonomyIds) { - this.taxonomyIds = taxonomyIds; - } +// public int[] getTaxonomyIds() { +// return taxonomyIds; +// } +// +// public void setTaxonomyIds(int[] taxonomyIds) { +// this.taxonomyIds = taxonomyIds; +// } public String getAssemblyAccession() { return assemblyAccession; @@ -60,6 +57,11 @@ public void setAssemblyAccession(String assemblyAccession) { this.assemblyAccession = assemblyAccession; } + public String getRsType() { + return rsType; + } + + public int getReleaseVersion() { return releaseVersion; } @@ -68,14 +70,31 @@ public void setReleaseVersion(int releaseVersion) { this.releaseVersion = releaseVersion; } + public void setRsType(String rsType) { + this.rsType = rsType; + } - public String getRsType() { - return rsType; + public Long getCount() { + return count; } - public void setRsType(String rsType) { - this.rsType = rsType; + public void setCount(Long count) { + this.count = count; } + + public Long getNewAddition() { + return newAddition; + } + + public void setNewAddition(Long newAddition) { + this.newAddition = newAddition; + } + + @Override + public String getKey() { + return this.assemblyAccession + "_" + this.releaseVersion; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java index 46342a2b..c6ac4076 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java @@ -20,23 +20,26 @@ @Entity @IdClass(ReleaseStatsPerTaxonomyViewPK.class) -@Table(name = "release_rs_count_per_taxonomy_id") -public class ReleaseStatsPerTaxonomyView { +@Table(name = "release_rs_count_per_taxonomy") +public class ReleaseStatsPerTaxonomyView implements ReleaseStatsView{ @Id private int taxonomyId; - @Id private int releaseVersion; + private String rsType; - private String[] assemblyAccessions; +// private String[] assemblyAccessions; - private String rsType; + private String scientificName; + + private String commonName; private Long count; @Column(name="new") - private Long newAddition; + protected Long newAddition; + public ReleaseStatsPerTaxonomyView() { } @@ -49,14 +52,19 @@ public void setTaxonomyId(int taxonomyId) { this.taxonomyId = taxonomyId; } - public String[] getAssemblyAccessions() { - return assemblyAccessions; - } +// public String[] getAssemblyAccessions() { +// return assemblyAccessions; +// } +// +// public void setAssemblyAccessions(String[] assemblyAccessions) { +// this.assemblyAccessions = assemblyAccessions; +// } - public void setAssemblyAccessions(String[] assemblyAccessions) { - this.assemblyAccessions = assemblyAccessions; + public String getRsType() { + return rsType; } + public int getReleaseVersion() { return releaseVersion; } @@ -65,11 +73,6 @@ public void setReleaseVersion(int releaseVersion) { this.releaseVersion = releaseVersion; } - - public String getRsType() { - return rsType; - } - public void setRsType(String rsType) { this.rsType = rsType; } @@ -90,6 +93,28 @@ public void setNewAddition(Long newAddition) { this.newAddition = newAddition; } + @Override + public String getKey() { + return this.taxonomyId + "_" + this.releaseVersion; + } + + + public String getScientificName() { + return scientificName; + } + + public void setScientificName(String scientificName) { + this.scientificName = scientificName; + } + + public String getCommonName() { + return commonName; + } + + public void setCommonName(String commonName) { + this.commonName = commonName; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java new file mode 100644 index 00000000..763fa585 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import javax.persistence.*; + +public interface ReleaseStatsView { + + public String getRsType(); + + + public int getReleaseVersion(); + + public void setReleaseVersion(int releaseVersion); + + public void setRsType(String rsType); + public Long getCount(); + + public void setCount(Long count); + + public Long getNewAddition(); + + public void setNewAddition(Long newAddition); + + public abstract String getKey(); +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java index 2177210d..94b9f71a 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java @@ -16,14 +16,22 @@ package uk.ac.ebi.eva.release.services; import org.springframework.stereotype.Service; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerAssemblyMapper; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerSpeciesMapper; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyView; import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyView; +import uk.ac.ebi.eva.release.models.ReleaseStatsView; import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerAssemblyViewRepository; import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerTaxonomyViewRepository; +import java.util.Collection; import java.util.HashMap; +import java.util.function.Predicate; +import java.util.stream.Collectors; @Service public class ReleaseStatsServicev2 { @@ -32,70 +40,118 @@ public class ReleaseStatsServicev2 { private final ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository; - private final ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper; - - private final ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper; public ReleaseStatsServicev2(ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository, - ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository, - ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper, - ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper) { + ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository) { this.releaseStatsPerTaxonomyRepository = releaseStatsPerTaxonomyRepository; this.releaseStatsPerAssemblyRepository = releaseStatsPerAssemblyRepository; - this.releaseStatsPerSpeciesMapper = releaseStatsPerSpeciesMapper; - this.releaseStatsPerAssemblyMapper = releaseStatsPerAssemblyMapper; } - public Iterable getReleaseStatsPerSpecies(Integer releaseVersion) { + public Iterable getReleaseStatsPerSpecies(boolean excludeUnmappedOnly) { + Iterable releaseData; + releaseData = releaseStatsPerTaxonomyRepository.findAll(); + return populateAllTaxonomyDtoFrom(releaseData, excludeUnmappedOnly, false); + } + + public Iterable getReleaseStatsPerSpecies(Integer releaseVersion, boolean excludeUnmappedOnly) { + Iterable releaseData; + releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); + return populateAllTaxonomyDtoFrom(releaseData, excludeUnmappedOnly, false); + } + + public Iterable getSpeciesWithNewRsIds(Integer releaseVersion){ Iterable releaseData; releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); + return populateAllTaxonomyDtoFrom(releaseData, false, true); + + } + + private Iterable populateAllTaxonomyDtoFrom( + Iterable releaseData, + boolean excludeUnmappedOnly, + boolean excludeNonNew + ){ HashMap keyToDto= new HashMap<>(); - for (ReleaseStatsPerTaxonomyView viewData : releaseData){ - String key = viewData.getTaxonomyId() + "_" + viewData.getReleaseVersion(); - if (! keyToDto.containsKey(key)){ + for (ReleaseStatsPerTaxonomyView viewData : releaseData) { + String key = viewData.getKey(); + if (!keyToDto.containsKey(key)) { keyToDto.put(key, new ReleaseStatsPerSpeciesV2Dto()); } ReleaseStatsPerSpeciesV2Dto dto = keyToDto.get(key); dto.setTaxonomyId(viewData.getTaxonomyId()); - dto.setReleaseVersion(viewData.getReleaseVersion()); - switch (viewData.getRsType()){ - case "current": - dto.setCurrentRs(viewData.getCount()); - dto.setNewCurrentRs(viewData.getNewAddition()); - break; - case "deprecated": - dto.setDeprecatedRs(viewData.getCount()); - dto.setNewDeprecatedRs(viewData.getNewAddition()); - break; - case "merged": - dto.setMergedRs(viewData.getCount()); - dto.setNewMergedRs(viewData.getNewAddition()); - break; - case "merged_deprecated": - dto.setMergedDeprecatedRs(viewData.getCount()); - dto.setNewMergedDeprecatedRs(viewData.getNewAddition()); - break; - case "multimap": - dto.setMultiMappedRs(viewData.getCount()); - dto.setNewMultiMappedRs(viewData.getNewAddition()); - break; - case "unmapped": - dto.setUnmappedRs(viewData.getCount()); - dto.setNewUnmappedRs(viewData.getNewAddition()); - break; - } + populateDtoFromViewData(dto, viewData); } - return keyToDto.values(); + return keyToDto.values().stream() + .filter(excludeUnmappedOnly? this::isNotUnmappedOnly : s -> true) + .filter(excludeNonNew? this::isNonNew :s -> true) + .collect(Collectors.toList()); } - private Iterable getReleaseDataByVersionExcludingUnmappedOnly(Integer releaseVersion) { - return getReleaseStatsPerSpecies(releaseVersion); + private Iterable populateAssemblyDtoFrom( + Iterable releaseData, + boolean excludeUnmappedOnly, + boolean excludeNonNew + ){ + HashMap keyToDto= new HashMap<>(); + for (ReleaseStatsPerAssemblyView viewData : releaseData) { + String key = viewData.getKey(); + if (!keyToDto.containsKey(key)) { + keyToDto.put(key, new ReleaseStatsPerAssemblyV2Dto()); + } + ReleaseStatsPerAssemblyV2Dto dto = keyToDto.get(key); + dto.setAssemblyAccession(viewData.getAssemblyAccession()); + populateDtoFromViewData(dto, viewData); + } + return keyToDto.values().stream() + .filter(excludeUnmappedOnly? this::isNotUnmappedOnly : s -> true) + .filter(excludeNonNew? this::isNonNew :s -> true) + .collect(Collectors.toList()); + } + private boolean isNotUnmappedOnly(ReleaseStatsPerV2Dto dto){ + return dto.getCurrentRs() != 0 && + dto.getMergedRs() != 0 && + dto.getDeprecatedRs() != 0 && + dto.getMergedDeprecatedRs() !=0; + } + private boolean isNonNew(ReleaseStatsPerV2Dto dto){ + return dto.getNewCurrentRs() > 0 || + dto.getNewMergedRs() > 0 || + dto.getNewDeprecatedRs() > 0 || + dto.getNewMultiMappedRs() > 0 || + dto.getNewUnmappedRs() > 0; } - private Iterable getReleaseDataExcludingUnmappedOnly() { - return getReleaseStatsPerSpecies(null); + private void populateDtoFromViewData(ReleaseStatsPerV2Dto dto, ReleaseStatsView viewData){ + dto.setReleaseVersion(viewData.getReleaseVersion()); + switch (viewData.getRsType()){ + case "current": + dto.setCurrentRs(viewData.getCount()); + dto.setNewCurrentRs(viewData.getNewAddition()); + break; + case "deprecated": + dto.setDeprecatedRs(viewData.getCount()); + dto.setNewDeprecatedRs(viewData.getNewAddition()); + break; + case "merged": + dto.setMergedRs(viewData.getCount()); + dto.setNewMergedRs(viewData.getNewAddition()); + break; + case "merged_deprecated": + dto.setMergedDeprecatedRs(viewData.getCount()); + dto.setNewMergedDeprecatedRs(viewData.getNewAddition()); + break; + case "multimap": + dto.setMultiMappedRs(viewData.getCount()); + dto.setNewMultiMappedRs(viewData.getNewAddition()); + break; + case "unmapped": + dto.setUnmappedRs(viewData.getCount()); + dto.setNewUnmappedRs(viewData.getNewAddition()); + break; + } } + // public Iterable getSpeciesWithNewRsIds(Integer releaseVersion) { // if (releaseVersion != null) { // return releaseStatsPerSpeciesMapper.toDto(releaseStatsPerSpeciesRepository @@ -105,23 +161,14 @@ private Iterable getReleaseDataExcludingUnmappedOnl // } // } // -// public Iterable getReleaseStatsPerAssembly(Integer releaseVersion) { -// Iterable releaseData; -// if (releaseVersion != null) { -// releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); -// } else { -// releaseData = releaseStatsPerAssemblyRepository.findAll(); -// } -// return releaseStatsPerAssemblyMapper.toDto(releaseData); -// } -// -// public Iterable getReleaseStatsPerAssemblyWithNewRsIds(Integer releaseVersion) { -// if (releaseVersion != null) { -// return releaseStatsPerAssemblyMapper.toDto( -// releaseStatsPerAssemblyRepository.findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L)); -// } else { -// return releaseStatsPerAssemblyMapper.toDto( -// releaseStatsPerAssemblyRepository.findByNewCurrentRsGreaterThan(0L)); -// } -// } + public Iterable getReleaseStatsPerAssembly(Integer releaseVersion, boolean excludeNonNew) { + Iterable releaseData; + if (releaseVersion != null) { + releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); + } else { + releaseData = releaseStatsPerAssemblyRepository.findAll(); + } + return populateAssemblyDtoFrom(releaseData, false, excludeNonNew); + } + } diff --git a/eva-release/src/main/resources/application.properties b/eva-release/src/main/resources/application.properties index c98613c3..1ff70901 100644 --- a/eva-release/src/main/resources/application.properties +++ b/eva-release/src/main/resources/application.properties @@ -18,4 +18,4 @@ spring.jmx.default-domain=eva.ebi.ac.uk.evarelease.|timestamp| # Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details. spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false # Because detection is disabled you have to set correct dialect by hand. -spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect \ No newline at end of file From 005f9c145e7134c2c56d3445773906db02ceba7d Mon Sep 17 00:00:00 2001 From: tcezard Date: Sun, 24 Mar 2024 11:04:47 +0000 Subject: [PATCH 03/12] Support postgesql arrays Change PK to be embeded to enable join with taxonomy Join with evapro.taxonomy to get scientific name and common name --- eva-release/pom.xml | 4 + .../controllers/ReleaseStatsv2Controller.java | 8 +- .../dto/ReleaseStatsPerAssemblyV2Dto.java | 17 +- .../dto/ReleaseStatsPerSpeciesV2Dto.java | 21 ++- .../mappers/ReleaseStatsMapperUtils.java | 70 ++++++++ .../ReleaseStatsPerAssemblyMapper.java | 49 ++++-- .../mappers/ReleaseStatsPerSpeciesMapper.java | 43 +++-- .../ebi/eva/release/models/ReleaseInfo.java | 2 +- .../models/ReleaseStatsPerAssembly.java | 2 +- ...ew.java => ReleaseStatsPerAssemblyV2.java} | 34 ++-- ....java => ReleaseStatsPerAssemblyV2PK.java} | 12 +- .../models/ReleaseStatsPerSpecies.java | 2 +- .../models/ReleaseStatsPerTaxonomyV2.java | 158 ++++++++++++++++++ ....java => ReleaseStatsPerTaxonomyV2PK.java} | 16 +- .../models/ReleaseStatsPerTaxonomyView.java | 143 ---------------- ...easeStatsView.java => ReleaseStatsV2.java} | 4 +- .../ac/ebi/eva/release/models/Taxonomy.java | 73 ++++++++ ...ReleaseStatsPerAssemblyViewRepository.java | 12 +- ...ReleaseStatsPerTaxonomyViewRepository.java | 12 +- .../services/ReleaseStatsServicev2.java | 97 ++++------- pom.xml | 5 + 21 files changed, 489 insertions(+), 295 deletions(-) create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java rename eva-release/src/main/java/uk/ac/ebi/eva/release/models/{ReleaseStatsPerAssemblyView.java => ReleaseStatsPerAssemblyV2.java} (77%) rename eva-release/src/main/java/uk/ac/ebi/eva/release/models/{ReleaseStatsPerAssemblyViewPK.java => ReleaseStatsPerAssemblyV2PK.java} (87%) create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java rename eva-release/src/main/java/uk/ac/ebi/eva/release/models/{ReleaseStatsPerTaxonomyViewPK.java => ReleaseStatsPerTaxonomyV2PK.java} (86%) delete mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java rename eva-release/src/main/java/uk/ac/ebi/eva/release/models/{ReleaseStatsView.java => ReleaseStatsV2.java} (94%) create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/Taxonomy.java diff --git a/eva-release/pom.xml b/eva-release/pom.xml index 7aa1be7c..a6a942cf 100644 --- a/eva-release/pom.xml +++ b/eva-release/pom.xml @@ -55,6 +55,10 @@ springfox-swagger2 compile + + io.hypersistence + hypersistence-utils-hibernate-52 + diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java index dc9771e5..e1695987 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java @@ -39,17 +39,13 @@ public ReleaseStatsv2Controller(ReleaseStatsServicev2 releaseStatsService) { public Iterable getReleaseStatsPerSpecies( @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion, @RequestParam(name = "excludeUnmappedOnly", required = false) boolean excludeUnmappedOnly) { - if (releaseVersion != null) { - return releaseStatsService.getReleaseStatsPerSpecies(releaseVersion, excludeUnmappedOnly); - }else{ - return releaseStatsService.getReleaseStatsPerSpecies(excludeUnmappedOnly); - } + return releaseStatsService.getReleaseStatsPerSpecies(releaseVersion, excludeUnmappedOnly); } @GetMapping("/per-species/new") public Iterable getSpeciesWithNewRsIds( @RequestParam(name = "releaseVersion") Integer releaseVersion) { - return releaseStatsService.getSpeciesWithNewRsIds(releaseVersion); + return releaseStatsService.getReleaseStatsPerSpeciesWithNewRsIds(releaseVersion); } @GetMapping("/per-assembly") diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java index 52b669ce..5049efc7 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java @@ -15,22 +15,19 @@ */ package uk.ac.ebi.eva.release.dto; -import javax.persistence.Id; import java.util.Objects; public class ReleaseStatsPerAssemblyV2Dto extends ReleaseStatsPerV2Dto { - @Id private String assemblyAccession; - @Id private int releaseVersion; private int[] taxonomyIds; private String releaseLink; - private String taxonomyLink; + private String[] taxonomyLinks; public ReleaseStatsPerAssemblyV2Dto() { } @@ -39,7 +36,7 @@ public int[] getTaxonomyIds() { return taxonomyIds; } - public void setTaxonomyId(int[] taxonomyIds) { + public void setTaxonomyIds(int[] taxonomyIds) { this.taxonomyIds = taxonomyIds; } @@ -51,12 +48,12 @@ public void setAssemblyAccession(String assemblyAccession) { this.assemblyAccession = assemblyAccession; } - public String getTaxonomyLink() { - return taxonomyLink; + public String[] getTaxonomyLinks() { + return taxonomyLinks; } - public void setTaxonomyLink(String taxonomyLink) { - this.taxonomyLink = taxonomyLink; + public void setTaxonomyLinks(String[] taxonomyLinks) { + this.taxonomyLinks = taxonomyLinks; } @@ -92,7 +89,7 @@ public String toString() { ", newDeprecatedRs=" + getNewDeprecatedRs() + ", newMergedDeprecatedRs=" + getNewMergedDeprecatedRs() + ", releaseLink='" + releaseLink + '\'' + - ", taxonomyLink='" + taxonomyLink + '\'' + + ", taxonomyLinks='" + taxonomyLinks + '\'' + '}'; } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java index ed252a17..5a7d9ad5 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java @@ -20,13 +20,16 @@ public class ReleaseStatsPerSpeciesV2Dto extends ReleaseStatsPerV2Dto { - @Id private int taxonomyId; + private String[] assemblyAccessions; + private String taxonomyLink; private String scientificName; + private String commonName; + public ReleaseStatsPerSpeciesV2Dto() { } @@ -46,6 +49,14 @@ public void setScientificName(String scientificName) { this.scientificName = scientificName; } + public String getCommonName() { + return commonName; + } + + public void setCommonName(String commonName) { + this.commonName = commonName; + } + public String getTaxonomyLink() { return taxonomyLink; } @@ -54,6 +65,14 @@ public void setTaxonomyLink(String taxonomyLink) { this.taxonomyLink = taxonomyLink; } + public String[] getAssemblyAccessions() { + return assemblyAccessions; + } + + public void setAssemblyAccessions(String[] assemblyAccessions) { + this.assemblyAccessions = assemblyAccessions; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java new file mode 100644 index 00000000..88cc10bf --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java @@ -0,0 +1,70 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.mappers; + +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; +import uk.ac.ebi.eva.release.models.ReleaseStatsV2; +import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; + +import java.util.HashMap; +import java.util.Map; + + +public class ReleaseStatsMapperUtils { + + private final ReleaseInfoRepository releaseInfoRepository; + + public ReleaseStatsMapperUtils(ReleaseInfoRepository releaseInfoRepository) { + this.releaseInfoRepository = releaseInfoRepository; + } + + public void populateDtoFromV2LongForm(ReleaseStatsPerV2Dto dto, ReleaseStatsV2 viewData){ + dto.setReleaseVersion(viewData.getReleaseVersion()); + switch (viewData.getRsType()){ + case "current": + dto.setCurrentRs(viewData.getCount()); + dto.setNewCurrentRs(viewData.getNewAddition()); + break; + case "deprecated": + dto.setDeprecatedRs(viewData.getCount()); + dto.setNewDeprecatedRs(viewData.getNewAddition()); + break; + case "merged": + dto.setMergedRs(viewData.getCount()); + dto.setNewMergedRs(viewData.getNewAddition()); + break; + case "merged_deprecated": + dto.setMergedDeprecatedRs(viewData.getCount()); + dto.setNewMergedDeprecatedRs(viewData.getNewAddition()); + break; + case "multimap": + dto.setMultiMappedRs(viewData.getCount()); + dto.setNewMultiMappedRs(viewData.getNewAddition()); + break; + case "unmapped": + dto.setUnmappedRs(viewData.getCount()); + dto.setNewUnmappedRs(viewData.getNewAddition()); + break; + } + } + + public Map getReleasesFtp() { + Map releaseFtp = new HashMap<>(); + releaseInfoRepository.findAll().forEach(r -> releaseFtp.put(r.getReleaseVersion(), r.getReleaseFtp())); + return releaseFtp; + } + +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java index 391ac261..d967b177 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java @@ -18,25 +18,54 @@ import org.springframework.stereotype.Component; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyDto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsV2; import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Component public class ReleaseStatsPerAssemblyMapper { + private static final String ASSEMBLY_DIRECTORY = "by_assembly/"; + private static final String SPECIES_DIRECTORY = "by_species/"; private static final String TAXONOMY_URL = "https://www.ebi.ac.uk/ena/browser/view/Taxon:"; - private final ReleaseInfoRepository releaseInfoRepository; + private final Map releaseLinkMap; + + private final ReleaseStatsMapperUtils releaseStatMapperUtils; public ReleaseStatsPerAssemblyMapper(ReleaseInfoRepository releaseInfoRepository) { - this.releaseInfoRepository = releaseInfoRepository; + this.releaseStatMapperUtils = new ReleaseStatsMapperUtils(releaseInfoRepository); + this.releaseLinkMap = this.releaseStatMapperUtils.getReleasesFtp(); + } + + public Collection toDtoV2(Iterable releaseData){ + HashMap keyToDto= new HashMap<>(); + for (ReleaseStatsPerAssemblyV2 assemblyData : releaseData) { + String key = assemblyData.getKey(); + if (!keyToDto.containsKey(key)) { + keyToDto.put(key, new ReleaseStatsPerAssemblyV2Dto()); + } + ReleaseStatsPerAssemblyV2Dto dto = keyToDto.get(key); + dto.setAssemblyAccession(assemblyData.getAssemblyAccession()); + this.releaseStatMapperUtils.populateDtoFromV2LongForm(dto, assemblyData); + String releaseLink = this.releaseLinkMap.get(assemblyData.getReleaseVersion()) + ASSEMBLY_DIRECTORY + + assemblyData.getAssemblyAccession(); + dto.setReleaseLink(releaseLink); + dto.setTaxonomyIds(assemblyData.getTaxonomyIds()); + String[] taxonomyLinks = Arrays.stream(assemblyData.getTaxonomyIds()) + .mapToObj(String::valueOf).map(t -> TAXONOMY_URL + t).toArray(String[]::new); + dto.setTaxonomyLinks(taxonomyLinks); + + + } + return keyToDto.values(); } public Iterable toDto(Iterable releaseStatsPerAssembly) { @@ -48,7 +77,7 @@ public Iterable toDto(Iterable releasesFtp = getReleasesFtp(); + Map releasesFtp = this.releaseStatMapperUtils.getReleasesFtp(); ReleaseStatsPerAssemblyDto releaseStatsPerAssemblyDto = new ReleaseStatsPerAssemblyDto(); releaseStatsPerAssemblyDto.setTaxonomyId(releaseStatsPerAssembly.getTaxonomyId()); @@ -81,10 +110,4 @@ private ReleaseStatsPerAssemblyDto toDto(ReleaseStatsPerAssembly releaseStatsPer return releaseStatsPerAssemblyDto; } - private Map getReleasesFtp() { - Map releaseFtp = new HashMap<>(); - releaseInfoRepository.findAll().forEach(r -> releaseFtp.put(r.getReleaseVersion(), r.getReleaseFtp())); - return releaseFtp; - } - } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java index 05eb9be5..f3bc2f0c 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java @@ -18,13 +18,12 @@ import org.springframework.stereotype.Component; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesDto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; import uk.ac.ebi.eva.release.models.ReleaseStatsPerSpecies; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2; import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Component public class ReleaseStatsPerSpeciesMapper { @@ -33,10 +32,35 @@ public class ReleaseStatsPerSpeciesMapper { private static final String TAXONOMY_URL = "https://www.ebi.ac.uk/ena/browser/view/Taxon:"; - private final ReleaseInfoRepository releaseInfoRepository; + + private final Map releaseLinkMap; + + private final ReleaseStatsMapperUtils releaseStatMapperUtils; public ReleaseStatsPerSpeciesMapper(ReleaseInfoRepository releaseInfoRepository) { - this.releaseInfoRepository = releaseInfoRepository; + this.releaseStatMapperUtils = new ReleaseStatsMapperUtils(releaseInfoRepository); + this.releaseLinkMap = this.releaseStatMapperUtils.getReleasesFtp(); + } + + public Collection toDtoV2(Iterable releaseData){ + HashMap keyToDto= new HashMap<>(); + for (ReleaseStatsPerTaxonomyV2 taxonomyData : releaseData) { + String key = taxonomyData.getKey(); + if (!keyToDto.containsKey(key)) { + keyToDto.put(key, new ReleaseStatsPerSpeciesV2Dto()); + } + ReleaseStatsPerSpeciesV2Dto dto = keyToDto.get(key); + dto.setTaxonomyId(taxonomyData.getTaxonomyId()); + dto.setScientificName(taxonomyData.getScientificName()); + dto.setCommonName(taxonomyData.getCommonName()); + this.releaseStatMapperUtils.populateDtoFromV2LongForm(dto, taxonomyData); + String releaseLink = this.releaseLinkMap.get(taxonomyData.getReleaseVersion()) + SPECIES_DIRECTORY + + taxonomyData.getReleaseFolder(); + dto.setReleaseLink(releaseLink); + dto.setAssemblyAccessions(taxonomyData.getAssemblyAccessions()); + dto.setTaxonomyLink(TAXONOMY_URL + taxonomyData.getTaxonomyId()); + } + return keyToDto.values(); } public Iterable toDto(Iterable releaseStatsPerSpecies) { @@ -48,7 +72,7 @@ public Iterable toDto(Iterable releasesFtp = getReleasesFtp(); + Map releasesFtp = this.releaseStatMapperUtils.getReleasesFtp(); ReleaseStatsPerSpeciesDto releaseStatsPerSpeciesDto = new ReleaseStatsPerSpeciesDto(); releaseStatsPerSpeciesDto.setTaxonomyId(releaseStatsPerSpecies.getTaxonomyId()); @@ -75,9 +99,4 @@ private ReleaseStatsPerSpeciesDto toDto(ReleaseStatsPerSpecies releaseStatsPerSp return releaseStatsPerSpeciesDto; } - private Map getReleasesFtp() { - Map releaseFtp = new HashMap<>(); - releaseInfoRepository.findAll().forEach(r -> releaseFtp.put(r.getReleaseVersion(), r.getReleaseFtp())); - return releaseFtp; - } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseInfo.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseInfo.java index 36463774..b70383e7 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseInfo.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseInfo.java @@ -22,7 +22,7 @@ import java.util.Objects; @Entity -@Table(name = "release_rs") +@Table(name = "release_rs", schema="eva_stats") public class ReleaseInfo { @Id diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssembly.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssembly.java index ad3c46d3..cf66aa1b 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssembly.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssembly.java @@ -23,7 +23,7 @@ @Entity @IdClass(ReleaseStatsPerAssemblyPK.class) -@Table(name = "release_rs_statistics_per_assembly") +@Table(name = "release_rs_statistics_per_assembly", schema="eva_stats") public class ReleaseStatsPerAssembly { @Id diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java similarity index 77% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java index 8ee0d6e3..dafae52f 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyView.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java @@ -15,15 +15,18 @@ */ package uk.ac.ebi.eva.release.models; +import io.hypersistence.utils.hibernate.type.array.IntArrayType; +import io.hypersistence.utils.hibernate.type.array.ListArrayType; import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; import javax.persistence.*; import java.util.Objects; @Entity -@IdClass(ReleaseStatsPerAssemblyViewPK.class) -@Table(name = "release_rs_count_per_assembly") -public class ReleaseStatsPerAssemblyView implements ReleaseStatsView { +@IdClass(ReleaseStatsPerAssemblyV2PK.class) +@Table(name = "release_rs_count_per_assembly", schema="eva_stats") +public class ReleaseStatsPerAssemblyV2 implements ReleaseStatsV2 { @Id private int releaseVersion; @@ -32,22 +35,27 @@ public class ReleaseStatsPerAssemblyView implements ReleaseStatsView { private String rsType; -// private int[] taxonomyIds; + @Type(type = "int-array") + @Column( + name = "taxonomy_ids", + columnDefinition = "integer[]" + ) + private int[] taxonomyIds; private Long count; @Column(name="new") protected Long newAddition; - public ReleaseStatsPerAssemblyView() { + public ReleaseStatsPerAssemblyV2() { } -// public int[] getTaxonomyIds() { -// return taxonomyIds; -// } -// -// public void setTaxonomyIds(int[] taxonomyIds) { -// this.taxonomyIds = taxonomyIds; -// } + public int[] getTaxonomyIds() { + return taxonomyIds; + } + + public void setTaxonomyIds(int[] taxonomyIds) { + this.taxonomyIds = taxonomyIds; + } public String getAssemblyAccession() { return assemblyAccession; @@ -99,7 +107,7 @@ public String getKey() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ReleaseStatsPerAssemblyView assembly = (ReleaseStatsPerAssemblyView) o; + ReleaseStatsPerAssemblyV2 assembly = (ReleaseStatsPerAssemblyV2) o; return releaseVersion == assembly.releaseVersion && Objects.equals(assemblyAccession, assembly.assemblyAccession) && Objects.equals(rsType, assembly.rsType); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java similarity index 87% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java index bc37c443..ff7a9f6a 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyViewPK.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java @@ -15,14 +15,12 @@ */ package uk.ac.ebi.eva.release.models; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.Embeddable; import java.io.Serializable; import java.util.Objects; -public class ReleaseStatsPerAssemblyViewPK implements Serializable { - +@Embeddable +public class ReleaseStatsPerAssemblyV2PK implements Serializable { private String assemblyAccession; @@ -30,7 +28,7 @@ public class ReleaseStatsPerAssemblyViewPK implements Serializable { private String rsType; - public ReleaseStatsPerAssemblyViewPK() { + public ReleaseStatsPerAssemblyV2PK() { } public String getAssemblyAccession() { @@ -61,7 +59,7 @@ public void setRsType(String rsType) { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ReleaseStatsPerAssemblyViewPK assembly = (ReleaseStatsPerAssemblyViewPK) o; + ReleaseStatsPerAssemblyV2PK assembly = (ReleaseStatsPerAssemblyV2PK) o; return releaseVersion == assembly.releaseVersion && Objects.equals(assemblyAccession, assembly.assemblyAccession) && Objects.equals(rsType, assembly.rsType); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerSpecies.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerSpecies.java index acd15a4c..89ccc396 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerSpecies.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerSpecies.java @@ -23,7 +23,7 @@ @Entity @IdClass(ReleaseStatsPerSpeciesPK.class) -@Table(name = "release_rs_statistics_per_species") +@Table(name = "release_rs_statistics_per_species", schema="eva_stats") public class ReleaseStatsPerSpecies { @Id diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java new file mode 100644 index 00000000..57696283 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java @@ -0,0 +1,158 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; +import org.hibernate.annotations.Type; + +import javax.persistence.*; +import java.util.Objects; + +@Entity +@Table(name = "release_rs_count_per_taxonomy", schema="eva_stats") +public class ReleaseStatsPerTaxonomyV2 implements ReleaseStatsV2 { + + @EmbeddedId + ReleaseStatsPerTaxonomyV2PK releaseStatsPerTaxonomyV2Id; + + @Column(insertable = false, updatable = false) + private int releaseVersion; + + @ManyToOne + @JoinColumn(name="taxonomyId", insertable = false, updatable = false) + @NotFound(action=NotFoundAction.IGNORE) + private Taxonomy taxonomy; + + @Type(type = "string-array") + @Column( + name = "assembly_accessions", + columnDefinition = "text[]" + ) + private String[] assemblyAccessions; + + private String releaseFolder; + + private Long count; + + @Column(name="new") + protected Long newAddition; + + + public ReleaseStatsPerTaxonomyV2() { + } + + public int getTaxonomyId() { + return releaseStatsPerTaxonomyV2Id.getTaxonomyId(); + } + + public String[] getAssemblyAccessions() { + return assemblyAccessions; + } + + public void setAssemblyAccessions(String[] assemblyAccessions) { + this.assemblyAccessions = assemblyAccessions; + } + + public String getRsType() { + return releaseStatsPerTaxonomyV2Id.getRsType(); + } + + public int getReleaseVersion() { + return releaseStatsPerTaxonomyV2Id.getReleaseVersion(); + } + + public void setReleaseVersion(int releaseVersion) { + this.releaseStatsPerTaxonomyV2Id.setReleaseVersion(releaseVersion); + } + + public void setRsType(String rsType) { + releaseStatsPerTaxonomyV2Id.setRsType(rsType); + } + + public String getReleaseFolder() { + return releaseFolder; + } + + public void setReleaseFolder(String releaseFolder) { + this.releaseFolder = releaseFolder; + } + + + public Long getCount() { + return count; + } + + public void setCount(Long count) { + this.count = count; + } + + public Long getNewAddition() { + return newAddition; + } + + public void setNewAddition(Long newAddition) { + this.newAddition = newAddition; + } + + @Override + public String getKey() { + return this.getTaxonomyId() + "_" + this.getReleaseVersion(); + } + + + public String getScientificName() { + if ( this.taxonomy != null) { + return taxonomy.getScientificName(); + }else { + return null; + } + } + + public String getCommonName() { + if ( this.taxonomy != null) { + return taxonomy.getCommonName(); + }else { + return null; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReleaseStatsPerTaxonomyV2 other_taxonomy = (ReleaseStatsPerTaxonomyV2) o; + return this.getReleaseVersion() == other_taxonomy.getReleaseVersion() && + Objects.equals(this.getTaxonomyId(), other_taxonomy.getTaxonomyId()) && + Objects.equals(this.getRsType(), other_taxonomy.getRsType()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getTaxonomyId(), this.getReleaseVersion(), this.getRsType()); + } + + @Override + public String toString() { + return "ReleaseStatsPerAssembly{" + + ", taxonomyId=" + this.getTaxonomyId() + + ", releaseVersion=" + this.getReleaseVersion() + + ", rsType='" + this.getRsType() + '\'' + + ", count=" + count + + ", new=" + newAddition + + '}'; + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java similarity index 86% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java index ed479472..44a8ffb1 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyViewPK.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java @@ -15,14 +15,14 @@ */ package uk.ac.ebi.eva.release.models; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.Table; +import javax.persistence.Embeddable; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import java.io.Serializable; import java.util.Objects; -public class ReleaseStatsPerTaxonomyViewPK implements Serializable { +@Embeddable +public class ReleaseStatsPerTaxonomyV2PK implements Serializable { private int taxonomyId; @@ -30,7 +30,7 @@ public class ReleaseStatsPerTaxonomyViewPK implements Serializable { private String rsType; - public ReleaseStatsPerTaxonomyViewPK() { + public ReleaseStatsPerTaxonomyV2PK() { } public int getTaxonomyId() { @@ -49,7 +49,6 @@ public void setReleaseVersion(int releaseVersion) { this.releaseVersion = releaseVersion; } - public String getRsType() { return rsType; } @@ -57,11 +56,12 @@ public String getRsType() { public void setRsType(String rsType) { this.rsType = rsType; } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ReleaseStatsPerTaxonomyViewPK taxonomy = (ReleaseStatsPerTaxonomyViewPK) o; + ReleaseStatsPerTaxonomyV2PK taxonomy = (ReleaseStatsPerTaxonomyV2PK) o; return releaseVersion == taxonomy.releaseVersion && Objects.equals(taxonomyId, taxonomy.taxonomyId) && Objects.equals(rsType, taxonomy.rsType); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java deleted file mode 100644 index c6ac4076..00000000 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyView.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2022 EMBL - European Bioinformatics Institute - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package uk.ac.ebi.eva.release.models; - -import javax.persistence.*; -import java.util.Objects; - -@Entity -@IdClass(ReleaseStatsPerTaxonomyViewPK.class) -@Table(name = "release_rs_count_per_taxonomy") -public class ReleaseStatsPerTaxonomyView implements ReleaseStatsView{ - - @Id - private int taxonomyId; - @Id - private int releaseVersion; - private String rsType; - -// private String[] assemblyAccessions; - - private String scientificName; - - private String commonName; - - private Long count; - - @Column(name="new") - protected Long newAddition; - - - public ReleaseStatsPerTaxonomyView() { - } - - public int getTaxonomyId() { - return taxonomyId; - } - - public void setTaxonomyId(int taxonomyId) { - this.taxonomyId = taxonomyId; - } - -// public String[] getAssemblyAccessions() { -// return assemblyAccessions; -// } -// -// public void setAssemblyAccessions(String[] assemblyAccessions) { -// this.assemblyAccessions = assemblyAccessions; -// } - - public String getRsType() { - return rsType; - } - - - public int getReleaseVersion() { - return releaseVersion; - } - - public void setReleaseVersion(int releaseVersion) { - this.releaseVersion = releaseVersion; - } - - public void setRsType(String rsType) { - this.rsType = rsType; - } - - public Long getCount() { - return count; - } - - public void setCount(Long count) { - this.count = count; - } - - public Long getNewAddition() { - return newAddition; - } - - public void setNewAddition(Long newAddition) { - this.newAddition = newAddition; - } - - @Override - public String getKey() { - return this.taxonomyId + "_" + this.releaseVersion; - } - - - public String getScientificName() { - return scientificName; - } - - public void setScientificName(String scientificName) { - this.scientificName = scientificName; - } - - public String getCommonName() { - return commonName; - } - - public void setCommonName(String commonName) { - this.commonName = commonName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ReleaseStatsPerTaxonomyView taxonomy = (ReleaseStatsPerTaxonomyView) o; - return releaseVersion == taxonomy.releaseVersion && - Objects.equals(taxonomyId, taxonomy.taxonomyId) && - Objects.equals(rsType, taxonomy.rsType); - } - - @Override - public int hashCode() { - return Objects.hash(taxonomyId, releaseVersion, rsType); - } - - @Override - public String toString() { - return "ReleaseStatsPerAssembly{" + - ", taxonomyId=" + taxonomyId + - ", releaseVersion=" + releaseVersion + - ", rsType='" + rsType + '\'' + - ", count=" + count + - ", new=" + newAddition + - '}'; - } -} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java similarity index 94% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java index 763fa585..133b860c 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsView.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java @@ -15,9 +15,7 @@ */ package uk.ac.ebi.eva.release.models; -import javax.persistence.*; - -public interface ReleaseStatsView { +public interface ReleaseStatsV2 { public String getRsType(); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/Taxonomy.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/Taxonomy.java new file mode 100644 index 00000000..07fb380a --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/Taxonomy.java @@ -0,0 +1,73 @@ +/* + * Copyright 2022 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.models; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Objects; + +@Entity +@Table(name = "taxonomy", schema="evapro") +public class Taxonomy { + + @Id + private int taxonomyId; + + private String commonName; + + private String scientificName; + + public Taxonomy() { + } + + public int getTaxonomyId() { + return taxonomyId; + } + + public void setTaxonomyId(int taxonomyId) { + this.taxonomyId = taxonomyId; + } + + public String getCommonName() { + return commonName; + } + + public void setCommonName(String commonName) { + this.commonName = commonName; + } + + public String getScientificName() { + return scientificName; + } + + public void setScientificName(String scientificName) { + this.scientificName = scientificName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Taxonomy taxonomy = (Taxonomy) o; + return taxonomyId == taxonomy.taxonomyId; + } + + @Override + public int hashCode() { + return Objects.hash(taxonomyId); + } +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java index a7d009d0..6cde1ed5 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java @@ -17,16 +17,14 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyPK; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyView; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyViewPK; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2PK; @Repository -public interface ReleaseStatsPerAssemblyViewRepository extends CrudRepository { +public interface ReleaseStatsPerAssemblyViewRepository extends CrudRepository { - Iterable findAllByReleaseVersion(int releaseVersion); + Iterable findAllByReleaseVersion(int releaseVersion); } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java index a997332c..513a1453 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java @@ -17,16 +17,14 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerSpecies; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerSpeciesPK; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyView; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyViewPK; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2PK; @Repository -public interface ReleaseStatsPerTaxonomyViewRepository extends CrudRepository { +public interface ReleaseStatsPerTaxonomyViewRepository extends CrudRepository { - Iterable findAllByReleaseVersion(int releaseVersion); + Iterable findAllByReleaseVersion(int releaseVersion); } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java index 94b9f71a..2ad9f411 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java @@ -21,16 +21,13 @@ import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerAssemblyMapper; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerSpeciesMapper; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyView; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyView; -import uk.ac.ebi.eva.release.models.ReleaseStatsView; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsV2; import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerAssemblyViewRepository; import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerTaxonomyViewRepository; -import java.util.Collection; import java.util.HashMap; -import java.util.function.Predicate; import java.util.stream.Collectors; @Service @@ -40,72 +37,68 @@ public class ReleaseStatsServicev2 { private final ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository; + private final ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper; + + private final ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper; public ReleaseStatsServicev2(ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository, - ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository) { + ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository, + ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper, + ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper) { this.releaseStatsPerTaxonomyRepository = releaseStatsPerTaxonomyRepository; this.releaseStatsPerAssemblyRepository = releaseStatsPerAssemblyRepository; - } - - public Iterable getReleaseStatsPerSpecies(boolean excludeUnmappedOnly) { - Iterable releaseData; - releaseData = releaseStatsPerTaxonomyRepository.findAll(); - return populateAllTaxonomyDtoFrom(releaseData, excludeUnmappedOnly, false); + this.releaseStatsPerSpeciesMapper = releaseStatsPerSpeciesMapper; + this.releaseStatsPerAssemblyMapper = releaseStatsPerAssemblyMapper; } public Iterable getReleaseStatsPerSpecies(Integer releaseVersion, boolean excludeUnmappedOnly) { - Iterable releaseData; - releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); + Iterable releaseData; + if (releaseVersion != null) { + releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); + }else{ + releaseData = releaseStatsPerTaxonomyRepository.findAll(); + } return populateAllTaxonomyDtoFrom(releaseData, excludeUnmappedOnly, false); } - public Iterable getSpeciesWithNewRsIds(Integer releaseVersion){ - Iterable releaseData; + public Iterable getReleaseStatsPerSpeciesWithNewRsIds(Integer releaseVersion){ + Iterable releaseData; releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); return populateAllTaxonomyDtoFrom(releaseData, false, true); } + public Iterable getReleaseStatsPerAssembly(Integer releaseVersion, boolean excludeNonNew) { + Iterable releaseData; + if (releaseVersion != null) { + releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); + } else { + releaseData = releaseStatsPerAssemblyRepository.findAll(); + } + return populateAssemblyDtoFrom(releaseData, false, excludeNonNew); + } + private Iterable populateAllTaxonomyDtoFrom( - Iterable releaseData, + Iterable releaseData, boolean excludeUnmappedOnly, boolean excludeNonNew ){ - HashMap keyToDto= new HashMap<>(); - for (ReleaseStatsPerTaxonomyView viewData : releaseData) { - String key = viewData.getKey(); - if (!keyToDto.containsKey(key)) { - keyToDto.put(key, new ReleaseStatsPerSpeciesV2Dto()); - } - ReleaseStatsPerSpeciesV2Dto dto = keyToDto.get(key); - dto.setTaxonomyId(viewData.getTaxonomyId()); - populateDtoFromViewData(dto, viewData); - } - return keyToDto.values().stream() + return this.releaseStatsPerSpeciesMapper.toDtoV2(releaseData).stream() .filter(excludeUnmappedOnly? this::isNotUnmappedOnly : s -> true) .filter(excludeNonNew? this::isNonNew :s -> true) .collect(Collectors.toList()); } private Iterable populateAssemblyDtoFrom( - Iterable releaseData, + Iterable releaseData, boolean excludeUnmappedOnly, boolean excludeNonNew ){ - HashMap keyToDto= new HashMap<>(); - for (ReleaseStatsPerAssemblyView viewData : releaseData) { - String key = viewData.getKey(); - if (!keyToDto.containsKey(key)) { - keyToDto.put(key, new ReleaseStatsPerAssemblyV2Dto()); - } - ReleaseStatsPerAssemblyV2Dto dto = keyToDto.get(key); - dto.setAssemblyAccession(viewData.getAssemblyAccession()); - populateDtoFromViewData(dto, viewData); - } - return keyToDto.values().stream() + return this.releaseStatsPerAssemblyMapper.toDtoV2(releaseData).stream() .filter(excludeUnmappedOnly? this::isNotUnmappedOnly : s -> true) .filter(excludeNonNew? this::isNonNew :s -> true) .collect(Collectors.toList()); + } private boolean isNotUnmappedOnly(ReleaseStatsPerV2Dto dto){ return dto.getCurrentRs() != 0 && @@ -121,7 +114,7 @@ private boolean isNonNew(ReleaseStatsPerV2Dto dto){ dto.getNewUnmappedRs() > 0; } - private void populateDtoFromViewData(ReleaseStatsPerV2Dto dto, ReleaseStatsView viewData){ + private void populateDtoFromViewData(ReleaseStatsPerV2Dto dto, ReleaseStatsV2 viewData){ dto.setReleaseVersion(viewData.getReleaseVersion()); switch (viewData.getRsType()){ case "current": @@ -151,24 +144,4 @@ private void populateDtoFromViewData(ReleaseStatsPerV2Dto dto, ReleaseStatsView } } - -// public Iterable getSpeciesWithNewRsIds(Integer releaseVersion) { -// if (releaseVersion != null) { -// return releaseStatsPerSpeciesMapper.toDto(releaseStatsPerSpeciesRepository -// .findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L)); -// } else { -// return releaseStatsPerSpeciesMapper.toDto(releaseStatsPerSpeciesRepository.findByNewCurrentRsGreaterThan(0L)); -// } -// } -// - public Iterable getReleaseStatsPerAssembly(Integer releaseVersion, boolean excludeNonNew) { - Iterable releaseData; - if (releaseVersion != null) { - releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); - } else { - releaseData = releaseStatsPerAssemblyRepository.findAll(); - } - return populateAssemblyDtoFrom(releaseData, false, excludeNonNew); - } - } diff --git a/pom.xml b/pom.xml index 34583b98..384eca6d 100644 --- a/pom.xml +++ b/pom.xml @@ -117,6 +117,11 @@ jackson-databind 2.9.7 + + io.hypersistence + hypersistence-utils-hibernate-52 + 3.7.3 + From 6e3325e6a1c897118aff6851dbd51bec627de326 Mon Sep 17 00:00:00 2001 From: Timothee Cezard Date: Sun, 24 Mar 2024 16:42:36 +0000 Subject: [PATCH 04/12] Apply suggestions from code review Co-authored-by: April Shen --- .../eva/release/controllers/ReleaseStatsv2Controller.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java index e1695987..a1f82431 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java @@ -25,11 +25,11 @@ import uk.ac.ebi.eva.release.services.ReleaseStatsServicev2; @RestController -@RequestMapping(value = "/v1/stats2", produces = "application/json") +@RequestMapping(value = "/v2/stats", produces = "application/json") @Api(tags = {"RS Release Statistics"}) -public class ReleaseStatsv2Controller { +public class ReleaseStatsV2Controller { - private final ReleaseStatsServicev2 releaseStatsService; + private final ReleaseStatsServiceV2 releaseStatsService; public ReleaseStatsv2Controller(ReleaseStatsServicev2 releaseStatsService) { this.releaseStatsService = releaseStatsService; From fe731930ef97ba227659e158ba8766bd5a3c6197 Mon Sep 17 00:00:00 2001 From: tcezard Date: Sun, 24 Mar 2024 16:49:15 +0000 Subject: [PATCH 05/12] Address review comments --- ...ler.java => ReleaseStatsV2Controller.java} | 4 ++-- .../dto/ReleaseStatsPerAssemblyV2Dto.java | 6 +----- .../dto/ReleaseStatsPerSpeciesV2Dto.java | 3 +-- ...tsPerV2Dto.java => ReleaseStatsV2Dto.java} | 7 ++----- .../mappers/ReleaseStatsMapperUtils.java | 4 ++-- .../ReleaseStatsPerAssemblyMapper.java | 2 -- ...vicev2.java => ReleaseStatsServiceV2.java} | 19 +++++++++---------- 7 files changed, 17 insertions(+), 28 deletions(-) rename eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/{ReleaseStatsv2Controller.java => ReleaseStatsV2Controller.java} (95%) rename eva-release/src/main/java/uk/ac/ebi/eva/release/dto/{ReleaseStatsPerV2Dto.java => ReleaseStatsV2Dto.java} (97%) rename eva-release/src/main/java/uk/ac/ebi/eva/release/services/{ReleaseStatsServicev2.java => ReleaseStatsServiceV2.java} (92%) diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java similarity index 95% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java index a1f82431..2d178a8c 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsv2Controller.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java @@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.RestController; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; -import uk.ac.ebi.eva.release.services.ReleaseStatsServicev2; +import uk.ac.ebi.eva.release.services.ReleaseStatsServiceV2; @RestController @RequestMapping(value = "/v2/stats", produces = "application/json") @@ -31,7 +31,7 @@ public class ReleaseStatsV2Controller { private final ReleaseStatsServiceV2 releaseStatsService; - public ReleaseStatsv2Controller(ReleaseStatsServicev2 releaseStatsService) { + public ReleaseStatsV2Controller(ReleaseStatsServiceV2 releaseStatsService) { this.releaseStatsService = releaseStatsService; } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java index 5049efc7..81356264 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerAssemblyV2Dto.java @@ -17,16 +17,12 @@ import java.util.Objects; -public class ReleaseStatsPerAssemblyV2Dto extends ReleaseStatsPerV2Dto { +public class ReleaseStatsPerAssemblyV2Dto extends ReleaseStatsV2Dto { private String assemblyAccession; - private int releaseVersion; - private int[] taxonomyIds; - private String releaseLink; - private String[] taxonomyLinks; public ReleaseStatsPerAssemblyV2Dto() { diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java index 5a7d9ad5..cf56a393 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java @@ -15,10 +15,9 @@ */ package uk.ac.ebi.eva.release.dto; -import javax.persistence.Id; import java.util.Objects; -public class ReleaseStatsPerSpeciesV2Dto extends ReleaseStatsPerV2Dto { +public class ReleaseStatsPerSpeciesV2Dto extends ReleaseStatsV2Dto { private int taxonomyId; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java similarity index 97% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java index 6b06d6df..7c737213 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java @@ -15,10 +15,7 @@ */ package uk.ac.ebi.eva.release.dto; -import javax.persistence.Id; -import java.util.Objects; - -public abstract class ReleaseStatsPerV2Dto { +public abstract class ReleaseStatsV2Dto { protected int releaseVersion; @@ -50,7 +47,7 @@ public abstract class ReleaseStatsPerV2Dto { protected String releaseLink; - public ReleaseStatsPerV2Dto() { + public ReleaseStatsV2Dto() { } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java index 88cc10bf..8e1a6046 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java @@ -15,7 +15,7 @@ */ package uk.ac.ebi.eva.release.mappers; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsV2Dto; import uk.ac.ebi.eva.release.models.ReleaseStatsV2; import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; @@ -31,7 +31,7 @@ public ReleaseStatsMapperUtils(ReleaseInfoRepository releaseInfoRepository) { this.releaseInfoRepository = releaseInfoRepository; } - public void populateDtoFromV2LongForm(ReleaseStatsPerV2Dto dto, ReleaseStatsV2 viewData){ + public void populateDtoFromV2LongForm(ReleaseStatsV2Dto dto, ReleaseStatsV2 viewData){ dto.setReleaseVersion(viewData.getReleaseVersion()); switch (viewData.getRsType()){ case "current": diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java index d967b177..e11427d0 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java @@ -19,10 +19,8 @@ import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyDto; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2; -import uk.ac.ebi.eva.release.models.ReleaseStatsV2; import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; import java.util.*; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java similarity index 92% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java index 2ad9f411..f9941559 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServicev2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java @@ -18,7 +18,7 @@ import org.springframework.stereotype.Service; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerV2Dto; +import uk.ac.ebi.eva.release.dto.ReleaseStatsV2Dto; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerAssemblyMapper; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerSpeciesMapper; import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2; @@ -27,11 +27,10 @@ import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerAssemblyViewRepository; import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerTaxonomyViewRepository; -import java.util.HashMap; import java.util.stream.Collectors; @Service -public class ReleaseStatsServicev2 { +public class ReleaseStatsServiceV2 { private final ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository; @@ -41,7 +40,7 @@ public class ReleaseStatsServicev2 { private final ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper; - public ReleaseStatsServicev2(ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository, + public ReleaseStatsServiceV2(ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository, ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository, ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper, ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper) { @@ -100,13 +99,13 @@ private Iterable populateAssemblyDtoFrom( .collect(Collectors.toList()); } - private boolean isNotUnmappedOnly(ReleaseStatsPerV2Dto dto){ - return dto.getCurrentRs() != 0 && - dto.getMergedRs() != 0 && - dto.getDeprecatedRs() != 0 && + private boolean isNotUnmappedOnly(ReleaseStatsV2Dto dto){ + return dto.getCurrentRs() != 0 || + dto.getMergedRs() != 0 || + dto.getDeprecatedRs() != 0 || dto.getMergedDeprecatedRs() !=0; } - private boolean isNonNew(ReleaseStatsPerV2Dto dto){ + private boolean isNonNew(ReleaseStatsV2Dto dto){ return dto.getNewCurrentRs() > 0 || dto.getNewMergedRs() > 0 || dto.getNewDeprecatedRs() > 0 || @@ -114,7 +113,7 @@ private boolean isNonNew(ReleaseStatsPerV2Dto dto){ dto.getNewUnmappedRs() > 0; } - private void populateDtoFromViewData(ReleaseStatsPerV2Dto dto, ReleaseStatsV2 viewData){ + private void populateDtoFromViewData(ReleaseStatsV2Dto dto, ReleaseStatsV2 viewData){ dto.setReleaseVersion(viewData.getReleaseVersion()); switch (viewData.getRsType()){ case "current": From 3fdf00d6561383956240792864dee02d1578d35f Mon Sep 17 00:00:00 2001 From: tcezard Date: Sun, 24 Mar 2024 21:13:30 +0000 Subject: [PATCH 06/12] Add release folder --- .../mappers/ReleaseStatsPerAssemblyMapper.java | 1 + .../mappers/ReleaseStatsPerSpeciesMapper.java | 1 + .../release/models/ReleaseStatsPerAssemblyV2.java | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java index e11427d0..fd8aa934 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java @@ -52,6 +52,7 @@ public Collection toDtoV2(Iterable toDtoV2(Iterable Date: Mon, 25 Mar 2024 13:53:31 +0000 Subject: [PATCH 07/12] Switch to using the Wide version of the aggregate count table --- .../mappers/ReleaseStatsMapperUtils.java | 32 ---- .../ReleaseStatsPerAssemblyMapper.java | 51 +++--- .../mappers/ReleaseStatsPerSpeciesMapper.java | 50 +++--- .../models/ReleaseStatsPerAssemblyV2.java | 126 ++++++++++----- .../models/ReleaseStatsPerAssemblyV2PK.java | 16 +- .../models/ReleaseStatsPerTaxonomyV2.java | 146 +++++++++++++----- .../models/ReleaseStatsPerTaxonomyV2PK.java | 15 +- .../eva/release/models/ReleaseStatsV2.java | 37 ----- ... ReleaseStatsPerAssemblyV2Repository.java} | 4 +- .../ReleaseStatsPerTaxonomyV2Repository.java | 42 +++++ ...ReleaseStatsPerTaxonomyViewRepository.java | 30 ---- .../services/ReleaseStatsServiceV2.java | 139 ++++++++--------- 12 files changed, 372 insertions(+), 316 deletions(-) delete mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java rename eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/{ReleaseStatsPerAssemblyViewRepository.java => ReleaseStatsPerAssemblyV2Repository.java} (76%) create mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyV2Repository.java delete mode 100644 eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java index 8e1a6046..4f11ff9d 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsMapperUtils.java @@ -15,8 +15,6 @@ */ package uk.ac.ebi.eva.release.mappers; -import uk.ac.ebi.eva.release.dto.ReleaseStatsV2Dto; -import uk.ac.ebi.eva.release.models.ReleaseStatsV2; import uk.ac.ebi.eva.release.repositories.ReleaseInfoRepository; import java.util.HashMap; @@ -31,36 +29,6 @@ public ReleaseStatsMapperUtils(ReleaseInfoRepository releaseInfoRepository) { this.releaseInfoRepository = releaseInfoRepository; } - public void populateDtoFromV2LongForm(ReleaseStatsV2Dto dto, ReleaseStatsV2 viewData){ - dto.setReleaseVersion(viewData.getReleaseVersion()); - switch (viewData.getRsType()){ - case "current": - dto.setCurrentRs(viewData.getCount()); - dto.setNewCurrentRs(viewData.getNewAddition()); - break; - case "deprecated": - dto.setDeprecatedRs(viewData.getCount()); - dto.setNewDeprecatedRs(viewData.getNewAddition()); - break; - case "merged": - dto.setMergedRs(viewData.getCount()); - dto.setNewMergedRs(viewData.getNewAddition()); - break; - case "merged_deprecated": - dto.setMergedDeprecatedRs(viewData.getCount()); - dto.setNewMergedDeprecatedRs(viewData.getNewAddition()); - break; - case "multimap": - dto.setMultiMappedRs(viewData.getCount()); - dto.setNewMultiMappedRs(viewData.getNewAddition()); - break; - case "unmapped": - dto.setUnmappedRs(viewData.getCount()); - dto.setNewUnmappedRs(viewData.getNewAddition()); - break; - } - } - public Map getReleasesFtp() { Map releaseFtp = new HashMap<>(); releaseInfoRepository.findAll().forEach(r -> releaseFtp.put(r.getReleaseVersion(), r.getReleaseFtp())); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java index fd8aa934..130be34b 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java @@ -43,28 +43,39 @@ public ReleaseStatsPerAssemblyMapper(ReleaseInfoRepository releaseInfoRepository this.releaseLinkMap = this.releaseStatMapperUtils.getReleasesFtp(); } - public Collection toDtoV2(Iterable releaseData){ - HashMap keyToDto= new HashMap<>(); + public Iterable toDtoV2(Iterable releaseData){ + List releaseStatsPerAssemblyDtos = new ArrayList(); for (ReleaseStatsPerAssemblyV2 assemblyData : releaseData) { - String key = assemblyData.getKey(); - if (!keyToDto.containsKey(key)) { - keyToDto.put(key, new ReleaseStatsPerAssemblyV2Dto()); - } - ReleaseStatsPerAssemblyV2Dto dto = keyToDto.get(key); - dto.setAssemblyAccession(assemblyData.getAssemblyAccession()); - dto.setReleaseFolder(assemblyData.getReleaseFolder()); - this.releaseStatMapperUtils.populateDtoFromV2LongForm(dto, assemblyData); - String releaseLink = this.releaseLinkMap.get(assemblyData.getReleaseVersion()) + ASSEMBLY_DIRECTORY + - assemblyData.getAssemblyAccession(); - dto.setReleaseLink(releaseLink); - dto.setTaxonomyIds(assemblyData.getTaxonomyIds()); - String[] taxonomyLinks = Arrays.stream(assemblyData.getTaxonomyIds()) - .mapToObj(String::valueOf).map(t -> TAXONOMY_URL + t).toArray(String[]::new); - dto.setTaxonomyLinks(taxonomyLinks); - - + releaseStatsPerAssemblyDtos.add(toDtoV2(assemblyData)); } - return keyToDto.values(); + return releaseStatsPerAssemblyDtos; + } + + public ReleaseStatsPerAssemblyV2Dto toDtoV2(ReleaseStatsPerAssemblyV2 assemblyData){ + HashMap keyToDto= new HashMap<>(); + ReleaseStatsPerAssemblyV2Dto dto = new ReleaseStatsPerAssemblyV2Dto(); + dto.setAssemblyAccession(assemblyData.getAssemblyAccession()); + dto.setReleaseVersion(assemblyData.getReleaseVersion()); + dto.setReleaseFolder(assemblyData.getReleaseFolder()); + String releaseLink = this.releaseLinkMap.get(assemblyData.getReleaseVersion()) + ASSEMBLY_DIRECTORY + + assemblyData.getAssemblyAccession(); + dto.setReleaseLink(releaseLink); + dto.setTaxonomyIds(assemblyData.getTaxonomyIds()); + String[] taxonomyLinks = Arrays.stream(assemblyData.getTaxonomyIds()) + .mapToObj(String::valueOf).map(t -> TAXONOMY_URL + t).toArray(String[]::new); + dto.setTaxonomyLinks(taxonomyLinks); + + dto.setCurrentRs(assemblyData.getCurrentRs()); + dto.setMultiMappedRs(assemblyData.getMultimapRs()); + dto.setMergedRs(assemblyData.getMergedRs()); + dto.setDeprecatedRs(assemblyData.getDeprecatedRs()); + dto.setMergedDeprecatedRs(assemblyData.getMergedDeprecatedRs()); + dto.setNewCurrentRs(assemblyData.getNewCurrentRs()); + dto.setNewMultiMappedRs(assemblyData.getNewMultimapRs()); + dto.setNewMergedRs(assemblyData.getNewMergedRs()); + dto.setNewDeprecatedRs(assemblyData.getNewDeprecatedRs()); + dto.setNewMergedDeprecatedRs(assemblyData.getNewMergedDeprecatedRs()); + return dto; } public Iterable toDto(Iterable releaseStatsPerAssembly) { diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java index 9bfaa309..c967b879 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java @@ -42,26 +42,40 @@ public ReleaseStatsPerSpeciesMapper(ReleaseInfoRepository releaseInfoRepository) this.releaseLinkMap = this.releaseStatMapperUtils.getReleasesFtp(); } - public Collection toDtoV2(Iterable releaseData){ - HashMap keyToDto= new HashMap<>(); + public Iterable toDtoV2(Iterable releaseData){ + List releaseStatsPerSpeciesDtos = new ArrayList(); for (ReleaseStatsPerTaxonomyV2 taxonomyData : releaseData) { - String key = taxonomyData.getKey(); - if (!keyToDto.containsKey(key)) { - keyToDto.put(key, new ReleaseStatsPerSpeciesV2Dto()); - } - ReleaseStatsPerSpeciesV2Dto dto = keyToDto.get(key); - dto.setTaxonomyId(taxonomyData.getTaxonomyId()); - dto.setScientificName(taxonomyData.getScientificName()); - dto.setCommonName(taxonomyData.getCommonName()); - this.releaseStatMapperUtils.populateDtoFromV2LongForm(dto, taxonomyData); - dto.setReleaseFolder(taxonomyData.getReleaseFolder()); - String releaseLink = this.releaseLinkMap.get(taxonomyData.getReleaseVersion()) + SPECIES_DIRECTORY + - taxonomyData.getReleaseFolder(); - dto.setReleaseLink(releaseLink); - dto.setAssemblyAccessions(taxonomyData.getAssemblyAccessions()); - dto.setTaxonomyLink(TAXONOMY_URL + taxonomyData.getTaxonomyId()); + releaseStatsPerSpeciesDtos.add(toDtoV2(taxonomyData)); } - return keyToDto.values(); + return releaseStatsPerSpeciesDtos; + } + + public ReleaseStatsPerSpeciesV2Dto toDtoV2(ReleaseStatsPerTaxonomyV2 taxonomyData){ + ReleaseStatsPerSpeciesV2Dto dto = new ReleaseStatsPerSpeciesV2Dto(); + dto.setTaxonomyId(taxonomyData.getTaxonomyId()); + dto.setTaxonomyLink(TAXONOMY_URL + taxonomyData.getTaxonomyId()); + dto.setReleaseVersion(taxonomyData.getReleaseVersion()); + dto.setScientificName(taxonomyData.getScientificName()); + dto.setCommonName(taxonomyData.getCommonName()); + dto.setReleaseFolder(taxonomyData.getReleaseFolder()); + String releaseLink = this.releaseLinkMap.get(taxonomyData.getReleaseVersion()) + SPECIES_DIRECTORY + + taxonomyData.getReleaseFolder(); + dto.setReleaseLink(releaseLink); + dto.setAssemblyAccessions(taxonomyData.getAssemblyAccessions()); + + dto.setCurrentRs(taxonomyData.getCurrentRs()); + dto.setMultiMappedRs(taxonomyData.getMultimapRs()); + dto.setMergedRs(taxonomyData.getMergedRs()); + dto.setDeprecatedRs(taxonomyData.getDeprecatedRs()); + dto.setMergedDeprecatedRs(taxonomyData.getMergedDeprecatedRs()); + dto.setUnmappedRs(taxonomyData.getUnmappedRs()); + dto.setNewCurrentRs(taxonomyData.getNewCurrentRs()); + dto.setNewMultiMappedRs(taxonomyData.getNewMultimapRs()); + dto.setNewMergedRs(taxonomyData.getNewMergedRs()); + dto.setNewDeprecatedRs(taxonomyData.getNewDeprecatedRs()); + dto.setNewMergedDeprecatedRs(taxonomyData.getNewMergedDeprecatedRs()); + dto.setNewUnmappedRs(taxonomyData.getNewUnmappedRs()); + return dto; } public Iterable toDto(Iterable releaseStatsPerSpecies) { diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java index 994087e8..69663050 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java @@ -26,16 +26,13 @@ @Entity @IdClass(ReleaseStatsPerAssemblyV2PK.class) @Table(name = "release_rs_count_per_assembly", schema="eva_stats") -public class ReleaseStatsPerAssemblyV2 implements ReleaseStatsV2 { +public class ReleaseStatsPerAssemblyV2 { @Id private int releaseVersion; @Id private String assemblyAccession; - @Id - private String rsType; - @Type(type = "int-array") @Column( name = "taxonomy_ids", @@ -45,12 +42,25 @@ public class ReleaseStatsPerAssemblyV2 implements ReleaseStatsV2 { private String releaseFolder; - private Long count; + private Long currentRs; + + private Long multimapRs; + + private Long mergedRs; + + private Long deprecatedRs; + + private Long mergedDeprecatedRs; - @Column(name="new") - protected Long newAddition; + private Long newCurrentRs; + private Long newMultimapRs; + private Long newMergedRs; + + private Long newDeprecatedRs; + + private Long newMergedDeprecatedRs; public ReleaseStatsPerAssemblyV2() { } @@ -71,9 +81,6 @@ public void setAssemblyAccession(String assemblyAccession) { this.assemblyAccession = assemblyAccession; } - public String getRsType() { - return rsType; - } public int getReleaseVersion() { @@ -84,9 +91,6 @@ public void setReleaseVersion(int releaseVersion) { this.releaseVersion = releaseVersion; } - public void setRsType(String rsType) { - this.rsType = rsType; - } public String getReleaseFolder() { return releaseFolder; @@ -96,25 +100,84 @@ public void setReleaseFolder(String releaseFolder) { this.releaseFolder = releaseFolder; } - public Long getCount() { - return count; + public Long getCurrentRs() { + return currentRs; } - public void setCount(Long count) { - this.count = count; + public void setCurrentRs(Long currentRs) { + this.currentRs = currentRs; + } + + public Long getNewMergedRs() { + return newMergedRs; } - public Long getNewAddition() { - return newAddition; + public void setNewMergedRs(Long newMergedRs) { + this.newMergedRs = newMergedRs; } - public void setNewAddition(Long newAddition) { - this.newAddition = newAddition; + public Long getMultimapRs() { + return multimapRs; } - @Override - public String getKey() { - return this.assemblyAccession + "_" + this.releaseVersion; + public void setMultimapRs(Long multimapRs) { + this.multimapRs = multimapRs; + } + + public Long getMergedRs() { + return mergedRs; + } + + public void setMergedRs(Long mergedRs) { + this.mergedRs = mergedRs; + } + + public Long getDeprecatedRs() { + return deprecatedRs; + } + + public void setDeprecatedRs(Long deprecatedRs) { + this.deprecatedRs = deprecatedRs; + } + + public Long getMergedDeprecatedRs() { + return mergedDeprecatedRs; + } + + public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { + this.mergedDeprecatedRs = mergedDeprecatedRs; + } + + public Long getNewCurrentRs() { + return newCurrentRs; + } + + public void setNewCurrentRs(Long newCurrentRs) { + this.newCurrentRs = newCurrentRs; + } + + public Long getNewMultimapRs() { + return newMultimapRs; + } + + public void setNewMultimapRs(Long newMultimapRs) { + this.newMultimapRs = newMultimapRs; + } + + public Long getNewDeprecatedRs() { + return newDeprecatedRs; + } + + public void setNewDeprecatedRs(Long newDeprecatedRs) { + this.newDeprecatedRs = newDeprecatedRs; + } + + public Long getNewMergedDeprecatedRs() { + return newMergedDeprecatedRs; + } + + public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { + this.newMergedDeprecatedRs = newMergedDeprecatedRs; } @Override @@ -123,23 +186,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; ReleaseStatsPerAssemblyV2 assembly = (ReleaseStatsPerAssemblyV2) o; return releaseVersion == assembly.releaseVersion && - Objects.equals(assemblyAccession, assembly.assemblyAccession) && - Objects.equals(rsType, assembly.rsType); + Objects.equals(assemblyAccession, assembly.assemblyAccession); } @Override public int hashCode() { - return Objects.hash(assemblyAccession, releaseVersion, rsType); + return Objects.hash(assemblyAccession, releaseVersion); } - @Override - public String toString() { - return "ReleaseStatsPerAssembly{" + - ", assemblyAccession='" + assemblyAccession + '\'' + - ", releaseVersion=" + releaseVersion + - ", rsType='" + rsType + '\'' + - ", count=" + count + - ", new=" + newAddition + - '}'; - } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java index ff7a9f6a..617550c8 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2PK.java @@ -26,8 +26,6 @@ public class ReleaseStatsPerAssemblyV2PK implements Serializable { private int releaseVersion; - private String rsType; - public ReleaseStatsPerAssemblyV2PK() { } @@ -47,27 +45,18 @@ public void setReleaseVersion(int releaseVersion) { this.releaseVersion = releaseVersion; } - public String getRsType() { - return rsType; - } - - public void setRsType(String rsType) { - this.rsType = rsType; - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ReleaseStatsPerAssemblyV2PK assembly = (ReleaseStatsPerAssemblyV2PK) o; return releaseVersion == assembly.releaseVersion && - Objects.equals(assemblyAccession, assembly.assemblyAccession) && - Objects.equals(rsType, assembly.rsType); + Objects.equals(assemblyAccession, assembly.assemblyAccession); } @Override public int hashCode() { - return Objects.hash(assemblyAccession, releaseVersion, rsType); + return Objects.hash(assemblyAccession, releaseVersion); } @Override @@ -75,7 +64,6 @@ public String toString() { return "ReleaseStatsPerAssembly{" + ", assemblyAccession='" + assemblyAccession + '\'' + ", releaseVersion=" + releaseVersion + - ", rsType='" + rsType + '\'' + '}'; } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java index 57696283..60daa722 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java @@ -24,7 +24,7 @@ @Entity @Table(name = "release_rs_count_per_taxonomy", schema="eva_stats") -public class ReleaseStatsPerTaxonomyV2 implements ReleaseStatsV2 { +public class ReleaseStatsPerTaxonomyV2 { @EmbeddedId ReleaseStatsPerTaxonomyV2PK releaseStatsPerTaxonomyV2Id; @@ -46,10 +46,29 @@ public class ReleaseStatsPerTaxonomyV2 implements ReleaseStatsV2 { private String releaseFolder; - private Long count; + private Long currentRs; - @Column(name="new") - protected Long newAddition; + private Long multimapRs; + + private Long mergedRs; + + private Long deprecatedRs; + + private Long mergedDeprecatedRs; + + private Long unmappedRs; + + private Long newCurrentRs; + + private Long newMultimapRs; + + private Long newMergedRs; + + private Long newDeprecatedRs; + + private Long newMergedDeprecatedRs; + + private Long newUnmappedRs; public ReleaseStatsPerTaxonomyV2() { @@ -67,10 +86,6 @@ public void setAssemblyAccessions(String[] assemblyAccessions) { this.assemblyAccessions = assemblyAccessions; } - public String getRsType() { - return releaseStatsPerTaxonomyV2Id.getRsType(); - } - public int getReleaseVersion() { return releaseStatsPerTaxonomyV2Id.getReleaseVersion(); } @@ -79,10 +94,6 @@ public void setReleaseVersion(int releaseVersion) { this.releaseStatsPerTaxonomyV2Id.setReleaseVersion(releaseVersion); } - public void setRsType(String rsType) { - releaseStatsPerTaxonomyV2Id.setRsType(rsType); - } - public String getReleaseFolder() { return releaseFolder; } @@ -92,27 +103,101 @@ public void setReleaseFolder(String releaseFolder) { } - public Long getCount() { - return count; + public Long getCurrentRs() { + return currentRs; } - public void setCount(Long count) { - this.count = count; + public void setCurrentRs(Long currentRs) { + this.currentRs = currentRs; } - public Long getNewAddition() { - return newAddition; + public Long getMultimapRs() { + return multimapRs; } - public void setNewAddition(Long newAddition) { - this.newAddition = newAddition; + public void setMultimapRs(Long multimapRs) { + this.multimapRs = multimapRs; } - @Override - public String getKey() { - return this.getTaxonomyId() + "_" + this.getReleaseVersion(); + public Long getMergedRs() { + return mergedRs; + } + + public void setMergedRs(Long mergedRs) { + this.mergedRs = mergedRs; + } + + public Long getDeprecatedRs() { + return deprecatedRs; + } + + public void setDeprecatedRs(Long deprecatedRs) { + this.deprecatedRs = deprecatedRs; + } + + public Long getMergedDeprecatedRs() { + return mergedDeprecatedRs; + } + + public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { + this.mergedDeprecatedRs = mergedDeprecatedRs; + } + + public Long getUnmappedRs() { + return unmappedRs; } + public void setUnmappedRs(Long unmappedRs) { + this.unmappedRs = unmappedRs; + } + + public Long getNewCurrentRs() { + return newCurrentRs; + } + + public void setNewCurrentRs(Long newCurrentRs) { + this.newCurrentRs = newCurrentRs; + } + + public Long getNewMultimapRs() { + return newMultimapRs; + } + + public void setNewMultimapRs(Long newMultimapRs) { + this.newMultimapRs = newMultimapRs; + } + + public Long getNewMergedRs() { + return newMergedRs; + } + + public void setNewMergedRs(Long newMergedRs) { + this.newMergedRs = newMergedRs; + } + + public Long getNewDeprecatedRs() { + return newDeprecatedRs; + } + + public void setNewDeprecatedRs(Long newDeprecatedRs) { + this.newDeprecatedRs = newDeprecatedRs; + } + + public Long getNewMergedDeprecatedRs() { + return newMergedDeprecatedRs; + } + + public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { + this.newMergedDeprecatedRs = newMergedDeprecatedRs; + } + + public Long getNewUnmappedRs() { + return newUnmappedRs; + } + + public void setNewUnmappedRs(Long newUnmappedRs) { + this.newUnmappedRs = newUnmappedRs; + } public String getScientificName() { if ( this.taxonomy != null) { @@ -136,23 +221,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; ReleaseStatsPerTaxonomyV2 other_taxonomy = (ReleaseStatsPerTaxonomyV2) o; return this.getReleaseVersion() == other_taxonomy.getReleaseVersion() && - Objects.equals(this.getTaxonomyId(), other_taxonomy.getTaxonomyId()) && - Objects.equals(this.getRsType(), other_taxonomy.getRsType()); + Objects.equals(this.getTaxonomyId(), other_taxonomy.getTaxonomyId()); } @Override public int hashCode() { - return Objects.hash(this.getTaxonomyId(), this.getReleaseVersion(), this.getRsType()); + return Objects.hash(this.getTaxonomyId(), this.getReleaseVersion()); } - @Override - public String toString() { - return "ReleaseStatsPerAssembly{" + - ", taxonomyId=" + this.getTaxonomyId() + - ", releaseVersion=" + this.getReleaseVersion() + - ", rsType='" + this.getRsType() + '\'' + - ", count=" + count + - ", new=" + newAddition + - '}'; - } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java index 44a8ffb1..3535fbb4 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2PK.java @@ -28,8 +28,6 @@ public class ReleaseStatsPerTaxonomyV2PK implements Serializable { private int releaseVersion; - private String rsType; - public ReleaseStatsPerTaxonomyV2PK() { } @@ -49,13 +47,6 @@ public void setReleaseVersion(int releaseVersion) { this.releaseVersion = releaseVersion; } - public String getRsType() { - return rsType; - } - - public void setRsType(String rsType) { - this.rsType = rsType; - } @Override public boolean equals(Object o) { @@ -63,13 +54,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; ReleaseStatsPerTaxonomyV2PK taxonomy = (ReleaseStatsPerTaxonomyV2PK) o; return releaseVersion == taxonomy.releaseVersion && - Objects.equals(taxonomyId, taxonomy.taxonomyId) && - Objects.equals(rsType, taxonomy.rsType); + Objects.equals(taxonomyId, taxonomy.taxonomyId); } @Override public int hashCode() { - return Objects.hash(taxonomyId, releaseVersion, rsType); + return Objects.hash(taxonomyId, releaseVersion); } @Override @@ -77,7 +67,6 @@ public String toString() { return "ReleaseStatsPerAssembly{" + ", taxonomyId=" + taxonomyId + ", releaseVersion=" + releaseVersion + - ", rsType='" + rsType + '\'' + '}'; } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java deleted file mode 100644 index 133b860c..00000000 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsV2.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022 EMBL - European Bioinformatics Institute - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package uk.ac.ebi.eva.release.models; - -public interface ReleaseStatsV2 { - - public String getRsType(); - - - public int getReleaseVersion(); - - public void setReleaseVersion(int releaseVersion); - - public void setRsType(String rsType); - public Long getCount(); - - public void setCount(Long count); - - public Long getNewAddition(); - - public void setNewAddition(Long newAddition); - - public abstract String getKey(); -} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyV2Repository.java similarity index 76% rename from eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java rename to eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyV2Repository.java index 6cde1ed5..dc8eb2fe 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyViewRepository.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerAssemblyV2Repository.java @@ -21,10 +21,12 @@ import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2PK; @Repository -public interface ReleaseStatsPerAssemblyViewRepository extends CrudRepository { Iterable findAllByReleaseVersion(int releaseVersion); + Iterable findByNewCurrentRsGreaterThan(long currentRs); + Iterable findByReleaseVersionAndNewCurrentRsGreaterThan(int releaseVersion, long currentRs); } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyV2Repository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyV2Repository.java new file mode 100644 index 00000000..6c06f2e3 --- /dev/null +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyV2Repository.java @@ -0,0 +1,42 @@ +/* + * Copyright 2020 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.ac.ebi.eva.release.repositories; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2PK; + +@Repository +public interface ReleaseStatsPerTaxonomyV2Repository extends CrudRepository { + + Iterable findAllByReleaseVersion(int releaseVersion); + + //All release data excluding rows with only unmapped data + Iterable findByCurrentRsNotAndMultimapRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan( + long currentRs, long MultimapRs, long mergedRs, long deprecatedRs, long mergedDeprecatedRs, + long unmappedRs); + + //Data by release version excluding rows with only unmapped data + Iterable findByReleaseVersionAndCurrentRsNotAndMultimapRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan( + int releaseVersion, long currentRs, long MultimapRs, long mergedRs, long deprecatedRs, + long mergedDeprecatedRs, long unmappedRs); + + Iterable findByNewCurrentRsGreaterThan(long currentRs); + + Iterable findByReleaseVersionAndNewCurrentRsGreaterThan(int releaseVersion, long currentRs); +} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java deleted file mode 100644 index 513a1453..00000000 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/repositories/ReleaseStatsPerTaxonomyViewRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 EMBL - European Bioinformatics Institute - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package uk.ac.ebi.eva.release.repositories; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2; -import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2PK; - -@Repository -public interface ReleaseStatsPerTaxonomyViewRepository extends CrudRepository { - - Iterable findAllByReleaseVersion(int releaseVersion); - - -} diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java index f9941559..5961610a 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java @@ -16,32 +16,30 @@ package uk.ac.ebi.eva.release.services; import org.springframework.stereotype.Service; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerAssemblyV2Dto; -import uk.ac.ebi.eva.release.dto.ReleaseStatsPerSpeciesV2Dto; -import uk.ac.ebi.eva.release.dto.ReleaseStatsV2Dto; +import uk.ac.ebi.eva.release.dto.*; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerAssemblyMapper; import uk.ac.ebi.eva.release.mappers.ReleaseStatsPerSpeciesMapper; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssembly; import uk.ac.ebi.eva.release.models.ReleaseStatsPerAssemblyV2; +import uk.ac.ebi.eva.release.models.ReleaseStatsPerSpecies; import uk.ac.ebi.eva.release.models.ReleaseStatsPerTaxonomyV2; -import uk.ac.ebi.eva.release.models.ReleaseStatsV2; -import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerAssemblyViewRepository; -import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerTaxonomyViewRepository; +import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerAssemblyV2Repository; +import uk.ac.ebi.eva.release.repositories.ReleaseStatsPerTaxonomyV2Repository; -import java.util.stream.Collectors; @Service public class ReleaseStatsServiceV2 { - private final ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository; + private final ReleaseStatsPerTaxonomyV2Repository releaseStatsPerTaxonomyRepository; - private final ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository; + private final ReleaseStatsPerAssemblyV2Repository releaseStatsPerAssemblyRepository; private final ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper; private final ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper; - public ReleaseStatsServiceV2(ReleaseStatsPerTaxonomyViewRepository releaseStatsPerTaxonomyRepository, - ReleaseStatsPerAssemblyViewRepository releaseStatsPerAssemblyRepository, + public ReleaseStatsServiceV2(ReleaseStatsPerTaxonomyV2Repository releaseStatsPerTaxonomyRepository, + ReleaseStatsPerAssemblyV2Repository releaseStatsPerAssemblyRepository, ReleaseStatsPerSpeciesMapper releaseStatsPerSpeciesMapper, ReleaseStatsPerAssemblyMapper releaseStatsPerAssemblyMapper) { this.releaseStatsPerTaxonomyRepository = releaseStatsPerTaxonomyRepository; @@ -50,20 +48,11 @@ public ReleaseStatsServiceV2(ReleaseStatsPerTaxonomyViewRepository releaseStatsP this.releaseStatsPerAssemblyMapper = releaseStatsPerAssemblyMapper; } - public Iterable getReleaseStatsPerSpecies(Integer releaseVersion, boolean excludeUnmappedOnly) { - Iterable releaseData; - if (releaseVersion != null) { - releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); - }else{ - releaseData = releaseStatsPerTaxonomyRepository.findAll(); - } - return populateAllTaxonomyDtoFrom(releaseData, excludeUnmappedOnly, false); - } public Iterable getReleaseStatsPerSpeciesWithNewRsIds(Integer releaseVersion){ Iterable releaseData; releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); - return populateAllTaxonomyDtoFrom(releaseData, false, true); + return this.releaseStatsPerSpeciesMapper.toDtoV2(releaseData); } @@ -74,72 +63,66 @@ public Iterable getReleaseStatsPerAssembly(Integer } else { releaseData = releaseStatsPerAssemblyRepository.findAll(); } - return populateAssemblyDtoFrom(releaseData, false, excludeNonNew); + return this.releaseStatsPerAssemblyMapper.toDtoV2(releaseData); } - private Iterable populateAllTaxonomyDtoFrom( - Iterable releaseData, - boolean excludeUnmappedOnly, - boolean excludeNonNew - ){ - return this.releaseStatsPerSpeciesMapper.toDtoV2(releaseData).stream() - .filter(excludeUnmappedOnly? this::isNotUnmappedOnly : s -> true) - .filter(excludeNonNew? this::isNonNew :s -> true) - .collect(Collectors.toList()); + public Iterable getReleaseStatsPerSpecies(Integer releaseVersion, + boolean excludeUnmappedOnly) { + Iterable releaseData; + if (releaseVersion != null) { + if (excludeUnmappedOnly) { + releaseData = getReleaseDataByVersionExcludingUnmappedOnly(releaseVersion); + } else { + releaseData = releaseStatsPerTaxonomyRepository.findAllByReleaseVersion(releaseVersion); + } + } else { + if (excludeUnmappedOnly) { + releaseData = getReleaseDataExcludingUnmappedOnly(); + } else { + releaseData = releaseStatsPerTaxonomyRepository.findAll(); + } + } + return releaseStatsPerSpeciesMapper.toDtoV2(releaseData); } - private Iterable populateAssemblyDtoFrom( - Iterable releaseData, - boolean excludeUnmappedOnly, - boolean excludeNonNew - ){ - return this.releaseStatsPerAssemblyMapper.toDtoV2(releaseData).stream() - .filter(excludeUnmappedOnly? this::isNotUnmappedOnly : s -> true) - .filter(excludeNonNew? this::isNonNew :s -> true) - .collect(Collectors.toList()); + private Iterable getReleaseDataByVersionExcludingUnmappedOnly(Integer releaseVersion) { + return releaseStatsPerTaxonomyRepository + .findByReleaseVersionAndCurrentRsNotAndMultimapRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan( + releaseVersion, 0, 0, 0, 0, 0, 0); + } + private Iterable getReleaseDataExcludingUnmappedOnly() { + return releaseStatsPerTaxonomyRepository + .findByCurrentRsNotAndMultimapRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan( + 0, 0, 0, 0, 0, 0); } - private boolean isNotUnmappedOnly(ReleaseStatsV2Dto dto){ - return dto.getCurrentRs() != 0 || - dto.getMergedRs() != 0 || - dto.getDeprecatedRs() != 0 || - dto.getMergedDeprecatedRs() !=0; + + public Iterable getSpeciesWithNewRsIds(Integer releaseVersion) { + if (releaseVersion != null) { + return releaseStatsPerSpeciesMapper.toDtoV2(releaseStatsPerTaxonomyRepository + .findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L)); + } else { + return releaseStatsPerSpeciesMapper.toDtoV2(releaseStatsPerTaxonomyRepository.findByNewCurrentRsGreaterThan(0L)); + } } - private boolean isNonNew(ReleaseStatsV2Dto dto){ - return dto.getNewCurrentRs() > 0 || - dto.getNewMergedRs() > 0 || - dto.getNewDeprecatedRs() > 0 || - dto.getNewMultiMappedRs() > 0 || - dto.getNewUnmappedRs() > 0; + + public Iterable getReleaseStatsPerAssembly(Integer releaseVersion) { + Iterable releaseData; + if (releaseVersion != null) { + releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); + } else { + releaseData = releaseStatsPerAssemblyRepository.findAll(); + } + return releaseStatsPerAssemblyMapper.toDtoV2(releaseData); } - private void populateDtoFromViewData(ReleaseStatsV2Dto dto, ReleaseStatsV2 viewData){ - dto.setReleaseVersion(viewData.getReleaseVersion()); - switch (viewData.getRsType()){ - case "current": - dto.setCurrentRs(viewData.getCount()); - dto.setNewCurrentRs(viewData.getNewAddition()); - break; - case "deprecated": - dto.setDeprecatedRs(viewData.getCount()); - dto.setNewDeprecatedRs(viewData.getNewAddition()); - break; - case "merged": - dto.setMergedRs(viewData.getCount()); - dto.setNewMergedRs(viewData.getNewAddition()); - break; - case "merged_deprecated": - dto.setMergedDeprecatedRs(viewData.getCount()); - dto.setNewMergedDeprecatedRs(viewData.getNewAddition()); - break; - case "multimap": - dto.setMultiMappedRs(viewData.getCount()); - dto.setNewMultiMappedRs(viewData.getNewAddition()); - break; - case "unmapped": - dto.setUnmappedRs(viewData.getCount()); - dto.setNewUnmappedRs(viewData.getNewAddition()); - break; + public Iterable getReleaseStatsPerAssemblyWithNewRsIds(Integer releaseVersion) { + if (releaseVersion != null) { + return releaseStatsPerAssemblyMapper.toDtoV2( + releaseStatsPerAssemblyRepository.findByReleaseVersionAndNewCurrentRsGreaterThan(releaseVersion, 0L)); + } else { + return releaseStatsPerAssemblyMapper.toDtoV2( + releaseStatsPerAssemblyRepository.findByNewCurrentRsGreaterThan(0L)); } } From 3c24d26d35ae295be415c5e4def3466a20b78939 Mon Sep 17 00:00:00 2001 From: tcezard Date: Mon, 25 Mar 2024 17:39:44 +0000 Subject: [PATCH 08/12] Fix endpoint with new RS --- .../controllers/ReleaseStatsV2Controller.java | 6 ++--- .../dto/ReleaseStatsPerSpeciesV2Dto.java | 6 ++--- .../eva/release/dto/ReleaseStatsV2Dto.java | 25 ++++++++++--------- .../services/ReleaseStatsServiceV2.java | 14 ++--------- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java index 2d178a8c..9bc306a8 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/controllers/ReleaseStatsV2Controller.java @@ -45,18 +45,18 @@ public Iterable getReleaseStatsPerSpecies( @GetMapping("/per-species/new") public Iterable getSpeciesWithNewRsIds( @RequestParam(name = "releaseVersion") Integer releaseVersion) { - return releaseStatsService.getReleaseStatsPerSpeciesWithNewRsIds(releaseVersion); + return releaseStatsService.getSpeciesWithNewRsIds(releaseVersion); } @GetMapping("/per-assembly") public Iterable getReleaseStatsPerAssemblies( @RequestParam(name = "releaseVersion", required = false) Integer releaseVersion) { - return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion, false); + return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion); } @GetMapping("/per-assembly/new") public Iterable getAssembliesWithNewRsIds( @RequestParam(name = "releaseVersion") Integer releaseVersion) { - return releaseStatsService.getReleaseStatsPerAssembly(releaseVersion, true); + return releaseStatsService.getReleaseStatsPerAssemblyWithNewRsIds(releaseVersion); } } diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java index cf56a393..bbeb8387 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsPerSpeciesV2Dto.java @@ -100,10 +100,8 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash(taxonomyId, releaseVersion, scientificName, releaseFolder, currentRs, multiMappedRs, - mergedRs, - deprecatedRs, mergedDeprecatedRs, unmappedRs, newCurrentRs, newMultiMappedRs, newMergedRs, - newDeprecatedRs, newMergedDeprecatedRs, newUnmappedRs, releaseLink, - taxonomyLink); + mergedRs, deprecatedRs, mergedDeprecatedRs, unmappedRs, newCurrentRs, newMultiMappedRs, newMergedRs, + newDeprecatedRs, newMergedDeprecatedRs, newUnmappedRs, releaseLink, taxonomyLink); } @Override diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java index 7c737213..5020ecf0 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java @@ -69,7 +69,7 @@ public void setReleaseFolder(String releaseFolder) { public Long getCurrentRs() { - if (currentRs == null){ + if (currentRs == null) { return new Long(0); } return currentRs; @@ -80,7 +80,7 @@ public void setCurrentRs(Long currentRs) { } public Long getMergedRs() { - if (mergedRs == null){ + if (mergedRs == null) { return new Long(0); } return mergedRs; @@ -91,7 +91,7 @@ public void setMergedRs(Long mergedRs) { } public Long getDeprecatedRs() { - if (deprecatedRs == null){ + if (deprecatedRs == null) { return new Long(0); } return deprecatedRs; @@ -102,7 +102,7 @@ public void setDeprecatedRs(Long deprecatedRs) { } public Long getMergedDeprecatedRs() { - if (mergedDeprecatedRs == null){ + if (mergedDeprecatedRs == null) { return new Long(0); } return mergedDeprecatedRs; @@ -113,7 +113,7 @@ public void setMergedDeprecatedRs(Long mergedDeprecatedRs) { } public Long getNewCurrentRs() { - if (newCurrentRs == null){ + if (newCurrentRs == null) { return new Long(0); } return newCurrentRs; @@ -124,7 +124,7 @@ public void setNewCurrentRs(Long newCurrentRs) { } public Long getNewMergedRs() { - if (newMergedRs == null){ + if (newMergedRs == null) { return new Long(0); } return newMergedRs; @@ -135,7 +135,7 @@ public void setNewMergedRs(Long newMergedRs) { } public Long getNewDeprecatedRs() { - if (newDeprecatedRs == null){ + if (newDeprecatedRs == null) { return new Long(0); } return newDeprecatedRs; @@ -146,7 +146,7 @@ public void setNewDeprecatedRs(Long newDeprecatedRs) { } public Long getNewMergedDeprecatedRs() { - if (newMergedDeprecatedRs == null){ + if (newMergedDeprecatedRs == null) { return new Long(0); } return newMergedDeprecatedRs; @@ -155,8 +155,9 @@ public Long getNewMergedDeprecatedRs() { public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { this.newMergedDeprecatedRs = newMergedDeprecatedRs; } + public Long getMultiMappedRs() { - if (multiMappedRs == null){ + if (multiMappedRs == null) { return new Long(0); } return multiMappedRs; @@ -167,7 +168,7 @@ public void setMultiMappedRs(Long multiMappedRs) { } public Long getNewMultiMappedRs() { - if (newMultiMappedRs == null){ + if (newMultiMappedRs == null) { return new Long(0); } return newMultiMappedRs; @@ -178,7 +179,7 @@ public void setNewMultiMappedRs(Long newMultiMappedRs) { } public Long getUnmappedRs() { - if (unmappedRs == null){ + if (unmappedRs == null) { return new Long(0); } return unmappedRs; @@ -189,7 +190,7 @@ public void setUnmappedRs(Long unmappedRs) { } public Long getNewUnmappedRs() { - if (newUnmappedRs == null){ + if (newUnmappedRs == null) { return new Long(0); } return newUnmappedRs; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java index 5961610a..2bba613f 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/services/ReleaseStatsServiceV2.java @@ -56,16 +56,6 @@ public Iterable getReleaseStatsPerSpeciesWithNewRsI } - public Iterable getReleaseStatsPerAssembly(Integer releaseVersion, boolean excludeNonNew) { - Iterable releaseData; - if (releaseVersion != null) { - releaseData = releaseStatsPerAssemblyRepository.findAllByReleaseVersion(releaseVersion); - } else { - releaseData = releaseStatsPerAssemblyRepository.findAll(); - } - return this.releaseStatsPerAssemblyMapper.toDtoV2(releaseData); - } - public Iterable getReleaseStatsPerSpecies(Integer releaseVersion, boolean excludeUnmappedOnly) { Iterable releaseData; @@ -77,7 +67,7 @@ public Iterable getReleaseStatsPerSpecies(Integer r } } else { if (excludeUnmappedOnly) { - releaseData = getReleaseDataExcludingUnmappedOnly(); + releaseData = getReleaseDataPerSpeciesExcludingUnmappedOnly(); } else { releaseData = releaseStatsPerTaxonomyRepository.findAll(); } @@ -91,7 +81,7 @@ private Iterable getReleaseDataByVersionExcludingUnma releaseVersion, 0, 0, 0, 0, 0, 0); } - private Iterable getReleaseDataExcludingUnmappedOnly() { + private Iterable getReleaseDataPerSpeciesExcludingUnmappedOnly() { return releaseStatsPerTaxonomyRepository .findByCurrentRsNotAndMultimapRsNotAndMergedRsNotAndDeprecatedRsNotAndMergedDeprecatedRsNotAndUnmappedRsGreaterThan( 0, 0, 0, 0, 0, 0); From a2da081bd9cfc9e7214f4947adffea69e612c256 Mon Sep 17 00:00:00 2001 From: Timothee Cezard Date: Wed, 27 Mar 2024 10:47:04 +0000 Subject: [PATCH 09/12] Apply suggestions from code review Co-authored-by: nitin-ebi <79518737+nitin-ebi@users.noreply.github.com> Co-authored-by: April Shen --- eva-release/pom.xml | 5 +---- .../java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java | 2 +- .../eva/release/mappers/ReleaseStatsPerAssemblyMapper.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/eva-release/pom.xml b/eva-release/pom.xml index a6a942cf..51c2cdf3 100644 --- a/eva-release/pom.xml +++ b/eva-release/pom.xml @@ -55,10 +55,7 @@ springfox-swagger2 compile - - io.hypersistence - hypersistence-utils-hibernate-52 - + diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java index 5020ecf0..8efdac55 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/dto/ReleaseStatsV2Dto.java @@ -15,7 +15,7 @@ */ package uk.ac.ebi.eva.release.dto; -public abstract class ReleaseStatsV2Dto { +public class ReleaseStatsV2Dto { protected int releaseVersion; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java index 130be34b..8e24d161 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java @@ -51,7 +51,7 @@ public Iterable toDtoV2(Iterable keyToDto= new HashMap<>(); ReleaseStatsPerAssemblyV2Dto dto = new ReleaseStatsPerAssemblyV2Dto(); dto.setAssemblyAccession(assemblyData.getAssemblyAccession()); From 59f9dc05d6b94b539cbea89a0f808b582bec6bb7 Mon Sep 17 00:00:00 2001 From: tcezard Date: Wed, 27 Mar 2024 10:48:24 +0000 Subject: [PATCH 10/12] Update the application.properties to ensure the Table will not get modified --- eva-release/src/main/resources/application.properties | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eva-release/src/main/resources/application.properties b/eva-release/src/main/resources/application.properties index 1ff70901..575ebd94 100644 --- a/eva-release/src/main/resources/application.properties +++ b/eva-release/src/main/resources/application.properties @@ -3,7 +3,10 @@ spring.datasource.url=|eva.evapro.jdbc.url|?currentSchema=|eva.evapro.eva-stats. spring.datasource.username=|eva.evapro.user| spring.datasource.password=|eva.evapro.password| +# Make the model read-only and prevent any modification spring.jpa.generate-ddl=false +# Disable automatic schema generation +spring.jpa.hibernate.ddl-auto=none spring.data.rest.base-path=/v1/ management.endpoints.web.exposure.include=info,health @@ -18,4 +21,4 @@ spring.jmx.default-domain=eva.ebi.ac.uk.evarelease.|timestamp| # Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details. spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false # Because detection is disabled you have to set correct dialect by hand. -spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect \ No newline at end of file +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect From cadf7d9cb0fafe053b568b30923308df6a59006c Mon Sep 17 00:00:00 2001 From: tcezard Date: Wed, 27 Mar 2024 11:42:45 +0000 Subject: [PATCH 11/12] Use EmbeddedId in ReleaseStatsPerAssemblyV2 --- eva-release/pom.xml | 5 +++- .../models/ReleaseStatsPerAssemblyV2.java | 30 ++++++++----------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/eva-release/pom.xml b/eva-release/pom.xml index 51c2cdf3..a6a942cf 100644 --- a/eva-release/pom.xml +++ b/eva-release/pom.xml @@ -55,7 +55,10 @@ springfox-swagger2 compile - + + io.hypersistence + hypersistence-utils-hibernate-52 + diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java index 69663050..1cc0d2e2 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java @@ -15,23 +15,21 @@ */ package uk.ac.ebi.eva.release.models; -import io.hypersistence.utils.hibernate.type.array.IntArrayType; -import io.hypersistence.utils.hibernate.type.array.ListArrayType; import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; import javax.persistence.*; import java.util.Objects; @Entity -@IdClass(ReleaseStatsPerAssemblyV2PK.class) @Table(name = "release_rs_count_per_assembly", schema="eva_stats") public class ReleaseStatsPerAssemblyV2 { - @Id + + @EmbeddedId + ReleaseStatsPerAssemblyV2PK releaseStatsPerAssemblyV2Id; + + @Column(insertable = false, updatable = false) private int releaseVersion; - @Id - private String assemblyAccession; @Type(type = "int-array") @Column( @@ -74,21 +72,19 @@ public void setTaxonomyIds(int[] taxonomyIds) { } public String getAssemblyAccession() { - return assemblyAccession; + return releaseStatsPerAssemblyV2Id.getAssemblyAccession(); } public void setAssemblyAccession(String assemblyAccession) { - this.assemblyAccession = assemblyAccession; + releaseStatsPerAssemblyV2Id.setAssemblyAccession(assemblyAccession); } - - public int getReleaseVersion() { - return releaseVersion; + return releaseStatsPerAssemblyV2Id.getReleaseVersion(); } public void setReleaseVersion(int releaseVersion) { - this.releaseVersion = releaseVersion; + releaseStatsPerAssemblyV2Id.setReleaseVersion(releaseVersion); } @@ -107,7 +103,7 @@ public Long getCurrentRs() { public void setCurrentRs(Long currentRs) { this.currentRs = currentRs; } - + public Long getNewMergedRs() { return newMergedRs; } @@ -185,13 +181,13 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ReleaseStatsPerAssemblyV2 assembly = (ReleaseStatsPerAssemblyV2) o; - return releaseVersion == assembly.releaseVersion && - Objects.equals(assemblyAccession, assembly.assemblyAccession); + return this.getReleaseVersion() == assembly.getReleaseVersion() && + Objects.equals(this.getAssemblyAccession(), assembly.getAssemblyAccession()); } @Override public int hashCode() { - return Objects.hash(assemblyAccession, releaseVersion); + return Objects.hash(this.getAssemblyAccession(), this.getReleaseVersion()); } } From 15c60e293123fc498aaa8d1c4b9afa8b21bee90a Mon Sep 17 00:00:00 2001 From: tcezard Date: Wed, 27 Mar 2024 17:28:06 +0000 Subject: [PATCH 12/12] Provide releaseLink via join on the database --- .../mappers/ReleaseStatsPerAssemblyMapper.java | 7 +------ .../mappers/ReleaseStatsPerSpeciesMapper.java | 9 +-------- .../release/models/ReleaseStatsPerAssemblyV2.java | 13 +++++++++++++ .../release/models/ReleaseStatsPerTaxonomyV2.java | 12 ++++++++++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java index 8e24d161..458b593b 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerAssemblyMapper.java @@ -34,13 +34,10 @@ public class ReleaseStatsPerAssemblyMapper { private static final String TAXONOMY_URL = "https://www.ebi.ac.uk/ena/browser/view/Taxon:"; - private final Map releaseLinkMap; - private final ReleaseStatsMapperUtils releaseStatMapperUtils; public ReleaseStatsPerAssemblyMapper(ReleaseInfoRepository releaseInfoRepository) { this.releaseStatMapperUtils = new ReleaseStatsMapperUtils(releaseInfoRepository); - this.releaseLinkMap = this.releaseStatMapperUtils.getReleasesFtp(); } public Iterable toDtoV2(Iterable releaseData){ @@ -57,9 +54,7 @@ private ReleaseStatsPerAssemblyV2Dto toDtoV2(ReleaseStatsPerAssemblyV2 assemblyD dto.setAssemblyAccession(assemblyData.getAssemblyAccession()); dto.setReleaseVersion(assemblyData.getReleaseVersion()); dto.setReleaseFolder(assemblyData.getReleaseFolder()); - String releaseLink = this.releaseLinkMap.get(assemblyData.getReleaseVersion()) + ASSEMBLY_DIRECTORY + - assemblyData.getAssemblyAccession(); - dto.setReleaseLink(releaseLink); + dto.setReleaseLink(assemblyData.getReleaseLink()); dto.setTaxonomyIds(assemblyData.getTaxonomyIds()); String[] taxonomyLinks = Arrays.stream(assemblyData.getTaxonomyIds()) .mapToObj(String::valueOf).map(t -> TAXONOMY_URL + t).toArray(String[]::new); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java index c967b879..b2010e48 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/mappers/ReleaseStatsPerSpeciesMapper.java @@ -32,14 +32,10 @@ public class ReleaseStatsPerSpeciesMapper { private static final String TAXONOMY_URL = "https://www.ebi.ac.uk/ena/browser/view/Taxon:"; - - private final Map releaseLinkMap; - private final ReleaseStatsMapperUtils releaseStatMapperUtils; public ReleaseStatsPerSpeciesMapper(ReleaseInfoRepository releaseInfoRepository) { this.releaseStatMapperUtils = new ReleaseStatsMapperUtils(releaseInfoRepository); - this.releaseLinkMap = this.releaseStatMapperUtils.getReleasesFtp(); } public Iterable toDtoV2(Iterable releaseData){ @@ -58,11 +54,8 @@ public ReleaseStatsPerSpeciesV2Dto toDtoV2(ReleaseStatsPerTaxonomyV2 taxonomyDat dto.setScientificName(taxonomyData.getScientificName()); dto.setCommonName(taxonomyData.getCommonName()); dto.setReleaseFolder(taxonomyData.getReleaseFolder()); - String releaseLink = this.releaseLinkMap.get(taxonomyData.getReleaseVersion()) + SPECIES_DIRECTORY + - taxonomyData.getReleaseFolder(); - dto.setReleaseLink(releaseLink); + dto.setReleaseLink(taxonomyData.getReleaseLink()); dto.setAssemblyAccessions(taxonomyData.getAssemblyAccessions()); - dto.setCurrentRs(taxonomyData.getCurrentRs()); dto.setMultiMappedRs(taxonomyData.getMultimapRs()); dto.setMergedRs(taxonomyData.getMergedRs()); diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java index 1cc0d2e2..cda40573 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerAssemblyV2.java @@ -15,6 +15,8 @@ */ package uk.ac.ebi.eva.release.models; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.Type; import javax.persistence.*; @@ -24,13 +26,20 @@ @Table(name = "release_rs_count_per_assembly", schema="eva_stats") public class ReleaseStatsPerAssemblyV2 { + private static final String ASSEMBLY_DIRECTORY = "by_assembly/"; @EmbeddedId ReleaseStatsPerAssemblyV2PK releaseStatsPerAssemblyV2Id; + @Column(insertable = false, updatable = false) private int releaseVersion; + @ManyToOne + @JoinColumn(name="releaseVersion", insertable = false, updatable = false) + @NotFound(action= NotFoundAction.IGNORE) + private ReleaseInfo releaseInfo; + @Type(type = "int-array") @Column( name = "taxonomy_ids", @@ -176,6 +185,10 @@ public void setNewMergedDeprecatedRs(Long newMergedDeprecatedRs) { this.newMergedDeprecatedRs = newMergedDeprecatedRs; } + public String getReleaseLink() { + return this.releaseInfo.getReleaseFtp() + ASSEMBLY_DIRECTORY + this.getReleaseFolder(); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java index 60daa722..7dd82433 100644 --- a/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java +++ b/eva-release/src/main/java/uk/ac/ebi/eva/release/models/ReleaseStatsPerTaxonomyV2.java @@ -22,10 +22,13 @@ import javax.persistence.*; import java.util.Objects; + @Entity @Table(name = "release_rs_count_per_taxonomy", schema="eva_stats") public class ReleaseStatsPerTaxonomyV2 { + private static final String SPECIES_DIRECTORY = "by_species/"; + @EmbeddedId ReleaseStatsPerTaxonomyV2PK releaseStatsPerTaxonomyV2Id; @@ -33,6 +36,11 @@ public class ReleaseStatsPerTaxonomyV2 { private int releaseVersion; @ManyToOne + @JoinColumn(name="releaseVersion", insertable = false, updatable = false) + @NotFound(action=NotFoundAction.IGNORE) + private ReleaseInfo releaseInfo; + + @ManyToOne() @JoinColumn(name="taxonomyId", insertable = false, updatable = false) @NotFound(action=NotFoundAction.IGNORE) private Taxonomy taxonomy; @@ -215,6 +223,10 @@ public String getCommonName() { } } + public String getReleaseLink() { + return this.releaseInfo.getReleaseFtp() + SPECIES_DIRECTORY + this.getReleaseFolder(); + } + @Override public boolean equals(Object o) { if (this == o) return true;