diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferenceImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferenceImpl.java index 7e0b8e63a..9b328acb0 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferenceImpl.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferenceImpl.java @@ -30,7 +30,7 @@ public class UniParcCrossReferenceImpl extends CrossReferenceImpl value; - public UniParcCrossReferencePair(){ - this(null, null); - } + public UniParcCrossReferencePair(String key, List value) { this.key = key; this.value = value; } - @Override public String getKey() { return key; diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java index f9fbec50c..cf6c11ffc 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java @@ -20,7 +20,7 @@ public class UniParcEntryLightBuilder implements Builder { private String uniParcId; private int crossReferenceCount; private List commonTaxons = new ArrayList<>(); - private LinkedHashSet uniProtKBAccessions = new LinkedHashSet<>(); + private Set uniProtKBAccessions = new LinkedHashSet<>(); private Sequence sequence; @@ -45,8 +45,8 @@ public class UniParcEntryLightBuilder implements Builder { public UniParcEntryLight build() { return new UniParcEntryLightImpl(uniParcId, crossReferenceCount, commonTaxons, uniProtKBAccessions, sequence, sequenceFeatures, oldestCrossRefCreated, - mostRecentCrossRefUpdated, (LinkedHashSet) organisms, (LinkedHashSet) proteinNames, - (LinkedHashSet) geneNames, (LinkedHashSet) proteomes, extraAttributes); + mostRecentCrossRefUpdated, organisms, proteinNames, + geneNames, proteomes, extraAttributes); } public @Nonnull UniParcEntryLightBuilder uniParcId(String uniParcId) { @@ -149,6 +149,11 @@ public UniParcEntryLight build() { return this; } + public @Nonnull UniParcEntryLightBuilder extraAttributesSet(Map extraAttributes) { + this.extraAttributes = new LinkedHashMap<>(extraAttributes); + return this; + } + public static @Nonnull UniParcEntryLightBuilder from(UniParcEntryLight uniParcEntryLight){ LinkedHashSet uniProtKBAccessions = new LinkedHashSet<>(uniParcEntryLight.getUniProtKBAccessions()); LinkedHashSet organisms = new LinkedHashSet<>(uniParcEntryLight.getOrganisms()); @@ -167,8 +172,8 @@ public UniParcEntryLight build() { .organismsSet(organisms) .proteinNamesSet(proteinNames) .geneNamesSet(geneNames) - .proteomesSet(proteomes); - builder.extraAttributes = new LinkedHashMap<>(uniParcEntryLight.getExtraAttributes()); + .proteomesSet(proteomes) + .extraAttributesSet(uniParcEntryLight.getExtraAttributes()); return builder; } } diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java index 2ac0f5d80..9e5a845f6 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java @@ -43,11 +43,11 @@ public class UniParcEntryLightImpl implements UniParcEntryLight { null, null, null, null, null); } UniParcEntryLightImpl(String uniParcId, int crossReferenceCount, - List commonTaxons, LinkedHashSet uniProtKBAccessions, + List commonTaxons, Set uniProtKBAccessions, Sequence sequence, List sequenceFeatures, LocalDate oldestCrossRefCreated, LocalDate mostRecentCrossRefUpdated, - LinkedHashSet organisms, LinkedHashSet proteinNames, LinkedHashSet geneNames, - LinkedHashSet proteomes, Map extraAttributes) { + Set organisms, Set proteinNames, Set geneNames, + Set proteomes, Map extraAttributes) { this.uniParcId = uniParcId; this.crossReferenceCount = crossReferenceCount; this.commonTaxons = Utils.unmodifiableList(commonTaxons); diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java index b94d2f384..c36e12651 100644 --- a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java @@ -14,6 +14,7 @@ import java.time.LocalDate; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import static org.junit.jupiter.api.Assertions.*; import static org.uniprot.core.ObjectsForTests.sequenceFeatures; @@ -224,6 +225,20 @@ void testProteomeIdsAdd() { assertTrue(entry.getProteomes().contains(proteomeId)); } + @Test + void testProteomesSetThenAdd() { + Proteome proteome1 = new ProteomeBuilder().id("UP000005640").component("chromosome").build(); + LinkedHashSet proteomes = new LinkedHashSet<>(List.of(proteome1)); + Proteome proteome2 = new ProteomeBuilder().id("UP000002494").component("chromosome").build(); + + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .proteomesSet(proteomes) + .proteomesAdd(proteome2) + .build(); + assertEquals(2, entry.getProteomes().size()); + assertTrue(entry.getProteomes().containsAll(List.of(proteome1, proteome2))); + } + @Test void testOrganismsSetThenAdd() { Organism organism1 = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build(); @@ -261,20 +276,6 @@ void testGeneNamesSetThenAdd() { assertTrue(entry.getGeneNames().containsAll(List.of("Gene1", "Gene2"))); } - @Test - void testProteomeIdsSetThenAdd() { - Proteome proteome1 = new ProteomeBuilder().id("UP000005640").component("chromosome").build(); - LinkedHashSet proteomes = new LinkedHashSet<>(List.of(proteome1)); - Proteome proteome2 = new ProteomeBuilder().id("UP000002494").component("chromosome").build(); - - UniParcEntryLight entry = new UniParcEntryLightBuilder() - .proteomesSet(proteomes) - .proteomesAdd(proteome2) - .build(); - assertEquals(2, entry.getProteomes().size()); - assertTrue(entry.getProteomes().containsAll(List.of(proteome1, proteome2))); - } - @Test void testFrom() { @@ -313,18 +314,7 @@ void testFrom() { UniParcEntryLight newEntry = UniParcEntryLightBuilder.from(originalEntry).build(); - assertEquals(originalEntry.getUniParcId(), newEntry.getUniParcId()); - assertEquals(originalEntry.getCrossReferenceCount(), newEntry.getCrossReferenceCount()); - assertEquals(originalEntry.getCommonTaxons(), newEntry.getCommonTaxons()); - assertEquals(originalEntry.getSequence(), newEntry.getSequence()); - assertEquals(originalEntry.getSequenceFeatures(), newEntry.getSequenceFeatures()); - assertEquals(originalEntry.getOldestCrossRefCreated(), newEntry.getOldestCrossRefCreated()); - assertEquals(originalEntry.getMostRecentCrossRefUpdated(), newEntry.getMostRecentCrossRefUpdated()); - assertEquals(originalEntry.getOrganisms(), newEntry.getOrganisms()); - assertEquals(originalEntry.getProteinNames(), newEntry.getProteinNames()); - assertEquals(originalEntry.getGeneNames(), newEntry.getGeneNames()); - assertEquals(originalEntry.getProteomes(), newEntry.getProteomes()); - assertEquals(originalEntry, newEntry); + verifyOriginalAndNewEntry(originalEntry, newEntry); } @Test @@ -361,4 +351,33 @@ void testAddExtraAttributes(){ assertEquals(false, updatedEntry.getExtraAttributes().get("hasActiveCrossRef")); } + @Test + void testSetExtraAttributes(){ + UniParcEntryLight entry = new UniParcEntryLightBuilder().uniParcId("UPI0000083A08").build(); + assertEquals("UPI0000083A08", entry.getUniParcId()); + assertTrue(entry.getExtraAttributes().isEmpty()); + // set extra attribute + UniParcEntryLight updatedEntry = UniParcEntryLightBuilder.from(entry) + .extraAttributesSet(Map.of("hasActiveCrossRef", false, "another", "random")).build(); + assertEquals("UPI0000083A08", updatedEntry.getUniParcId()); + assertEquals(2, updatedEntry.getExtraAttributes().size()); + assertEquals(false, updatedEntry.getExtraAttributes().get("hasActiveCrossRef")); + assertEquals("random", updatedEntry.getExtraAttributes().get("another")); + } + + private void verifyOriginalAndNewEntry(UniParcEntryLight originalEntry, UniParcEntryLight newEntry) { + assertEquals(originalEntry.getUniParcId(), newEntry.getUniParcId()); + assertEquals(originalEntry.getCrossReferenceCount(), newEntry.getCrossReferenceCount()); + assertEquals(originalEntry.getCommonTaxons(), newEntry.getCommonTaxons()); + assertEquals(originalEntry.getSequence(), newEntry.getSequence()); + assertEquals(originalEntry.getSequenceFeatures(), newEntry.getSequenceFeatures()); + assertEquals(originalEntry.getOldestCrossRefCreated(), newEntry.getOldestCrossRefCreated()); + assertEquals(originalEntry.getMostRecentCrossRefUpdated(), newEntry.getMostRecentCrossRefUpdated()); + assertEquals(originalEntry.getOrganisms(), newEntry.getOrganisms()); + assertEquals(originalEntry.getProteinNames(), newEntry.getProteinNames()); + assertEquals(originalEntry.getGeneNames(), newEntry.getGeneNames()); + assertEquals(originalEntry.getProteomes(), newEntry.getProteomes()); + assertEquals(originalEntry, newEntry); + } + } diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java index c07fd3289..e6107d3e0 100644 --- a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java @@ -24,7 +24,6 @@ class UniParcEntryLightImplTest { void needDefaultConstructorForJsonDeserialization() { UniParcEntryLight lightObject = new UniParcEntryLightImpl(); assertNotNull(lightObject); - UniParcEntryLightBuilder.from(lightObject); } @Test diff --git a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java index e4bd60e86..dfb0f271f 100644 --- a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java +++ b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java @@ -1,23 +1,15 @@ package org.uniprot.core.parser.tsv.uniparc; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - import org.uniprot.core.parser.tsv.NamedValueMap; import org.uniprot.core.uniparc.UniParcCrossReference; import org.uniprot.core.uniparc.UniParcDatabase; import org.uniprot.core.util.Utils; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; + /** * @author jluo * @date: 24 Jun 2019 @@ -36,8 +28,6 @@ public class UniParcCrossReferenceMap implements NamedValueMap { "protein", "proteome", "accession", - "first_seen", - "last_seen", "database", "active", "ncbiGi", @@ -57,22 +47,17 @@ public UniParcCrossReferenceMap(List uniParcCrossReferenc @Override public Map attributeValues() { Map map = new HashMap<>(); - Optional firstSeen = getFirstSeenDate(); - Optional lastSeen = getLastSeenDate(); map.put(FIELDS.get(0), getGeneNames()); map.put(FIELDS.get(1), getProteinNames()); map.put(FIELDS.get(2), getProteomes()); map.put(FIELDS.get(3), getUniProtKBAccessions()); - map.put(FIELDS.get(4), firstSeen.map(LocalDate::toString).orElse("")); - map.put(FIELDS.get(5), lastSeen.map(LocalDate::toString).orElse("")); - map.put(FIELDS.get(6), getDatabases()); - map.put(FIELDS.get(7), getActives()); - map.put(FIELDS.get(8), getNcbiGis()); - map.put(FIELDS.get(9), getTimelines()); - map.put(FIELDS.get(10), getVersions()); - map.put(FIELDS.get(11), getVersionIs()); + map.put(FIELDS.get(4), getDatabases()); + map.put(FIELDS.get(5), getActives()); + map.put(FIELDS.get(6), getNcbiGis()); + map.put(FIELDS.get(7), getTimelines()); + map.put(FIELDS.get(8), getVersions()); + map.put(FIELDS.get(9), getVersionIs()); map.putAll(getDatabasesMap()); - return map; } diff --git a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java index e5313709e..ef86b4755 100644 --- a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java +++ b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java @@ -17,7 +17,7 @@ public class UniParcEntryValueMapper implements EntityValueMapper { private static final List UNIPARC_FIELDS = - List.of("upi", "oldestCrossRefCreated", "mostRecentCrossRefUpdated"); + List.of("upi", "first_seen", "last_seen"); @Override public Map mapEntity(UniParcEntry entry, List fields) { @@ -60,14 +60,14 @@ private Map getSimpleAttributeValues(UniParcEntry entry, List> entry = new UniParcCrossReferencePair(completeUniParcEntry.getUniParcId().getValue(), completeUniParcEntry.getUniParcCrossReferences()); -/* - ValidateJson.verifyJsonRoundTripParser( - UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), completeUniParcEntry.getUniParcCrossReferences().get(0)); - - ValidateJson.verifyJsonRoundTripParser( - UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), new ArrayList<>(completeUniParcEntry.getUniParcCrossReferences())); -*/ - ValidateJson.verifyJsonRoundTripParser( UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), entry); ValidateJson.verifyEmptyFields(entry);