Skip to content

Commit

Permalink
Merge pull request #35 from DiSSCo/feature/media-object-ror-biocase
Browse files Browse the repository at this point in the history
Feature/media object ror biocase
  • Loading branch information
southeo authored Sep 15, 2023
2 parents 62c9166 + 43a3ac2 commit 85adad2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private void processUnit(DataSet dataset, Unit unit)
kafkaService.sendMessage("digital-specimen",
mapper.writeValueAsString(
new DigitalSpecimenEvent(enrichmentServices(false), digitalSpecimen)));
processDigitalMediaObjects(physicalSpecimenId, unit);
processDigitalMediaObjects(physicalSpecimenId, unit, organisationId);
} catch (DiSSCoDataException e) {
log.error("Encountered data issue with record: {}", unitAttributes, e);
}
Expand Down Expand Up @@ -370,23 +370,23 @@ private JsonNode cleanupRedundantFields(ObjectNode unitData) {
return data;
}

private void processDigitalMediaObjects(String physicalSpecimenId, Unit unit)
private void processDigitalMediaObjects(String physicalSpecimenId, Unit unit, String organisationId)
throws JsonProcessingException {
if (unit.getMultiMediaObjects() != null && !unit.getMultiMediaObjects().getMultiMediaObject()
.isEmpty()) {
for (MultiMediaObject media : unit.getMultiMediaObjects().getMultiMediaObject()) {
processDigitalMediaObject(physicalSpecimenId, media);
processDigitalMediaObject(physicalSpecimenId, media, organisationId);
}
}
}

private void processDigitalMediaObject(String physicalSpecimenId, MultiMediaObject media)
private void processDigitalMediaObject(String physicalSpecimenId, MultiMediaObject media, String organisationId)
throws JsonProcessingException {
var attributes = getData(mapper.valueToTree(media));
var digitalMediaObject = new DigitalMediaObject(
termMapper.retrieveFromABCD(new MediaType(), attributes),
physicalSpecimenId,
harmonizeMedia(attributes),
harmonizeMedia(attributes, organisationId),
attributes
);
log.debug("Result digital media object: {}", digitalMediaObject);
Expand All @@ -395,12 +395,13 @@ private void processDigitalMediaObject(String physicalSpecimenId, MultiMediaObje
new DigitalMediaObjectEvent(enrichmentServices(true), digitalMediaObject)));
}

private JsonNode harmonizeMedia(JsonNode mediaAttributes) {
private JsonNode harmonizeMedia(JsonNode mediaAttributes, String organisationId) {
var attributes = mapper.createObjectNode();
attributes.put(AccessUri.TERM, termMapper.retrieveFromABCD(new AccessUri(), mediaAttributes));
attributes.put(SourceSystemId.TERM, webClientProperties.getSourceSystemId());
attributes.put(Format.TERM, termMapper.retrieveFromABCD(new Format(), mediaAttributes));
attributes.put(License.TERM, termMapper.retrieveFromABCD(new License(), mediaAttributes));
attributes.put(OrganisationId.TERM, organisationId);
return attributes;
}

Expand Down
21 changes: 12 additions & 9 deletions src/main/java/eu/dissco/core/translator/service/DwcaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,38 +174,39 @@ private void processDigitalSpecimen(Collection<ObjectNode> fullRecords)
private void processMedia(String recordId, JsonNode fullDigitalSpecimen)
throws JsonProcessingException {
var extensions = fullDigitalSpecimen.get(EXTENSIONS);
var orgId = termMapper.retrieveFromDWCA(new OrganisationId(), fullDigitalSpecimen);
if (fullDigitalSpecimen.get(DWC_ASSOCIATED_MEDIA) != null) {
publishAssociatedMedia(recordId, fullDigitalSpecimen.get(DWC_ASSOCIATED_MEDIA).asText());
publishAssociatedMedia(recordId, fullDigitalSpecimen.get(DWC_ASSOCIATED_MEDIA).asText(), orgId);
} else if (extensions != null) {
if (extensions.get(GBIF_MULTIMEDIA) != null) {
var imageArray = extensions.get(GBIF_MULTIMEDIA);
if (imageArray.isArray() && imageArray.size() > 0) {
extractMultiMedia(recordId, imageArray);
extractMultiMedia(recordId, imageArray, orgId);
}
} else if (extensions.get(AC_MULTIMEDIA) != null) {
var imageArray = extensions.get(AC_MULTIMEDIA);
if (imageArray.isArray() && imageArray.size() > 0) {
extractMultiMedia(recordId, imageArray);
extractMultiMedia(recordId, imageArray, orgId);
}
}
}
}

private void extractMultiMedia(String recordId, JsonNode imageArray)
private void extractMultiMedia(String recordId, JsonNode imageArray, String orgId)
throws JsonProcessingException {
for (var image : imageArray) {
var type = termMapper.retrieveFromDWCA(new MediaType(), image);
log.debug("Type of digitalMediaObject is: {}", type);
var digitalMediaObject = new DigitalMediaObject(
type,
recordId,
harmonizeMedia(image),
harmonizeMedia(image, orgId),
image);
publishDigitalMediaObject(digitalMediaObject);
}
}

private void publishAssociatedMedia(String recordId, String associatedMedia)
private void publishAssociatedMedia(String recordId, String associatedMedia, String orgId)
throws JsonProcessingException {
log.debug("Digital Specimen: {}, has associatedMedia {}", recordId,
associatedMedia);
Expand All @@ -214,16 +215,17 @@ private void publishAssociatedMedia(String recordId, String associatedMedia)
var digitalMediaObject = new DigitalMediaObject(
UNKNOWN,
recordId,
harmonizeAssociatedMedia(mediaUrl),
harmonizeAssociatedMedia(mediaUrl, orgId),
null);
publishDigitalMediaObject(digitalMediaObject);
}
}

private JsonNode harmonizeAssociatedMedia(String mediaUrl) {
private JsonNode harmonizeAssociatedMedia(String mediaUrl, String orgId) {
var attributes = mapper.createObjectNode();
attributes.put(AccessUri.TERM, mediaUrl);
attributes.put(SourceSystemId.TERM, webClientProperties.getSourceSystemId());
attributes.put(OrganisationId.TERM, orgId);
return attributes;
}

Expand Down Expand Up @@ -372,12 +374,13 @@ private void postExtensions(Set<ArchiveFile> extensions) {
log.info("Finished posting extensions archive to database");
}

private JsonNode harmonizeMedia(JsonNode media) {
private JsonNode harmonizeMedia(JsonNode media, String orgId) {
var attributes = mapper.createObjectNode();
attributes.put(AccessUri.TERM, termMapper.retrieveFromDWCA(new AccessUri(), media));
attributes.put(SourceSystemId.TERM, webClientProperties.getSourceSystemId());
attributes.put(Format.TERM, termMapper.retrieveFromDWCA(new Format(), media));
attributes.put(License.TERM, termMapper.retrieveFromDWCA(new License(), media));
attributes.put(OrganisationId.TERM, orgId);
return attributes;
}

Expand Down

0 comments on commit 85adad2

Please sign in to comment.