Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +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.
3 changes: 3 additions & 0 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,9 @@ By default, download URLs to files will be included in Schema.org JSON-LD output

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

Can also be set via *MicroProfile Config API* sources, e.g. the environment
variable ``DATAVERSE_FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS``.

For more on Schema.org JSON-LD, see the :doc:`/admin/metadataexport` section of the Admin Guide.

.. _useripaddresssourceheader:
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.util.MarkupChecker;
import edu.harvard.iq.dataverse.util.PersonOrOrgUtil;
import edu.harvard.iq.dataverse.util.BundleUtil;
Expand Down Expand Up @@ -2134,10 +2135,8 @@ public String getJsonLd() {
fileObject.add("description", fileMetadata.getDescription());
fileObject.add("@id", filePidUrlAsString);
fileObject.add("identifier", filePidUrlAsString);
String hideFilesBoolean = System.getProperty(SystemConfig.FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS);
if (hideFilesBoolean != null && hideFilesBoolean.equals("true")) {
// no-op
} else {
boolean hideFilesBoolean = JvmSettings.HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS.lookupOptional(Boolean.class).orElse(false);
if (!hideFilesBoolean) {
String nullDownloadType = null;
fileObject.add("contentUrl", dataverseSiteUrl + FileUtil.getFileDownloadUrlPath(nullDownloadType, fileMetadata.getDataFile().getId(), false, fileMetadata.getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum JvmSettings {
SCOPE_FEATURED_ITEMS(SCOPE_FILES, "featured-items"),
FEATURED_ITEMS_IMAGE_MAXSIZE(SCOPE_FEATURED_ITEMS, "image-maxsize"),
FEATURED_ITEMS_IMAGE_UPLOADS_DIRECTORY(SCOPE_FEATURED_ITEMS, "image-uploads"),
HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS(SCOPE_FILES, "hide-schema-dot-org-download-urls"),

//STORAGE DRIVER SETTINGS
SCOPE_DRIVER(SCOPE_FILES),
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ public class SystemConfig {
AuthenticationServiceBean authenticationService;

public static final String DATAVERSE_PATH = "/dataverse/";

/**
* Some installations may not want download URLs to their files to be
* available in Schema.org JSON-LD output.
*/
public static final String FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS = "dataverse.files.hide-schema-dot-org-download-urls";

/**
* A JVM option to override the number of minutes for which a password reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import edu.harvard.iq.dataverse.license.LicenseServiceBean;
import edu.harvard.iq.dataverse.mocks.MockDatasetFieldSvc;

import static edu.harvard.iq.dataverse.util.SystemConfig.FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.json.JsonParseException;
Expand Down Expand Up @@ -171,6 +169,23 @@ public void testExportDescriptionTruncation() throws JsonParseException, ParseEx

assertTrue(json2.getString("description").endsWith("at..."));
}

@Test
@JvmSetting(key = JvmSettings.HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS, value = "true")
public void testExportWithoutDownloadUrl() throws IOException, JsonParseException, ParseException {
File datasetVersionJson = new File("src/test/resources/json/dataset-finch2.json");
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));

JsonObject json = JsonUtil.getJsonObject(datasetVersionAsJson);
ExportDataProvider exportDataProviderStub = Mockito.mock(ExportDataProvider.class);
Mockito.when(exportDataProviderStub.getDatasetJson()).thenReturn(json);

JsonObject json2 = createExportFromJson(exportDataProviderStub);

assertEquals("DataDownload", json2.getJsonArray("distribution").getJsonObject(0).getString("@type"));
assertEquals("README.md", json2.getJsonArray("distribution").getJsonObject(0).getString("name"));
assertFalse(json2.getJsonArray("distribution").getJsonObject(0).containsKey("contentUrl"));
}

private JsonObject createExportFromJson(ExportDataProvider provider) throws JsonParseException, ParseException {
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);
Expand All @@ -195,10 +210,6 @@ private JsonObject createExportFromJson(ExportDataProvider provider) throws Json
Dataverse dataverse = new Dataverse();
dataverse.setName("LibraScholar");
dataset.setOwner(dataverse);
boolean hideFileUrls = false;
if (hideFileUrls) {
System.setProperty(FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS, "true");
}

FileMetadata fmd = new FileMetadata();
DataFile dataFile = new DataFile();
Expand Down