-
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.
- Loading branch information
1 parent
1f48123
commit 1131089
Showing
43 changed files
with
1,191 additions
and
209 deletions.
There are no files selected for viewing
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
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
105 changes: 0 additions & 105 deletions
105
...va/eu/dissco/core/translator/terms/specimen/identification/taxonomy/AbstractTaxonomy.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 |
---|---|---|
@@ -1,128 +1,23 @@ | ||
package eu.dissco.core.translator.terms.specimen.identification.taxonomy; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import eu.dissco.core.translator.terms.Term; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
public abstract class AbstractTaxonomy extends Term { | ||
|
||
protected static final String IDENTIFICATION = "abcd:identifications/identification/"; | ||
protected static final String EXTENSIONS = "extensions"; | ||
protected static final String IDENTIFICATION_EXTENSION = "dwc:Identification"; | ||
protected static final String IDENTIFICATION_VERIFICATION_STATUS = "dwc:identificationVerificationStatus"; | ||
private static final String IDENTIFICATION_INDEX = "ods:taxonIdentificationIndex"; | ||
private static final Pair<String, String> ABCD_TAXON_RANK = | ||
Pair.of("result/taxonIdentified/higherTaxa/higherTaxon/", | ||
"/higherTaxonRank"); | ||
private static final Pair<String, String> ABCD_VALUE = | ||
Pair.of("result/taxonIdentified/higherTaxa/higherTaxon/", | ||
"/higherTaxonName"); | ||
private static final Pair<String, String> abcdPreferredFlag = Pair.of(IDENTIFICATION, | ||
"/preferredFlag"); | ||
|
||
protected String getTaxonFromDWCA(JsonNode unit, List<String> dwcaTerms) { | ||
var result = super.searchJsonForTerm(unit, dwcaTerms); | ||
if (result != null) { | ||
return result; | ||
} else if (unit.get(EXTENSIONS) != null | ||
&& unit.get(EXTENSIONS).get(IDENTIFICATION_EXTENSION) != null) { | ||
var identificationIndex = getIdentificationIndexDWCA(unit); | ||
if (identificationIndex != null) { | ||
return searchJsonForTerm( | ||
unit.get(EXTENSIONS).get(IDENTIFICATION_EXTENSION) | ||
.get(Integer.parseInt(identificationIndex)), dwcaTerms); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private Optional<String> determineIdentificationIndexDWCA(JsonNode unit) { | ||
if (unit.get(EXTENSIONS) != null | ||
&& unit.get(EXTENSIONS).get(IDENTIFICATION_EXTENSION) != null) { | ||
var identifications = unit.get(EXTENSIONS).get(IDENTIFICATION_EXTENSION); | ||
for (int i = 0; i < identifications.size(); i++) { | ||
var identification = identifications.get(i); | ||
if (identification.get(IDENTIFICATION_VERIFICATION_STATUS) == null) { | ||
return Optional.of(String.valueOf(i)); | ||
} else { | ||
var verificationStatus = identification.get(IDENTIFICATION_VERIFICATION_STATUS) | ||
.asText(); | ||
if (verificationStatus.equals("1")) { | ||
return Optional.of(String.valueOf(i)); | ||
} | ||
} | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
protected String getIdentificationIndexDWCA(JsonNode unit) { | ||
if (unit.get(IDENTIFICATION_INDEX) != null) { | ||
return unit.get(IDENTIFICATION_INDEX).asText(); | ||
} else { | ||
var optionalIndex = determineIdentificationIndexDWCA(unit); | ||
if (optionalIndex.isPresent()) { | ||
((ObjectNode) unit).put(IDENTIFICATION_INDEX, optionalIndex.get()); | ||
return optionalIndex.get(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
protected String getIdentificationIndexABCD(JsonNode unit) { | ||
if (unit.get(IDENTIFICATION_INDEX) != null) { | ||
return unit.get(IDENTIFICATION_INDEX).asText(); | ||
} else { | ||
var identificationIndex = determineIdentificationIndexABCD(unit); | ||
((ObjectNode) unit).put(IDENTIFICATION_INDEX, identificationIndex); | ||
return identificationIndex; | ||
} | ||
} | ||
|
||
private String determineIdentificationIndexABCD(JsonNode unit) { | ||
var numberFound = 0; | ||
while (true) { | ||
if (unit.get(getStringAtIndex(abcdPreferredFlag, numberFound)) != null) { | ||
var optionalResult = checkPreferredFlag(unit, numberFound); | ||
if (optionalResult.isPresent()) { | ||
return optionalResult.get(); | ||
} else { | ||
numberFound++; | ||
} | ||
} else { | ||
return "0"; | ||
} | ||
} | ||
} | ||
|
||
protected String searchABCDSplitTerms(JsonNode unit, List<String> searchTerms) { | ||
return searchABCDSplitTerms(unit, searchTerms, | ||
Pair.of(ABCD_TAXON_RANK.getLeft(), ABCD_TAXON_RANK.getRight()), | ||
Pair.of(ABCD_VALUE.getLeft(), ABCD_VALUE.getRight())); | ||
} | ||
|
||
protected String searchABCDTerms(JsonNode unit, List<String> searchTerms) { | ||
var identificationIndex = getIdentificationIndexABCD(unit); | ||
var terms = searchTerms.stream().map( | ||
term -> IDENTIFICATION + identificationIndex + "/result/taxonIdentified" + term).toList(); | ||
return searchJsonForTerm(unit, terms); | ||
} | ||
|
||
protected String getStringAtIndex(Pair<String, String> string, int numberFound) { | ||
return string.getLeft() + numberFound + string.getRight(); | ||
} | ||
|
||
private Optional<String> checkPreferredFlag(JsonNode unit, int numberFound) { | ||
var preferred = unit.get(getStringAtIndex(abcdPreferredFlag, numberFound)).asBoolean(); | ||
if (preferred) { | ||
return Optional.of(String.valueOf(numberFound)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/eu/dissco/core/translator/terms/media/AccessRightsTest.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,38 @@ | ||
package eu.dissco.core.translator.terms.media; | ||
|
||
import static eu.dissco.core.translator.TestUtils.MAPPER; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AccessRightsTest { | ||
|
||
private final AccessRights accessRights = new AccessRights(); | ||
|
||
@Test | ||
void testRetrieveFromDWCA() { | ||
// Given | ||
var accessUriString = "https://accessuri.eu/image_1"; | ||
var unit = MAPPER.createObjectNode(); | ||
unit.put("ac:accessRights", accessUriString); | ||
|
||
// When | ||
var result = accessRights.retrieveFromDWCA(unit); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(accessUriString); | ||
} | ||
|
||
@Test | ||
void testGetTerm() { | ||
// When | ||
var result = accessRights.getTerm(); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(AccessRights.TERM); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/eu/dissco/core/translator/terms/media/CreatedTest.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,39 @@ | ||
package eu.dissco.core.translator.terms.media; | ||
|
||
import static eu.dissco.core.translator.TestUtils.MAPPER; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.checkerframework.checker.units.qual.C; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class Created { | ||
|
||
private final Created created = new Created(); | ||
|
||
@Test | ||
void testRetrieveFromDWCA() { | ||
// Given | ||
var accessUriString = "https://accessuri.eu/image_1"; | ||
var unit = MAPPER.createObjectNode(); | ||
unit.put("ac:accessRights", accessUriString); | ||
|
||
// When | ||
var result = accessRights.retrieveFromDWCA(unit); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(accessUriString); | ||
} | ||
|
||
@Test | ||
void testGetTerm() { | ||
// When | ||
var result = created.getTerm(); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(AccessRights.TERM); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/eu/dissco/core/translator/terms/media/CreatorTest.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,53 @@ | ||
package eu.dissco.core.translator.terms.media; | ||
|
||
import static eu.dissco.core.translator.TestUtils.MAPPER; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CreatorTest { | ||
|
||
private final Created created = new Created(); | ||
|
||
@Test | ||
void testRetrieveFromDWCA() { | ||
// Given | ||
var createdString = "18-09-2023"; | ||
var unit = MAPPER.createObjectNode(); | ||
unit.put("dcterms:created", createdString); | ||
|
||
// When | ||
var result = created.retrieveFromDWCA(unit); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(createdString); | ||
} | ||
|
||
@Test | ||
void testRetrieveFromAbcd() { | ||
// Given | ||
var createdString = "18-09-2023"; | ||
var unit = MAPPER.createObjectNode(); | ||
unit.put("abcd:createdDate", createdString); | ||
|
||
// When | ||
var result = created.retrieveFromABCD(unit); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(createdString); | ||
} | ||
|
||
|
||
@Test | ||
void testGetTerm() { | ||
// When | ||
var result = created.getTerm(); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(Created.TERM); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/eu/dissco/core/translator/terms/media/DescriptionTest.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,53 @@ | ||
package eu.dissco.core.translator.terms.media; | ||
|
||
import static eu.dissco.core.translator.TestUtils.MAPPER; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DescriptionTest { | ||
|
||
private final Creator creator = new Creator(); | ||
|
||
@Test | ||
void testRetrieveFromDWCA() { | ||
// Given | ||
var creatorString = "Sam Leeflang"; | ||
var unit = MAPPER.createObjectNode(); | ||
unit.put("dcterms:creator", creatorString); | ||
|
||
// When | ||
var result = creator.retrieveFromDWCA(unit); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(creatorString); | ||
} | ||
|
||
@Test | ||
void testRetrieveFromAbcd() { | ||
// Given | ||
var createdString = "Sam Leeflang"; | ||
var unit = MAPPER.createObjectNode(); | ||
unit.put("abcd:creator", createdString); | ||
|
||
// When | ||
var result = creator.retrieveFromABCD(unit); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(createdString); | ||
} | ||
|
||
|
||
@Test | ||
void testGetTerm() { | ||
// When | ||
var result = creator.getTerm(); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(Creator.TERM); | ||
} | ||
|
||
} |
Oops, something went wrong.