Skip to content

Commit d8a55a9

Browse files
authored
Merge pull request #11482 from vera/mpconfig-schema-dot-org-hide-download-urls
feat: migrate FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS to MPConfig
2 parents 3c90f6a + 5ca64d5 commit d8a55a9

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The `dataverse.files.hide-schema-dot-org-download-urls` setting now supports configuration via MicroProfile Config. In addition to the existing `asadmin` JVM option method, any [supported MicroProfile Config API source](https://docs.payara.fish/community/docs/Technical%20Documentation/MicroProfile/Config/Overview.html) can now be used to set its value.

doc/sphinx-guides/source/installation/config.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,9 @@ By default, download URLs to files will be included in Schema.org JSON-LD output
30533053

30543054
``./asadmin create-jvm-options '-Ddataverse.files.hide-schema-dot-org-download-urls=true'``
30553055

3056+
Can also be set via *MicroProfile Config API* sources, e.g. the environment
3057+
variable ``DATAVERSE_FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS``.
3058+
30563059
For more on Schema.org JSON-LD, see the :doc:`/admin/metadataexport` section of the Admin Guide.
30573060

30583061
.. _useripaddresssourceheader:

src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.harvard.iq.dataverse;
22

3+
import edu.harvard.iq.dataverse.settings.JvmSettings;
34
import edu.harvard.iq.dataverse.util.MarkupChecker;
45
import edu.harvard.iq.dataverse.util.PersonOrOrgUtil;
56
import edu.harvard.iq.dataverse.util.BundleUtil;
@@ -2134,10 +2135,8 @@ public String getJsonLd() {
21342135
fileObject.add("description", fileMetadata.getDescription());
21352136
fileObject.add("@id", filePidUrlAsString);
21362137
fileObject.add("identifier", filePidUrlAsString);
2137-
String hideFilesBoolean = System.getProperty(SystemConfig.FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS);
2138-
if (hideFilesBoolean != null && hideFilesBoolean.equals("true")) {
2139-
// no-op
2140-
} else {
2138+
boolean hideFilesBoolean = JvmSettings.HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS.lookupOptional(Boolean.class).orElse(false);
2139+
if (!hideFilesBoolean) {
21412140
String nullDownloadType = null;
21422141
fileObject.add("contentUrl", dataverseSiteUrl + FileUtil.getFileDownloadUrlPath(nullDownloadType, fileMetadata.getDataFile().getId(), false, fileMetadata.getId()));
21432142
}

src/main/java/edu/harvard/iq/dataverse/settings/JvmSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public enum JvmSettings {
5555
SCOPE_FEATURED_ITEMS(SCOPE_FILES, "featured-items"),
5656
FEATURED_ITEMS_IMAGE_MAXSIZE(SCOPE_FEATURED_ITEMS, "image-maxsize"),
5757
FEATURED_ITEMS_IMAGE_UPLOADS_DIRECTORY(SCOPE_FEATURED_ITEMS, "image-uploads"),
58+
HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS(SCOPE_FILES, "hide-schema-dot-org-download-urls"),
5859

5960
//STORAGE DRIVER SETTINGS
6061
SCOPE_DRIVER(SCOPE_FILES),

src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ public class SystemConfig {
5757
AuthenticationServiceBean authenticationService;
5858

5959
public static final String DATAVERSE_PATH = "/dataverse/";
60-
61-
/**
62-
* Some installations may not want download URLs to their files to be
63-
* available in Schema.org JSON-LD output.
64-
*/
65-
public static final String FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS = "dataverse.files.hide-schema-dot-org-download-urls";
6660

6761
/**
6862
* A JVM option to override the number of minutes for which a password reset

src/test/java/edu/harvard/iq/dataverse/export/SchemaDotOrgExporterTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import edu.harvard.iq.dataverse.license.LicenseServiceBean;
1010
import edu.harvard.iq.dataverse.mocks.MockDatasetFieldSvc;
1111

12-
import static edu.harvard.iq.dataverse.util.SystemConfig.FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS;
13-
1412
import edu.harvard.iq.dataverse.settings.JvmSettings;
1513
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
1614
import edu.harvard.iq.dataverse.util.json.JsonParseException;
@@ -171,6 +169,23 @@ public void testExportDescriptionTruncation() throws JsonParseException, ParseEx
171169

172170
assertTrue(json2.getString("description").endsWith("at..."));
173171
}
172+
173+
@Test
174+
@JvmSetting(key = JvmSettings.HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS, value = "true")
175+
public void testExportWithoutDownloadUrl() throws IOException, JsonParseException, ParseException {
176+
File datasetVersionJson = new File("src/test/resources/json/dataset-finch2.json");
177+
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
178+
179+
JsonObject json = JsonUtil.getJsonObject(datasetVersionAsJson);
180+
ExportDataProvider exportDataProviderStub = Mockito.mock(ExportDataProvider.class);
181+
Mockito.when(exportDataProviderStub.getDatasetJson()).thenReturn(json);
182+
183+
JsonObject json2 = createExportFromJson(exportDataProviderStub);
184+
185+
assertEquals("DataDownload", json2.getJsonArray("distribution").getJsonObject(0).getString("@type"));
186+
assertEquals("README.md", json2.getJsonArray("distribution").getJsonObject(0).getString("name"));
187+
assertFalse(json2.getJsonArray("distribution").getJsonObject(0).containsKey("contentUrl"));
188+
}
174189

175190
private JsonObject createExportFromJson(ExportDataProvider provider) throws JsonParseException, ParseException {
176191
License license = new License("CC0 1.0", "You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.", URI.create("http://creativecommons.org/publicdomain/zero/1.0/"), URI.create("/resources/images/cc0.png"), true, 1l);
@@ -195,10 +210,6 @@ private JsonObject createExportFromJson(ExportDataProvider provider) throws Json
195210
Dataverse dataverse = new Dataverse();
196211
dataverse.setName("LibraScholar");
197212
dataset.setOwner(dataverse);
198-
boolean hideFileUrls = false;
199-
if (hideFileUrls) {
200-
System.setProperty(FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS, "true");
201-
}
202213

203214
FileMetadata fmd = new FileMetadata();
204215
DataFile dataFile = new DataFile();

0 commit comments

Comments
 (0)