Skip to content

Commit 59216b6

Browse files
authored
Simple URL harvester - replace % char from property names (#8863)
1 parent 02ac664 commit 59216b6

File tree

1 file changed

+5
-8
lines changed
  • harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleurl

1 file changed

+5
-8
lines changed

harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleurl/Harvester.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//=============================================================================
2-
//=== Copyright (C) 2001-2023 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
//===
@@ -221,9 +221,8 @@ private void collectRecordsFromJson(JsonNode jsonObj,
221221
params.recordIdPath, e.getMessage()));
222222
}
223223
String apiUrlPath = params.url.split("\\?")[0];
224-
URL apiUrl = null;
225224
try {
226-
apiUrl = new URL(apiUrlPath);
225+
URL apiUrl = new URL(apiUrlPath);
227226
String nodeUrl = new StringBuilder(apiUrl.getProtocol()).append("://").append(apiUrl.getAuthority()).toString();
228227
Element xml = convertJsonRecordToXml(jsonRecord, uuid, apiUrlPath, nodeUrl);
229228
uuids.put(uuid, xml);
@@ -277,10 +276,8 @@ private void collectRecordsFromXml(Element xmlObj,
277276
log.debug(String.format("%d records found in XML response.", xmlNodes.size()));
278277

279278
xmlNodes.forEach(element -> {
280-
String uuid =
281-
null;
282279
try {
283-
uuid = getXmlElementTextValue(Xml.selectSingle(element, params.recordIdPath, element.getAdditionalNamespaces()));
280+
String uuid = getXmlElementTextValue(Xml.selectSingle(element, params.recordIdPath, element.getAdditionalNamespaces()));
284281
uuids.put(uuid, applyConversion(element, null));
285282
} catch (JDOMException e) {
286283
log.error(String.format("Failed to extract UUID for record. Error is %s.",
@@ -333,7 +330,7 @@ protected List<String> buildListOfUrl(SimpleUrlParams params, int numberOfRecord
333330
}
334331

335332
final String pageFromParamValue = params.url.replaceAll(".*[?&]" + params.pageFromParam + "=([0-9]+).*", "$1");
336-
boolean startAtZero = false;
333+
boolean startAtZero;
337334
if (StringUtils.isNumeric(pageFromParamValue)) {
338335
startAtZero = Integer.parseInt(pageFromParamValue) == 0;
339336
} else {
@@ -370,7 +367,7 @@ private Element convertJsonRecordToXml(JsonNode jsonRecord, String uuid, String
370367
recordAsXml = Xml.stripNonValidXMLCharacters(recordAsXml)
371368
.replace("<@", "<")
372369
.replace("</@", "</")
373-
.replaceAll("(:)(?![^<>]*<)", "_"); // this removes colon from property names
370+
.replaceAll("(:|%)(?![^<>]*<)", "_"); // this removes colon and % from property names
374371
Element recordAsElement = Xml.loadString(recordAsXml, false);
375372
recordAsElement.addContent(new Element("uuid").setText(uuid));
376373
recordAsElement.addContent(new Element("apiUrl").setText(apiUrl));

0 commit comments

Comments
 (0)