use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testCollectionEvents.
@Test
public void testCollectionEvents() throws Exception {
DocumentModel doc1;
DocumentModel doc2;
DocumentModel doc3;
List<FileSystemItemChange> changes;
DocumentModel locallyEditedCollection;
try {
log.trace("Create 2 test docs and them to the 'Locally Edited' collection");
doc1 = session.createDocumentModel(folder1.getPathAsString(), "doc1", "File");
doc1.setPropertyValue("file:content", new StringBlob("File content."));
doc1 = session.createDocument(doc1);
doc2 = session.createDocumentModel(folder1.getPathAsString(), "doc2", "File");
doc2.setPropertyValue("file:content", new StringBlob("File content."));
doc2 = session.createDocument(doc2);
nuxeoDriveManager.addToLocallyEditedCollection(session, doc1);
nuxeoDriveManager.addToLocallyEditedCollection(session, doc2);
DocumentModel userCollections = collectionManager.getUserDefaultCollections(folder1, session);
DocumentRef locallyEditedCollectionRef = new PathRef(userCollections.getPath().toString(), NuxeoDriveManager.LOCALLY_EDITED_COLLECTION_NAME);
locallyEditedCollection = session.getDocument(locallyEditedCollectionRef);
// Re-fetch documents to get rid of the disabled events in context
// data
doc1 = session.getDocument(doc1.getRef());
doc2 = session.getDocument(doc2.getRef());
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 8 (among which 7 distinct) changes:
// - addedToCollection for doc2
// - documentModified for 'Locally Edited' collection (2 occurrences)
// - rootRegistered for 'Locally Edited' collection
// - addedToCollection for doc1
// - documentCreated for 'Locally Edited' collection
// - documentCreated for doc2
// - documentCreated for doc1
changes = getChanges(session.getPrincipal());
assertEquals(8, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
log.trace("Update doc1 member of the 'Locally Edited' collection");
doc1.setPropertyValue("file:content", new StringBlob("Updated file content."));
session.saveDocument(doc1);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 1 change: documentModified for doc1
changes = getChanges(session.getPrincipal());
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(doc1.getId(), "documentModified"), toSimpleFileSystemItemChange(changes.get(0)));
log.trace("Remove doc1 from the 'Locally Edited' collection, delete doc2 and add doc 3 to the collection");
collectionManager.removeFromCollection(locallyEditedCollection, doc1, session);
doc2.followTransition(LifeCycleConstants.DELETE_TRANSITION);
doc3 = session.createDocumentModel(folder1.getPathAsString(), "doc3", "File");
doc3.setPropertyValue("file:content", new StringBlob("File content."));
doc3 = session.createDocument(doc3);
collectionManager.addToCollection(locallyEditedCollection, doc3, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 6 (among which 5 distinct) changes:
// - addedToCollection for doc3
// - documentModified for 'Locally Edited' collection (2 occurrences)
// - documentCreated for doc3
// - deleted for doc2
// - deleted for doc1
changes = getChanges(session.getPrincipal());
assertEquals(6, changes.size());
List<SimpleFileSystemItemChange> expectedChanges = new ArrayList<>();
expectedChanges.add(new SimpleFileSystemItemChange(doc3.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(doc3.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "deleted"));
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "deleted"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
log.trace("Unregister the 'Locally Edited' collection as a sync root");
nuxeoDriveManager.unregisterSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 1 change: deleted for 'Locally Edited' collection
changes = getChanges(session.getPrincipal());
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "deleted"), toSimpleFileSystemItemChange(changes.get(0)));
log.trace("Register the 'Locally Edited' collection back as a sync root");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 1 change: rootRegistered for 'Locally Edited'
// collection
changes = getChanges(session.getPrincipal());
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "rootRegistered"), toSimpleFileSystemItemChange(changes.get(0)));
log.trace("Delete the 'Locally Edited' collection");
locallyEditedCollection.followTransition(LifeCycleConstants.DELETE_TRANSITION);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 1 change: deleted for 'Locally Edited' collection
changes = getChanges(session.getPrincipal());
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(locallyEditedCollection.getId(), "deleted"), toSimpleFileSystemItemChange(changes.get(0)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange 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());
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testSyncRootParentPermissionChange.
@Test
public void testSyncRootParentPermissionChange() throws Exception {
List<FileSystemItemChange> changes;
DocumentModel subFolder;
try {
// No sync roots
changes = getChanges();
assertTrue(changes.isEmpty());
// Create a subfolder in a sync root
subFolder = session.createDocumentModel("/folder1", "subFolder", "Folder");
subFolder = session.createDocument(subFolder);
// Grant READ_WRITE permission to user1 on the subfolder
setPermissions(subFolder, 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 subfolder
resetPermissions(subFolder, "user1");
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changes = getChanges(user1Session.getPrincipal());
// Expecting 1 change: securityUpdated for subFolder with a non-null FileSystemItem and FileSystemItem name
// since the user can still access it by inheritance
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals(new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "defaultSyncRootFolderItemFactory#test#" + subFolder.getId(), "subFolder"), toSimpleFileSystemItemChange(change));
assertNotNull(change);
assertEquals("subFolder", change.getFileSystemItemName());
// Remove READ_WRITE permission granted to user1 on the parent folder
resetPermissions(folder1, "user1");
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changes = getChanges(user1Session.getPrincipal());
// Expecting 1 change: securityUpdated for subFolder with a null FileSystemItem and FileSystemItem name
// since the user cannot access it anymore
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals(new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "test#" + subFolder.getId(), "subFolder"), toSimpleFileSystemItemChange(change));
assertNull(change.getFileSystemItem());
assertNull(change.getFileSystemItemName());
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class GroupChangesTestSuite method testGroupChangesOnSyncRootChild.
/**
* Tests changes on a group that has access to a child of a synchronization root.
*/
@Test
public void testGroupChangesOnSyncRootChild() throws Exception {
DocumentModel child;
try {
DocumentModel syncRoot = session.createDocument(session.createDocumentModel("/", "syncRoot", "Folder"));
child = session.createDocument(session.createDocumentModel("/syncRoot", "child", "Folder"));
log.trace("Grant ReadWrite to group1 on syncRoot");
setPermissions(syncRoot, new ACE("group1", SecurityConstants.READ_WRITE));
log.trace("Block inheritance on child");
setPermissions(child, ACE.BLOCK);
log.trace("Grant ReadWrite to group2 on child");
setPermissions(child, new ACE("group2", SecurityConstants.READ_WRITE));
nuxeoDriveManager.registerSynchronizationRoot(userSession.getPrincipal(), syncRoot, userSession);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
List<FileSystemItemChange> changes = getChanges(userSession.getPrincipal());
// Folder creation and sync root registration events
assertEquals(3, changes.size());
} finally {
commitAndWaitForAsyncCompletion();
}
testGroupChanges(child, "defaultFileSystemItemFactory", "group2", false);
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class GroupChangesTestSuite method testGroupChangesOnSyncRoot.
/**
* Tests changes on a group that has access to a synchronization root.
*/
@Test
public void testGroupChangesOnSyncRoot() throws Exception {
DocumentModel syncRoot;
try {
syncRoot = session.createDocument(session.createDocumentModel("/", "syncRoot", "Folder"));
log.trace("Grant ReadWrite to group1 on syncRoot");
setPermissions(syncRoot, new ACE("group1", SecurityConstants.READ_WRITE));
nuxeoDriveManager.registerSynchronizationRoot(userSession.getPrincipal(), syncRoot, userSession);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
List<FileSystemItemChange> changes = getChanges(userSession.getPrincipal());
// Sync root creation and registration events
assertEquals(2, changes.size());
} finally {
commitAndWaitForAsyncCompletion();
}
testGroupChanges(syncRoot, "defaultSyncRootFolderItemFactory", "group1", false);
}
Aggregations