Search in sources :

Example 76 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testFolderishCollection3.

/**
 * <pre>
 * /folder1                 -> isMemberOf(collectionFolder)
 *   |-- collectionFolder   -> synchronization root
 * /collectionSyncRoot      -> synchronization root
 * /testDoc                 -> isMemberOf(collectionFolder, collectionSyncRoot)
 * </pre>
 */
@Test
public void testFolderishCollection3() throws Exception {
    DocumentModel collectionFolder;
    DocumentModel collectionSyncRoot;
    DocumentModel testDoc;
    List<FileSystemItemChange> changes;
    try {
        log.trace("testFolderishCollection3():" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside a folder (\"folder1\") and register it as a sycnhronization root;" + "\nAdd \"folder1\" to the \"collectionFolder\" collection;" + "\nCreate a collection \"collectionSyncRoot\" and register it as a synchronization root;" + "\nCreate a document \"testDoc\" and add it to both collections \"collectionFolder\" and \"collectionSyncRoot\".\n");
        collectionFolder = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
        collectionFolder = session.createDocument(collectionFolder);
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionFolder, session);
        collectionManager.addToCollection(collectionFolder, folder1, session);
        collectionSyncRoot = collectionManager.createCollection(session, "collectionSyncRoot", null, "/");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot, session);
        testDoc = session.createDocumentModel("/", "testDoc", "File");
        testDoc.setPropertyValue("file:content", new StringBlob("The content of testDoc."));
        testDoc = session.createDocument(testDoc);
        collectionManager.addToCollection(collectionFolder, testDoc, session);
        collectionManager.addToCollection(collectionSyncRoot, testDoc, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Expecting 12 (among which 10 distinct) changes:
        // - addedToCollection for testDoc
        // - documentModified for collectionSyncRoot
        // - addedToCollection for testDoc
        // - documentModified for collectionFolder
        // - documentCreated for testDoc
        // - rootRegistered for collectionSyncRoot
        // - documentCreated for collectionSyncRoot
        // - addedToCollection for folder1
        // - documentModified for collectionFolder
        // - rootRegistered for collectionFolder
        // - documentCreated for collectionFolder
        // - documentCreated for folder1
        changes = getChanges(session.getPrincipal());
        assertEquals(12, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentModified"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "documentModified"));
        expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 77 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testSyncRootParentWithSingleQuotePermissionChange.

@Test
public void testSyncRootParentWithSingleQuotePermissionChange() throws Exception {
    List<FileSystemItemChange> changes;
    DocumentModel folder;
    DocumentModel subFolder;
    try {
        // No sync roots
        changes = getChanges();
        assertTrue(changes.isEmpty());
        // Create a folder with a single quote including a subfolder
        folder = session.createDocumentModel("/", "fol'der", "Folder");
        folder = session.createDocument(folder);
        subFolder = session.createDocumentModel("/fol'der", "subFolder", "Folder");
        subFolder = session.createDocument(subFolder);
        // Grant READ_WRITE permission to user1 on the parent folder
        setPermissions(folder, new ACE("user1", SecurityConstants.READ_WRITE));
        // Mark subfolder as a sync root for user1
        nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), subFolder, user1Session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Get changes for user1
        changes = getChanges(user1Session.getPrincipal());
        // Folder creation and sync root registration events
        assertEquals(2, changes.size());
        // Remove READ_WRITE permission granted to user1 on the parent folder
        resetPermissions(folder, "user1");
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changes = getChanges(user1Session.getPrincipal());
        // Expecting 1 change: securityUpdated for the subfolder with a null FileSystemItem and FileSystemItem name
        // since the user cannot access it anymore
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        SimpleFileSystemItemChange simpleChange = new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "test#" + subFolder.getId(), "subFolder");
        assertEquals(simpleChange, toSimpleFileSystemItemChange(change));
        assertNull(change.getFileSystemItem());
        assertNull(change.getFileSystemItemName());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 78 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testFolderishCollection4.

/**
 * <pre>
 * /collectionSyncRoot1     -> synchronization root
 * /folder1                 -> isMemberOf(collectionSyncRoot1)
 *   |-- collectionFolder
 * /collectionSyncRoot2     -> synchronization root
 * /testDoc                 -> isMemberOf(collectionFolder, collectionSyncRoot2)
 * </pre>
 */
@Test
public void testFolderishCollection4() throws Exception {
    DocumentModel collectionSyncRoot1;
    DocumentModel collectionSyncRoot2;
    DocumentModel testDoc;
    List<FileSystemItemChange> changes;
    try {
        log.trace("testFolderishCollection4():" + "\nCreate a collection \"collectionSyncRoot1\" and register it as a synchronization root;" + "\nAdd \"folder1\" to the \"collectionSyncRoot1\" collection;" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside (\"folder1\");" + "\nCreate a collection \"collectionSyncRoot\" and register it as a synchronization root;" + "\nCreate a document \"testDoc\" and add it to both collections \"collectionFolder\" and \"collectionSyncRoot\".\n");
        collectionSyncRoot1 = collectionManager.createCollection(session, "collectionSyncRoot1", null, "/");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot1, session);
        collectionManager.addToCollection(collectionSyncRoot1, folder1, session);
        DocumentModel collectionFolder = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
        collectionFolder = session.createDocument(collectionFolder);
        collectionSyncRoot2 = collectionManager.createCollection(session, "collectionSyncRoot2", null, "/");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot2, session);
        testDoc = session.createDocumentModel("/", "testDoc", "File");
        testDoc.setPropertyValue("file:content", new StringBlob("The content of testDoc."));
        testDoc = session.createDocument(testDoc);
        collectionManager.addToCollection(collectionFolder, testDoc, session);
        collectionManager.addToCollection(collectionSyncRoot2, testDoc, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Expecting 11 (among which 10 distinct) changes:
        // - addedToCollection for testDoc
        // - documentModified for collectionSyncRoot2
        // - addedToCollection for testDoc
        // - documentCreated for testDoc
        // - rootRegistered for collectionSyncRoot2
        // - documentCreated for collectionSyncRoot2
        // - addedToCollection for folder1
        // - documentModified for collectionSyncRoot1
        // - rootRegistered for collectionSyncRoot1
        // - documentCreated for collectionSyncRoot1
        // - documentCreated for folder1
        changes = getChanges(session.getPrincipal());
        assertEquals(11, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "documentModified"));
        expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "documentModified"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testMoveToOtherUsersSyncRoot.

@Test
public void testMoveToOtherUsersSyncRoot() throws Exception {
    DocumentModel subFolder;
    List<FileSystemItemChange> changes;
    try {
        // Create a subfolder in folder1 as Administrator
        subFolder = session.createDocument(session.createDocumentModel(folder1.getPathAsString(), "subFolder", "Folder"));
        // Register folder1 as a sync root for user1
        nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder1, user1Session);
        // Register folder2 as a sync root for Administrator
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder2, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes for user1, expecting 3:
        // - rootRegistered for folder1
        // - documentCreated for subFolder1
        // - documentCreated for folder1 at init
        changes = getChanges(user1Session.getPrincipal());
        assertEquals(3, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
        // As Administrator, move subfolder from folder1 (sync root for
        // user1) to folder2 (sync root for Administrator but not for
        // user1)
        session.move(subFolder.getRef(), folder2.getRef(), null);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes for user1, expecting 1: deleted for subFolder
        changes = getChanges(user1Session.getPrincipal());
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(subFolder.getId(), "deleted"), toSimpleFileSystemItemChange(changes.get(0)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 80 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testLockUnlock.

@Test
public void testLockUnlock() throws Exception {
    DocumentModel doc;
    List<FileSystemItemChange> changes;
    try {
        log.trace("Register a sync root and create a document inside it");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
        doc = session.createDocumentModel("/folder1", "doc", "File");
        doc.setPropertyValue("file:content", new StringBlob("The file content"));
        doc = session.createDocument(doc);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 3:
        // - documentCreated for doc
        // - rootRegistered for folder1
        // - documentCreated for folder1
        changes = getChanges(session.getPrincipal());
        assertEquals(3, changes.size());
        log.trace("Lock doc");
        session.setLock(doc.getRef());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 1:
        // - documentLocked for doc
        changes = getChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "documentLocked", "test", "defaultFileSystemItemFactory#test#" + doc.getId(), "doc"), toSimpleFileSystemItemChange(changes.get(0)));
        log.trace("Unlock doc");
        session.removeLock(doc.getRef());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 1:
        // - documentUnlocked for doc
        changes = getChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "documentUnlocked", "test", "defaultFileSystemItemFactory#test#" + doc.getId(), "doc"), toSimpleFileSystemItemChange(changes.get(0)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7