-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRM-27505: Add reason for entry deletion
- Loading branch information
1 parent
a8324b8
commit c4e9010
Showing
8 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
core-domain/src/main/java/org/uniprot/core/uniprotkb/DeletedReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> 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<Integer> 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."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core-domain/src/test/java/org/uniprot/core/uniprotkb/DeletedReasonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters