From c4e901078571b95ac42480b702dcd59b3f40ed86 Mon Sep 17 00:00:00 2001 From: LeonardoGonzales Date: Tue, 23 Apr 2024 11:38:43 +0100 Subject: [PATCH] TRM-27505: Add reason for entry deletion --- .../uniprot/core/uniprotkb/DeletedReason.java | 48 +++++++++++++++++++ .../core/uniprotkb/EntryInactiveReason.java | 2 + .../impl/EntryInactiveReasonBuilder.java | 13 ++++- .../impl/EntryInactiveReasonImpl.java | 12 ++++- .../core/uniprotkb/DeletedReasonTest.java | 36 ++++++++++++++ .../impl/EntryInactiveReasonBuilderTest.java | 11 +++++ .../impl/EntryInactiveReasonImplTest.java | 4 ++ .../json/parser/uniprot/UniProtKBEntryIT.java | 3 +- 8 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 core-domain/src/main/java/org/uniprot/core/uniprotkb/DeletedReason.java create mode 100644 core-domain/src/test/java/org/uniprot/core/uniprotkb/DeletedReasonTest.java diff --git a/core-domain/src/main/java/org/uniprot/core/uniprotkb/DeletedReason.java b/core-domain/src/main/java/org/uniprot/core/uniprotkb/DeletedReason.java new file mode 100644 index 000000000..c75e35e9f --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniprotkb/DeletedReason.java @@ -0,0 +1,48 @@ +package org.uniprot.core.uniprotkb; + +import org.uniprot.core.util.EnumDisplay; + +import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.List; + +public enum DeletedReason implements EnumDisplay { + + UNKNOWN( "Unknown reason", 0, 4, 5, 7, 9, 12), + SOURCE_DELETION( "Sequence source deletion", 1, 6, 8, 11), + SWISSPROT_DELETION( "SwissProt deletion", 2), + REDUNDANCY( "Sequence redundancy", 3), + ENTRY_TYPE_CHANGE( "Entry type change", 10), + PROTEOME_REDUNDANCY( "Proteome Redundancy", 13), + PROTEOME_EXCLUSION( "Proteome Exclusion", 14), + OVERREPRESENTED( "Overrepresented sequence", 15); + + private final List ids; + private final String description; + + DeletedReason(String description,Integer ... id) { + this.ids = Arrays.asList(id); + this.description = description; + } + + @Nonnull + @Override + public String getName() { + return description; + } + + public List getIds() { + return ids; + } + + public static DeletedReason fromId(String id) { + try { + return Arrays.stream(DeletedReason.values()) + .filter(reason -> reason.getIds().contains(Integer.parseInt(id))) + .findFirst() + .orElseThrow(); + } catch (Exception e) { + throw new IllegalArgumentException("The DeletedReason id '" + id + "' doesn't exist."); + } + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniprotkb/EntryInactiveReason.java b/core-domain/src/main/java/org/uniprot/core/uniprotkb/EntryInactiveReason.java index 380395e0b..0e02906be 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniprotkb/EntryInactiveReason.java +++ b/core-domain/src/main/java/org/uniprot/core/uniprotkb/EntryInactiveReason.java @@ -7,4 +7,6 @@ public interface EntryInactiveReason extends Serializable { InactiveReasonType getInactiveReasonType(); List getMergeDemergeTos(); + + DeletedReason getDeletedReason(); } diff --git a/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilder.java index e0807fac3..a3bac5f9b 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilder.java +++ b/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilder.java @@ -8,6 +8,7 @@ import javax.annotation.Nonnull; import org.uniprot.core.Builder; +import org.uniprot.core.uniprotkb.DeletedReason; import org.uniprot.core.uniprotkb.EntryInactiveReason; import org.uniprot.core.uniprotkb.InactiveReasonType; import org.uniprot.core.util.Utils; @@ -17,11 +18,18 @@ public class EntryInactiveReasonBuilder implements Builder private InactiveReasonType inactiveReasonType; private List mergeDemergeTos = new ArrayList<>(); + private DeletedReason deletedReason; + public @Nonnull EntryInactiveReasonBuilder type(InactiveReasonType inactiveReasonType) { this.inactiveReasonType = inactiveReasonType; return this; } + public @Nonnull EntryInactiveReasonBuilder deletedReason(DeletedReason deletedReason) { + this.deletedReason = deletedReason; + return this; + } + public @Nonnull EntryInactiveReasonBuilder mergeDemergeTosSet(List mergeDemergeTo) { this.mergeDemergeTos = modifiableList(mergeDemergeTo); return this; @@ -34,12 +42,13 @@ public class EntryInactiveReasonBuilder implements Builder @Override public @Nonnull EntryInactiveReason build() { - return new EntryInactiveReasonImpl(inactiveReasonType, mergeDemergeTos); + return new EntryInactiveReasonImpl(inactiveReasonType, mergeDemergeTos, deletedReason); } public static @Nonnull EntryInactiveReasonBuilder from(@Nonnull EntryInactiveReason instance) { return new EntryInactiveReasonBuilder() .type(instance.getInactiveReasonType()) - .mergeDemergeTosSet(instance.getMergeDemergeTos()); + .mergeDemergeTosSet(instance.getMergeDemergeTos()) + .deletedReason(instance.getDeletedReason()); } } diff --git a/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImpl.java b/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImpl.java index 3c54fe6c6..c965fde93 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImpl.java +++ b/core-domain/src/main/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImpl.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; +import org.uniprot.core.uniprotkb.DeletedReason; import org.uniprot.core.uniprotkb.EntryInactiveReason; import org.uniprot.core.uniprotkb.InactiveReasonType; import org.uniprot.core.util.Utils; @@ -11,14 +12,16 @@ public class EntryInactiveReasonImpl implements EntryInactiveReason { private static final long serialVersionUID = 1358481260367130982L; private InactiveReasonType inactiveReasonType; private List mergeDemergeTo; + private DeletedReason deletedReason; EntryInactiveReasonImpl() { this.mergeDemergeTo = Collections.emptyList(); } - EntryInactiveReasonImpl(InactiveReasonType inactiveReasonType, List mergeDemergeTo) { + EntryInactiveReasonImpl(InactiveReasonType inactiveReasonType, List mergeDemergeTo, DeletedReason deletedReason) { this.inactiveReasonType = inactiveReasonType; this.mergeDemergeTo = Utils.unmodifiableList(mergeDemergeTo); + this.deletedReason = deletedReason; } @Override @@ -31,6 +34,11 @@ public List getMergeDemergeTos() { return mergeDemergeTo; } + @Override + public DeletedReason getDeletedReason() { + return deletedReason; + } + @Override public int hashCode() { final int prime = 31; @@ -38,6 +46,7 @@ public int hashCode() { result = prime * result + ((inactiveReasonType == null) ? 0 : inactiveReasonType.hashCode()); result = prime * result + ((mergeDemergeTo == null) ? 0 : mergeDemergeTo.hashCode()); + result = prime * result + ((deletedReason == null) ? 0 : deletedReason.hashCode()); return result; } @@ -48,6 +57,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; EntryInactiveReasonImpl other = (EntryInactiveReasonImpl) obj; if (inactiveReasonType != other.inactiveReasonType) return false; + if (deletedReason != other.deletedReason) return false; return mergeDemergeTo.equals(other.mergeDemergeTo); } } diff --git a/core-domain/src/test/java/org/uniprot/core/uniprotkb/DeletedReasonTest.java b/core-domain/src/test/java/org/uniprot/core/uniprotkb/DeletedReasonTest.java new file mode 100644 index 000000000..4b2aa4f18 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniprotkb/DeletedReasonTest.java @@ -0,0 +1,36 @@ +package org.uniprot.core.uniprotkb; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class DeletedReasonTest { + + @Test + void canGetIds() { + assertEquals(List.of(2), DeletedReason.SWISSPROT_DELETION.getIds()); + } + + @Test + void canGetName() { + assertEquals("Overrepresented sequence", DeletedReason.OVERREPRESENTED.getName()); + } + + @Test + void canGetFromIdWithValidSingleId() { + assertEquals(DeletedReason.PROTEOME_REDUNDANCY, DeletedReason.fromId("13")); + } + + @Test + void canGetFromIdWithValidMultipleId() { + assertEquals(DeletedReason.SOURCE_DELETION, DeletedReason.fromId("8")); + } + + @Test + void canGetFromIdWithInValidIdThrowsException() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> DeletedReason.fromId("99")); + assertEquals("The DeletedReason id '99' doesn't exist.", exception.getMessage()); + } +} \ No newline at end of file diff --git a/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilderTest.java index 3ba25564c..5d2a31210 100644 --- a/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilderTest.java +++ b/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonBuilderTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; +import org.uniprot.core.uniprotkb.DeletedReason; import org.uniprot.core.uniprotkb.EntryInactiveReason; class EntryInactiveReasonBuilderTest { @@ -16,6 +17,16 @@ void canBuildWithMergeDemergeTo() { assertEquals("merge", reason.getMergeDemergeTos().get(0)); } + @Test + void canBuildWithDeletedReason() { + DeletedReason deletedReason = DeletedReason.SWISSPROT_DELETION; + EntryInactiveReason reason = new EntryInactiveReasonBuilder() + .deletedReason(deletedReason) + .build(); + assertNotNull(reason.getDeletedReason()); + assertEquals(deletedReason, reason.getDeletedReason()); + } + @Test void canCreateBuilderFromInstance() { EntryInactiveReason reason = new EntryInactiveReasonBuilder().build(); diff --git a/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImplTest.java b/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImplTest.java index e939ff25f..56cc9c238 100644 --- a/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImplTest.java +++ b/core-domain/src/test/java/org/uniprot/core/uniprotkb/impl/EntryInactiveReasonImplTest.java @@ -6,6 +6,7 @@ import java.util.Collections; import org.junit.jupiter.api.Test; +import org.uniprot.core.uniprotkb.DeletedReason; import org.uniprot.core.uniprotkb.EntryInactiveReason; import org.uniprot.core.uniprotkb.InactiveReasonType; @@ -35,12 +36,15 @@ void testEntryInactiveReasonImplMerge() { @Test void testEntryInactiveReasonImplDelete() { + DeletedReason deletedReason = DeletedReason.PROTEOME_REDUNDANCY; EntryInactiveReason reason = new EntryInactiveReasonBuilder() .type(InactiveReasonType.DELETED) + .deletedReason(deletedReason) .mergeDemergeTosSet(null) .build(); assertEquals(InactiveReasonType.DELETED, reason.getInactiveReasonType()); + assertEquals(deletedReason, reason.getDeletedReason()); assertTrue(reason.getMergeDemergeTos().isEmpty()); } diff --git a/json-parser/src/test/java/org/uniprot/core/json/parser/uniprot/UniProtKBEntryIT.java b/json-parser/src/test/java/org/uniprot/core/json/parser/uniprot/UniProtKBEntryIT.java index 2aedabee0..bf2e79fc0 100644 --- a/json-parser/src/test/java/org/uniprot/core/json/parser/uniprot/UniProtKBEntryIT.java +++ b/json-parser/src/test/java/org/uniprot/core/json/parser/uniprot/UniProtKBEntryIT.java @@ -34,13 +34,14 @@ /** @author lgonzales */ public class UniProtKBEntryIT { - private static Logger logger = LoggerFactory.getLogger(UniProtKBEntryIT.class); + private static final Logger logger = LoggerFactory.getLogger(UniProtKBEntryIT.class); @Test void testInactiveUniProtEntryComplete() { EntryInactiveReason inactiveReason = new EntryInactiveReasonBuilder() .type(InactiveReasonType.MERGED) + .deletedReason(DeletedReason.SWISSPROT_DELETION) .mergeDemergeTosAdd("merge id") .build();