Skip to content

Commit

Permalink
Editor / Remove wrong ERROR log message on multilingual records (#8049)
Browse files Browse the repository at this point in the history
* Editor / Remove wrong ERROR log message on multilingual records

This type of errors were reported but are wrong on multilingual records:

```
2024-05-16T10:45:08,952 ERROR [geonetwork.editor] - Element not found at ref = 554
2024-05-16T10:45:08,953 ERROR [geonetwork.editor] - Element not found at ref = 556
```

Multilingual elements have reference like `_lang_EN_123` and are managed by `updatedLocalizedTextElement` method and the schema plugin. There is no need to search for them in the preprocess phase.

* Update AjaxEditUtils.java
  • Loading branch information
fxprunayre authored Jun 6, 2024
1 parent 09f7702 commit 0758a8e
Showing 1 changed file with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ protected Element applyChangesEmbedded(String id,
continue;
}

// Ignore element if ref starts with "P" or "X"
if (originalRef.startsWith("X") || originalRef.startsWith("P")) {
// No pre processes for ref starting
// with "P" (for XPath mode)
// or "X" (for XML mode)
// or "lang_" (for multilingual fields)
// Updates for these refs are handled in next step
if (originalRef.startsWith("X") || originalRef.startsWith("P") || originalRef.startsWith("lang_")) {
continue;
}

Expand Down Expand Up @@ -190,9 +194,8 @@ protected Element applyChangesEmbedded(String id,
if (ref.startsWith("X")) {
ref = ref.substring(1);
xmlInputs.put(ref, value);
continue;
} else if (ref.startsWith("P") && ref.endsWith("_xml")) {
continue;
// P{key}=xpath works with P{key}_xml=XML snippet, see next condition
} else if (ref.startsWith("P") && !ref.endsWith("_xml")) {
// Catch element starting with a P for xpath update mode
String snippet = changes.get(ref + "_xml");
Expand All @@ -207,45 +210,42 @@ protected Element applyChangesEmbedded(String id,
} else {
Log.warning(Geonet.EDITOR, "No XML snippet or value found for xpath " + value + " and element ref " + ref);
}
continue;
}

if (updatedLocalizedTextElement(md, schema, ref, value, editLib)) {
continue;
}

int at = ref.indexOf('_');
if (at != -1) {
attribute = ref.substring(at + 1);
ref = ref.substring(0, at);
}

Element el = editLib.findElement(md, ref);
if (el == null) {
Log.error(Geonet.EDITOR, EditLib.MSG_ELEMENT_NOT_FOUND_AT_REF + ref);
continue;
}
} else if (ref.startsWith("lang_")) {
updatedLocalizedTextElement(md, schema, ref, value, editLib);
} else {
int at = ref.indexOf('_');
if (at != -1) {
attribute = ref.substring(at + 1);
ref = ref.substring(0, at);
}

// Process attribute
if (attribute != null) {
Pair<Namespace, String> attInfo = parseAttributeName(attribute, EditLib.COLON_SEPARATOR, id, md, editLib);
String localname = attInfo.two();
Namespace attrNS = attInfo.one();
if (el.getAttribute(localname, attrNS) != null) {
el.setAttribute(new Attribute(localname, value, attrNS));
Element el = editLib.findElement(md, ref);
if (el == null) {
Log.error(Geonet.EDITOR, EditLib.MSG_ELEMENT_NOT_FOUND_AT_REF + ref);
continue;
}
} else {
// Process element value
@SuppressWarnings("unchecked")
List<Content> content = el.getContent();

for (Iterator<Content> iterator = content.iterator(); iterator.hasNext(); ) {
Content content2 = iterator.next();
if (content2 instanceof Text) {
iterator.remove();
// Process attribute
if (attribute != null) {
Pair<Namespace, String> attInfo = parseAttributeName(attribute, EditLib.COLON_SEPARATOR, id, md, editLib);
String localname = attInfo.two();
Namespace attrNS = attInfo.one();
if (el.getAttribute(localname, attrNS) != null) {
el.setAttribute(new Attribute(localname, value, attrNS));
}
} else {
// Process element value
@SuppressWarnings("unchecked")
List<Content> content = el.getContent();

for (Iterator<Content> iterator = content.iterator(); iterator.hasNext(); ) {
Content content2 = iterator.next();
if (content2 instanceof Text) {
iterator.remove();
}
}
el.addContent(value);
}
el.addContent(value);
}
}

Expand Down

0 comments on commit 0758a8e

Please sign in to comment.