Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add objects when not empty #75

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,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;
Expand All @@ -266,6 +267,12 @@
@RequiredArgsConstructor
public abstract class BaseDigitalObjectDirector {

private static final Georeference EMPTY_GEOREFERENCE = new Georeference().withType(
"ods:Georeference");
private static final GeologicalContext EMPTY_GEOLOGICAL_CONTEXT = new GeologicalContext().withType(
"ods:GeologicalContext");
private static final Location EMPTY_LOCATION = new Location().withType("ods:Location");

protected final ObjectMapper mapper;
protected final TermMapper termMapper;
private final OrganisationNameComponent organisationNameComponent;
Expand Down Expand Up @@ -619,6 +626,12 @@ private List<Event> assembleEventTerms(JsonNode data, boolean dwc) {
setMinMaxMeterField(new MaximumElevationInMeters(), location, data, dwc);
setMinMaxMeterField(new MinimumDepthInMeters(), location, data, dwc);
setMinMaxMeterField(new MaximumDepthInMeters(), location, data, dwc);
if (!Objects.equals(geoReference, EMPTY_GEOREFERENCE)) {
location.setOdsHasGeoreference(geoReference);
}
if (!Objects.equals(geologicalContext, EMPTY_GEOLOGICAL_CONTEXT)) {
location.setOdsHasGeologicalContext(geologicalContext);
}
var assertions = new EventAssertions().gatherEventAssertions(mapper, data, dwc);
var event = new Event()
.withType("ods:Event")
Expand Down Expand Up @@ -650,8 +663,10 @@ private List<Event> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -61,7 +63,10 @@ protected List<Citation> 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;
}
Expand Down
Loading