Skip to content

Commit

Permalink
Merge pull request #67 from DiSSCo/feature/agent-improvements
Browse files Browse the repository at this point in the history
Support multiple agents parsing, eventType, media licenses
  • Loading branch information
samleeflang authored Nov 11, 2024
2 parents 6217451 + 171a015 commit 8c4f7fe
Show file tree
Hide file tree
Showing 14 changed files with 405 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package eu.dissco.core.translator.domain;

public enum AgenRoleType {
import lombok.Getter;

@Getter
public enum AgentRoleType {

COLLECTOR("collector"),
DATA_TRANSLATOR("data-translator"),
CREATOR("creator"),
IDENTIFIER("identifier"),
GEOREFERENCER("georeferencer");
GEOREFERENCER("georeferencer"),
RIGHTS_OWNER("rights-owner");

private final String name;

AgenRoleType(String name) {
AgentRoleType(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package eu.dissco.core.translator.terms;

import static eu.dissco.core.translator.domain.AgenRoleType.CREATOR;
import static eu.dissco.core.translator.domain.AgenRoleType.DATA_TRANSLATOR;
import static eu.dissco.core.translator.domain.AgenRoleType.GEOREFERENCER;
import static eu.dissco.core.translator.domain.AgenRoleType.IDENTIFIER;
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;
import static eu.dissco.core.translator.domain.RelationshipType.HAS_FDO_TYPE;
import static eu.dissco.core.translator.domain.RelationshipType.HAS_LICENSE;
import static eu.dissco.core.translator.domain.RelationshipType.HAS_ORGANISATION_ID;
Expand All @@ -14,17 +16,16 @@
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 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.AgenRoleType;
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;
import eu.dissco.core.translator.schema.Agent;
import eu.dissco.core.translator.schema.Citation;
import eu.dissco.core.translator.schema.DigitalMedia;
import eu.dissco.core.translator.schema.DigitalMedia.DctermsType;
Expand All @@ -39,7 +40,6 @@
import eu.dissco.core.translator.schema.Identification;
import eu.dissco.core.translator.schema.Identifier;
import eu.dissco.core.translator.schema.Location;
import eu.dissco.core.translator.schema.OdsHasRole;
import eu.dissco.core.translator.schema.TaxonIdentification;
import eu.dissco.core.translator.terms.media.AccessURI;
import eu.dissco.core.translator.terms.media.Available;
Expand Down Expand Up @@ -70,9 +70,11 @@
import eu.dissco.core.translator.terms.media.Subtype;
import eu.dissco.core.translator.terms.media.SubtypeLiteral;
import eu.dissco.core.translator.terms.media.TimeOfDay;
import eu.dissco.core.translator.terms.media.UsageTerms;
import eu.dissco.core.translator.terms.media.Variant;
import eu.dissco.core.translator.terms.media.VariantDescription;
import eu.dissco.core.translator.terms.media.VariantLiteral;
import eu.dissco.core.translator.terms.media.WebStatement;
import eu.dissco.core.translator.terms.specimen.AccessRights;
import eu.dissco.core.translator.terms.specimen.BasisOfRecord;
import eu.dissco.core.translator.terms.specimen.CollectionID;
Expand Down Expand Up @@ -116,6 +118,7 @@
import eu.dissco.core.translator.terms.specimen.event.EventDate;
import eu.dissco.core.translator.terms.specimen.event.EventRemark;
import eu.dissco.core.translator.terms.specimen.event.EventRemarks;
import eu.dissco.core.translator.terms.specimen.event.EventType;
import eu.dissco.core.translator.terms.specimen.event.FieldNotes;
import eu.dissco.core.translator.terms.specimen.event.FieldNumber;
import eu.dissco.core.translator.terms.specimen.event.GeoreferenceVerificationStatus;
Expand All @@ -138,6 +141,7 @@
import eu.dissco.core.translator.terms.specimen.identification.IdentificationRemarks;
import eu.dissco.core.translator.terms.specimen.identification.IdentificationVerificationStatus;
import eu.dissco.core.translator.terms.specimen.identification.IdentifiedBy;
import eu.dissco.core.translator.terms.specimen.identification.IdentifiedByID;
import eu.dissco.core.translator.terms.specimen.identification.TypeStatus;
import eu.dissco.core.translator.terms.specimen.identification.VerbatimIdentification;
import eu.dissco.core.translator.terms.specimen.identification.taxonomy.AcceptedNameUsage;
Expand Down Expand Up @@ -280,19 +284,20 @@ private void setCalculatedFields(DigitalSpecimen ds, JsonNode data) {
protected abstract List<Identification> assembleIdentifications(JsonNode data, boolean dwc);

protected Citation createCitation(JsonNode data, boolean dwc) {
return new Citation()
var citation = new Citation()
.withId(termMapper.retrieveTerm(new ReferenceIRI(), data, dwc))
.withType("ods:Citation")
.withDctermsBibliographicCitation(
termMapper.retrieveTerm(new BibliographicCitation(), data, dwc))
.withDctermsDescription(termMapper.retrieveTerm(new CitationDescription(), data, dwc))
.withDctermsIdentifier(termMapper.retrieveTerm(new ReferenceIRI(), data, dwc))
.withOdsHasAgents(getAgent(termMapper.retrieveTerm(
new eu.dissco.core.translator.terms.specimen.citation.Creator(),
data, dwc), null, CREATOR, SCHEMA_PERSON))
.withDctermsType(termMapper.retrieveTerm(new Type(), data, dwc))
.withDctermsDate(termMapper.retrieveTerm(new Date(), data, dwc))
.withDctermsTitle(termMapper.retrieveTerm(new Title(), data, dwc));
citation.setOdsHasAgents(addAgent(citation.getOdsHasAgents(), termMapper.retrieveTerm(
new eu.dissco.core.translator.terms.specimen.citation.Creator(),
data, dwc), null, CREATOR, SCHEMA_PERSON));
return citation;
}

private DigitalSpecimen assembleDigitalSpecimenTerms(JsonNode data, boolean dwc)
Expand Down Expand Up @@ -338,10 +343,7 @@ private DigitalSpecimen assembleDigitalSpecimenTerms(JsonNode data, boolean dwc)
.withDwcDisposition(termMapper.retrieveTerm(new Disposition(), data, dwc))
.withDwcInformationWithheld(termMapper.retrieveTerm(new InformationWithheld(), data, dwc))
.withDwcVerbatimLabel(termMapper.retrieveTerm(new VerbatimLabel(), data, dwc))
.withDwcDataGeneralizations(termMapper.retrieveTerm(new DataGeneralizations(), data, dwc))
.withOdsHasAgents(getAgent(termMapper.retrieveTerm(new RecordedBy(), data, dwc),
termMapper.retrieveTerm(new RecordedByID(), data, dwc), AgenRoleType.COLLECTOR,
SCHEMA_PERSON));
.withDwcDataGeneralizations(termMapper.retrieveTerm(new DataGeneralizations(), data, dwc));
}

private String getOrganisationName(String organisationId) throws OrganisationException {
Expand Down Expand Up @@ -382,14 +384,14 @@ private List<EntityRelationship> assembleDigitalSpecimenEntityRelationships(

private EntityRelationship getEntityRelationship(RelationshipType relationshipType,
String relatedResource) {
return new EntityRelationship()
var entityRelationship = new EntityRelationship()
.withType("ods:EntityRelationship")
.withDwcRelationshipOfResource(relationshipType.getName())
.withDwcRelatedResourceID(relatedResource)
.withOdsHasAgents(
getAgent(fdoProperties.getApplicationName(), fdoProperties.getApplicationPID(),
DATA_TRANSLATOR, SCHEMA_SOFTWARE_APPLICATION))
.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<eu.dissco.core.translator.schema.Identifier> assembleIdentifiers(JsonNode data) {
Expand Down Expand Up @@ -445,7 +447,7 @@ protected Identification createIdentification(JsonNode data, boolean dwc) {
.withDwcSuperfamily(termMapper.retrieveTerm(new Superfamily(), data, dwc))
.withDwcTribe(termMapper.retrieveTerm(new Tribe(), data, dwc));
var identificationId = termMapper.retrieveTerm(new IdentificationID(), data, dwc);
return new Identification()
var identification = new Identification()
.withId(identificationId)
.withType("ods:Identification")
.withDwcIdentificationID(identificationId)
Expand All @@ -457,11 +459,11 @@ protected Identification createIdentification(JsonNode data, boolean dwc) {
termMapper.retrieveTerm(new IdentificationRemarks(), data, dwc))
.withDwcVerbatimIdentification(
termMapper.retrieveTerm(new VerbatimIdentification(), data, dwc))
.withOdsHasAgents(
getAgent(termMapper.retrieveTerm(new IdentifiedBy(), data, dwc), null, IDENTIFIER,
SCHEMA_PERSON))
.withOdsHasTaxonIdentifications(List.of(mappedTaxonIdentification))
.withOdsHasCitations(assembleIdentificationCitations(data, dwc));
identification.setOdsHasAgents(addAgent(identification.getOdsHasAgents(), termMapper.retrieveTerm(new IdentifiedBy(), data, dwc),
termMapper.retrieveTerm(new IdentifiedByID(), data, dwc), IDENTIFIER, SCHEMA_PERSON));
return identification;
}


Expand All @@ -488,10 +490,9 @@ private List<Event> assembleEventTerms(JsonNode data, boolean dwc) {
.withDwcGeoreferencedDate(termMapper.retrieveTerm(new GeoreferencedDate(), data, dwc))
.withDwcGeoreferenceRemarks(termMapper.retrieveTerm(new GeoreferenceRemarks(), data, dwc))
.withDwcGeoreferenceSources(termMapper.retrieveTerm(new GeoreferenceSources(), data, dwc))
.withDwcPointRadiusSpatialFit(parseToDouble(new PointRadiusSpatialFit(), data, dwc))
.withOdsHasAgents(
getAgent(termMapper.retrieveTerm(new GeoreferencedBy(), data, dwc), null,
GEOREFERENCER, SCHEMA_PERSON));
.withDwcPointRadiusSpatialFit(parseToDouble(new PointRadiusSpatialFit(), data, dwc));
geoReference.setOdsHasAgents(addAgent(geoReference.getOdsHasAgents(), termMapper.retrieveTerm(
new GeoreferencedBy(), data, dwc), null, GEOREFERENCER, SCHEMA_PERSON));
var geologicalContext = new GeologicalContext()
.withType("ods:GeologicalContext")
.withDwcLowestBiostratigraphicZone(
Expand Down Expand Up @@ -559,6 +560,7 @@ private List<Event> assembleEventTerms(JsonNode data, boolean dwc) {
var assertions = new EventAssertions().gatherEventAssertions(mapper, data, dwc);
var event = new Event()
.withType("ods:Event")
.withDwcEventType(termMapper.retrieveTerm(new EventType(), data, dwc))
.withDwcFieldNumber(termMapper.retrieveTerm(new FieldNumber(), data, dwc))
.withDwcEventDate(termMapper.retrieveTerm(new EventDate(), data, dwc))
.withDwcVerbatimEventDate(termMapper.retrieveTerm(new VerbatimEventDate(), data, dwc))
Expand Down Expand Up @@ -588,6 +590,8 @@ private List<Event> 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));
return List.of(event);
}

Expand Down Expand Up @@ -653,6 +657,8 @@ public DigitalMedia assembleDigitalMedia(boolean dwc, JsonNode mediaRecord,
.withOdsOrganisationName(getOrganisationName(organisationId))
.withAcAccessURI(termMapper.retrieveTerm(new AccessURI(), mediaRecord, dwc))
.withDctermsRights(termMapper.retrieveTerm(new License(), mediaRecord, dwc))
.withXmpRightsUsageTerms(termMapper.retrieveTerm(new UsageTerms(), mediaRecord, dwc))
.withXmpRightsWebStatement(termMapper.retrieveTerm(new WebStatement(), mediaRecord, dwc))
.withDctermsFormat(termMapper.retrieveTerm(new Format(), mediaRecord, dwc))
.withDctermsType(retrieveEnum(new MediaType(), mediaRecord, dwc, DctermsType.class))
.withDctermsSource(termMapper.retrieveTerm(new Source(), mediaRecord, dwc))
Expand Down Expand Up @@ -696,33 +702,16 @@ public DigitalMedia assembleDigitalMedia(boolean dwc, JsonNode mediaRecord,
termMapper.retrieveTerm(new Modified(), mediaRecord, dwc))
.withDctermsDescription(termMapper.retrieveTerm(new Description(), mediaRecord, dwc))
.withOdsHasIdentifiers(assembleIdentifiers(mediaRecord))
.withOdsHasAssertions(new MediaAssertions().gatherAssertions(mediaRecord, dwc))
.withOdsHasAgents(getAgent(termMapper.retrieveTerm(new Creator(), mediaRecord, dwc),
null, AgenRoleType.CREATOR, SCHEMA_PERSON));
.withOdsHasAssertions(new MediaAssertions().gatherAssertions(mediaRecord, dwc));
digitalMedia.setOdsHasAgents(addAgent(digitalMedia.getOdsHasAgents(), termMapper
.retrieveTerm(new Creator(), mediaRecord, dwc), null, CREATOR, SCHEMA_PERSON));
digitalMedia.setOdsHasAgents(addAgent(digitalMedia.getOdsHasAgents(), termMapper
.retrieveTerm(new RightsOwner(), mediaRecord, dwc), null, RIGHTS_OWNER, SCHEMA_PERSON));
digitalMedia.withOdsHasEntityRelationships(
assembleDigitalMediaEntityRelationships(digitalMedia));
return digitalMedia;
}

private List<Agent> getAgent(String name, String id, AgenRoleType role, Agent.Type type) {
if (name != null || id != null) {
var agent = new Agent()
.withId(id)
.withType(type)
.withSchemaName(name)
.withSchemaIdentifier(id)
.withOdsHasRoles(
List.of(new OdsHasRole().withType("schema:Role").withSchemaRoleName(role.getName())));
if (id != null) {
agent.withOdsHasIdentifiers(List.of(
new Identifier().withId(id).withType("ods:Identifier").withDctermsIdentifier(id)));

}
return List.of(agent);
}
return null;
}

private List<EntityRelationship> assembleDigitalMediaEntityRelationships(
DigitalMedia digitalMedia) {
var relationships = new ArrayList<EntityRelationship>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eu.dissco.core.translator.terms.media;

import com.fasterxml.jackson.databind.JsonNode;
import eu.dissco.core.translator.terms.Term;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UsageTerms extends Term {

public static final String TERM = "xmpRights:UsageTerms";
private final List<String> dwcaTerms = List.of(TERM);

@Override
public String retrieveFromDWCA(JsonNode unit) {
return super.searchJsonForTerm(unit, dwcaTerms);
}

@Override
public String getTerm() {
return TERM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class WebStatement extends Term {

public static final String TERM = "xmpRights:webStatement";
public static final String TERM = "xmpRights:WebStatement";
private final List<String> dwcaTerms = List.of(TERM);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.dissco.core.translator.terms.specimen.event;

import com.fasterxml.jackson.databind.JsonNode;
import eu.dissco.core.translator.terms.Term;
import java.util.List;

public class EventType extends Term {

public static final String TERM = DWC_PREFIX + "eventType";

private final List<String> dwcaTerms = List.of(TERM);

@Override
public String retrieveFromDWCA(JsonNode unit) {
var eventType = super.searchJsonForTerm(unit, dwcaTerms);
if (eventType == null) {
eventType = "Collecting Event";
}
return eventType;
}

@Override
public String getTerm() {
return TERM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class IdentifiedByID extends Term {

public static final String TERM = DWC_PREFIX + "identifiedById";
public static final String TERM = DWC_PREFIX + "identifiedByID";

private final List<String> dwcaTerms = List.of(TERM);

Expand Down
Loading

0 comments on commit 8c4f7fe

Please sign in to comment.