use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveManagerImpl method addToLocallyEditedCollection.
@Override
public void addToLocallyEditedCollection(CoreSession session, DocumentModel doc) {
// Add document to "Locally Edited" collection, creating if if not
// exists
CollectionManager cm = Framework.getService(CollectionManager.class);
DocumentModel userCollections = cm.getUserDefaultCollections(doc, session);
DocumentRef locallyEditedCollectionRef = new PathRef(userCollections.getPath().toString(), LOCALLY_EDITED_COLLECTION_NAME);
DocumentModel locallyEditedCollection = null;
if (session.exists(locallyEditedCollectionRef)) {
locallyEditedCollection = session.getDocument(locallyEditedCollectionRef);
cm.addToCollection(locallyEditedCollection, doc, session);
} else {
cm.addToNewCollection(LOCALLY_EDITED_COLLECTION_NAME, "Documents locally edited with Nuxeo Drive", doc, session);
locallyEditedCollection = session.getDocument(locallyEditedCollectionRef);
}
// Register "Locally Edited" collection as a synchronization root if not
// already the case
Set<IdRef> syncRootRefs = getSynchronizationRootReferences(session);
if (!syncRootRefs.contains(new IdRef(locallyEditedCollection.getId()))) {
registerSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveManagerImpl method computeCollectionSyncRootMemberIds.
@SuppressWarnings("unchecked")
protected Map<String, Set<String>> computeCollectionSyncRootMemberIds(Principal principal) {
Map<String, Set<String>> collectionSyncRootMemberIds = new HashMap<String, Set<String>>();
PageProviderService pageProviderService = Framework.getService(PageProviderService.class);
RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
for (String repositoryName : repositoryManager.getRepositoryNames()) {
Set<String> collectionMemberIds = new HashSet<String>();
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
Map<String, Serializable> props = new HashMap<String, Serializable>();
props.put(CORE_SESSION_PROPERTY, (Serializable) session);
PageProvider<DocumentModel> collectionPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(CollectionConstants.ALL_COLLECTIONS_PAGE_PROVIDER, null, null, 0L, props);
List<DocumentModel> collections = collectionPageProvider.getCurrentPage();
for (DocumentModel collection : collections) {
if (isSynchronizationRoot(principal, collection)) {
PageProvider<DocumentModel> collectionMemberPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER, null, COLLECTION_CONTENT_PAGE_SIZE, 0L, props, collection.getId());
List<DocumentModel> collectionMembers = collectionMemberPageProvider.getCurrentPage();
for (DocumentModel collectionMember : collectionMembers) {
collectionMemberIds.add(collectionMember.getId());
}
}
}
collectionSyncRootMemberIds.put(repositoryName, collectionMemberIds);
}
}
return collectionSyncRootMemberIds;
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFolderishCollection2.
/**
* <pre>
* /folder1 -> synchronization root && isMemberOf(collectionFolder)
* |-- collectionFolder
* /collectionSyncRoot -> synchronization root
* /testDoc -> isMemberOf(collectionFolder, collectionSyncRoot)
* </pre>
*/
@Test
public void testFolderishCollection2() throws Exception {
DocumentModel collectionFolder;
DocumentModel collectionSyncRoot;
DocumentModel testDoc;
List<FileSystemItemChange> changes;
try {
log.trace("testFolderishCollection2():" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside a folder (\"folder1\");" + "\nAdd \"folder1\" to the \"collectionFolder\" collection;" + "\nRegister \"folder1\" as a synchronization root;" + "\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);
collectionManager.addToCollection(collectionFolder, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), 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
// - rootRegistered for folder1
// - addedToCollection for folder1
// - documentModified 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(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFindSecurityChanges.
@Test
public void testFindSecurityChanges() throws Exception {
List<FileSystemItemChange> changes;
DocumentModel subFolder;
try {
// No sync roots
changes = getChanges();
assertTrue(changes.isEmpty());
// Create a folder in a sync root
subFolder = user1Session.createDocumentModel("/folder1", "subFolder", "Folder");
subFolder = user1Session.createDocument(subFolder);
// Sync roots for user1
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder1, user1Session);
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder2, user1Session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Get changes for user1
changes = getChanges(user1Session.getPrincipal());
// Folder creation and sync root registration events
assertEquals(3, changes.size());
// Permission changes: deny Read
// Deny Read to user1 on a regular doc
setPermissions(subFolder, new ACE(SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING), ACE.BLOCK);
// Deny Read to user1 on a sync root
setPermissions(folder2, new ACE(SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING), ACE.BLOCK);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changes = getChanges(user1Session.getPrincipal());
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder2.getId(), "securityUpdated", "test", "test#" + folder2.getId(), "folder2"));
expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "test#" + subFolder.getId(), "subFolder"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Changed documents are not adaptable as a FileSystemItem since no Read permission
for (FileSystemItemChange change : changes) {
assertNull(change.getFileSystemItem());
}
// Permission changes: grant Read
// Grant Read to user1 on a regular doc
setPermissions(subFolder, new ACE("user1", SecurityConstants.READ));
// Grant Read to user1 on a sync root
setPermissions(folder2, new ACE("user1", SecurityConstants.READ));
} finally {
commitAndWaitForAsyncCompletion();
}
changes = getChanges(user1Session.getPrincipal());
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder2.getId(), "securityUpdated", "test", "defaultSyncRootFolderItemFactory#test#" + folder2.getId(), "folder2"));
expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "defaultFileSystemItemFactory#test#" + subFolder.getId(), "subFolder"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Changed documents are adaptable as a FileSystemItem since Read permission
for (FileSystemItemChange change : changes) {
assertNotNull(change.getFileSystemItem());
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFolderishCollection1.
/**
* <pre>
* /folder1 -> isMemberOf(collectionFolder2)
* |-- collectionFolder1
* |-- collectionFolder2
* /collectionSyncRoot -> synchronization root
* /testDoc -> isMemberOf(collectionFolder1, collectionSyncRoot)
* </pre>
*/
@Test
public void testFolderishCollection1() throws Exception {
DocumentModel collectionSyncRoot;
DocumentModel testDoc;
List<FileSystemItemChange> changes;
try {
log.trace("testFolderishCollection1():" + "\nCreate a folder with the Collection facet (\"collectionFolder1\") inside a folder (\"folder1\");" + "\nCreate a folder with the Collection facet (\"collectionFolder2\") inside a folder (\"folder1\");" + "\nAdd \"folder1\" to the \"collectionFolder2\" collection;" + "\nCreate a collection \"collectionSyncRoot\" and register it as a synchronization root;" + "\nCreate a document \"testDoc\" and add it to both collections \"collectionFolder1\" and \"collectionSyncRoot\".\n");
DocumentModel collectionFolder1 = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
collectionFolder1 = session.createDocument(collectionFolder1);
DocumentModel collectionFolder2 = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
collectionFolder2 = session.createDocument(collectionFolder2);
collectionManager.addToCollection(collectionFolder2, 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(collectionFolder1, testDoc, session);
collectionManager.addToCollection(collectionSyncRoot, testDoc, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 6 (among which 5 distinct) changes:
// - addedToCollection for testDoc
// - documentModified for collectionSyncRoot
// - addedToCollection for testDoc
// - documentCreated for testDoc
// - rootRegistered for collectionSyncRoot
// - documentCreated for collectionSyncRoot
changes = getChanges(session.getPrincipal());
assertEquals(6, 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(testDoc.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
Aggregations