如何使用REST API将Nuxeo的文件/文件夹移动到Trash

时间:2014-12-04 10:36:00

标签: rest nuxeo

从Nuxeo REST API文档中,我可以使用此代码在TRASH中看到已删除的文件/文件夹

SELECT * FROM Document WHERE ecm:mixinType != 'HiddenInNavigation' 
AND ecm:currentLifeCycleState = 'deleted' AND ecm:isProxy = 0 AND ecm:isCheckedInVersion = 0

但是如何使用ecm:currentLifeCycleState更新文档以将文档移至TRASH?

谢谢

2 个答案:

答案 0 :(得分:2)

您应该使用Document.SetLifeCycle操作来跟踪delete转换。

答案 1 :(得分:2)

以下是我用于将文档移至垃圾箱的代码。

  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;
    }
  }