From 65a738487e9eb8e9523bd8a4f8a0deda5cb4a230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Thu, 28 Dec 2023 12:23:46 +0100 Subject: [PATCH] Migrate OAIPMH server API to Spring MVC --- docs/manual/docs/api/oai-pmh.md | 2 +- .../org/fao/geonet/api/oaipmh/OaiPmhApi.java | 108 ++++++++++++++++++ .../services/main/OaiPmhDispatcher.java | 61 ---------- .../config-security-mapping.xml | 3 +- web/src/main/webapp/WEB-INF/config.xml | 1 - .../WEB-INF/config/config-service-oai.xml | 32 ------ 6 files changed, 110 insertions(+), 97 deletions(-) create mode 100644 services/src/main/java/org/fao/geonet/api/oaipmh/OaiPmhApi.java delete mode 100644 services/src/main/java/org/fao/geonet/services/main/OaiPmhDispatcher.java delete mode 100644 web/src/main/webapp/WEB-INF/config/config-service-oai.xml diff --git a/docs/manual/docs/api/oai-pmh.md b/docs/manual/docs/api/oai-pmh.md index d4aabf96807..099f82c7077 100644 --- a/docs/manual/docs/api/oai-pmh.md +++ b/docs/manual/docs/api/oai-pmh.md @@ -4,7 +4,7 @@ The OAI-PMH end point exposes the metadata records in your catalog in XML format ## Configuration -The following URL is the standard end point for the catalog (substitute your GeoNetwork URL): ? +The following URL is the standard end point for the catalog (substitute your GeoNetwork URL): ? ## Requests diff --git a/services/src/main/java/org/fao/geonet/api/oaipmh/OaiPmhApi.java b/services/src/main/java/org/fao/geonet/api/oaipmh/OaiPmhApi.java new file mode 100644 index 00000000000..19f2ab244ea --- /dev/null +++ b/services/src/main/java/org/fao/geonet/api/oaipmh/OaiPmhApi.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2001-2023 Food and Agriculture Organization of the + * United Nations (FAO-UN), United Nations World Food Programme (WFP) + * and United Nations Environment Programme (UNEP) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, + * Rome - Italy. email: geonetwork@osgeo.org + */ + +package org.fao.geonet.api.oaipmh; + +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jeeves.server.context.ServiceContext; +import org.apache.commons.lang.StringUtils; +import org.fao.geonet.api.ApiUtils; +import org.fao.geonet.api.tools.i18n.LanguageUtils; +import org.fao.geonet.kernel.oaipmh.OaiPmhDispatcher; +import org.jdom.Element; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.Locale; + +@RequestMapping(value = { + "/{portal}/api/oaipmh" +}) +@Tag(name = "oaipmh", + description = "OAIPMH server operations") +@Controller("oaipmh") +public class OaiPmhApi { + + @Autowired + private LanguageUtils languageUtils; + + @Autowired + private OaiPmhDispatcher oaiPmhDispatcher; + + @io.swagger.v3.oas.annotations.Operation( + summary = "Oaiphm server", + description = "") + @GetMapping( + produces = MediaType.APPLICATION_XML_VALUE) + @ResponseStatus(HttpStatus.OK) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Oaiphm server response.") + }) + @ResponseBody + public Element dispatch( + @RequestParam(required = false) final String verb, + @RequestParam(required = false) final String metadataPrefix, + @RequestParam(required = false) final String set, + @RequestParam(required = false) final String from, + @RequestParam(required = false) final String until, + @RequestParam(required = false) final String resumptionToken, + final HttpServletRequest request + ) { + Locale locale = languageUtils.parseAcceptLanguage(request.getLocales()); + ServiceContext serviceContext = ApiUtils.createServiceContext(request, locale.getISO3Country()); + + Element params = new Element("params"); + if (StringUtils.isNotEmpty(verb)) { + params.addContent(new Element("verb").setText(verb)); + } + + if (StringUtils.isNotEmpty(metadataPrefix)) { + params.addContent(new Element("metadataPrefix").setText(metadataPrefix)); + } + + if (StringUtils.isNotEmpty(set)) { + params.addContent(new Element("set").setText(set)); + } + + if (StringUtils.isNotEmpty(from)) { + params.addContent(new Element("from").setText(from)); + } + + if (StringUtils.isNotEmpty(until)) { + params.addContent(new Element("until").setText(until)); + } + + if (StringUtils.isNotEmpty(resumptionToken)) { + params.addContent(new Element("resumptionToken").setText(resumptionToken)); + } + + return oaiPmhDispatcher.dispatch(params, serviceContext); + } + +} diff --git a/services/src/main/java/org/fao/geonet/services/main/OaiPmhDispatcher.java b/services/src/main/java/org/fao/geonet/services/main/OaiPmhDispatcher.java deleted file mode 100644 index 4a3fddef375..00000000000 --- a/services/src/main/java/org/fao/geonet/services/main/OaiPmhDispatcher.java +++ /dev/null @@ -1,61 +0,0 @@ -//============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the -//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) -//=== and United Nations Environment Programme (UNEP) -//=== -//=== This program is free software; you can redistribute it and/or modify -//=== it under the terms of the GNU General Public License as published by -//=== the Free Software Foundation; either version 2 of the License, or (at -//=== your option) any later version. -//=== -//=== This program is distributed in the hope that it will be useful, but -//=== WITHOUT ANY WARRANTY; without even the implied warranty of -//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -//=== General Public License for more details. -//=== -//=== You should have received a copy of the GNU General Public License -//=== along with this program; if not, write to the Free Software -//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -//=== -//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, -//=== Rome - Italy. email: geonetwork@osgeo.org -//============================================================================== - -package org.fao.geonet.services.main; - -import jeeves.interfaces.Service; -import jeeves.server.ServiceConfig; -import jeeves.server.context.ServiceContext; -import org.fao.geonet.GeonetContext; -import org.fao.geonet.constants.Geonet; -import org.jdom.Element; - -import java.nio.file.Path; - -//============================================================================= - -public class OaiPmhDispatcher implements Service { - //-------------------------------------------------------------------------- - //--- - //--- Init - //--- - //-------------------------------------------------------------------------- - - public void init(Path appPath, ServiceConfig config) throws Exception { - } - - //-------------------------------------------------------------------------- - //--- - //--- Service - //--- - //-------------------------------------------------------------------------- - - public Element exec(Element params, ServiceContext context) throws Exception { - GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); - - return gc.getBean(org.fao.geonet.kernel.oaipmh.OaiPmhDispatcher.class).dispatch(params, context); - } -} - -//============================================================================= - diff --git a/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml b/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml index 1da3e0c5fac..64516502640 100644 --- a/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml +++ b/web/src/main/webapp/WEB-INF/config-security/config-security-mapping.xml @@ -78,7 +78,6 @@ - @@ -236,7 +235,7 @@ - + diff --git a/web/src/main/webapp/WEB-INF/config.xml b/web/src/main/webapp/WEB-INF/config.xml index a6971c431fd..e4d0cfde308 100644 --- a/web/src/main/webapp/WEB-INF/config.xml +++ b/web/src/main/webapp/WEB-INF/config.xml @@ -149,7 +149,6 @@ config/config-service-search.xml config/config-service-sru.xml - config/config-service-oai.xml config/config-service-rss.xml config/config-service-dcat-rdf.xml config/config-service-thesaurus.xml diff --git a/web/src/main/webapp/WEB-INF/config/config-service-oai.xml b/web/src/main/webapp/WEB-INF/config/config-service-oai.xml deleted file mode 100644 index fb0868ab871..00000000000 --- a/web/src/main/webapp/WEB-INF/config/config-service-oai.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - Open Archive Initiative, Protocol for Metadata Harvesting - - - -