01-10-2012 11:33 AM
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
01-12-2012 01:59 PM
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);
}
}
01-12-2012 07:21 AM
There is no such operation in default Nuxeo.
You could easily create one, the basic API to use is CoreSession.restoreToVersion.
01-12-2012 01:59 PM
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);
}
}
09-17-2013 01:51 PM
I'd like to try your code!
05-14-2015 03:35 AM
Hi, I would like to know how to do this in version 7.2?
09-17-2013 01:36 PM
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.
Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.