diff --git a/src/main/java/eu/dissco/core/translator/service/BioCaseService.java b/src/main/java/eu/dissco/core/translator/service/BioCaseService.java index a034e2f..be20cbd 100644 --- a/src/main/java/eu/dissco/core/translator/service/BioCaseService.java +++ b/src/main/java/eu/dissco/core/translator/service/BioCaseService.java @@ -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); } @@ -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); @@ -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; } 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 c8b9799..a45251a 100644 --- a/src/main/java/eu/dissco/core/translator/service/DwcaService.java +++ b/src/main/java/eu/dissco/core/translator/service/DwcaService.java @@ -174,24 +174,25 @@ private void processDigitalSpecimen(Collection 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); @@ -199,13 +200,13 @@ private void extractMultiMedia(String recordId, JsonNode imageArray) 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); @@ -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; } @@ -372,12 +374,13 @@ private void postExtensions(Set 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; }