diff --git a/services/src/main/java/org/fao/geonet/api/records/MetadataWorkflowApi.java b/services/src/main/java/org/fao/geonet/api/records/MetadataWorkflowApi.java index dd72b20e8fe..a134e727c7c 100644 --- a/services/src/main/java/org/fao/geonet/api/records/MetadataWorkflowApi.java +++ b/services/src/main/java/org/fao/geonet/api/records/MetadataWorkflowApi.java @@ -68,6 +68,8 @@ import org.jdom.Element; import org.jdom.input.JDOMParseException; import org.jdom.output.XMLOutputter; +import org.json.JSONException; +import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.domain.PageRequest; @@ -1261,9 +1263,29 @@ private String getValidatedStateText(MetadataStatus metadataStatus, State state, checkCanViewStatus(stateText, httpSession); } + if (isValidJSON(stateText)) { + JSONObject json = new JSONObject(stateText); + String xmlRecord = json.getString("xmlRecord"); + return xmlRecord; + } + return stateText; } + /** + * Check if the input string is valid JSON format string + * @param json input string + * @return boolean if string is JSON format + */ + private boolean isValidJSON(String json) { + try { + new JSONObject(json); + } catch (JSONException e) { + return false; + } + return true; + } + /** * Checks if the metadata workflow is enabled. *