From b4b8ebc31a31292a92b29c03677b09454657973a Mon Sep 17 00:00:00 2001 From: Leonid Andreev Date: Wed, 13 Jul 2022 17:56:37 -0400 Subject: [PATCH] mpconfig for the oai server parameters (experimental? #8372) --- .../server/web/servlet/OAIServlet.java | 32 +++++++++++++------ .../settings/SettingsServiceBean.java | 16 +--------- .../iq/dataverse/util/SystemConfig.java | 27 ---------------- .../META-INF/microprofile-config.properties | 7 ++++ 4 files changed, 31 insertions(+), 51 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/harvest/server/web/servlet/OAIServlet.java b/src/main/java/edu/harvard/iq/dataverse/harvest/server/web/servlet/OAIServlet.java index d3876e76cf7..5eacb1addb6 100644 --- a/src/main/java/edu/harvard/iq/dataverse/harvest/server/web/servlet/OAIServlet.java +++ b/src/main/java/edu/harvard/iq/dataverse/harvest/server/web/servlet/OAIServlet.java @@ -6,7 +6,6 @@ package edu.harvard.iq.dataverse.harvest.server.web.servlet; import io.gdcc.xoai.dataprovider.DataProvider; -//import io.gdcc.xoai.dataprovider.builder.OAIRequestParametersBuilder; import io.gdcc.xoai.dataprovider.repository.Repository; import io.gdcc.xoai.dataprovider.repository.RepositoryConfiguration; import io.gdcc.xoai.dataprovider.model.Context; @@ -36,10 +35,10 @@ import java.io.IOException; -import java.util.Date; -import java.util.HashMap; import java.util.logging.Logger; import javax.ejb.EJB; +import javax.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; import javax.mail.internet.InternetAddress; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -47,6 +46,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.stream.XMLStreamException; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; /** * @@ -69,6 +70,18 @@ public class OAIServlet extends HttpServlet { @EJB SystemConfig systemConfig; + + @Inject + @ConfigProperty(name = "dataverse.oai.server.maxidentifiers", defaultValue="100") + private Integer maxListIdentifiers; + + @Inject + @ConfigProperty(name = "dataverse.oai.server.maxsets", defaultValue="100") + private Integer maxListSets; + + @Inject + @ConfigProperty(name = "dataverse.oai.server.maxrecords", defaultValue="10") + private Integer maxListRecords; private static final Logger logger = Logger.getLogger("edu.harvard.iq.dataverse.harvest.server.web.servlet.OAIServlet"); // If we are going to stick with this solution - of providing a minimalist @@ -165,9 +178,10 @@ private boolean isDataverseOaiExtensionsSupported() { } private RepositoryConfiguration createRepositoryConfiguration() { - - String repositoryName = settingsService.getValueForKey(SettingsServiceBean.Key.oaiServerRepositoryName); - if (repositoryName == null) { + Config config = ConfigProvider.getConfig(); + String repositoryName = config.getOptionalValue("dataverse.oai.server.repositoryname", String.class).orElse(""); + + if (repositoryName == null || repositoryName.isEmpty()) { String dataverseName = dataverseService.getRootDataverseName(); repositoryName = StringUtils.isEmpty(dataverseName) || "Root".equals(dataverseName) ? "Test Dataverse OAI Archive" : dataverseName + " Dataverse OAI Archive"; } @@ -185,9 +199,9 @@ private RepositoryConfiguration createRepositoryConfiguration() { .withCompression("deflate") .withAdminEmail(systemEmailAddress != null ? systemEmailAddress.getAddress() : null) .withDeleteMethod(DeletedRecord.TRANSIENT) - .withMaxListIdentifiers(systemConfig.getOaiServerMaxIdentifiers()) - .withMaxListRecords(systemConfig.getOaiServerMaxRecords()) - .withMaxListSets(systemConfig.getOaiServerMaxSets()); + .withMaxListIdentifiers(maxListIdentifiers) + .withMaxListRecords(maxListRecords) + .withMaxListSets(maxListSets); return repositoryConfiguration; } diff --git a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java index 9c40999829b..12ae777f3f8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java @@ -522,21 +522,7 @@ Whether Harvesting (OAI) service is enabled * would also work) of never muted notifications that cannot be turned off by the users. AlwaysMuted setting overrides * Nevermuted setting warning is logged. */ - NeverMuted, - /* - * The following values are for the OAI server, to limit the output of - * the ListIdentifiers, ListRecords and ListSets verbs to the number - * of records specified. Sensible defaults are going to be provided for - * these by SystemConfig. - */ - oaiServerMaxListIdentifiers, - oaiServerMaxListRecords, - oaiServerMaxListSets, - /* - * The OAI "repository name", shown by the OAI Identify verb, needs - * to be configurable as well. - */ - oaiServerRepositoryName + NeverMuted ; @Override diff --git a/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java b/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java index 64f08c5dd19..b3b8b5c7a9f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java @@ -1204,31 +1204,4 @@ public Map getCurationLabels() { } return labelMap; } - - public int getOaiServerMaxIdentifiers() { - return getIntSettingOrDefault(SettingsServiceBean.Key.oaiServerMaxListIdentifiers, 100); - } - - public int getOaiServerMaxSets() { - return getIntSettingOrDefault(SettingsServiceBean.Key.oaiServerMaxListSets, 100); - } - - public int getOaiServerMaxRecords() { - return getIntSettingOrDefault(SettingsServiceBean.Key.oaiServerMaxListRecords, 10); - } - - private int getIntSettingOrDefault(SettingsServiceBean.Key key, int defaultValue) { - String settingValue = settingsService.getValueForKey(key); - if (settingValue != null) { - try { - int intFromSetting = Integer.parseInt(settingValue); - if (intFromSetting > 0) { - return intFromSetting; - } - } catch (NumberFormatException ex) { - // will use the default - } - } - return defaultValue; } -} diff --git a/src/main/resources/META-INF/microprofile-config.properties b/src/main/resources/META-INF/microprofile-config.properties index 09d71dfbf3a..8298c883403 100644 --- a/src/main/resources/META-INF/microprofile-config.properties +++ b/src/main/resources/META-INF/microprofile-config.properties @@ -3,3 +3,10 @@ dataverse.db.host=localhost dataverse.db.port=5432 dataverse.db.user=dataverse dataverse.db.name=dataverse +# OAI SERVER +dataverse.oai.server.maxidentifiers=100 +dataverse.oai.server.maxrecords=10 +dataverse.oai.server.maxsets=100 +# the OAI repository name, as shown by the Identify verb, +# can be customized via the setting below: +#dataverse.oai.server.repositoryname=