Search in sources :

Example 6 with FileSystemChangeSummary

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

the class AbstractChangeFinderTestCase method getChangeSummary.

/**
 * Gets the document changes summary for the given user's synchronization roots using the {@link NuxeoDriveManager}
 * and updates {@link #lastEventLogId}.
 */
protected FileSystemChangeSummary getChangeSummary(Principal principal) throws InterruptedException {
    Map<String, Set<IdRef>> lastSyncActiveRootRefs = RootDefinitionsHelper.parseRootDefinitions(lastSyncActiveRootDefinitions);
    FileSystemChangeSummary changeSummary = nuxeoDriveManager.getChangeSummaryIntegerBounds(principal, lastSyncActiveRootRefs, lastEventLogId);
    assertNotNull(changeSummary);
    lastEventLogId = changeSummary.getUpperBound();
    lastSyncActiveRootDefinitions = changeSummary.getActiveSynchronizationRootDefinitions();
    return changeSummary;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary)

Example 7 with FileSystemChangeSummary

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

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

the class AuditChangeFinderTestSuite method testGetChangeSummary.

@Test
public void testGetChangeSummary() throws Exception {
    FileSystemChangeSummary changeSummary;
    Principal admin = new NuxeoPrincipalImpl("Administrator");
    DocumentModel doc1;
    DocumentModel doc2;
    try {
        // No sync roots => shouldn't find any changes
        changeSummary = getChangeSummary(admin);
        assertNotNull(changeSummary);
        assertTrue(changeSummary.getFileSystemChanges().isEmpty());
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
        // Register sync roots => should find changes: the newly
        // synchronized root folders as they are updated by the
        // synchronization
        // registration process
        nuxeoDriveManager.registerSynchronizationRoot(admin, folder1, session);
        nuxeoDriveManager.registerSynchronizationRoot(admin, folder2, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changeSummary = getChangeSummary(admin);
        assertEquals(2, changeSummary.getFileSystemChanges().size());
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Create 3 documents, only 2 in sync roots => should find 2 changes
    try {
        doc1 = session.createDocumentModel("/folder1", "doc1", "File");
        doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
        doc1 = session.createDocument(doc1);
        doc2 = session.createDocumentModel("/folder2", "doc2", "File");
        doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
        doc2 = session.createDocument(doc2);
        session.createDocument(session.createDocumentModel("/folder3", "doc3", "File"));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changeSummary = getChangeSummary(admin);
        List<FileSystemItemChange> changes = changeSummary.getFileSystemChanges();
        assertEquals(2, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        SimpleFileSystemItemChange simpleChange = new SimpleFileSystemItemChange(doc2.getId(), "documentCreated", "test");
        simpleChange.setLifeCycleState("project");
        expectedChanges.add(simpleChange);
        simpleChange = new SimpleFileSystemItemChange(doc1.getId(), "documentCreated", "test");
        simpleChange.setLifeCycleState("project");
        expectedChanges.add(simpleChange);
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
        // Create a document that should not be synchronized because not
        // adaptable as a FileSystemItem (not Folderish nor a BlobHolder
        // with a
        // blob) => should not be considered as a change
        session.createDocument(session.createDocumentModel("/folder1", "notSynchronizableDoc", "NotSynchronizable"));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changeSummary = getChangeSummary(admin);
        assertTrue(changeSummary.getFileSystemChanges().isEmpty());
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
        // Create 2 documents in the same sync root: "/folder1" and 1 document in another sync root => should find 2
        // changes for "/folder1"
        DocumentModel doc3 = session.createDocumentModel("/folder1", "doc3", "File");
        doc3.setPropertyValue("file:content", new StringBlob("The content of file 3."));
        doc3 = session.createDocument(doc3);
        DocumentModel doc4 = session.createDocumentModel("/folder1", "doc4", "File");
        doc4.setPropertyValue("file:content", new StringBlob("The content of file 4."));
        doc4 = session.createDocument(doc4);
        DocumentModel doc5 = session.createDocumentModel("/folder2", "doc5", "File");
        doc5.setPropertyValue("file:content", new StringBlob("The content of file 5."));
        doc5 = session.createDocument(doc5);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changeSummary = getChangeSummary(admin);
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
        assertEquals(3, changeSummary.getFileSystemChanges().size());
        // No changes since last successful sync
        changeSummary = getChangeSummary(admin);
        assertTrue(changeSummary.getFileSystemChanges().isEmpty());
        assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
        // Test too many changes
        session.followTransition(doc1.getRef(), "delete");
        session.followTransition(doc2.getRef(), "delete");
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    Framework.getProperties().put("org.nuxeo.drive.document.change.limit", "1");
    changeSummary = getChangeSummary(admin);
    assertTrue(changeSummary.getFileSystemChanges().isEmpty());
    assertEquals(Boolean.TRUE, changeSummary.getHasTooManyChanges());
}
Also used : NuxeoPrincipalImpl(org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl) FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) Principal(java.security.Principal) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with FileSystemChangeSummary

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

the class TestPermissionHierarchyFileSystemChanges method getChanges.

protected List<FileSystemItemChange> getChanges(Principal principal) throws InterruptedException {
    FileSystemChangeSummary changeSummary = nuxeoDriveManager.getChangeSummaryIntegerBounds(principal, Collections.<String, Set<IdRef>>emptyMap(), lastEventLogId);
    assertNotNull(changeSummary);
    lastEventLogId = changeSummary.getUpperBound();
    return changeSummary.getFileSystemChanges();
}
Also used : FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) IdRef(org.nuxeo.ecm.core.api.IdRef)

Example 10 with FileSystemChangeSummary

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

the class TestGetChangeSummary method testGetChangesSummary.

@Test
public void testGetChangesSummary() throws Exception {
    // No sync roots => shouldn't find any changes
    FileSystemChangeSummary changeSummary = getChangeSummary();
    assertTrue(changeSummary.getFileSystemChanges().isEmpty());
    assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
    // Register sync roots and create 2 documents and 1 folder => should find 3 changes
    DocumentModel doc1;
    DocumentModel doc2;
    DocumentModel folder3;
    try {
        Principal administrator = session.getPrincipal();
        nuxeoDriveManager.registerSynchronizationRoot(administrator, folder1, session);
        nuxeoDriveManager.registerSynchronizationRoot(administrator, folder2, session);
        doc1 = session.createDocumentModel("/folder1", "doc1", "File");
        doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
        doc1 = session.createDocument(doc1);
        doc2 = session.createDocumentModel("/folder2", "doc2", "File");
        doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
        doc2 = session.createDocument(doc2);
        folder3 = session.createDocumentModel("/folder2", "folder3", "Folder");
        folder3 = session.createDocument(folder3);
        session.save();
    } finally {
        TransactionHelper.commitOrRollbackTransaction();
        TransactionHelper.startTransaction();
    }
    changeSummary = getChangeSummary();
    List<FileSystemItemChange> docChanges = changeSummary.getFileSystemChanges();
    assertEquals(3, docChanges.size());
    Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
    expectedChanges.add(new SimpleFileSystemItemChange(folder3.getId(), "documentChanged", "test"));
    expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentChanged", "test"));
    expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentChanged", "test"));
    Set<SimpleFileSystemItemChange> changes = new HashSet<>();
    docChanges.forEach(docChange -> {
        changes.add(new SimpleFileSystemItemChange(docChange.getDocUuid(), docChange.getEventId(), docChange.getRepositoryId()));
        assertNotNull(docChange.getFileSystemItem());
    });
    assertTrue(CollectionUtils.isEqualCollection(expectedChanges, changes));
    assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
}
Also used : FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Principal(java.security.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)11 HashSet (java.util.HashSet)6 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)6 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)6 Test (org.junit.Test)5 Principal (java.security.Principal)4 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)4 Set (java.util.Set)3 IdRef (org.nuxeo.ecm.core.api.IdRef)3 SimpleFileSystemItemChange (org.nuxeo.drive.fixtures.SimpleFileSystemItemChange)2 Blob (org.nuxeo.ecm.automation.client.model.Blob)2 NuxeoPrincipalImpl (org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)1 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)1 TooManyChangesException (org.nuxeo.drive.service.TooManyChangesException)1