这是我用来将文档移动到垃圾箱的代码。
public boolean deleteDocument(Session session, String documentId) throws Exception {
try {
Document document = getDocumentById(session, documentId);
// When delete a document, only move it to Trash
session.newRequest("Document.SetLifeCycle")
.setInput(document).set("value", "delete").execute();
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw e;
}
}
以下代码将永久删除该文档。
public static boolean deleteDocument(Session session, String documentId) throws Exception {
try {
Document document = getDocumentById(session, documentId);
// Delete the document permanently
session.newRequest("Document.Delete").setInput(document).execute();
return true;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw e;
}
}
一种方法是首先通过 NXQL 在垃圾箱中查找文档,例如:
SELECT * FROM Document WHERE ecm:currentLifeCycleState = 'deleted'
然后通过上述方法永久删除它们。还有一篇文章提到了这一点: http: //answers.nuxeo.com/questions/1830/actioncommand-to-permanently-delete-all-document-in-trash
实用方法:通过 documentId 获取文档:
public static Document getDocumentById(Session session, String documentId) throws Exception {
try {
return (Document) session.newRequest("Document.Fetch").set("value", documentId)
.setHeader(Constants.HEADER_NX_SCHEMAS, "*").execute();
} catch (Exception e) {
log.error("Failed to fetch document: " + e.getMessage(), e);
throw e;
}
}