Skip to content

Commit 121a8c5

Browse files
josegar74jodygarnett
authored andcommitted
Remove RDF searcher and related APIs.
The related code was not implemented after the migration to Elasticsearch. Use CSW GetRecords with dcat output schema to retrieve the metadata in DCAT/RDF format
1 parent d703377 commit 121a8c5

File tree

5 files changed

+1
-785
lines changed

5 files changed

+1
-785
lines changed

services/src/main/java/org/fao/geonet/api/records/CatalogApi.java

Lines changed: 1 addition & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2001-2024 Food and Agriculture Organization of the
2+
* Copyright (C) 2001-2025 Food and Agriculture Organization of the
33
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
* and United Nations Environment Programme (UNEP)
55
*
@@ -28,15 +28,11 @@
2828
import com.fasterxml.jackson.databind.ObjectMapper;
2929
import com.google.common.collect.ImmutableSet;
3030
import io.swagger.v3.oas.annotations.Parameter;
31-
import io.swagger.v3.oas.annotations.Parameters;
32-
import io.swagger.v3.oas.annotations.enums.ParameterIn;
33-
import io.swagger.v3.oas.annotations.media.Schema;
3431
import io.swagger.v3.oas.annotations.responses.ApiResponse;
3532
import io.swagger.v3.oas.annotations.responses.ApiResponses;
3633
import io.swagger.v3.oas.annotations.tags.Tag;
3734
import jeeves.server.UserSession;
3835
import jeeves.server.context.ServiceContext;
39-
import jeeves.server.sources.http.ServletPathFinder;
4036
import jeeves.services.ReadWriteController;
4137
import jeeves.xlink.Processor;
4238
import org.apache.commons.csv.CSVFormat;
@@ -45,14 +41,11 @@
4541
import org.apache.commons.io.FileUtils;
4642
import org.apache.commons.lang.StringUtils;
4743
import org.apache.commons.lang.text.StrSubstitutor;
48-
import org.fao.geonet.ApplicationContextHolder;
4944
import org.fao.geonet.api.API;
5045
import org.fao.geonet.api.ApiParams;
5146
import org.fao.geonet.api.ApiUtils;
5247
import org.fao.geonet.api.records.model.related.AssociatedRecord;
5348
import org.fao.geonet.api.records.model.related.RelatedItemType;
54-
import org.fao.geonet.api.records.rdf.RdfOutputManager;
55-
import org.fao.geonet.api.records.rdf.RdfSearcher;
5649
import org.fao.geonet.api.tools.i18n.LanguageUtils;
5750
import org.fao.geonet.constants.Geonet;
5851
import org.fao.geonet.domain.Metadata;
@@ -64,22 +57,18 @@
6457
import org.fao.geonet.kernel.search.EsSearchManager;
6558
import org.fao.geonet.kernel.setting.SettingInfo;
6659
import org.fao.geonet.kernel.setting.SettingManager;
67-
import org.fao.geonet.languages.IsoLanguagesMapper;
6860
import org.fao.geonet.repository.MetadataRepository;
6961
import org.fao.geonet.util.XslUtil;
7062
import org.fao.geonet.utils.Log;
7163
import org.fao.geonet.utils.Xml;
7264
import org.fao.geonet.web.DefaultLanguage;
7365
import org.jdom.*;
7466
import org.springframework.beans.factory.annotation.Autowired;
75-
import org.springframework.context.ApplicationContext;
7667
import org.springframework.http.HttpHeaders;
7768
import org.springframework.http.MediaType;
7869
import org.springframework.stereotype.Controller;
7970
import org.springframework.web.bind.annotation.*;
8071

81-
import javax.servlet.ServletContext;
82-
import javax.servlet.ServletOutputStream;
8372
import javax.servlet.http.HttpServletRequest;
8473
import javax.servlet.http.HttpServletResponse;
8574
import javax.servlet.http.HttpSession;
@@ -107,7 +96,6 @@
10796
@ReadWriteController
10897
public class CatalogApi {
10998

110-
public static final String HITS_PER_PAGE_PARAM = "hitsPerPage";
11199
private static final Set<String> searchFieldsForPdf;
112100

113101
static {
@@ -132,8 +120,6 @@ public class CatalogApi {
132120
@Autowired
133121
DefaultLanguage defaultLanguage;
134122
@Autowired
135-
ThesaurusManager thesaurusManager;
136-
@Autowired
137123
MetadataRepository metadataRepository;
138124
@Autowired
139125
IMetadataUtils metadataUtils;
@@ -148,31 +134,12 @@ public class CatalogApi {
148134
@Autowired
149135
EsSearchManager searchManager;
150136
@Autowired
151-
AccessManager accessManage;
152-
@Autowired
153137
SettingInfo settingInfo;
154138
@Autowired
155139
LanguageUtils languageUtils;
156140
@Autowired
157-
IsoLanguagesMapper isoLanguagesMapper;
158-
@Autowired
159-
private ServletContext servletContext;
160-
@Autowired
161141
private XmlSerializer xmlSerializer;
162142

163-
/*
164-
* <p>Retrieve all parameters (except paging parameters) as a string.</p>
165-
*/
166-
private static String paramsAsString(Map<String, String> requestParams) {
167-
StringBuilder paramNonPaging = new StringBuilder();
168-
for (Entry<String, String> pair : requestParams.entrySet()) {
169-
if (!pair.getKey().equals("from") && !pair.getKey().equals("to")) {
170-
paramNonPaging.append(paramNonPaging.toString().isEmpty() ? "" : "&").append(pair.getKey()).append("=").append(pair.getValue());
171-
}
172-
}
173-
return paramNonPaging.toString();
174-
}
175-
176143
@io.swagger.v3.oas.annotations.Operation(
177144
summary = "Get a set of metadata records as ZIP",
178145
description = "Metadata Exchange Format (MEF) is returned. MEF is a ZIP file containing " +
@@ -680,196 +647,6 @@ private static void buildRecordProperties(String internalSep, List<Namespace> na
680647
}
681648
}
682649

683-
684-
@io.swagger.v3.oas.annotations.Operation(
685-
summary = "Get catalog content as RDF. This endpoint supports the same Lucene query parameters as for the GUI search.",
686-
description = ".")
687-
@GetMapping(
688-
consumes = {
689-
MediaType.ALL_VALUE
690-
},
691-
produces = {
692-
"application/rdf+xml", "*"
693-
})
694-
@Parameters({
695-
@Parameter(name = "from", description = "Indicates the start position in a sorted list of matches that the client wants to use as the beginning of a page result.", required = false,
696-
in = ParameterIn.QUERY, schema = @Schema(type = "integer", format = "int32", defaultValue = "1")),
697-
@Parameter(name = HITS_PER_PAGE_PARAM, description = "Indicates the number of hits per page.", required = false,
698-
in = ParameterIn.QUERY, schema = @Schema(type = "integer", format = "int32")),
699-
//@Parameter(name="to", value = "Indicates the end position in a sorted list of matches that the client wants to use as the ending of a page result", required = false, defaultValue ="10", dataType = "int", paramType = "query"),
700-
@Parameter(name = "any", description = "Search key", required = false,
701-
in = ParameterIn.QUERY, schema = @Schema(type = "string")),
702-
@Parameter(name = "title", description = "A search key for the title.", required = false,
703-
in = ParameterIn.QUERY, schema = @Schema(type = "string")),
704-
@Parameter(name = "facet.q", description = "A search facet in the Lucene index. Use the GeoNetwork GUI search to generate the suitable filter values. Example: standard/dcat-ap&createDateYear/2018&sourceCatalog/6d93613e-2b76-4e26-94af-4b4c420a1758 (filter by creation year and source catalog).", required = false,
705-
in = ParameterIn.QUERY, schema = @Schema(type = "string")),
706-
@Parameter(name = "sortBy", description = "Lucene sortBy criteria. Relevant values: relevance, title, changeDate.", required = false,
707-
in = ParameterIn.QUERY, schema = @Schema(type = "string")),
708-
@Parameter(name = "sortOrder", description = "Sort order. Possible values: reverse.", required = false,
709-
in = ParameterIn.QUERY, schema = @Schema(type = "string")),
710-
@Parameter(name = "similarity", description = "Use the Lucene FuzzyQuery. Values range from 0.0 to 1.0 and defaults to 0.8.", required = false,
711-
in = ParameterIn.QUERY, schema = @Schema(type = "number", format = "float", defaultValue = "0.8"))
712-
})
713-
@ApiResponses(value = {
714-
@ApiResponse(responseCode = "200", description = "Return the catalog content as RDF."
715-
// responseHeaders = {
716-
// @ResponseHeader(name = "Link", description = " This response header parameter is used to indicate any of the links defined by LDP Paging: first page links, next page links, last page links, previous page links. " +
717-
// "First page link: " +
718-
// "a link to the first in-sequence page resource P1 (first) of a page sequence. The first page is the one that a LDP Paging server redirects to (303 response) in response to a retrieval request for the paged resource's URI. Syntactically, a HTTP Link <P1>; rel=\"first\" header [RFC5988]. " +
719-
// "Next page link: " +
720-
// "a link to the next in-sequence page resource of a page sequence. Syntactically, a HTTP Link <Pi>; rel=\"next\" header [RFC5988] where the context URI identifies some Pi=1 (first)...n-1 (next to last) and the target URI identifies Pi+1. " +
721-
// "Last page link: " +
722-
// "a link to the last in-sequence page resource Pn (last) of a page sequence. The last page is the page that terminates a forward traversal, because it contains no next page link. Syntactically, a HTTP Link <Pn>; rel=\"last\" header [RFC5988]. " +
723-
// "Previous page link: " +
724-
// "a link to the previous in-sequence page resource of a page sequence Syntactically, a HTTP Link <Pi>; rel=\"prev\" header [RFC5988] where the context URI identifies some Pi=2...n (last) and the target URI identifies Pi-1. "
725-
// , response = String.class),
726-
// @ResponseHeader(name = "ETag", description = "The ETag HTTP response header is an identifier for a specific version of a resource. If the resource at a given URL changes, a new Etag value must be generated. On this API, the ETag value is the version token of the Lucene index. ")
727-
// }
728-
),
729-
@ApiResponse(responseCode = "303", description = "Redirect the client to the first in-sequence page resource. This happens when the paging parameters (from, hitsPerPage) are not included in the request.")
730-
})
731-
public
732-
@ResponseBody
733-
void getAsRdf(
734-
@Parameter(hidden = true)
735-
@RequestParam
736-
Map<String, String> allRequestParams,
737-
HttpServletResponse response,
738-
HttpServletRequest request
739-
) throws Exception {
740-
//Retrieve the host URL from the GeoNetwork settings
741-
String hostURL = getHostURL();
742-
743-
//Retrieve the paging parameter values (if present)
744-
int hitsPerPage = (allRequestParams.get(CatalogApi.HITS_PER_PAGE_PARAM) != null ? Integer.parseInt(allRequestParams.get(CatalogApi.HITS_PER_PAGE_PARAM)) : 0);
745-
int from = (allRequestParams.get("from") != null ? Integer.parseInt(allRequestParams.get("from")) : 0);
746-
int to = (allRequestParams.get("to") != null ? Integer.parseInt(allRequestParams.get("to")) : 0);
747-
748-
//If the paging parameters (from, hitsPerPage) are not included in the request, redirect the client to the first in-sequence page resource. Use default paging parameter values.
749-
if (hitsPerPage <= 0 || from <= 0) {
750-
if (hitsPerPage <= 0) {
751-
hitsPerPage = 10;
752-
allRequestParams.put(CatalogApi.HITS_PER_PAGE_PARAM, Integer.toString(hitsPerPage));
753-
}
754-
if (from <= 0) {
755-
from = 1;
756-
allRequestParams.put("from", Integer.toString(from));
757-
}
758-
response.setStatus(303);
759-
response.setHeader("Location", hostURL + request.getRequestURI() + "?" + paramsAsString(allRequestParams) + "&from=1&to=" + hitsPerPage);
760-
return;
761-
}
762-
763-
//Lower 'from' to the greatest multiple of hitsPerPage (by substracting the modulus).
764-
if (hitsPerPage > 1) {
765-
from = from - (from % hitsPerPage) + 1;
766-
}
767-
//Check if the constraint to=from+hitsPerPage-1 holds. Otherwise, force it.
768-
if (to <= 0) {
769-
if (from + hitsPerPage - 1 > 0) {
770-
to = from + hitsPerPage - 1;
771-
} else {
772-
to = 10;
773-
}
774-
}
775-
allRequestParams.put("to", Integer.toString(to));
776-
allRequestParams.put(CatalogApi.HITS_PER_PAGE_PARAM, Integer.toString(hitsPerPage));
777-
allRequestParams.put("from", Integer.toString(from));
778-
779-
ServiceContext context = ApiUtils.createServiceContext(request);
780-
RdfOutputManager manager = new RdfOutputManager(
781-
thesaurusManager.buildResultfromThTable(context), hitsPerPage);
782-
783-
// Copy all request parameters
784-
/// Mimic old Jeeves param style
785-
Element params = new Element("params");
786-
allRequestParams.forEach((k, v) -> params.addContent(new Element(k).setText(v)));
787-
788-
// Perform the search on the Lucene Index
789-
RdfSearcher rdfSearcher = new RdfSearcher(params, context);
790-
List results = rdfSearcher.search(context);
791-
rdfSearcher.close();
792-
793-
// Calculates the pagination information, needed for the LDP Paging and Hydra Paging
794-
int numberMatched = rdfSearcher.getSize();
795-
int firstPageFrom = numberMatched > 0 ? 1 : 0;
796-
int firstPageTo = numberMatched > hitsPerPage ? hitsPerPage : numberMatched;
797-
int nextFrom = to < numberMatched ? to + 1 : to;
798-
int nextTo = to + hitsPerPage < numberMatched ? to + hitsPerPage : numberMatched;
799-
int prevFrom = from - hitsPerPage > 0 ? from - hitsPerPage : 1;
800-
int prevTo = to - hitsPerPage > 0 ? to - hitsPerPage : numberMatched;
801-
int lastPageFrom = 0 < (numberMatched % hitsPerPage) ? numberMatched - (numberMatched % hitsPerPage) + 1 : (numberMatched - hitsPerPage + 1 > 0 ? numberMatched - hitsPerPage + 1 : numberMatched);
802-
long versionTokenETag = rdfSearcher.getVersionToken();
803-
String canonicalURL = hostURL + request.getRequestURI();
804-
String currentPage = canonicalURL + "?" + paramsAsString(allRequestParams) + "&from=" + from + "&to=" + to;
805-
String lastPage = canonicalURL + "?" + paramsAsString(allRequestParams) + "&from=" + lastPageFrom + "&to=" + numberMatched;
806-
String firstPage = canonicalURL + "?" + paramsAsString(allRequestParams) + "&from=" + firstPageFrom + "&to=" + firstPageTo;
807-
String previousPage = canonicalURL + "?" + paramsAsString(allRequestParams) + "&from=" + prevFrom + "&to=" + prevTo;
808-
String nextPage = canonicalURL + "?" + paramsAsString(allRequestParams) + "&from=" + nextFrom + "&to=" + nextTo;
809-
810-
// Hydra Paging information (see also: http://www.hydra-cg.com/spec/latest/core/)
811-
String hydraPagedCollection = "<hydra:PagedCollection xmlns:hydra=\"http://www.w3.org/ns/hydra/core#\" rdf:about=\"" + currentPage.replace("&", "&amp;") + "\">\n" +
812-
"<rdf:type rdf:resource=\"hydra:PartialCollectionView\"/>" +
813-
"<hydra:lastPage>" + lastPage.replace("&", "&amp;") + "</hydra:lastPage>\n" +
814-
"<hydra:totalItems rdf:datatype=\"http://www.w3.org/2001/XMLSchema#integer\">" + numberMatched + "</hydra:totalItems>\n" +
815-
((prevFrom <= prevTo && prevFrom < from && prevTo < to) ? "<hydra:previousPage>" + previousPage.replace("&", "&amp;") + "</hydra:previousPage>\n" : "") +
816-
((nextFrom <= nextTo && from < nextFrom && to < nextTo) ? "<hydra:nextPage>" + nextPage.replace("&", "&amp;") + "</hydra:nextPage>\n" : "") +
817-
"<hydra:firstPage>" + firstPage.replace("&", "&amp;") + "</hydra:firstPage>\n" +
818-
"<hydra:itemsPerPage rdf:datatype=\"http://www.w3.org/2001/XMLSchema#integer\">" + hitsPerPage + "</hydra:itemsPerPage>\n" +
819-
"</hydra:PagedCollection>";
820-
// Construct the RDF output
821-
File rdfFile = manager.createRdfFile(context, results, 1, hydraPagedCollection);
822-
823-
try (
824-
ServletOutputStream out = response.getOutputStream();
825-
InputStream in = new FileInputStream(rdfFile)
826-
) {
827-
byte[] bytes = new byte[1024];
828-
int bytesRead;
829-
830-
response.setContentType("application/rdf+xml");
831-
832-
//Set the Lucene versionToken as ETag response header parameter
833-
response.addHeader("ETag", Long.toString(versionTokenETag));
834-
//Include the response header "link" parameters as suggested by the W3C Linked Data Platform paging specification (see also: https://www.w3.org/2012/ldp/hg/ldp-paging.html).
835-
response.addHeader("Link", "<http://www.w3.org/ns/ldp#Page>; rel=\"type\"");
836-
response.addHeader("Link", canonicalURL + "; rel=\"canonical\"; etag=" + versionTokenETag);
837-
838-
response.addHeader("Link", "<" + firstPage + "> ; rel=\"first\"");
839-
if (nextFrom <= nextTo && from < nextFrom && to < nextTo) {
840-
response.addHeader("Link", "<" + nextPage + "> ; rel=\"next\"");
841-
}
842-
if (prevFrom <= prevTo && prevFrom < from && prevTo < to) {
843-
response.addHeader("Link", "<" + previousPage + "> ; rel=\"prev\"");
844-
}
845-
response.addHeader("Link", "<" + lastPage + "> ; rel=\"last\"");
846-
847-
//Write the paged RDF result to the message body
848-
while ((bytesRead = in.read(bytes)) != -1) {
849-
out.write(bytes, 0, bytesRead);
850-
}
851-
} catch (FileNotFoundException e) {
852-
Log.error(API.LOG_MODULE_NAME, "Get catalog content as RDF. Error: " + e.getMessage(), e);
853-
} catch (IOException e) {
854-
Log.error(API.LOG_MODULE_NAME, "Get catalog content as RDF. Error: " + e.getMessage(), e);
855-
} finally {
856-
FileUtils.deleteQuietly(rdfFile);
857-
}
858-
859-
}
860-
861-
/*
862-
* <p>Retrieve the base URL from the GeoNetwork settings.</p>
863-
*/
864-
private String getHostURL() {
865-
//Retrieve the base URL from the GeoNetwork settings
866-
ApplicationContext applicationContext = ApplicationContextHolder.get();
867-
SettingManager sm = applicationContext.getBean(SettingManager.class);
868-
ServletPathFinder pathFinder = new ServletPathFinder(servletContext);
869-
return sm.getBaseURL().replaceAll(pathFinder.getBaseUrl() + "/", "");
870-
871-
}
872-
873650
private String replaceFilenamePlaceholder(String fileName, String extension) {
874651
// Checks for a parameter documentFileName with the document file name,
875652
// otherwise uses a default value

0 commit comments

Comments
 (0)