Search in sources :

Example 26 with FileSystemItemChange

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

the class GroupChangesTestSuite method testGroupChanges.

/**
 * Tests changes on the given group that has access to the given document:
 * <ul>
 * <li>Remove the test user from the group</li>
 * <li>Add the test user to the group</li>
 * <li>Delete the group</li>
 * <li>Create the group including the test user</li>
 * </ul>
 */
protected void testGroupChanges(DocumentModel doc, String factoryName, String groupName, boolean needsParentGroup) throws Exception {
    List<FileSystemItemChange> changes;
    try {
        log.trace("Remove user from " + groupName);
        updateGroup(groupName, Collections.emptyList(), null);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changes = getChanges(userManager.getPrincipal("user"));
        // securityUpdated on doc with a null FileSystemItem
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "securityUpdated", "test", "test#" + doc.getId()), toSimpleFileSystemItemChange(change));
        assertNull(change.getFileSystemItem());
        assertNull(change.getFileSystemItemName());
        log.trace("Add user to " + groupName);
        updateGroup(groupName, Arrays.asList("user"), null);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changes = getChanges(userManager.getPrincipal("user"));
        // securityUpdated on doc with a non-null FileSystemItem
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "securityUpdated", "test", factoryName + "#test#" + doc.getId()), toSimpleFileSystemItemChange(change));
        assertNotNull(change.getFileSystemItem());
        assertEquals(doc.getTitle(), change.getFileSystemItemName());
        log.trace("Delete " + groupName);
        deleteGroup(groupName);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        changes = getChanges(userManager.getPrincipal("user"));
        // securityUpdated on doc with a null FileSystemItem
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "securityUpdated", "test", "test#" + doc.getId()), toSimpleFileSystemItemChange(change));
        assertNull(change.getFileSystemItem());
        assertNull(change.getFileSystemItemName());
        log.trace("Create " + groupName);
        createGroup(groupName, Arrays.asList("user"), null);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    if (needsParentGroup) {
        try {
            changes = getChanges(userManager.getPrincipal("user"));
            // No events since the newly created group has not been added yet as a subgroup of parentGroup
            assertTrue(changes.isEmpty());
            log.trace("Add " + groupName + " as a subgroup of parentGroup");
            updateGroup("parentGroup", null, Arrays.asList(groupName));
        } finally {
            commitAndWaitForAsyncCompletion();
        }
    }
    try {
        changes = getChanges(userManager.getPrincipal("user"));
        // securityUpdated on doc with a non-null FileSystemItem
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "securityUpdated", "test", factoryName + "#test#" + doc.getId()), toSimpleFileSystemItemChange(change));
        assertNotNull(change.getFileSystemItem());
        assertEquals(doc.getTitle(), change.getFileSystemItemName());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange)

Example 27 with FileSystemItemChange

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

the class AuditChangeFinderClusteringEnabledTestSuite method testClusteringEnabled.

@Test
public void testClusteringEnabled() throws Exception {
    List<FileSystemItemChange> changes;
    DocumentModel file1;
    DocumentModel file2;
    try {
        // No sync roots
        changes = getChanges();
        assertNotNull(changes);
        assertTrue(changes.isEmpty());
        log.trace("Register a sync root and create a document inside it");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
        file1 = session.createDocumentModel("/folder1", "file1", "File");
        file1.setPropertyValue("file:content", new StringBlob("The file content"));
        file1 = session.createDocument(file1);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // NXP-22284: Cannot expect to have no changes if the clustering delay is not expired since waiting for
        // async completion has an unknown duration
        // Wait for (2 * clustering delay + 1 second) then check changes, expecting at least 2:
        // - documentCreated for file1
        // - rootRegistered for folder1
        // The documentCreated event for folder1 might have already been "swallowed" by the first call to
        // #getChanges() if the test initialization takes too much time, sometimes happens with an Oracle database
        Thread.sleep(3000);
        changes = getChanges();
        assertTrue(changes.size() >= 2);
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(file1.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + file1.getId(), "file1"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId(), "folder1"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId(), "folder1"));
        assertTrue(CollectionUtils.isSubCollection(toSimpleFileSystemItemChanges(changes), expectedChanges));
        log.trace("Update existing document and create a new one");
        file1.setPropertyValue("dc:description", "Upated description");
        session.saveDocument(file1);
        file2 = session.createDocumentModel("/folder1", "file2", "File");
        file2.setPropertyValue("file:content", new StringBlob("The second file content"));
        file2 = session.createDocument(file2);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // NXP-22284: Cannot expect to have no changes if the clustering delay is not expired since waiting for
    // async completion has an unknown duration
    // Wait for (2 * clustering delay + 1 second) then check changes, expecting 2:
    // - documentCreated for file2
    // - documentModified for file1
    Thread.sleep(3000);
    changes = getChanges();
    assertEquals(2, changes.size());
    Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
    expectedChanges.add(new SimpleFileSystemItemChange(file2.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + file2.getId(), "file2"));
    expectedChanges.add(new SimpleFileSystemItemChange(file1.getId(), "documentModified", "test", "defaultFileSystemItemFactory#test#" + file1.getId(), "file1"));
    assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
}
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 28 with FileSystemItemChange

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

the class TestPermissionHierarchyFileSystemChanges method testAdaptableUnregisteredSyncRootChange.

/**
 * When an unregistered synchronization root can still be adapted as a FileSystemItem, for example in the case of
 * the "My Docs" virtual folder in the permission based hierarchy implementation, checks that the related
 * {@link FileSystemItemChange} computed by the {@link AuditChangeFinder} contains a null {@code fileSystemItem}
 * attribute, see https://jira.nuxeo.com/browse/NXP-16478.
 */
@Test
public void testAdaptableUnregisteredSyncRootChange() throws InterruptedException {
    commitAndWaitForAsyncCompletion();
    lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
    // user1
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session1).contains(new IdRef(userWorkspace1.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        List<FileSystemItemChange> changes = getChanges(principal1);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(userWorkspace1ItemId, change.getFileSystemItemId());
        assertEquals("My Docs", change.getFileSystemItemName());
        assertNotNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // user1
    try {
        nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
        assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session1).contains(new IdRef(userWorkspace1.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        List<FileSystemItemChange> changes = getChanges(principal1);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("test#" + userWorkspace1.getId(), change.getFileSystemItemId());
        assertNull(change.getFileSystemItemName());
        assertNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) IdRef(org.nuxeo.ecm.core.api.IdRef) Test(org.junit.Test)

Example 29 with FileSystemItemChange

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

the class TestPermissionHierarchyFileSystemChanges method testRootlessItems.

/**
 * Tests the rootless file system items, typically:
 * <ul>
 * <li>A folder registered as a synchronization root but that is not adaptable as a {@link FileSystemItem}. For
 * example if it is handled by the {@link PermissionSyncRootFactory} and
 * {@link PermissionSyncRootFactory#isFileSystemItem(DocumentModel, boolean)} returns {@code false} because of the
 * missing required permission.</li>
 * <li>A file created in such a folder.</li>
 * <li>A file created in a folder registered as a synchronization root on which the user doesn't have Read
 * access.</li>
 * </ul>
 * For the test, the required permission for a folder to be adapted by the {@link PermissionSyncRootFactory} is
 * Everything.
 *
 * <pre>
 * Server side hierarchy for the test
 * ==================================
 *
 * /user1 (user workspace)
 *   |-- user1Folder1       (registered as a synchronization root with Everything permission for user2)
 *   |-- user1Folder2       (registered as a synchronization root with ReadWrite permission only for user2)
 *   |     |-- user1File1
 *   |     |-- user1File2
 * </pre>
 */
@Test
@Deploy("org.nuxeo.drive.operations.test:OSGI-INF/test-nuxeodrive-hierarchy-permission-adapter-contrib.xml")
public void testRootlessItems() throws Exception {
    commitAndWaitForAsyncCompletion();
    DocumentModel user1Folder1;
    DocumentModel user1Folder2;
    DocumentModel user1File2;
    try {
        // Populate user1's personal workspace
        user1Folder1 = createFolder(session1, userWorkspace1.getPathAsString(), "user1Folder1", "Folder");
        user1Folder2 = createFolder(session1, userWorkspace1.getPathAsString(), "user1Folder2", "Folder");
        session1.save();
        setPermission(session1, user1Folder1, "user2", SecurityConstants.EVERYTHING, true);
        setPermission(session1, user1Folder2, "user2", SecurityConstants.READ_WRITE, true);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
    // so appears in the file system changes
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), user1Folder1, session2);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(user1Folder1.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals(SYNC_ROOT_ID_PREFIX + user1Folder1.getId(), change.getFileSystemItemId());
        assertEquals("user1Folder1", change.getFileSystemItemName());
        assertNotNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // adaptable so doesn't appear in the file system changes
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), user1Folder2, session2);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(user1Folder2.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertTrue(changes.isEmpty());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // the file system changes
    try {
        createFile(session1, user1Folder2.getPathAsString(), "user1File1", "File", "user1File1.txt", CONTENT_PREFIX + "user1File1");
        session1.save();
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertTrue(changes.isEmpty());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // the file system changes
    try {
        resetPermissions(session1, user1Folder2.getRef(), "user2");
        user1File2 = createFile(session1, user1Folder2.getPathAsString(), "user1File2", "File", "user1File2.txt", CONTENT_PREFIX + "user1File2");
        setPermission(session1, user1File2, "user2", SecurityConstants.READ, true);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Security updates
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(2, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("securityUpdated", change.getEventId());
        assertEquals("test#" + user1File2.getId(), change.getFileSystemItemId());
        assertNull(change.getFileSystemItemName());
        // Not adaptable as a FileSystemItem since parent is not
        assertNull(change.getFileSystemItem());
        change = changes.get(1);
        assertEquals("securityUpdated", change.getEventId());
        assertEquals("test#" + user1Folder2.getId(), change.getFileSystemItemId());
        assertNull(change.getFileSystemItemName());
        // Not adaptable as a FileSystemItem since no Read permission
        assertNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test) Deploy(org.nuxeo.runtime.test.runner.Deploy)

Example 30 with FileSystemItemChange

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

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