コード例 #1
0
ファイル: TestTreeIndexing.java プロジェクト: mindis/nuxeo
  @Test
  public void shouldIndexMovedSubTree() throws Exception {
    buildAndIndexTree();
    startTransaction();
    DocumentRef ref = new PathRef("/folder0/folder1/folder2");
    Assert.assertTrue(session.exists(ref));
    DocumentModel doc = session.getDocument(ref);

    // move in the same folder : rename
    session.move(ref, doc.getParentRef(), "folderA");

    TransactionHelper.commitOrRollbackTransaction();
    waitForCompletion();
    if (syncMode) {
      // in sync we split recursive update into 2 commands:
      // 1 sync non recurse + 1 async recursive
      assertNumberOfCommandProcessed(9);
    } else {
      assertNumberOfCommandProcessed(8);
    }

    startTransaction();
    SearchResponse searchResponse =
        esa.getClient()
            .prepareSearch(IDX_NAME)
            .setTypes(TYPE_NAME)
            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setFrom(0)
            .setSize(60)
            .execute()
            .actionGet();
    Assert.assertEquals(10, searchResponse.getHits().getTotalHits());

    // check sub tree search
    searchResponse =
        esa.getClient()
            .prepareSearch(IDX_NAME)
            .setTypes(TYPE_NAME)
            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1/folder2"))
            .execute()
            .actionGet();
    Assert.assertEquals(0, searchResponse.getHits().getTotalHits());

    searchResponse =
        esa.getClient()
            .prepareSearch(IDX_NAME)
            .setTypes(TYPE_NAME)
            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1/folderA"))
            .execute()
            .actionGet();
    Assert.assertEquals(8, searchResponse.getHits().getTotalHits());

    searchResponse =
        esa.getClient()
            .prepareSearch(IDX_NAME)
            .setTypes(TYPE_NAME)
            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
            .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1"))
            .execute()
            .actionGet();
    Assert.assertEquals(9, searchResponse.getHits().getTotalHits());
  }
コード例 #2
0
  // copied from TestAPI in nuxeo-core-facade
  @Test
  public void testPermissionChecks() throws Throwable {

    CoreSession joeReaderSession = null;
    CoreSession joeContributorSession = null;
    CoreSession joeLocalManagerSession = null;

    DocumentRef ref = createDocumentModelWithSamplePermissions("docWithPerms");

    try {
      // reader only has the right to consult the document
      joeReaderSession = openSessionAs("joe_reader");
      DocumentModel joeReaderDoc = joeReaderSession.getDocument(ref);
      try {
        joeReaderSession.saveDocument(joeReaderDoc);
        fail("should have raised a security exception");
      } catch (DocumentSecurityException e) {
      }

      try {
        joeReaderSession.createDocument(
            new DocumentModelImpl(joeReaderDoc.getPathAsString(), "child", "File"));
        fail("should have raised a security exception");
      } catch (DocumentSecurityException e) {
      }

      try {
        joeReaderSession.removeDocument(ref);
        fail("should have raised a security exception");
      } catch (DocumentSecurityException e) {
      }
      joeReaderSession.save();

      // contributor only has the right to write the properties of
      // document
      joeContributorSession = openSessionAs("joe_contributor");
      DocumentModel joeContributorDoc = joeContributorSession.getDocument(ref);

      joeContributorSession.saveDocument(joeContributorDoc);

      DocumentRef childRef =
          joeContributorSession
              .createDocument(
                  new DocumentModelImpl(joeContributorDoc.getPathAsString(), "child", "File"))
              .getRef();
      joeContributorSession.save();

      // joe contributor can copy the newly created doc
      joeContributorSession.copy(childRef, ref, "child_copy");

      // joe contributor cannot move the doc
      try {
        joeContributorSession.move(childRef, ref, "child_move");
        fail("should have raised a security exception");
      } catch (DocumentSecurityException e) {
      }

      // joe contributor cannot remove the folder either
      try {
        joeContributorSession.removeDocument(ref);
        fail("should have raised a security exception");
      } catch (DocumentSecurityException e) {
      }

      joeContributorSession.save();

      // local manager can read, write, create and remove
      joeLocalManagerSession = openSessionAs("joe_localmanager");
      DocumentModel joeLocalManagerDoc = joeLocalManagerSession.getDocument(ref);

      joeLocalManagerSession.saveDocument(joeLocalManagerDoc);

      childRef =
          joeLocalManagerSession
              .createDocument(
                  new DocumentModelImpl(joeLocalManagerDoc.getPathAsString(), "child2", "File"))
              .getRef();
      joeLocalManagerSession.save();

      // joe local manager can copy the newly created doc
      joeLocalManagerSession.copy(childRef, ref, "child2_copy");

      // joe local manager cannot move the doc
      joeLocalManagerSession.move(childRef, ref, "child2_move");

      joeLocalManagerSession.removeDocument(ref);
      joeLocalManagerSession.save();

    } finally {
      Throwable rethrow = null;
      if (joeReaderSession != null) {
        try {
          closeSession(joeReaderSession);
        } catch (Throwable t) {
          rethrow = t;
        }
      }
      if (joeContributorSession != null) {
        try {
          closeSession(joeContributorSession);
        } catch (Throwable t) {
          if (rethrow == null) {
            rethrow = t;
          }
        }
      }
      if (joeLocalManagerSession != null) {
        try {
          closeSession(joeLocalManagerSession);
        } catch (Throwable t) {
          if (rethrow == null) {
            rethrow = t;
          }
        }
      }
      if (rethrow != null) {
        throw rethrow;
      }
    }
  }