Automation service - Restore Version
Hi, Is there an automation service allowing to restore a previous version of a document ? By restore , i mean set an older version as the current document.
If not , and i want to add an operation , could someone point me on what Nuxeo classes i will need to do so.
tx Michel
Great it works just fine !
@Operation(id = RestoreDocument.ID,
category = Constants.CAT_DOCUMENT,
label = "RestoreDocument",
description = "Restore the input Document version.")
public class RestoreDocument {
public final static String ID = "Document.RestoreDocument";
@Context
protected CoreSession session;
@Param(name = "versionDocumentId")
protected String versionDocumentId;
@OperationMethod
public DocumentModel run(DocumentModel doc) throws Exception {
List<DocumentModel> versions = session.getVersions(doc.getRef());
if (versions != null) {
for (DocumentModel version : versions) {
if (version.getId().equals(versionDocumentId)) {
session.restoreToVersion(doc.getRef(), version.getRef());
return version;
}
}
}
throw new Exception("Version Document Id not found: " + versionDocumentId);
}
}
thanks in advance
There is no such operation in default Nuxeo.
You could easily create one, the basic API to use is CoreSession.restoreToVersion.
I'd like to try your code! :) But I have not figured out how to add this operation and how to call it by a remote automation client. I have read the documentation on how to “contribute an operation” (http://doc.nuxeo.com/display/NXDOC/Contributing+an+Operation) but is not clear for me where how and where add the operation… in which xml? in a jar?
thanks in advance.