From 508884df5981341b28646488dee700d02da7f5bd Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Mon, 18 Nov 2024 17:09:08 +0100 Subject: [PATCH 1/5] Update EntityRelationship + IIIF mediaType --- pom.xml | 16 ++++- .../core/translator/service/DwcaService.java | 2 +- .../terms/BaseDigitalObjectDirector.java | 58 ++++++++-------- .../terms/BiocaseDigitalObjectDirector.java | 3 +- .../terms/DwcaDigitalObjectDirector.java | 5 +- .../translator/terms/media/MediaType.java | 4 ++ .../translator/terms/specimen/DatasetID.java | 1 + .../terms/specimen/DynamicProperties.java | 1 + .../translator/terms/specimen/OrganismID.java | 1 + .../terms/specimen/OrganismName.java | 1 + .../terms/specimen/OrganismRemarks.java | 1 + .../terms/specimen/OrganismScope.java | 1 + .../terms/specimen/SpecimenName.java | 3 +- .../terms/specimen/TopicDiscipline.java | 3 +- .../translator/terms/utils/AgentsUtils.java | 19 ++++-- .../terms/utils/EntityRelationshipUtils.java | 42 ++++++++++++ .../OrganisationNameComponentTest.java | 41 ++++++------ .../repository/DataMappingRepositoryIT.java | 2 +- .../service/BioCaseServiceTest.java | 5 +- .../translator/service/DwcaServiceTest.java | 4 +- .../BiocaseDigitalObjectDirectorTest.java | 9 ++- .../terms/DwcaDigitalObjectDirectorTest.java | 24 ++++--- .../translator/terms/media/MediaTypeTest.java | 1 + .../utils/EntityRelationshipUtilsTest.java | 67 +++++++++++++++++++ 24 files changed, 232 insertions(+), 82 deletions(-) create mode 100644 src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java create mode 100644 src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java diff --git a/pom.xml b/pom.xml index ce1de76..052b1bd 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ 1.9.4 3.1.0 1.27.1 + 4.1.115.Final 2.1.3 4.0.2 5.2.0 @@ -87,8 +88,15 @@ org.gbif dwca-io ${dwca-io.version} + + + + commons-io + commons-io + + - + commons-beanutils commons-beanutils @@ -100,6 +108,12 @@ commons-compress ${commons-compress.version} + + + io.netty + netty-common + ${netty-common.version} + org.codehaus.mojo jaxb2-maven-plugin diff --git a/src/main/java/eu/dissco/core/translator/service/DwcaService.java b/src/main/java/eu/dissco/core/translator/service/DwcaService.java index ce2ba8a..304f645 100644 --- a/src/main/java/eu/dissco/core/translator/service/DwcaService.java +++ b/src/main/java/eu/dissco/core/translator/service/DwcaService.java @@ -137,7 +137,7 @@ public void getSpecimenData(Set ids, Archive archive, AtomicInteger proc var specimenData = dwcaRepository.getCoreRecords(batch, getTableName(archive.getCore())); log.info("Got specimen batch: {}", batch.size()); addExtensionsToSpecimen(archive, batch, specimenData); - log.info("Start translation and publishing of batch: {}", specimenData.values().size()); + log.info("Start translation and publishing of batch: {}", specimenData.size()); processDigitalSpecimen(specimenData.values(), optionalEmlData, processedRecords); } } catch (ReachedMaximumLimitException e) { diff --git a/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java b/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java index e957f52..e7a0c7a 100644 --- a/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java @@ -2,7 +2,6 @@ import static eu.dissco.core.translator.domain.AgentRoleType.COLLECTOR; import static eu.dissco.core.translator.domain.AgentRoleType.CREATOR; -import static eu.dissco.core.translator.domain.AgentRoleType.DATA_TRANSLATOR; import static eu.dissco.core.translator.domain.AgentRoleType.GEOREFERENCER; import static eu.dissco.core.translator.domain.AgentRoleType.IDENTIFIER; import static eu.dissco.core.translator.domain.AgentRoleType.RIGHTS_OWNER; @@ -15,14 +14,13 @@ import static eu.dissco.core.translator.domain.RelationshipType.HAS_SOURCE_SYSTEM_ID; import static eu.dissco.core.translator.domain.RelationshipType.HAS_URL; import static eu.dissco.core.translator.schema.Agent.Type.SCHEMA_PERSON; -import static eu.dissco.core.translator.schema.Agent.Type.SCHEMA_SOFTWARE_APPLICATION; import static eu.dissco.core.translator.terms.utils.AgentsUtils.addAgent; +import static eu.dissco.core.translator.terms.utils.EntityRelationshipUtils.addEntityRelationship; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.dissco.core.translator.component.OrganisationNameComponent; import eu.dissco.core.translator.component.SourceSystemComponent; -import eu.dissco.core.translator.domain.RelationshipType; import eu.dissco.core.translator.exception.OrganisationException; import eu.dissco.core.translator.exception.UnknownPhysicalSpecimenIdType; import eu.dissco.core.translator.properties.FdoProperties; @@ -235,7 +233,6 @@ import eu.dissco.core.translator.terms.specimen.stratigraphy.lithostratigraphic.Group; import eu.dissco.core.translator.terms.specimen.stratigraphy.lithostratigraphic.LithostratigraphicTerms; import eu.dissco.core.translator.terms.specimen.stratigraphy.lithostratigraphic.Member; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; @@ -362,38 +359,32 @@ private String getOrganisationName(String organisationId) throws OrganisationExc private List assembleDigitalSpecimenEntityRelationships( DigitalSpecimen ds) { var relationships = new ArrayList(); - relationships.add(getEntityRelationship(HAS_ORGANISATION_ID, ds.getOdsOrganisationID())); - relationships.add(getEntityRelationship(HAS_SOURCE_SYSTEM_ID, ds.getOdsSourceSystemID())); - relationships.add(getEntityRelationship(HAS_FDO_TYPE, fdoProperties.getDigitalSpecimenType())); + relationships.add(addEntityRelationship(HAS_ORGANISATION_ID, ds.getOdsOrganisationID(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); + relationships.add(addEntityRelationship(HAS_SOURCE_SYSTEM_ID, ds.getOdsSourceSystemID(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); + relationships.add(addEntityRelationship(HAS_FDO_TYPE, fdoProperties.getDigitalSpecimenType(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); if (ds.getOdsPhysicalSpecimenIDType().equals(OdsPhysicalSpecimenIDType.RESOLVABLE)) { relationships.add( - getEntityRelationship(HAS_PHYSICAL_IDENTIFIER, ds.getOdsPhysicalSpecimenID())); + addEntityRelationship(HAS_PHYSICAL_IDENTIFIER, ds.getOdsPhysicalSpecimenID(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); } if (ds.getDctermsLicense() != null && ds.getDctermsLicense().startsWith("http")) { - relationships.add(getEntityRelationship(HAS_LICENSE, ds.getDctermsLicense())); + relationships.add(addEntityRelationship(HAS_LICENSE, ds.getDctermsLicense(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); } if (ds.getOdsHasCitations() != null) { for (Citation citation : ds.getOdsHasCitations()) { if (citation.getId() != null && citation.getId().startsWith("http")) { - relationships.add(getEntityRelationship(HAS_REFERENCE, citation.getId())); + relationships.add(addEntityRelationship(HAS_REFERENCE, citation.getId(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); } } } return relationships; } - private EntityRelationship getEntityRelationship(RelationshipType relationshipType, - String relatedResource) { - var entityRelationship = new EntityRelationship() - .withType("ods:EntityRelationship") - .withDwcRelationshipOfResource(relationshipType.getName()) - .withDwcRelatedResourceID(relatedResource) - .withDwcRelationshipEstablishedDate(java.util.Date.from(Instant.now())); - entityRelationship.setOdsHasAgents(addAgent(entityRelationship.getOdsHasAgents(), fdoProperties.getApplicationName(), - fdoProperties.getApplicationPID(), DATA_TRANSLATOR, SCHEMA_SOFTWARE_APPLICATION)); - return entityRelationship; - } - private List assembleIdentifiers(JsonNode data) { var identifiers = new ArrayList(); for (String identifierTerm : identifierTerms) { @@ -461,7 +452,8 @@ protected Identification createIdentification(JsonNode data, boolean dwc) { termMapper.retrieveTerm(new VerbatimIdentification(), data, dwc)) .withOdsHasTaxonIdentifications(List.of(mappedTaxonIdentification)) .withOdsHasCitations(assembleIdentificationCitations(data, dwc)); - identification.setOdsHasAgents(addAgent(identification.getOdsHasAgents(), termMapper.retrieveTerm(new IdentifiedBy(), data, dwc), + identification.setOdsHasAgents(addAgent(identification.getOdsHasAgents(), + termMapper.retrieveTerm(new IdentifiedBy(), data, dwc), termMapper.retrieveTerm(new IdentifiedByID(), data, dwc), IDENTIFIER, SCHEMA_PERSON)); return identification; } @@ -590,8 +582,9 @@ private List assembleEventTerms(JsonNode data, boolean dwc) { .withDwcVitality(termMapper.retrieveTerm(new Vitality(), data, dwc)) .withOdsHasLocation(location) .withOdsHasAssertions(assertions); - event.setOdsHasAgents(addAgent(event.getOdsHasAgents(), termMapper.retrieveTerm(new RecordedBy(), data, dwc), - termMapper.retrieveTerm(new RecordedByID(), data, dwc), COLLECTOR, SCHEMA_PERSON)); + event.setOdsHasAgents( + addAgent(event.getOdsHasAgents(), termMapper.retrieveTerm(new RecordedBy(), data, dwc), + termMapper.retrieveTerm(new RecordedByID(), data, dwc), COLLECTOR, SCHEMA_PERSON)); return List.of(event); } @@ -714,19 +707,24 @@ public DigitalMedia assembleDigitalMedia(boolean dwc, JsonNode mediaRecord, private List assembleDigitalMediaEntityRelationships( DigitalMedia digitalMedia) { var relationships = new ArrayList(); - relationships.add(getEntityRelationship(HAS_URL, digitalMedia.getAcAccessURI())); + relationships.add(addEntityRelationship(HAS_URL, digitalMedia.getAcAccessURI(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); relationships.add( - getEntityRelationship(HAS_ORGANISATION_ID, digitalMedia.getOdsOrganisationID())); + addEntityRelationship(HAS_ORGANISATION_ID, digitalMedia.getOdsOrganisationID(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); relationships.add( - getEntityRelationship(HAS_FDO_TYPE, fdoProperties.getDigitalMediaType())); + addEntityRelationship(HAS_FDO_TYPE, fdoProperties.getDigitalMediaType(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); if (digitalMedia.getDctermsRights() != null && digitalMedia.getDctermsRights() .startsWith("http")) { relationships.add( - getEntityRelationship(HAS_LICENSE, digitalMedia.getDctermsRights())); + addEntityRelationship(HAS_LICENSE, digitalMedia.getDctermsRights(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); } if (digitalMedia.getDctermsSource() != null && digitalMedia.getDctermsSource() .startsWith("http")) { - relationships.add(getEntityRelationship(HAS_SOURCE, digitalMedia.getDctermsSource())); + relationships.add(addEntityRelationship(HAS_SOURCE, digitalMedia.getDctermsSource(), + fdoProperties.getApplicationName(), fdoProperties.getApplicationPID())); } return relationships; } diff --git a/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java b/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java index 9013737..b9160a3 100644 --- a/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java @@ -24,7 +24,8 @@ public class BiocaseDigitalObjectDirector extends BaseDigitalObjectDirector { public BiocaseDigitalObjectDirector(ObjectMapper mapper, TermMapper termMapper, OrganisationNameComponent rorComponent, SourceSystemComponent sourceSystemComponent, FdoProperties fdoProperties) { - super(mapper, termMapper, rorComponent, sourceSystemComponent, fdoProperties, identifierTerms()); + super(mapper, termMapper, rorComponent, sourceSystemComponent, fdoProperties, + identifierTerms()); } private static List identifierTerms() { diff --git a/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java b/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java index 91f4878..aeaf37f 100644 --- a/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java @@ -25,7 +25,8 @@ public class DwcaDigitalObjectDirector extends BaseDigitalObjectDirector { public DwcaDigitalObjectDirector(ObjectMapper mapper, TermMapper termMapper, OrganisationNameComponent rorComponent, SourceSystemComponent sourceSystemComponent, FdoProperties fdoProperties) { - super(mapper, termMapper, rorComponent, sourceSystemComponent, fdoProperties, identifierTerms()); + super(mapper, termMapper, rorComponent, sourceSystemComponent, fdoProperties, + identifierTerms()); } private static List identifierTerms() { @@ -52,7 +53,7 @@ protected List assembleSpecimenCitations(JsonNode data, boolean dwc) { var references = data.get(EXTENSION).get("gbif:Reference"); for (int i = 0; i < references.size(); i++) { var citationJson = references.get(i); - if (citationJson.properties().size() <= 1){ + if (citationJson.properties().size() <= 1) { log.debug("Skipping citation with only one property: {}", citationJson); } else { citations.add(createCitation(citationJson, dwc)); diff --git a/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java b/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java index 8b07282..4ac49fb 100644 --- a/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java +++ b/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java @@ -12,9 +12,11 @@ public class MediaType extends Term { private static final String STILL_IMAGE = "Still_Image"; private static final String SOUND = "Sound"; private static final String MOVING_IMAGE = "Moving_Image"; + private static final String DATASET = "Dataset"; private final List dwcaTerms = List.of(TERM, "dc:type"); private final List imageFormats = List.of("IMAGE/JPG", "JPG", "IMAGE/JPEG", "JPEG", "IMAGE/PNG", "PNG", "IMAGE/TIF", "TIF"); + private final List datasetFormats = List.of("APPLICATION/JSON"); @Override public String retrieveFromDWCA(JsonNode unit) { @@ -51,6 +53,8 @@ public String retrieveFromABCD(JsonNode unit) { format = format.toUpperCase(); if (imageFormats.contains(format)) { return STILL_IMAGE; + } else if (datasetFormats.contains(format)) { + return DATASET; } else { log.warn("Unable to determine media type of digital media object"); return null; diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/DatasetID.java b/src/main/java/eu/dissco/core/translator/terms/specimen/DatasetID.java index f602d83..8235111 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/DatasetID.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/DatasetID.java @@ -5,6 +5,7 @@ import java.util.List; public class DatasetID extends Term { + public static final String TERM = DWC_PREFIX + "datasetID"; private final List dwcaTerms = List.of(TERM); diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/DynamicProperties.java b/src/main/java/eu/dissco/core/translator/terms/specimen/DynamicProperties.java index 27b494e..2113b06 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/DynamicProperties.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/DynamicProperties.java @@ -5,6 +5,7 @@ import java.util.List; public class DynamicProperties extends Term { + public static final String TERM = DWC_PREFIX + "dynamicProperties"; private final List dwcaTerms = List.of(TERM); diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismID.java b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismID.java index ac85beb..f4e624e 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismID.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismID.java @@ -5,6 +5,7 @@ import java.util.List; public class OrganismID extends Term { + public static final String TERM = DWC_PREFIX + "organismID"; private final List dwcaTerms = List.of(TERM); diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismName.java b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismName.java index 848719d..9f0e6fb 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismName.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismName.java @@ -5,6 +5,7 @@ import java.util.List; public class OrganismName extends Term { + public static final String TERM = DWC_PREFIX + "organismName"; private final List dwcaTerms = List.of(TERM); diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismRemarks.java b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismRemarks.java index d743a99..7ba3f62 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismRemarks.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismRemarks.java @@ -5,6 +5,7 @@ import java.util.List; public class OrganismRemarks extends Term { + public static final String TERM = DWC_PREFIX + "organismRemarks"; private final List dwcaTerms = List.of(TERM); diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismScope.java b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismScope.java index 06eeadf..85d5b7d 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismScope.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/OrganismScope.java @@ -5,6 +5,7 @@ import java.util.List; public class OrganismScope extends Term { + public static final String TERM = DWC_PREFIX + "organismScope"; private final List dwcaTerms = List.of(TERM); diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/SpecimenName.java b/src/main/java/eu/dissco/core/translator/terms/specimen/SpecimenName.java index 4f70550..d00933f 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/SpecimenName.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/SpecimenName.java @@ -9,7 +9,8 @@ public class SpecimenName extends Term { public String calculate(DigitalSpecimen ds) { var acceptedIdentification = retrieveAcceptedIdentification(ds); - if (acceptedIdentification != null && acceptedIdentification.getOdsHasTaxonIdentifications() != null + if (acceptedIdentification != null + && acceptedIdentification.getOdsHasTaxonIdentifications() != null && !acceptedIdentification.getOdsHasTaxonIdentifications().isEmpty()) { if (acceptedIdentification.getOdsHasTaxonIdentifications().get(0) .getDwcScientificName() != null) { diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/TopicDiscipline.java b/src/main/java/eu/dissco/core/translator/terms/specimen/TopicDiscipline.java index 37b8846..cc3673c 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/TopicDiscipline.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/TopicDiscipline.java @@ -19,7 +19,8 @@ public class TopicDiscipline extends Term { public OdsTopicDiscipline calculate(DigitalSpecimen ds) { var basisOfRecord = ds.getDwcBasisOfRecord(); var acceptedIdentification = retrieveAcceptedIdentification(ds); - if (acceptedIdentification != null && acceptedIdentification.getOdsHasTaxonIdentifications() != null + if (acceptedIdentification != null + && acceptedIdentification.getOdsHasTaxonIdentifications() != null && !acceptedIdentification.getOdsHasTaxonIdentifications().isEmpty()) { return getDiscipline(basisOfRecord, acceptedIdentification.getOdsHasTaxonIdentifications().get(0).getDwcKingdom()); diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java index 7fe17c4..b5b21e4 100644 --- a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java +++ b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java @@ -66,7 +66,8 @@ private static void handleMultipleAgents( var ids = new String[0]; var agentValues = new String[0]; if (agentValue != null && (agentValue.contains("&") || agentValue.contains("|"))) { - agentValues = Arrays.stream(agentValue.split("[&|]")).map(String::trim).toArray(String[]::new); + agentValues = Arrays.stream(agentValue.split("[&|]")).map(String::trim) + .toArray(String[]::new); } if (agentId != null && (agentId.contains("&") || agentId.contains("|"))) { ids = Arrays.stream(agentId.split("[&|]")).map(String::trim).toArray(String[]::new); @@ -76,16 +77,20 @@ private static void handleMultipleAgents( constructAgent(agents, agentValues[i], ids[i], role, type); } } else if (agentValues.length > ids.length) { - log.warn( - "The number of agentValues values is greater than ids, ignoring ids for term: {} and agentId: {}", - agentValue, agentId); + if (ids.length != 0) { + log.warn( + "The number of agentValues values is greater than ids, ignoring ids for term: {} and agentId: {}", + agentValue, agentId); + } for (String agent : agentValues) { constructAgent(agents, agent, null, role, type); } } else { - log.warn( - "The number of ids is greater than agentValue, ignoring agentValue values for term: {} and agentId: {}", - agentValue, agentId); + if (agentValues.length != 0) { + log.warn( + "The number of ids is greater than agentValue, ignoring agentValue values for term: {} and agentId: {}", + agentValue, agentId); + } for (String idValue : ids) { constructAgent(agents, null, idValue, role, type); } diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java new file mode 100644 index 0000000..b003447 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java @@ -0,0 +1,42 @@ +package eu.dissco.core.translator.terms.utils; + +import static eu.dissco.core.translator.domain.AgentRoleType.DATA_TRANSLATOR; +import static eu.dissco.core.translator.schema.Agent.Type.SCHEMA_SOFTWARE_APPLICATION; +import static eu.dissco.core.translator.terms.utils.AgentsUtils.addAgent; + +import eu.dissco.core.translator.domain.RelationshipType; +import eu.dissco.core.translator.schema.EntityRelationship; +import java.net.URI; +import java.net.URISyntaxException; +import java.time.Instant; +import java.util.Date; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class EntityRelationshipUtils { + + private EntityRelationshipUtils() { + // This is a Utility class + } + + public static EntityRelationship addEntityRelationship( + RelationshipType relationshipType, String relatedResource, String agentName, String agentId) { + var entityRelationship = new EntityRelationship() + .withType("ods:EntityRelationship") + .withDwcRelationshipOfResource(relationshipType.getName()) + .withDwcRelatedResourceID(relatedResource) + .withDwcRelationshipEstablishedDate(Date.from(Instant.now())); + entityRelationship.setOdsHasAgents( + addAgent(entityRelationship.getOdsHasAgents(), agentName, agentId, DATA_TRANSLATOR, + SCHEMA_SOFTWARE_APPLICATION)); + if (relatedResource.startsWith("http")) { + try { + entityRelationship.setOdsRelatedResourceURI(new URI(relatedResource)); + } catch (URISyntaxException e) { + log.warn("Could not create URI for related resource: " + relatedResource); + } + } + return entityRelationship; + } + +} \ No newline at end of file diff --git a/src/test/java/eu/dissco/core/translator/component/OrganisationNameComponentTest.java b/src/test/java/eu/dissco/core/translator/component/OrganisationNameComponentTest.java index 640892b..eb66271 100644 --- a/src/test/java/eu/dissco/core/translator/component/OrganisationNameComponentTest.java +++ b/src/test/java/eu/dissco/core/translator/component/OrganisationNameComponentTest.java @@ -50,12 +50,30 @@ class OrganisationNameComponentTest { private CompletableFuture jsonFuture; private OrganisationNameComponent rorComponent; + private static Stream badRorResponse() throws JsonProcessingException { + return Stream.of( + Arguments.of( + MAPPER.readTree(""" + { + "names":"De MuseumFabriek" + } + """) + ), + Arguments.of( + MAPPER.readTree(""" + { + "names": ["De MuseumFabriek"] + } + """) + ) + ); + } + @BeforeEach void setup() { this.rorComponent = new OrganisationNameComponent(client); } - @Test void testGetRorId() throws Exception { // Given @@ -98,7 +116,7 @@ void testGetRorIdFirst() throws Exception { @ParameterizedTest @MethodSource("badRorResponse") - void testBadRorResponse(JsonNode rorResponse) throws Exception { + void testBadRorResponse(JsonNode rorResponse) throws Exception { // Given givenWebclient(); given(jsonFuture.get()).willReturn(rorResponse); @@ -108,25 +126,6 @@ void testBadRorResponse(JsonNode rorResponse) throws Exception { } - private static Stream badRorResponse() throws JsonProcessingException { - return Stream.of( - Arguments.of( - MAPPER.readTree(""" - { - "names":"De MuseumFabriek" - } - """) - ), - Arguments.of( - MAPPER.readTree(""" - { - "names": ["De MuseumFabriek"] - } - """) - ) - ); - } - @Test void testWikidataId() throws Exception { // Given diff --git a/src/test/java/eu/dissco/core/translator/repository/DataMappingRepositoryIT.java b/src/test/java/eu/dissco/core/translator/repository/DataMappingRepositoryIT.java index fad898a..eeb11dc 100644 --- a/src/test/java/eu/dissco/core/translator/repository/DataMappingRepositoryIT.java +++ b/src/test/java/eu/dissco/core/translator/repository/DataMappingRepositoryIT.java @@ -55,7 +55,7 @@ private void givenInsertRecords(String mapping) { .set(DATA_MAPPING.VERSION, 1) .set(DATA_MAPPING.NAME, "Royal Botanic Garden Edinburgh Living Plant Collections Mapping") .set(DATA_MAPPING.CREATOR, "e2befba6-9324-4bb4-9f41-d7dfae4a44b0") - .set(DATA_MAPPING.DATE_CREATED,Instant.parse("2022-09-16T08:25:01.00Z")) + .set(DATA_MAPPING.DATE_CREATED, Instant.parse("2022-09-16T08:25:01.00Z")) .set(DATA_MAPPING.DATE_MODIFIED, Instant.parse("2022-09-16T08:25:01.00Z")) .set(DATA_MAPPING.MAPPING_DATA_STANDARD, "dwc") .set(DATA_MAPPING.DATA, JSONB.valueOf(mapping)) diff --git a/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java b/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java index 7b92ed5..f01c85c 100644 --- a/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java +++ b/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java @@ -49,9 +49,9 @@ class BioCaseServiceTest { private final XMLInputFactory factory = XMLInputFactory.newFactory(); private final ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); + private final ApplicationProperties properties = new ApplicationProperties(); @Mock private WebClient webClient; - private final ApplicationProperties properties = new ApplicationProperties(); @Mock private SourceSystemComponent sourceSystemComponent; @Mock @@ -75,7 +75,8 @@ void setup() throws IOException { var configuration = new Configuration(Configuration.VERSION_2_3_31); configuration.setTemplateLoader( new FileTemplateLoader(new ClassPathResource("templates").getFile())); - service = new BioCaseService(mapper, properties, webClient, sourceSystemComponent, configuration, factory, + service = new BioCaseService(mapper, properties, webClient, sourceSystemComponent, + configuration, factory, kafkaService, enrichmentProperties, digitalSpecimenDirector, fdoProperties); // Given diff --git a/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java b/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java index 7e9983e..1ef79ea 100644 --- a/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java +++ b/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java @@ -64,6 +64,7 @@ class DwcaServiceTest { private final XMLInputFactory factory = XMLInputFactory.newFactory(); + private final ApplicationProperties applicationProperties = new ApplicationProperties(); @Mock private WebClient webClient; @Mock @@ -86,9 +87,6 @@ class DwcaServiceTest { private BaseDigitalObjectDirector digitalSpecimenDirector; @Mock private FdoProperties fdoProperties; - private final ApplicationProperties applicationProperties = new ApplicationProperties(); - - private DwcaService service; private static void cleanup(String first) throws IOException { diff --git a/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java b/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java index e04fc0b..8b24601 100644 --- a/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java @@ -118,10 +118,13 @@ void testConstructAbcdDigitalSpecimen(ObjectNode identifications, int totalIdent // Then assertThat(result).isNotNull(); assertThat(result.getOdsStatus()).isEqualTo(OdsStatus.ACTIVE); - assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(4); - assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(4); + assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(4); + assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(4); assertThat(result.getOdsHasCitations()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(1); - assertThat(result.getOdsHasIdentifications()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(totalIdentifications); + assertThat(result.getOdsHasIdentifications()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(totalIdentifications); } @ParameterizedTest diff --git a/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java b/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java index 3e82c67..4540abe 100644 --- a/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java @@ -65,10 +65,13 @@ void testConstructDwcaDigitalSpecimen() throws Exception { // Then assertThat(result).isNotNull(); assertThat(result.getOdsStatus()).isEqualTo(OdsStatus.ACTIVE); - assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(3); - assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(3); + assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(3); + assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(3); assertThat(result.getOdsHasCitations()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(2); - assertThat(result.getOdsHasIdentifications()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(2); + assertThat(result.getOdsHasIdentifications()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(2); } @Test @@ -89,10 +92,13 @@ void testConstructDwcaDigitalSpecimenSingleIdentification() throws Exception { // Then assertThat(result).isNotNull(); - assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(3); - assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(3); + assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(3); + assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(3); assertThat(result.getOdsHasCitations()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(1); - assertThat(result.getOdsHasIdentifications()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(1); + assertThat(result.getOdsHasIdentifications()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(1); assertThat(((eu.dissco.core.translator.schema.Identification) result.getOdsHasIdentifications() .get(0)).getOdsIsVerifiedIdentification()).isTrue(); } @@ -113,8 +119,10 @@ void testConstructDwcaDigitalMedia() throws JsonProcessingException, Organisatio // Then assertThat(result).isNotNull(); - assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(3); - assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(2); + assertThat(result.getOdsHasEntityRelationships()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(3); + assertThat(result.getOdsHasIdentifiers()).asInstanceOf(InstanceOfAssertFactories.LIST) + .hasSize(2); } private JsonNode givenDwcaMediaObject() throws JsonProcessingException { diff --git a/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java b/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java index d129444..513c2ef 100644 --- a/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java @@ -40,6 +40,7 @@ private static Stream provideFormatTypes() { private static Stream provideABCDFormats() { return Stream.of( Arguments.of("image/jpeg", "Still_Image"), + Arguments.of("APPLICATION/JSON", "Dataset"), Arguments.of("unknown/format", null), Arguments.of(null, null) ); diff --git a/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java b/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java new file mode 100644 index 0000000..cea8713 --- /dev/null +++ b/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java @@ -0,0 +1,67 @@ +package eu.dissco.core.translator.terms.utils; + +import static eu.dissco.core.translator.domain.AgentRoleType.DATA_TRANSLATOR; +import static eu.dissco.core.translator.domain.RelationshipType.HAS_ORGANISATION_ID; +import static eu.dissco.core.translator.schema.Agent.Type.SCHEMA_SOFTWARE_APPLICATION; +import static org.assertj.core.api.Assertions.assertThat; + +import eu.dissco.core.translator.domain.RelationshipType; +import eu.dissco.core.translator.schema.EntityRelationship; +import java.net.URI; +import java.net.URISyntaxException; +import java.time.Instant; +import java.util.Date; +import java.util.List; +import java.util.stream.Stream; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class EntityRelationshipUtilsTest { + + public static final String APP_NAME = "DiSSCo Translator Service"; + public static final String APP_PID = "https://hdl.handle.net/TEST/XXX-XXX-XXX"; + + public static Stream erProvider() throws URISyntaxException { + return Stream.of( + Arguments.of(HAS_ORGANISATION_ID, "https://ror.org/0566bfb96", + new URI("https://ror.org/0566bfb96") + ), + Arguments.of(HAS_ORGANISATION_ID, "0566bfb96", null + ), + Arguments.of(HAS_ORGANISATION_ID, "https://ror.org/05^^@^#^66bfb96", null + ) + ); + } + + @ParameterizedTest + @MethodSource("erProvider") + void testAddEntityRelationship(RelationshipType relationshipType, String relatedResource, + URI relatedResourceURI) { + // Given + var expected = createEntityRelationship(relationshipType, relatedResource, relatedResourceURI); + + // When + var result = EntityRelationshipUtils.addEntityRelationship(relationshipType, relatedResource, APP_NAME, APP_PID); + + // Then + assertThat(result).usingRecursiveComparison().ignoringFields("dwcRelationshipEstablishedDate") + .isEqualTo(expected); + } + + private EntityRelationship createEntityRelationship(RelationshipType relationshipType, + String relatedResource, URI relatedResourceURI) { + return new EntityRelationship() + .withType("ods:EntityRelationship") + .withDwcRelationshipOfResource(relationshipType.getName()) + .withDwcRelatedResourceID(relatedResource) + .withOdsRelatedResourceURI(relatedResourceURI) + .withDwcRelationshipEstablishedDate(Date.from(Instant.now())) + .withOdsHasAgents(AgentsUtils.addAgent(List.of(), APP_NAME, APP_PID, + DATA_TRANSLATOR, SCHEMA_SOFTWARE_APPLICATION)); + + } +} From 94cd2a433c3aa6921e04a700bdd3f4df78a4fa13 Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Mon, 18 Nov 2024 17:24:56 +0100 Subject: [PATCH 2/5] Fix tests + add NPE check --- .../terms/utils/EntityRelationshipUtils.java | 5 +++++ .../terms/BiocaseDigitalObjectDirectorTest.java | 2 ++ .../terms/DwcaDigitalObjectDirectorTest.java | 6 ++++++ .../terms/utils/EntityRelationshipUtilsTest.java | 15 ++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java index b003447..0cb5d9a 100644 --- a/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java +++ b/src/main/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtils.java @@ -21,6 +21,11 @@ private EntityRelationshipUtils() { public static EntityRelationship addEntityRelationship( RelationshipType relationshipType, String relatedResource, String agentName, String agentId) { + if (relatedResource == null) { + log.warn("Related resource for type {} is null. Skipping entity relationship creation.", + relationshipType.getName()); + return null; + } var entityRelationship = new EntityRelationship() .withType("ods:EntityRelationship") .withDwcRelationshipOfResource(relationshipType.getName()) diff --git a/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java b/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java index 8b24601..ae2b8cb 100644 --- a/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java @@ -111,6 +111,8 @@ void testConstructAbcdDigitalSpecimen(ObjectNode identifications, int totalIdent .willReturn("https://www.wikidata.org/wiki/Q604487"); given(termMapper.retrieveTerm(any(PhysicalSpecimenIDType.class), eq(specimenJson), eq(false))) .willReturn(OdsPhysicalSpecimenIDType.RESOLVABLE.value()); + given(fdoProperties.getDigitalSpecimenType()).willReturn( + "https://hdl.handle.net/21.T11148/ce794a6f4df42eb7e77e"); // When var result = director.assembleDigitalSpecimenTerm(specimenJson, false); diff --git a/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java b/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java index 4540abe..8835973 100644 --- a/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java @@ -58,6 +58,8 @@ void testConstructDwcaDigitalSpecimen() throws Exception { .willReturn("https://ror.org/0443cwa12"); given(termMapper.retrieveTerm(any(PhysicalSpecimenIDType.class), eq(specimenJson), eq(true))) .willReturn(OdsPhysicalSpecimenIDType.LOCAL.value()); + given(fdoProperties.getDigitalSpecimenType()).willReturn( + "https://hdl.handle.net/21.T11148/ce794a6f4df42eb7e77e"); // When var result = director.assembleDigitalSpecimenTerm(specimenJson, true); @@ -86,6 +88,8 @@ void testConstructDwcaDigitalSpecimenSingleIdentification() throws Exception { .willReturn("https://ror.org/0443cwa12"); given(termMapper.retrieveTerm(any(PhysicalSpecimenIDType.class), eq(specimenJson), eq(true))) .willReturn(OdsPhysicalSpecimenIDType.LOCAL.value()); + given(fdoProperties.getDigitalSpecimenType()).willReturn( + "https://hdl.handle.net/21.T11148/ce794a6f4df42eb7e77e"); // When var result = director.assembleDigitalSpecimenTerm(specimenJson, true); @@ -112,6 +116,8 @@ void testConstructDwcaDigitalMedia() throws JsonProcessingException, Organisatio "National Museum of Natural History"); given(termMapper.retrieveTerm(any(Term.class), eq(specimenJson), eq(true))).willReturn( "a mapped term"); + given(fdoProperties.getDigitalMediaType()).willReturn( + "https://hdl.handle.net/21.T11148/ce794a6f4df42eb7e77e"); // When var result = director.assembleDigitalMedia(true, specimenJson, diff --git a/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java b/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java index cea8713..a270e1a 100644 --- a/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java @@ -1,6 +1,7 @@ package eu.dissco.core.translator.terms.utils; import static eu.dissco.core.translator.domain.AgentRoleType.DATA_TRANSLATOR; +import static eu.dissco.core.translator.domain.RelationshipType.HAS_FDO_TYPE; import static eu.dissco.core.translator.domain.RelationshipType.HAS_ORGANISATION_ID; import static eu.dissco.core.translator.schema.Agent.Type.SCHEMA_SOFTWARE_APPLICATION; import static org.assertj.core.api.Assertions.assertThat; @@ -13,6 +14,7 @@ import java.util.Date; import java.util.List; import java.util.stream.Stream; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -45,13 +47,24 @@ void testAddEntityRelationship(RelationshipType relationshipType, String related var expected = createEntityRelationship(relationshipType, relatedResource, relatedResourceURI); // When - var result = EntityRelationshipUtils.addEntityRelationship(relationshipType, relatedResource, APP_NAME, APP_PID); + var result = EntityRelationshipUtils.addEntityRelationship(relationshipType, relatedResource, + APP_NAME, APP_PID); // Then assertThat(result).usingRecursiveComparison().ignoringFields("dwcRelationshipEstablishedDate") .isEqualTo(expected); } + @Test + void testNullRelatedResource() { + // When + var result = EntityRelationshipUtils.addEntityRelationship(HAS_FDO_TYPE, null, APP_NAME, + APP_PID); + + // Then + assertThat(result).isNull(); + } + private EntityRelationship createEntityRelationship(RelationshipType relationshipType, String relatedResource, URI relatedResourceURI) { return new EntityRelationship() From 13c41c9182be94fa4419f8737033b6812689a29e Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Mon, 18 Nov 2024 17:34:10 +0100 Subject: [PATCH 3/5] Reduce complexity --- .../dissco/core/translator/terms/utils/AgentsUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java index b5b21e4..b89e42e 100644 --- a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java +++ b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java @@ -65,11 +65,11 @@ private static void handleMultipleAgents( List agents, String agentValue, String agentId, AgentRoleType role, Type type) { var ids = new String[0]; var agentValues = new String[0]; - if (agentValue != null && (agentValue.contains("&") || agentValue.contains("|"))) { + if (checkIfNeedsParsing(agentValue)) { agentValues = Arrays.stream(agentValue.split("[&|]")).map(String::trim) .toArray(String[]::new); } - if (agentId != null && (agentId.contains("&") || agentId.contains("|"))) { + if (checkIfNeedsParsing(agentId)) { ids = Arrays.stream(agentId.split("[&|]")).map(String::trim).toArray(String[]::new); } if (agentValues.length == ids.length) { @@ -96,4 +96,8 @@ private static void handleMultipleAgents( } } } + + private static boolean checkIfNeedsParsing(String value) { + return value != null && (value.contains("&") || value.contains("|")); + } } From 8d961f58d50ec4be0ca008bfb98d53de4dfb27be Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Tue, 19 Nov 2024 14:38:12 +0100 Subject: [PATCH 4/5] Change mediaType for IIIF to interactiveResource --- .../eu/dissco/core/translator/terms/media/MediaType.java | 8 ++++---- .../dissco/core/translator/terms/media/MediaTypeTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java b/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java index 4ac49fb..78bb64a 100644 --- a/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java +++ b/src/main/java/eu/dissco/core/translator/terms/media/MediaType.java @@ -12,11 +12,11 @@ public class MediaType extends Term { private static final String STILL_IMAGE = "Still_Image"; private static final String SOUND = "Sound"; private static final String MOVING_IMAGE = "Moving_Image"; - private static final String DATASET = "Dataset"; + private static final String INTERACTIVE_RESOURCE = "Interactive_Resource"; private final List dwcaTerms = List.of(TERM, "dc:type"); private final List imageFormats = List.of("IMAGE/JPG", "JPG", "IMAGE/JPEG", "JPEG", "IMAGE/PNG", "PNG", "IMAGE/TIF", "TIF"); - private final List datasetFormats = List.of("APPLICATION/JSON"); + private final List interactiveResourceFormats = List.of("APPLICATION/JSON"); @Override public String retrieveFromDWCA(JsonNode unit) { @@ -53,8 +53,8 @@ public String retrieveFromABCD(JsonNode unit) { format = format.toUpperCase(); if (imageFormats.contains(format)) { return STILL_IMAGE; - } else if (datasetFormats.contains(format)) { - return DATASET; + } else if (interactiveResourceFormats.contains(format)) { + return INTERACTIVE_RESOURCE; } else { log.warn("Unable to determine media type of digital media object"); return null; diff --git a/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java b/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java index 513c2ef..18824e7 100644 --- a/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/media/MediaTypeTest.java @@ -40,7 +40,7 @@ private static Stream provideFormatTypes() { private static Stream provideABCDFormats() { return Stream.of( Arguments.of("image/jpeg", "Still_Image"), - Arguments.of("APPLICATION/JSON", "Dataset"), + Arguments.of("APPLICATION/JSON", "Interactive_Resource"), Arguments.of("unknown/format", null), Arguments.of(null, null) ); From e8ee889a3974c695a9e33f1d8ff10c87910b3440 Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Tue, 19 Nov 2024 14:44:18 +0100 Subject: [PATCH 5/5] Code review --- .../eu/dissco/core/translator/terms/utils/AgentsUtils.java | 6 +++--- .../translator/terms/utils/EntityRelationshipUtilsTest.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java index b89e42e..44b6081 100644 --- a/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java +++ b/src/main/java/eu/dissco/core/translator/terms/utils/AgentsUtils.java @@ -65,11 +65,11 @@ private static void handleMultipleAgents( List agents, String agentValue, String agentId, AgentRoleType role, Type type) { var ids = new String[0]; var agentValues = new String[0]; - if (checkIfNeedsParsing(agentValue)) { + if (needsParsing(agentValue)) { agentValues = Arrays.stream(agentValue.split("[&|]")).map(String::trim) .toArray(String[]::new); } - if (checkIfNeedsParsing(agentId)) { + if (needsParsing(agentId)) { ids = Arrays.stream(agentId.split("[&|]")).map(String::trim).toArray(String[]::new); } if (agentValues.length == ids.length) { @@ -97,7 +97,7 @@ private static void handleMultipleAgents( } } - private static boolean checkIfNeedsParsing(String value) { + private static boolean needsParsing(String value) { return value != null && (value.contains("&") || value.contains("|")); } } diff --git a/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java b/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java index a270e1a..c5a2c59 100644 --- a/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/utils/EntityRelationshipUtilsTest.java @@ -4,6 +4,7 @@ import static eu.dissco.core.translator.domain.RelationshipType.HAS_FDO_TYPE; import static eu.dissco.core.translator.domain.RelationshipType.HAS_ORGANISATION_ID; import static eu.dissco.core.translator.schema.Agent.Type.SCHEMA_SOFTWARE_APPLICATION; +import static eu.dissco.core.translator.terms.utils.AgentsUtils.addAgent; import static org.assertj.core.api.Assertions.assertThat; import eu.dissco.core.translator.domain.RelationshipType; @@ -73,7 +74,7 @@ private EntityRelationship createEntityRelationship(RelationshipType relationshi .withDwcRelatedResourceID(relatedResource) .withOdsRelatedResourceURI(relatedResourceURI) .withDwcRelationshipEstablishedDate(Date.from(Instant.now())) - .withOdsHasAgents(AgentsUtils.addAgent(List.of(), APP_NAME, APP_PID, + .withOdsHasAgents(addAgent(List.of(), APP_NAME, APP_PID, DATA_TRANSLATOR, SCHEMA_SOFTWARE_APPLICATION)); }