From a2b1f680abc60980d43906577f1dd2b64acfa725 Mon Sep 17 00:00:00 2001 From: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:52:25 -0400 Subject: [PATCH 1/2] Eliminating enum FileTypes from the code base --- .../song/server/model/entity/FileEntity.java | 5 -- .../resources/schemas/fileUpdateRequest.json | 13 +---- .../song/server/constants/ConstantsTest.java | 53 ------------------- .../server/service/DeserializationTest.java | 3 +- .../song/server/service/EntityTest.java | 9 ++-- .../song/server/service/FileServiceTest.java | 3 +- .../server/service/PublishAnalysisTest.java | 10 ++-- 7 files changed, 10 insertions(+), 86 deletions(-) diff --git a/song-server/src/main/java/bio/overture/song/server/model/entity/FileEntity.java b/song-server/src/main/java/bio/overture/song/server/model/entity/FileEntity.java index 5ae7c3a98..8948fe4c5 100644 --- a/song-server/src/main/java/bio/overture/song/server/model/entity/FileEntity.java +++ b/song-server/src/main/java/bio/overture/song/server/model/entity/FileEntity.java @@ -21,7 +21,6 @@ import bio.overture.song.core.model.FileData; import bio.overture.song.core.model.Metadata; import bio.overture.song.core.model.enums.AccessTypes; -import bio.overture.song.core.model.enums.FileTypes; import bio.overture.song.server.model.enums.TableAttributeNames; import bio.overture.song.server.model.enums.TableNames; import com.fasterxml.jackson.annotation.JsonInclude; @@ -81,10 +80,6 @@ public void setFileType(@NonNull String fileType) { this.fileType = fileType; } - public void setFileType(@NonNull FileTypes type) { - this.fileType = type.toString(); - } - public void setFileAccess(@NonNull String fileAccess) { this.fileAccess = fileAccess; } diff --git a/song-server/src/main/resources/schemas/fileUpdateRequest.json b/song-server/src/main/resources/schemas/fileUpdateRequest.json index 7e6b390a3..8b65abdcf 100644 --- a/song-server/src/main/resources/schemas/fileUpdateRequest.json +++ b/song-server/src/main/resources/schemas/fileUpdateRequest.json @@ -52,18 +52,7 @@ "pattern": "^[A-Za-z0-9_\\.\\-\\[\\]\\(\\)]+$" }, "fileType": { - "type": "string", - "enum": [ - "FASTA", - "FAI", - "FASTQ", - "BAM", - "BAI", - "VCF", - "TBI", - "IDX", - "XML" - ] + "type": "string" } } } diff --git a/song-server/src/test/java/bio/overture/song/server/constants/ConstantsTest.java b/song-server/src/test/java/bio/overture/song/server/constants/ConstantsTest.java index 122167ae8..53581e4eb 100644 --- a/song-server/src/test/java/bio/overture/song/server/constants/ConstantsTest.java +++ b/song-server/src/test/java/bio/overture/song/server/constants/ConstantsTest.java @@ -23,18 +23,6 @@ import static bio.overture.song.core.model.enums.AnalysisStates.PUBLISHED; import static bio.overture.song.core.model.enums.AnalysisStates.SUPPRESSED; import static bio.overture.song.core.model.enums.AnalysisStates.UNPUBLISHED; -import static bio.overture.song.core.model.enums.FileTypes.BAI; -import static bio.overture.song.core.model.enums.FileTypes.BAM; -import static bio.overture.song.core.model.enums.FileTypes.FAI; -import static bio.overture.song.core.model.enums.FileTypes.FASTA; -import static bio.overture.song.core.model.enums.FileTypes.FASTQ; -import static bio.overture.song.core.model.enums.FileTypes.IDX; -import static bio.overture.song.core.model.enums.FileTypes.TBI; -import static bio.overture.song.core.model.enums.FileTypes.TGZ; -import static bio.overture.song.core.model.enums.FileTypes.VCF; -import static bio.overture.song.core.model.enums.FileTypes.XML; -import static bio.overture.song.core.model.enums.FileTypes.resolveFileType; -import static bio.overture.song.core.model.enums.FileTypes.values; import static bio.overture.song.core.testing.SongErrorAssertions.assertExceptionThrownBy; import static bio.overture.song.server.model.enums.InfoSearchResponseColumns.ANALYSIS_ID; import static bio.overture.song.server.model.enums.InfoSearchResponseColumns.INFO; @@ -91,47 +79,6 @@ public void testAccessTypes() { IllegalStateException.class, () -> resolveAccessType("somethingNotAccessType")); } - @Test - public void testFileTypes() { - assertEquals(FASTA.toString(), "FASTA"); - assertEquals(FAI.toString(), "FAI"); - assertEquals(FASTQ.toString(), "FASTQ"); - assertEquals(BAM.toString(), "BAM"); - assertEquals(BAI.toString(), "BAI"); - assertEquals(VCF.toString(), "VCF"); - assertEquals(TBI.toString(), "TBI"); - assertEquals(IDX.toString(), "IDX"); - assertEquals(XML.toString(), "XML"); - assertEquals(TGZ.toString(), "TGZ"); - - assertEquals(FASTA.getExtension(), "fasta"); - assertEquals(FAI.getExtension(), "fai"); - assertEquals(FASTQ.getExtension(), "fastq"); - assertEquals(BAM.getExtension(), "bam"); - assertEquals(BAI.getExtension(), "bai"); - assertEquals(VCF.getExtension(), "vcf"); - assertEquals(TBI.getExtension(), "tbi"); - assertEquals(IDX.getExtension(), "idx"); - assertEquals(XML.getExtension(), "xml"); - assertEquals(TGZ.getExtension(), "tgz"); - - assertEquals(values().length, 10); - - assertEquals(resolveFileType("FASTA"), FASTA); - assertEquals(resolveFileType("FAI"), FAI); - assertEquals(resolveFileType("FASTQ"), FASTQ); - assertEquals(resolveFileType("BAM"), BAM); - assertEquals(resolveFileType("BAI"), BAI); - assertEquals(resolveFileType("VCF"), VCF); - assertEquals(resolveFileType("TBI"), TBI); - assertEquals(resolveFileType("IDX"), IDX); - assertEquals(resolveFileType("XML"), XML); - assertEquals(resolveFileType("TGZ"), TGZ); - - assertExceptionThrownBy( - IllegalStateException.class, () -> resolveFileType("somethingThatsNotAFileType")); - } - @Test public void testInfoTypes() { assertEquals(STUDY.toString(), "Study"); diff --git a/song-server/src/test/java/bio/overture/song/server/service/DeserializationTest.java b/song-server/src/test/java/bio/overture/song/server/service/DeserializationTest.java index 0042c9f6a..ee2ebb480 100644 --- a/song-server/src/test/java/bio/overture/song/server/service/DeserializationTest.java +++ b/song-server/src/test/java/bio/overture/song/server/service/DeserializationTest.java @@ -18,7 +18,6 @@ package bio.overture.song.server.service; import static bio.overture.song.core.model.enums.AnalysisStates.UNPUBLISHED; -import static bio.overture.song.core.model.enums.FileTypes.BAM; import static bio.overture.song.core.utils.JsonUtils.fromJson; import static bio.overture.song.core.utils.JsonUtils.objectToTree; import static bio.overture.song.core.utils.JsonUtils.readTree; @@ -123,7 +122,7 @@ public void nonEmptyInfoFields_allEmpty_success() { .objectId("sfdsdfsdf") .studyId("ABC123") .fileName("something.bam") - .fileType(BAM.toString()) + .fileType("BAM") .build(); val fileList = List.of(f1); val fff = new ObjectMapper().valueToTree(f1); diff --git a/song-server/src/test/java/bio/overture/song/server/service/EntityTest.java b/song-server/src/test/java/bio/overture/song/server/service/EntityTest.java index ff18536c4..95a1248c6 100644 --- a/song-server/src/test/java/bio/overture/song/server/service/EntityTest.java +++ b/song-server/src/test/java/bio/overture/song/server/service/EntityTest.java @@ -29,8 +29,6 @@ import static bio.overture.song.server.utils.TestConstants.TUMOUR_NORMAL_DESIGNATION; import static bio.overture.song.server.utils.TestFiles.assertInfoKVPair; import static com.google.common.collect.Lists.newArrayList; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.toList; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -38,7 +36,6 @@ import static org.junit.Assert.assertTrue; import bio.overture.song.core.model.Metadata; -import bio.overture.song.core.model.enums.FileTypes; import bio.overture.song.server.model.Upload; import bio.overture.song.server.model.entity.Donor; import bio.overture.song.server.model.entity.FileEntity; @@ -53,6 +50,7 @@ import bio.overture.song.server.model.legacy.LegacyEntity; import com.fasterxml.jackson.databind.JsonNode; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import lombok.val; import org.junit.Test; @@ -60,8 +58,7 @@ public class EntityTest { private static final String DEFAULT_STUDY_ID = "ABC123"; private static final List SAMPLE_TYPES = newArrayList(SAMPLE_TYPE); - private static final List FILE_TYPES = - stream(FileTypes.values()).map(FileTypes::toString).collect(toList()); + private static final List FILE_TYPES = Arrays.asList("mp3", "mp4", "BAM"); @Test public void testNullMetadata() { @@ -634,7 +631,7 @@ public void testFile() { file1.setFileMd5sum("b1"); file1.setFileName("c1"); file1.setFileSize(13L); - file1.setFileType(FILE_TYPES.get(0)); + file1.setFileType("mp4"); file1.setObjectId("d1"); file1.setStudyId("e1"); diff --git a/song-server/src/test/java/bio/overture/song/server/service/FileServiceTest.java b/song-server/src/test/java/bio/overture/song/server/service/FileServiceTest.java index 81b9557c5..4803ab5fa 100644 --- a/song-server/src/test/java/bio/overture/song/server/service/FileServiceTest.java +++ b/song-server/src/test/java/bio/overture/song/server/service/FileServiceTest.java @@ -20,7 +20,6 @@ import static bio.overture.song.core.exceptions.ServerErrors.STUDY_ID_DOES_NOT_EXIST; import static bio.overture.song.core.model.enums.AccessTypes.CONTROLLED; import static bio.overture.song.core.model.enums.AccessTypes.OPEN; -import static bio.overture.song.core.model.enums.FileTypes.FAI; import static bio.overture.song.core.testing.SongErrorAssertions.assertSongError; import static bio.overture.song.core.utils.RandomGenerator.createRandomGenerator; import static bio.overture.song.server.utils.TestConstants.DEFAULT_ANALYSIS_ID; @@ -109,7 +108,7 @@ public void testCreateAndDeleteFile() { f.setFileSize(0L); f.setDataType(randomGenerator.generateRandomAsciiString(10)); - f.setFileType(FAI); + f.setFileType("FAI"); f.setFileMd5sum("6bb8ee7218e96a59e0ad898b4f5360f1"); f.setInfo(metadata); f.setFileAccess(OPEN); diff --git a/song-server/src/test/java/bio/overture/song/server/service/PublishAnalysisTest.java b/song-server/src/test/java/bio/overture/song/server/service/PublishAnalysisTest.java index 2061d8b46..5f08b64c5 100644 --- a/song-server/src/test/java/bio/overture/song/server/service/PublishAnalysisTest.java +++ b/song-server/src/test/java/bio/overture/song/server/service/PublishAnalysisTest.java @@ -22,8 +22,6 @@ import static bio.overture.song.core.exceptions.ServerErrors.MISSING_STORAGE_OBJECTS; import static bio.overture.song.core.model.enums.AnalysisStates.PUBLISHED; import static bio.overture.song.core.model.enums.AnalysisStates.UNPUBLISHED; -import static bio.overture.song.core.model.enums.FileTypes.BAM; -import static bio.overture.song.core.model.enums.FileTypes.VCF; import static bio.overture.song.core.utils.RandomGenerator.createRandomGenerator; import static bio.overture.song.core.utils.RandomGenerator.randomList; import static bio.overture.song.server.service.PublishAnalysisTest.RangeType.ALL; @@ -356,11 +354,11 @@ public FileEntity generateFile(Analysis a) { String fileName = randomGenerator.generateRandomUUIDAsString() + "."; if (legacyAnalysisTypeName == LegacyAnalysisTypeName.SEQUENCING_READ) { - fileType = BAM.toString(); - fileName += BAM.getExtension(); + fileType = "BAM"; + fileName += "BAM"; } else if (legacyAnalysisTypeName == LegacyAnalysisTypeName.VARIANT_CALL) { - fileType = VCF.toString(); - fileName += VCF.getExtension() + ".gz"; + fileType = "VCF"; + fileName += "VCF" + ".gz"; } val file = FileEntity.builder() From 40fbe84e71459186377fe54fe88fdb4de2193942 Mon Sep 17 00:00:00 2001 From: Azher2Ali <121898125+Azher2Ali@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:07:40 -0400 Subject: [PATCH 2/2] Removing FileTypes and it's following reference --- .../song/core/model/enums/FileTypes.java | 56 ------------------- .../securestudy/impl/SecureFileTester.java | 3 +- 2 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 song-core/src/main/java/bio/overture/song/core/model/enums/FileTypes.java diff --git a/song-core/src/main/java/bio/overture/song/core/model/enums/FileTypes.java b/song-core/src/main/java/bio/overture/song/core/model/enums/FileTypes.java deleted file mode 100644 index 61c7e7efb..000000000 --- a/song-core/src/main/java/bio/overture/song/core/model/enums/FileTypes.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018. Ontario Institute for Cancer Research - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package bio.overture.song.core.model.enums; - -import static bio.overture.song.core.utils.Streams.stream; -import static java.lang.String.format; - -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public enum FileTypes { - FASTA("fasta"), - FAI("fai"), - FASTQ("fastq"), - BAM("bam"), - BAI("bai"), - VCF("vcf"), - TBI("tbi"), - IDX("idx"), - XML("xml"), - TGZ("tgz"); - - @Getter private final String extension; - - public static FileTypes resolveFileType(@NonNull String fileType) { - return stream(values()) - .filter(x -> x.toString().equals(fileType)) - .findFirst() - .orElseThrow( - () -> - new IllegalStateException( - format("The file type '%s' cannot be resolved", fileType))); - } - - @Override - public String toString() { - return this.name(); - } -} diff --git a/song-server/src/test/java/bio/overture/song/server/utils/securestudy/impl/SecureFileTester.java b/song-server/src/test/java/bio/overture/song/server/utils/securestudy/impl/SecureFileTester.java index 545db6f85..a39d5567f 100644 --- a/song-server/src/test/java/bio/overture/song/server/utils/securestudy/impl/SecureFileTester.java +++ b/song-server/src/test/java/bio/overture/song/server/utils/securestudy/impl/SecureFileTester.java @@ -21,7 +21,6 @@ import static java.lang.String.format; import bio.overture.song.core.model.enums.AccessTypes; -import bio.overture.song.core.model.enums.FileTypes; import bio.overture.song.core.utils.RandomGenerator; import bio.overture.song.server.model.entity.FileEntity; import bio.overture.song.server.service.FileService; @@ -64,7 +63,7 @@ protected String createId(String existingStudyId, Object context) { analysisService.checkAnalysisExists(analysisData.getExistingId()); val existingAnalysisId = analysisData.getExistingId(); - val type = getRandomGenerator().randomEnum(FileTypes.class).toString(); + val type = "mp4"; val file = FileEntity.builder() .fileAccess(getRandomGenerator().randomEnum(AccessTypes.class).toString())