From c25b5d0649e657c9ba265f338f13177fcda408a5 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Tue, 10 Dec 2024 12:11:52 +0100 Subject: [PATCH 1/4] Retrieving current dataset metadata more efficiently and less often. --- pom.xml | 2 +- .../core/dansbag/DansBagMappingService.java | 3 +- .../dansbag/DansBagMappingServiceImpl.java | 52 ++++++++++--------- .../core/dansbag/DansDepositConverter.java | 5 +- .../core/dansbag/DansDepositSupport.java | 11 ++-- .../core/service/DataverseService.java | 2 + .../core/service/DataverseServiceImpl.java | 9 +++- .../dansbag/DansDepositConverterTest.java | 2 +- 8 files changed, 52 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 0aa6ca0..7fd4616 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ nl.knaw.dans dans-dataverse-client-lib - 1.0.2 + 1.0.3-SNAPSHOT nl.knaw.dans diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java index f5d3f7b..b48312a 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java @@ -21,6 +21,7 @@ import nl.knaw.dans.dvingest.core.yaml.EditPermissions; import nl.knaw.dans.lib.dataverse.DataverseException; import nl.knaw.dans.lib.dataverse.model.dataset.Dataset; +import nl.knaw.dans.lib.dataverse.model.dataset.DatasetVersion; import java.io.IOException; import java.nio.file.Path; @@ -30,7 +31,7 @@ public interface DansBagMappingService { DansBagDeposit readDansDeposit(Path depositDir) throws InvalidDepositException; - Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit); + Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion updatesDataset); EditFiles getEditFilesFromDansDeposit(DansBagDeposit dansDeposit, String updatesDataset); diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java index 6bba7cd..7599fd4 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java @@ -33,6 +33,7 @@ import nl.knaw.dans.lib.dataverse.DataverseException; import nl.knaw.dans.lib.dataverse.model.RoleAssignment; import nl.knaw.dans.lib.dataverse.model.dataset.Dataset; +import nl.knaw.dans.lib.dataverse.model.dataset.DatasetVersion; import nl.knaw.dans.lib.dataverse.model.user.AuthenticatedUser; import nl.knaw.dans.lib.util.ZipUtil; import org.apache.commons.lang3.StringUtils; @@ -88,37 +89,38 @@ public String getUpdatesDataset(Path depositDir) throws IOException, DataverseEx .findFirst().orElseThrow(() -> new IllegalArgumentException("No bag found in deposit")); var bagInfo = new LightweightBagInfo(bag.resolve("bag-info.txt")); var isVersionOf = bagInfo.get("Is-Version-Of"); - if (isVersionOf != null) { - log.debug("Found Is-Version-Of in bag-info.txt, so this is an update-deposit: {}", isVersionOf); - List results; - if (dansDepositProperties.getSwordToken() != null) { - log.debug("Found sword token in deposit.properties, looking for target dataset by sword token"); - results = dataverseService.findDoiByMetadataField("dansSwordToken", dansDepositProperties.getSwordToken()); - } - else if (depositToDvDatasetMetadataMapper.isMigration()) { - log.debug("This is a migration deposit, looking for target dataset by dansBagIt. Note that this will only work for two versions of the same dataset"); - results = dataverseService.findDoiByMetadataField("dansBagId", isVersionOf); - - } - else { - throw new IllegalArgumentException("Update deposit should have either a sword token or be a migration deposit"); - } - if (results.size() == 1) { - return results.get(0); - } - else { - throw new IllegalArgumentException("Update deposit should update exactly one dataset, found " + results.size()); - } - } - else { + + if (isVersionOf == null) { log.debug("No Is-Version-Of found in bag-info.txt, so this is a deposit of a new dataset"); return null; } + + log.debug("Found Is-Version-Of in bag-info.txt, so this is an update-deposit: {}", isVersionOf); + List results; + + if (dansDepositProperties.getSwordToken() != null) { + log.debug("Found sword token in deposit.properties, looking for target dataset by sword token"); + results = dataverseService.findDoiByMetadataField("dansSwordToken", dansDepositProperties.getSwordToken()); + } + else if (depositToDvDatasetMetadataMapper.isMigration()) { + log.debug("This is a migration deposit, looking for target dataset by dansBagId"); + results = dataverseService.findDoiByMetadataField("dansBagId", isVersionOf); + } + else { + throw new IllegalArgumentException("Update deposit should have either a sword token or be a migration deposit"); + } + + if (results.size() == 1) { + return results.get(0); + } + else { + throw new IllegalArgumentException("Update deposit should update exactly one dataset, found " + results.size()); + } } } @Override - public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit) { + public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion currentMetadata) { var dataset = depositToDvDatasetMetadataMapper.toDataverseDataset( dansDeposit.getDdm(), dansDeposit.getOtherDoiId(), @@ -136,6 +138,8 @@ public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit) { if (!dansDeposit.allowAccessRequests() && StringUtils.isBlank(version.getTermsOfAccess())) { version.setTermsOfAccess("N/a"); } + + version.setLicense(supportedLicenses.getLicenseFromDansDeposit(dansDeposit)); return dataset; } diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverter.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverter.java index 7f0d83f..2c4e928 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverter.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverter.java @@ -21,6 +21,7 @@ import nl.knaw.dans.dvingest.core.yaml.EditFilesRoot; import nl.knaw.dans.dvingest.core.yaml.EditPermissionsRoot; import nl.knaw.dans.dvingest.core.yaml.UpdateState; +import nl.knaw.dans.lib.dataverse.model.dataset.DatasetVersion; import java.io.IOException; @@ -28,6 +29,7 @@ public class DansDepositConverter { private final DansBagDeposit dansDeposit; private final String updatesDataset; + private final DatasetVersion currentMetadata; private final DansBagMappingService mappingService; private final YamlService yamlService; @@ -35,7 +37,7 @@ public void run() throws IOException { // TODO: pass to getEditFilesFromDansDeposit so that update-deposit can register it as a replaced file var originalMetadataPath = mappingService.packageOriginalMetadata(dansDeposit); - var dataset = mappingService.getDatasetMetadataFromDansDeposit(dansDeposit); + var dataset = mappingService.getDatasetMetadataFromDansDeposit(dansDeposit, currentMetadata); yamlService.writeYaml(dataset, dansDeposit.getBagDir().resolve("dataset.yml")); var editFiles = mappingService.getEditFilesFromDansDeposit(dansDeposit, updatesDataset); @@ -48,5 +50,4 @@ public void run() throws IOException { updateState.setAction("publish-major"); yamlService.writeYaml(updateState, dansDeposit.getBagDir().resolve("update-state.yml")); } - } diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupport.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupport.java index 94c1873..cfc4bd7 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupport.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupport.java @@ -29,6 +29,7 @@ import nl.knaw.dans.dvingest.core.service.DataverseService; import nl.knaw.dans.dvingest.core.service.YamlService; import nl.knaw.dans.lib.dataverse.DataverseException; +import nl.knaw.dans.lib.dataverse.model.dataset.DatasetVersion; import java.io.IOException; import java.nio.file.Path; @@ -49,7 +50,8 @@ public class DansDepositSupport implements Deposit { private DansBagDeposit dansDeposit; - public DansDepositSupport(DataverseIngestDeposit dataverseIngestDeposit, ValidateDansBagService validateDansBagService, DansBagMappingService dansBagMappingService, DataverseService dataverseService, YamlService yamlService) { + public DansDepositSupport(DataverseIngestDeposit dataverseIngestDeposit, ValidateDansBagService validateDansBagService, DansBagMappingService dansBagMappingService, + DataverseService dataverseService, YamlService yamlService) { this.validateDansBagService = validateDansBagService; this.ingestDataverseIngestDeposit = dataverseIngestDeposit; this.dansBagMappingService = dansBagMappingService; @@ -69,11 +71,13 @@ public boolean convertDansDepositIfNeeded() { log.info("Converting deposit to Dataverse ingest metadata"); try { var updatesDataset = dansBagMappingService.getUpdatesDataset(ingestDataverseIngestDeposit.getLocation()); + DatasetVersion currentMetadata = null; if (updatesDataset != null) { ingestDataverseIngestDeposit.updateProperties(Map.of(UPDATES_DATASET_KEY, updatesDataset)); + currentMetadata = dataverseService.getDatasetMetadata(updatesDataset); } dansDeposit = dansBagMappingService.readDansDeposit(ingestDataverseIngestDeposit.getLocation()); - new DansDepositConverter(dansDeposit, updatesDataset, dansBagMappingService, yamlService).run(); + new DansDepositConverter(dansDeposit, updatesDataset, currentMetadata, dansBagMappingService, yamlService).run(); log.info("Conversion successful"); return true; } @@ -119,7 +123,8 @@ public void onSuccess(@NonNull String pid, String message) { "identifier.urn", nbn ) ); - } catch (IOException | DataverseException e) { + } + catch (IOException | DataverseException e) { throw new RuntimeException("Error getting URN:NBN", e); // Cancelling the "success" } } diff --git a/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseService.java b/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseService.java index 9f5d43c..8f8c36c 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseService.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseService.java @@ -72,4 +72,6 @@ public interface DataverseService { void addEmbargo(String pid, Embargo embargo) throws IOException, DataverseException; List findDoiByMetadataField(String fieldName, String value) throws IOException, DataverseException; + + DatasetVersion getDatasetMetadata(String pid) throws IOException, DataverseException; } diff --git a/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseServiceImpl.java b/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseServiceImpl.java index c4e3cf9..4434189 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseServiceImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/service/DataverseServiceImpl.java @@ -206,6 +206,11 @@ public String getDatasetUrnNbn(String pid) throws IOException, DataverseExceptio .findFirst().orElseThrow(() -> new IllegalStateException("No URN:NBN found in dataset")); } + @Override + public DatasetVersion getDatasetMetadata(String pid) throws IOException, DataverseException { + return dataverseClient.dataset(pid).getVersion().getData(); + } + // TODO: move this to dans-dataverse-client-lib; it is similar to awaitLockState. public void waitForState(String datasetId, String expectedState) { var numberOfTimesTried = 0; @@ -239,8 +244,8 @@ public void waitForState(String datasetId, String expectedState) { } private String getDatasetState(String datasetId) throws IOException, DataverseException { - var version = dataverseClient.dataset(datasetId).getLatestVersion(); - return version.getData().getLatestVersion().getVersionState(); + var version = dataverseClient.dataset(datasetId).getVersion(Version.LATEST.toString(), true); + return version.getData().getVersionState(); } } diff --git a/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java b/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java index 7ce4573..6c532be 100644 --- a/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java +++ b/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java @@ -44,7 +44,7 @@ public void run_converts_dans_sword_all_mappings_example_to_dataverse_ingest_dep var deposit = dansBagDepositReader.readDeposit(depositDir); // When - new DansDepositConverter(deposit, null, mappingService, yamlService).run(); + new DansDepositConverter(deposit, null, null, mappingService, yamlService).run(); // Then assertThat(deposit.getBagDir().resolve("dataset.yml")).exists(); From 7c182d54236ed94791af5b27e26a972da3a7415f Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Tue, 10 Dec 2024 12:14:04 +0100 Subject: [PATCH 2/4] Retrieving current dataset metadata more efficient and less often. --- .../knaw/dans/dvingest/core/dansbag/DansBagMappingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java index b48312a..b55e326 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingService.java @@ -31,7 +31,7 @@ public interface DansBagMappingService { DansBagDeposit readDansDeposit(Path depositDir) throws InvalidDepositException; - Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion updatesDataset); + Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion currentMetadata); EditFiles getEditFilesFromDansDeposit(DansBagDeposit dansDeposit, String updatesDataset); From d29619355042b3ad1f65c01acfd156870cc14bc0 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Tue, 10 Dec 2024 14:31:11 +0100 Subject: [PATCH 3/4] Implemented setTermsOfAccess and setFileAccessRequest. --- .../core/dansbag/DansBagMappingServiceImpl.java | 13 ++++++++----- .../dvingest/core/dansbag/SupportedLicenses.java | 1 + .../core/dansbag/DansBagMappingServiceTest.java | 5 ----- .../core/dansbag/DansDepositConverterTest.java | 3 +++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java index 7599fd4..6642c86 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java @@ -132,14 +132,17 @@ public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, Dat dansDeposit.getHasOrganizationalIdentifier(), dansDeposit.getHasOrganizationalIdentifierVersion()); var version = dataset.getDatasetVersion(); - version.setFileAccessRequest(dansDeposit.allowAccessRequests()); - // TODO: when processing an update-deposit, retrieve terms of access from the previous version - if (!dansDeposit.allowAccessRequests() && StringUtils.isBlank(version.getTermsOfAccess())) { + // Allow access requests only if it was not forbidden in previous versions + var fileAccessRequest = dansDeposit.allowAccessRequests() && (currentMetadata == null || currentMetadata.getFileAccessRequest()); + version.setFileAccessRequest(fileAccessRequest); + if (StringUtils.isBlank(version.getTermsOfAccess()) && currentMetadata != null) { + version.setTermsOfAccess(currentMetadata.getTermsOfAccess()); + } + if (!fileAccessRequest && StringUtils.isBlank(version.getTermsOfAccess())) { + // Dataverse requires terms of access to be set if file access requests are disabled, so set it to "N/a" if not explicitly provided version.setTermsOfAccess("N/a"); } - - version.setLicense(supportedLicenses.getLicenseFromDansDeposit(dansDeposit)); return dataset; } diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/SupportedLicenses.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/SupportedLicenses.java index 9660d3c..4e25c46 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/SupportedLicenses.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/SupportedLicenses.java @@ -30,6 +30,7 @@ import static nl.knaw.dans.dvingest.core.dansbag.xml.XPathConstants.DDM_DCMI_METADATA; +// TODO: move to mapping package public class SupportedLicenses { private final Map supportedLicenses; diff --git a/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceTest.java b/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceTest.java index 34176c5..5776e26 100644 --- a/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceTest.java +++ b/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceTest.java @@ -47,9 +47,4 @@ public void getUpdatesDataset_finds_dataset_for_update_deposit() throws Exceptio // When / Then assertThat(mappingService.getUpdatesDataset(testDepositDir)).isEqualTo(doi); } - - - - - } diff --git a/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java b/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java index 6c532be..102b149 100644 --- a/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java +++ b/src/test/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositConverterTest.java @@ -27,6 +27,9 @@ import static org.assertj.core.api.Assertions.assertThat; +/** + * Test class for {@link DansDepositConverter}. It uses the valid examples from the dd-dans-sword2-examples project. + */ public class DansDepositConverterTest extends DansConversionFixture { private final YamlService yamlService = new YamlServiceImpl(); From dbb35a643486b3f0f85d2914b5da6cc561ce780a Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Tue, 10 Dec 2024 15:18:39 +0100 Subject: [PATCH 4/4] Added embargo for subsequent versions. --- .../dansbag/DansBagMappingServiceImpl.java | 1 + .../core/dansbag/EditFilesComposer.java | 31 ++++++++++++------- .../dansbag/EditFilesComposerForUpdate.java | 6 ++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java index 6642c86..5d9cb17 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java @@ -121,6 +121,7 @@ else if (depositToDvDatasetMetadataMapper.isMigration()) { @Override public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion currentMetadata) { + // TODO: rename to DatasetComposer en push the terms stuff into it as well. var dataset = depositToDvDatasetMetadataMapper.toDataverseDataset( dansDeposit.getDdm(), dansDeposit.getOtherDoiId(), diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposer.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposer.java index 8421ecb..b692be8 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposer.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposer.java @@ -31,6 +31,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -65,13 +66,8 @@ public EditFiles composeEditFiles() { editFiles.setAddUnrestrictedFiles(getUnrestrictedFilesToAdd(pathFileInfoMap)); editFiles.setUpdateFileMetas(getUpdatedFileMetas(pathFileInfoMap)); - var filePathsToEmbargo = getEmbargoedFiles(pathFileInfoMap, dateAvailable); - if (!filePathsToEmbargo.isEmpty()) { - var addEmbargo = new AddEmbargo(); - addEmbargo.setDateAvailable(yyyymmddFormat.format(Date.from(dateAvailable))); - addEmbargo.setFilePaths(filePathsToEmbargo.stream().map(Path::toString).toList()); - editFiles.setAddEmbargoes(List.of(addEmbargo)); - } + addEmbargo(editFiles, pathFileInfoMap.keySet()); + return editFiles; } @@ -123,10 +119,23 @@ private List getUpdatedFileMetas(Map files) { .toList(); } - private List getEmbargoedFiles(Map files, Instant dateAvailable) { - var now = Instant.now(); - if (dateAvailable.isAfter(now)) { - return files.keySet().stream() + protected void addEmbargo(EditFiles editFiles, Set candidates) { + if (dateAvailable.isAfter(Instant.now())) { + var filesToEmbargo = candidates.stream() + .filter(f -> !embargoExclusions.contains(f.toString())).toList(); + + if (!filesToEmbargo.isEmpty()) { + var addEmbargo = new AddEmbargo(); + addEmbargo.setDateAvailable(yyyymmddFormat.format(Date.from(dateAvailable))); + addEmbargo.setFilePaths(filesToEmbargo.stream().map(Path::toString).toList()); + editFiles.setAddEmbargoes(List.of(addEmbargo)); + } + } + } + + private List getEmbargoedFiles(Set candidates, Instant dateAvailable) { + if (dateAvailable.isAfter(Instant.now())) { + return candidates.stream() .filter(f -> !embargoExclusions.contains(f.toString())).toList(); } else { diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposerForUpdate.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposerForUpdate.java index c5ce787..34d5e3b 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposerForUpdate.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/EditFilesComposerForUpdate.java @@ -19,6 +19,7 @@ import nl.knaw.dans.dvingest.core.bagprocessor.FilesInDatasetCache; import nl.knaw.dans.dvingest.core.dansbag.deposit.FileInfo; import nl.knaw.dans.dvingest.core.service.DataverseService; +import nl.knaw.dans.dvingest.core.yaml.AddEmbargo; import nl.knaw.dans.dvingest.core.yaml.EditFiles; import nl.knaw.dans.dvingest.core.yaml.FromTo; import nl.knaw.dans.lib.dataverse.DataverseException; @@ -27,6 +28,7 @@ import java.io.IOException; import java.nio.file.Path; import java.time.Instant; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -144,11 +146,11 @@ public EditFiles composeEditFiles() { editFiles.setAddUnrestrictedFiles(pathsToAdd.stream() .filter(p -> !pathFileInfoMap.get(p).getMetadata().getRestricted()).toList().stream().map(Path::toString).toList()); - // todo: embargoes - + addEmbargo(editFiles, SetUtils.union(pathsToAdd, filesToReplace)); return editFiles; } + private Set getFilesToReplace(Map pathToFileInfo, Map fileReplacementCandidates) { var intersection = SetUtils.intersection(pathToFileInfo.keySet(), fileReplacementCandidates.keySet());