Skip to content

Commit

Permalink
mpconfig for the oai server parameters (experimental? #8372)
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Jul 13, 2022
1 parent f81a010 commit b4b8ebc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,17 +35,19 @@


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;
import javax.servlet.http.HttpServlet;
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;

/**
*
Expand All @@ -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
Expand Down Expand Up @@ -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";
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1204,31 +1204,4 @@ public Map<String, String[]> 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;
}
}
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/microprofile-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit b4b8ebc

Please sign in to comment.