use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveSyncRootCopyListener method handleEvent.
@Override
public void handleEvent(Event event) {
if (Framework.getService(ConfigurationService.class).isBooleanPropertyFalse(RESET_SYNC_ROOTS_ON_COPY_CONFIGURATION_PROPERTY)) {
return;
}
EventContext context = event.getContext();
if (!(context instanceof DocumentEventContext)) {
return;
}
DocumentModel doc = ((DocumentEventContext) context).getSourceDocument();
CoreSession session = context.getCoreSession();
DocumentModelList syncRoots = getSyncRoots(doc, session);
for (DocumentModel syncRoot : syncRoots) {
syncRoot.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
syncRoot.putContextData("source", "drive");
syncRoot.putContextData(CoreSession.SOURCE, "drive");
session.saveDocument(syncRoot);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testAddToLocallyEditedCollection.
@Test
public void testAddToLocallyEditedCollection() {
// Create a test document and add it to the "Locally Edited" collection
DocumentModel doc1 = session.createDocument(session.createDocumentModel(workspace_1.getPathAsString(), "driveEditFile1", "File"));
nuxeoDriveManager.addToLocallyEditedCollection(session, doc1);
// Check that the "Locally Edited" collection has been created, the test
// document is member of it and the collection is registered as a
// synchronization root
CollectionManager cm = Framework.getService(CollectionManager.class);
DocumentModel userCollections = cm.getUserDefaultCollections(doc1, session);
DocumentRef locallyEditedCollectionRef = new PathRef(userCollections.getPath().toString(), NuxeoDriveManager.LOCALLY_EDITED_COLLECTION_NAME);
assertTrue(session.exists(locallyEditedCollectionRef));
DocumentModel locallyEditedCollection = session.getDocument(locallyEditedCollectionRef);
assertTrue(cm.isCollection(locallyEditedCollection));
// Re-fetch document from session to refresh it
doc1 = session.getDocument(doc1.getRef());
assertTrue(cm.isInCollection(locallyEditedCollection, doc1, session));
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
// Add another document to the "Locally Edited" collection, check
// collection membership
DocumentModel doc2 = session.createDocument(session.createDocumentModel(workspace_1.getPathAsString(), "driveEditFile2", "File"));
nuxeoDriveManager.addToLocallyEditedCollection(session, doc2);
doc2 = session.getDocument(doc2.getRef());
assertTrue(cm.isInCollection(locallyEditedCollection, doc2, session));
// Unregister the "Locally Edited" collection and add another document
// to it, check collection membership and the collection is registered
// as a synchronization root once again
nuxeoDriveManager.unregisterSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
DocumentModel doc3 = session.createDocument(session.createDocumentModel(workspace_1.getPathAsString(), "driveEditFile3", "File"));
nuxeoDriveManager.addToLocallyEditedCollection(session, doc3);
doc3 = session.getDocument(doc3.getRef());
assertTrue(cm.isInCollection(locallyEditedCollection, doc3, session));
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testSectionRegistration.
@Test
public void testSectionRegistration() {
log.trace("Create a Section and register it as a synchronization root for user1");
DocumentModel section = session.createDocument(session.createDocumentModel("/", "section", "Section"));
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), section, user1Session);
assertTrue(isUserSubscribed("user1", section));
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testFilterVersionSyncRoots.
@Test
public void testFilterVersionSyncRoots() {
// Create a version document
DocumentRef versionRef = session.checkIn(workspace_1.getRef(), VersioningOption.MAJOR, null);
DocumentModel version = session.getDocument(versionRef);
// Force its registration as a synchronization root
version.addFacet(NuxeoDriveManagerImpl.NUXEO_DRIVE_FACET);
Map<String, Serializable> subscription = new HashMap<>();
subscription.put("username", session.getPrincipal().getName());
subscription.put("enabled", Boolean.TRUE);
List<Map<String, Serializable>> subscriptions = Collections.singletonList(subscription);
version.setPropertyValue("drv:subscriptions", (Serializable) subscriptions);
version.putContextData(CoreSession.ALLOW_VERSION_WRITE, Boolean.TRUE);
session.saveDocument(version);
txFeature.nextTransaction();
// Check the version is filtered among the synchronization roots
assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), version));
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testChildRootRegistration.
@Test
public void testChildRootRegistration() {
log.trace("Register a folder as a sync root");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder_1_1, session);
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), folder_1_1));
log.trace("Create 'Locally Edited' collection and register it as a sync root");
CollectionManager cm = Framework.getService(CollectionManager.class);
DocumentModel locallyEditedCollection = cm.createCollection(session, NuxeoDriveManager.LOCALLY_EDITED_COLLECTION_NAME, "Locally Edited collection", workspace_1.getPathAsString());
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
log.trace("Register a parent as a sync root, should unregister children sync roots, except for 'Locally Edited'");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), workspace_1, session);
assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), folder_1_1));
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
log.trace("Register child folder as a sync root, should have no effect");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder_1_1, session);
assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), folder_1_1));
log.trace("Unregister 'Locally Edited' collection");
nuxeoDriveManager.unregisterSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
log.trace("Register 'Locally Edited' collection as a sync root, should be registered");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
}
Aggregations