diff --git a/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java b/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java index 4c1ae81..1521518 100644 --- a/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java +++ b/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java @@ -81,7 +81,17 @@ public void listen(String message) { String stableDatasetId = metadataService.getDataset(datasetsDbTableId).getStableId(); log.info("Reference id {} mapped to dataset id {}", requestedDatasetId, stableDatasetId); requestedDatasetId = stableDatasetId; // use stable dataset id instead of reference to complete the export as normal - Collection approvedMappedDatasetIds = approvedDatasetIds.stream().map(x -> metadataService.getDataset(metadataService.findByReferenceId(x).getDatasetId()).getStableId()).toList(); + Collection approvedMappedDatasetIds = approvedDatasetIds.stream() + .map(x -> { + var reference = metadataService.findByReferenceId(x); + if (reference != null && reference.getDatasetId() != null) { + var dataset = metadataService.getDataset(reference.getDatasetId()); + return dataset != null ? dataset.getStableId() : x; + } else { + return x; + } + }) + .toList(); approvedDatasetIds = approvedMappedDatasetIds; } exportDataset(user, approvedDatasetIds, requestedDatasetId, exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate());