Skip to content

Commit

Permalink
optimisation attempt, do not ask saxon for a jdom tree in order to se…
Browse files Browse the repository at this point in the history
…rialize it after, directly write in servlet ouptut
  • Loading branch information
cmangeat committed Feb 22, 2019
1 parent dcb8e98 commit 1a55396
Showing 1 changed file with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.fao.geonet.repository.OperationAllowedRepository;
import org.fao.geonet.repository.specification.MetadataValidationSpecs;
import org.fao.geonet.utils.Xml;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.output.XMLOutputter;
Expand All @@ -69,6 +68,7 @@
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jeeves.server.context.ServiceContext;
Expand Down Expand Up @@ -118,8 +118,7 @@ public class MetadataEditingApi {
@ApiResponse(code = 200, message = "The editor form."),
@ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_EDIT)
})
@ResponseBody
public Element startEditing(
public void startEditing(
@ApiParam(value = API_PARAM_RECORD_UUID,
required = true)
@PathVariable
Expand All @@ -142,7 +141,8 @@ public Element startEditing(
@ApiParam(hidden = true)
@RequestParam
Map<String,String> allRequestParams,
HttpServletRequest request
HttpServletRequest request,
HttpServletResponse response
) throws Exception {
AbstractMetadata metadata = ApiUtils.canEditRecord(metadataUuid, request);

Expand All @@ -161,11 +161,10 @@ public Element startEditing(
context,
String.valueOf(metadata.getId()),
true, showValidationErrors);
return buildEditorForm(
buildEditorForm(
currTab, session, allRequestParams,
request, metadata.getId(), elMd, metadata.getDataInfo().getSchemaId(),
showValidationErrors,
context, applicationContext, false, false);
request, elMd, metadata.getDataInfo().getSchemaId(),
context, applicationContext, false, false, response);
}


Expand All @@ -186,8 +185,7 @@ public Element startEditing(
@ApiResponse(code = 200, message = "The editor form."),
@ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_EDIT)
})
@ResponseBody
public Element saveEdits(
public void saveEdits(
@ApiParam(value = API_PARAM_RECORD_UUID,
required = true)
@PathVariable
Expand Down Expand Up @@ -237,6 +235,7 @@ public Element saveEdits(
@RequestParam
Map<String,String> allRequestParams,
HttpServletRequest request,
HttpServletResponse response,
@ApiIgnore
@ApiParam(hidden = true)
HttpSession httpSession
Expand Down Expand Up @@ -314,7 +313,7 @@ public Element saveEdits(

//--- if finished then remove the XML from the session
if ((commit) && (!terminate)) {
return null;
return;
}
if (terminate) {
SettingManager sm = context.getBean(SettingManager.class);
Expand Down Expand Up @@ -368,7 +367,7 @@ public Element saveEdits(
"the editing session. The public record '%s' was unpublished.",
metadata.getUuid()));
} else {
return null;
return;
}
}

Expand All @@ -380,11 +379,13 @@ public Element saveEdits(
context,
String.valueOf(id),
true, withValidationErrors);
return buildEditorForm(
tab, httpSession, forwardedParams,
request, metadata.getId(), elMd, metadata.getDataInfo().getSchemaId(),
withValidationErrors,
context, applicationContext, false, false);


buildEditorForm(
tab, httpSession, forwardedParams,
request, elMd, metadata.getDataInfo().getSchemaId(),
context, applicationContext, false, false, response);

}


Expand Down Expand Up @@ -448,8 +449,7 @@ public void cancelEdits(
@ApiResponse(code = 200, message = "Element added."),
@ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_EDIT)
})
@ResponseBody
public Element addElement(
public void addElement(
@ApiParam(value = API_PARAM_RECORD_UUID,
required = true)
@PathVariable
Expand Down Expand Up @@ -483,6 +483,7 @@ public Element addElement(
@RequestParam
Map<String,String> allRequestParams,
HttpServletRequest request,
HttpServletResponse response,
@ApiIgnore
@ApiParam(hidden = true)
HttpSession httpSession
Expand Down Expand Up @@ -512,11 +513,10 @@ public Element addElement(
Element md = (Element) findRoot(elResp).clone();
EditLib.removeDisplayTag(elResp);

return buildEditorForm(
buildEditorForm(
allRequestParams.get("currTab"), httpSession, allRequestParams,
request, metadata.getId(), md, metadata.getDataInfo().getSchemaId(),
false,
context, applicationContext, true, true);
request, md, metadata.getDataInfo().getSchemaId(),
context, applicationContext, true, true, response);
}


Expand Down Expand Up @@ -704,33 +704,31 @@ private Element findRoot(Element element) {
* legacy Jeeves XML processed by XSLT. Only
* element required for the editor are created.
*/
private Element buildEditorForm(
String tab,
HttpSession session,
Map<String, String> allRequestParams,
HttpServletRequest request,
int id,
Element xml,
String schema,
boolean showValidationErrors,
ServiceContext context,
ApplicationContext applicationContext, boolean isEmbedded, boolean embedded) throws Exception {
private void buildEditorForm(
String tab,
HttpSession session,
Map<String, String> allRequestParams,
HttpServletRequest request,
Element xml,
String schema,
ServiceContext context,
ApplicationContext applicationContext, boolean isEmbedded, boolean embedded, HttpServletResponse response) throws Exception {


UserSession userSession = ApiUtils.getUserSession(session);
Element root = buildResourceDocument(applicationContext, context, userSession);
root.addContent(xml);
Element gui = root.getChild("gui");
gui.addContent(
new Element("currTab").setText(tab));
new Element("currTab").setText(tab));
// This flag is used to generate top tool bar or not
gui.addContent(
new Element("reqService").setText(embedded ? "embedded" : "md.edit"));
new Element("reqService").setText(embedded ? "embedded" : "md.edit"));
String iso3langCode = languageUtils.getIso3langCode(request.getLocales());
gui.addContent(
new Element("language").setText(iso3langCode));
new Element("language").setText(iso3langCode));
gui.addContent(
getSchemaStrings(schema, context)
getSchemaStrings(schema, context)
);

Element requestParams = new Element ("request");
Expand All @@ -741,14 +739,13 @@ private Element buildEditorForm(

GeonetworkDataDirectory dataDirectory = applicationContext.getBean(GeonetworkDataDirectory.class);
Path xslt = dataDirectory.getWebappDir().resolve(
isEmbedded ?
"xslt/ui-metadata/edit/edit-embedded.xsl" :
"xslt/ui-metadata/edit/edit.xsl");
return Xml.transform(root, xslt);
isEmbedded ?
"xslt/ui-metadata/edit/edit-embedded.xsl" :
"xslt/ui-metadata/edit/edit.xsl");
Xml.transform(root, xslt, response.getOutputStream());
}



private Element buildResourceDocument(
ApplicationContext applicationContext,
ServiceContext context,
Expand Down

0 comments on commit 1a55396

Please sign in to comment.