Skip to content

Commit

Permalink
Return xml inside JSON status (#8580)
Browse files Browse the repository at this point in the history
Co-authored-by: WANGF <[email protected]>
  • Loading branch information
geonetworkbuild and wangf1122 authored Dec 24, 2024
1 parent 546ca24 commit 8d31caa
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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;
Expand Down Expand Up @@ -1259,9 +1261,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.
*
Expand Down

0 comments on commit 8d31caa

Please sign in to comment.