From d29619355042b3ad1f65c01acfd156870cc14bc0 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Tue, 10 Dec 2024 14:31:11 +0100 Subject: [PATCH] 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();