forked from geonetwork/core-geonetwork
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate OAIPMH server API to Spring MVC
- Loading branch information
Showing
6 changed files
with
110 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
services/src/main/java/org/fao/geonet/api/oaipmh/OaiPmhApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [email protected] | ||
*/ | ||
|
||
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); | ||
} | ||
|
||
} |
61 changes: 0 additions & 61 deletions
61
services/src/main/java/org/fao/geonet/services/main/OaiPmhDispatcher.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.