Skip to content

Commit

Permalink
Migrate OAIPMH server API to Spring MVC
Browse files Browse the repository at this point in the history
  • Loading branch information
josegar74 committed Dec 28, 2023
1 parent c0849bd commit 9655067
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 97 deletions.
2 changes: 1 addition & 1 deletion docs/manual/docs/api/oai-pmh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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): <http://localhost:8080/geonetwork/srv/eng/oaipmh>?
The following URL is the standard end point for the catalog (substitute your GeoNetwork URL): <http://localhost:8080/geonetwork/srv/api/oaipmh>?

## Requests

Expand Down
85 changes: 85 additions & 0 deletions services/src/main/java/org/fao/geonet/api/oaipmh/OaiPmhApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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
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);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@

<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/[a-z]{2,3}/q!?.*" access="permitAll"/>
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/[a-z]{2,3}/qi!?.*" access="permitAll"/>
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/[a-z]{2,3}/oaipmh!?.*" access="permitAll"/>
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/[a-z]{2,3}/info!?.*" access="permitAll"/>


Expand Down Expand Up @@ -236,7 +235,7 @@
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/atom/describe/service!?.*" access="permitAll"/>
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/atom/describe/dataset!?.*" access="permitAll"/>
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/atom/download/dataset!?.*" access="permitAll"/>

<!-- Metadata identifier templates -->
<sec:intercept-url pattern="/[a-zA-Z0-9_\-]+/[a-z]{2,3}/metadataIdentifierTemplates!?.*"
access="hasAuthority('Editor')"/>
Expand Down
1 change: 0 additions & 1 deletion web/src/main/webapp/WEB-INF/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@

<include>config/config-service-search.xml</include>
<include>config/config-service-sru.xml</include>
<include>config/config-service-oai.xml</include>
<include>config/config-service-rss.xml</include>
<include>config/config-service-dcat-rdf.xml</include>
<include>config/config-service-thesaurus.xml</include>
Expand Down
32 changes: 0 additions & 32 deletions web/src/main/webapp/WEB-INF/config/config-service-oai.xml

This file was deleted.

0 comments on commit 9655067

Please sign in to comment.