Search in sources :

Example 16 with FileSystemItemChange

use of org.nuxeo.drive.service.FileSystemItemChange 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 17 with FileSystemItemChange

use of org.nuxeo.drive.service.FileSystemItemChange 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 18 with FileSystemItemChange

use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testGetChangeSummaryOnRootDocuments.

@Test
public void testGetChangeSummaryOnRootDocuments() throws Exception {
    Principal admin = new NuxeoPrincipalImpl("Administrator");
    Principal otherUser = new NuxeoPrincipalImpl("some-other-user");
    Set<IdRef> activeRootRefs;
    FileSystemChangeSummary changeSummary;
    List<FileSystemItemChange> changes;
    try {
        // No root registered by default: no changes
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertTrue(activeRootRefs.isEmpty());
        changeSummary = getChangeSummary(admin);
        assertNotNull(changeSummary);
        assertTrue(changeSummary.getFileSystemChanges().isEmpty());
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
        // Register a root for someone else
        nuxeoDriveManager.registerSynchronizationRoot(otherUser, folder1, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Administrator does not see any change
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertTrue(activeRootRefs.isEmpty());
        changeSummary = getChangeSummary(admin);
        assertNotNull(changeSummary);
        assertTrue(changeSummary.getFileSystemChanges().isEmpty());
        assertFalse(changeSummary.getHasTooManyChanges());
        // Register a new sync root
        nuxeoDriveManager.registerSynchronizationRoot(admin, folder1, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertEquals(1, activeRootRefs.size());
        assertEquals(folder1.getRef(), activeRootRefs.iterator().next());
        // The new sync root is detected in the change summary
        changeSummary = getChangeSummary(admin);
        assertNotNull(changeSummary);
        changes = changeSummary.getFileSystemChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
        // Check that root unregistration is detected as a deletion
        nuxeoDriveManager.unregisterSynchronizationRoot(admin, folder1, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertTrue(activeRootRefs.isEmpty());
        changeSummary = getChangeSummary(admin);
        changes = changeSummary.getFileSystemChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "deleted", "test", "test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
        // Register back the root, it's activity is again detected by the
        // client
        nuxeoDriveManager.registerSynchronizationRoot(admin, folder1, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertEquals(activeRootRefs.size(), 1);
        changeSummary = getChangeSummary(admin);
        changes = changeSummary.getFileSystemChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
        // Test deletion of a root
        session.followTransition(folder1.getRef(), "delete");
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertTrue(activeRootRefs.isEmpty());
        // The root is no longer active
        activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
        assertNotNull(activeRootRefs);
        assertTrue(activeRootRefs.isEmpty());
        // The deletion of the root itself is mapped as filesystem
        // deletion event
        changeSummary = getChangeSummary(admin);
        changes = changeSummary.getFileSystemChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "deleted", "test", "test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : NuxeoPrincipalImpl(org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl) FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) IdRef(org.nuxeo.ecm.core.api.IdRef) Principal(java.security.Principal) Test(org.junit.Test)

Example 19 with FileSystemItemChange

use of org.nuxeo.drive.service.FileSystemItemChange 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)

Example 20 with FileSystemItemChange

use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testSection.

@Test
public void testSection() throws Exception {
    DocumentModel section;
    DocumentModel doc1;
    DocumentModel proxy1;
    DocumentModel proxy2;
    List<FileSystemItemChange> changes;
    try {
        // Create a Section and register it as a synchronization root
        section = session.createDocument(session.createDocumentModel("/", "sectionSyncRoot", "Section"));
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), section, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 2:
        // - rootRegistered for section
        // - documentCreated for section
        changes = getChanges(session.getPrincipal());
        assertEquals(2, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(section.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + section.getId(), "sectionSyncRoot"));
        expectedChanges.add(new SimpleFileSystemItemChange(section.getId(), "documentCreated", "test", "defaultSyncRootFolderItemFactory#test#" + section.getId(), "sectionSyncRoot"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
        // Publish 2 documents in the section
        doc1 = session.createDocumentModel("/folder1", "doc1", "File");
        doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
        doc1 = session.createDocument(doc1);
        proxy1 = session.publishDocument(doc1, section);
        DocumentModel doc2 = session.createDocumentModel("/folder1", "doc2", "File");
        doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
        doc2 = session.createDocument(doc2);
        proxy2 = session.publishDocument(doc2, section);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 4:
        // - documentProxyPublished for proxy2
        // - documentCreated for proxy2
        // - documentProxyPublished for proxy1
        // - documentCreated for proxy1
        changes = getChanges();
        assertEquals(4, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(proxy2.getId(), "documentProxyPublished", "test", "defaultFileSystemItemFactory#test#" + proxy2.getId(), "doc2"));
        expectedChanges.add(new SimpleFileSystemItemChange(proxy2.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + proxy2.getId(), "doc2"));
        expectedChanges.add(new SimpleFileSystemItemChange(proxy1.getId(), "documentProxyPublished", "test", "defaultFileSystemItemFactory#test#" + proxy1.getId(), "doc1"));
        expectedChanges.add(new SimpleFileSystemItemChange(proxy1.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + proxy1.getId(), "doc1"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
        // Update an existing proxy
        doc1.setPropertyValue("file:content", new StringBlob("The updated content of file 1."));
        session.saveDocument(doc1);
        session.publishDocument(doc1, section);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 1:
        // - documentProxyPublished for proxy1
        changes = getChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(proxy1.getId(), "documentProxyPublished", "test", "defaultFileSystemItemFactory#test#" + proxy1.getId(), "doc1"), 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)30 Test (org.junit.Test)26 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)24 HashSet (java.util.HashSet)17 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)13 IdRef (org.nuxeo.ecm.core.api.IdRef)7 ACE (org.nuxeo.ecm.core.api.security.ACE)7 FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)6 Principal (java.security.Principal)5 ArrayList (java.util.ArrayList)3 SimpleFileSystemItemChange (org.nuxeo.drive.fixtures.SimpleFileSystemItemChange)2 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)2 TooManyChangesException (org.nuxeo.drive.service.TooManyChangesException)2 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)2 NuxeoPrincipalImpl (org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1