From cde73bb307df68db06335975fb84646fd947d3ac Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Thu, 21 Nov 2024 15:50:22 +0100 Subject: [PATCH 1/2] Only add objects when not empty --- .../terms/BaseDigitalObjectDirector.java | 25 ++++++++++++++++--- .../terms/DwcaDigitalObjectDirector.java | 7 +++++- 2 files changed, 27 insertions(+), 5 deletions(-) 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 fabe28d..ba6dd96 100644 --- a/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java @@ -256,6 +256,7 @@ import eu.dissco.core.translator.terms.specimen.stratigraphy.lithostratigraphic.Member; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -265,6 +266,12 @@ @RequiredArgsConstructor public abstract class BaseDigitalObjectDirector { + private final static Georeference EMPTY_GEOREFERENCE = new Georeference().withType( + "ods:Georeference"); + private final static GeologicalContext EMPTY_GEOLOGICAL_CONTEXT = new GeologicalContext().withType( + "ods:GeologicalContext"); + private final static Location EMPTY_LOCATION = new Location().withType("ods:Location"); + protected final ObjectMapper mapper; protected final TermMapper termMapper; private final OrganisationNameComponent organisationNameComponent; @@ -605,9 +612,17 @@ private List assembleEventTerms(JsonNode data, boolean dwc) { .withDwcVerbatimElevation(termMapper.retrieveTerm(new VerbatimElevation(), data, dwc)) .withDwcVerticalDatum(termMapper.retrieveTerm(new VerticalDatum(), data, dwc)) .withDwcLocationAccordingTo(termMapper.retrieveTerm(new LocationAccordingTo(), data, dwc)) - .withDwcLocationRemarks(termMapper.retrieveTerm(new LocationRemarks(), data, dwc)) - .withOdsHasGeoreference(geoReference) - .withOdsHasGeologicalContext(geologicalContext); + .withDwcLocationRemarks(termMapper.retrieveTerm(new LocationRemarks(), data, dwc)); + if (!Objects.equals(geoReference, EMPTY_GEOREFERENCE)) { + location.setOdsHasGeoreference(geoReference); + } + if (!Objects.equals(geologicalContext, EMPTY_GEOLOGICAL_CONTEXT)) { + location.setOdsHasGeologicalContext(geologicalContext); + } + setMinMaxMeterField(new MinimumElevationInMeters(), location, data, dwc); + setMinMaxMeterField(new MaximumElevationInMeters(), location, data, dwc); + setMinMaxMeterField(new MinimumDepthInMeters(), location, data, dwc); + setMinMaxMeterField(new MaximumDepthInMeters(), location, data, dwc); var assertions = new EventAssertions().gatherEventAssertions(mapper, data, dwc); var event = new Event() .withType("ods:Event") @@ -639,8 +654,10 @@ private List assembleEventTerms(JsonNode data, boolean dwc) { .withDwcSampleSizeValue(parseToDouble(new SampleSizeValue(), data, dwc)) .withDwcCaste(termMapper.retrieveTerm(new Caste(), data, dwc)) .withDwcVitality(termMapper.retrieveTerm(new Vitality(), data, dwc)) - .withOdsHasLocation(location) .withOdsHasAssertions(assertions); + if (!Objects.equals(location, EMPTY_LOCATION)) { + event.setOdsHasLocation(location); + } event.setOdsHasAgents( addAgent(event.getOdsHasAgents(), termMapper.retrieveTerm(new RecordedBy(), data, dwc), termMapper.retrieveTerm(new RecordedByID(), data, dwc), COLLECTOR, SCHEMA_PERSON)); 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 aff9fd9..0c060df 100644 --- a/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java @@ -12,6 +12,7 @@ import eu.dissco.core.translator.schema.Identification; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -22,6 +23,7 @@ public class DwcaDigitalObjectDirector extends BaseDigitalObjectDirector { private static final String EXTENSION = "extensions"; + private static final Citation EMTPY_CITATION = new Citation().withType("ods:Citation"); public DwcaDigitalObjectDirector(ObjectMapper mapper, TermMapper termMapper, OrganisationNameComponent rorComponent, SourceSystemComponent sourceSystemComponent, @@ -61,7 +63,10 @@ protected List assembleSpecimenCitations(JsonNode data, boolean dwc) { } } } else { - citations.add(createCitation(data, dwc)); + var citation = createCitation(data, dwc); + if (!Objects.equals(citation, EMTPY_CITATION)) { + citations.add(citation); + } } return citations; } From 19246664211575783d1d11c1748a2f705d1517f3 Mon Sep 17 00:00:00 2001 From: Sam Leeflang Date: Mon, 25 Nov 2024 08:36:58 +0100 Subject: [PATCH 2/2] Fix sonar issue --- .../core/translator/terms/BaseDigitalObjectDirector.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 3034017..4e1f4c5 100644 --- a/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java @@ -267,11 +267,11 @@ @RequiredArgsConstructor public abstract class BaseDigitalObjectDirector { - private final static Georeference EMPTY_GEOREFERENCE = new Georeference().withType( + private static final Georeference EMPTY_GEOREFERENCE = new Georeference().withType( "ods:Georeference"); - private final static GeologicalContext EMPTY_GEOLOGICAL_CONTEXT = new GeologicalContext().withType( + private static final GeologicalContext EMPTY_GEOLOGICAL_CONTEXT = new GeologicalContext().withType( "ods:GeologicalContext"); - private final static Location EMPTY_LOCATION = new Location().withType("ods:Location"); + private static final Location EMPTY_LOCATION = new Location().withType("ods:Location"); protected final ObjectMapper mapper; protected final TermMapper termMapper;