Un pattern de type command a été mis en place pour faciliter l'appel du client automation. Il gère implicitement :
Une commande doit implémenter l'interface INuxeoCommand. La méthode getID identifie la commande au niveau du gestionnaire de cache.
public class DocumentFetchCommand implements INuxeoCommand {
String path;
public DocumentFetchCommand(String path) {
super();
this.path = path;
}
public Object execute( Session session) throws Exception {
Document doc = (Document) session
.newRequest("Document.Fetch").setHeader(Constants.HEADER_NX_SCHEMAS, "*").set("value", path)
.execute();
return doc;
}
public String getId() {
return "DocumentFetchCommand/" + path;
};
}
L'exemple ci-dessous correspond à un appel effectué depuis la méthode doView d'un portlet.
protected void doView(RenderRequest request, RenderResponse response) {
NuxeoController nuxeoCtrl = new NuxeoController(req, res, getPortletContext());
try {
...
Document doc = (Document) nuxeoCtrl.executeNuxeoCommand(new DocumentFetchCommand(path));
...
} catch( NuxeoException e){
PortletErrorHandler.handleGenericErrors(response, e);
}
}