Search in sources :

Example 31 with DocumentModel

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);
    }
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) EventContext(org.nuxeo.ecm.core.event.EventContext) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) ConfigurationService(org.nuxeo.runtime.services.config.ConfigurationService) CoreSession(org.nuxeo.ecm.core.api.CoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 32 with DocumentModel

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));
}
Also used : DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CollectionManager(org.nuxeo.ecm.collections.api.CollectionManager) PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 33 with DocumentModel

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));
}
Also used : DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 34 with DocumentModel

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));
}
Also used : Serializable(java.io.Serializable) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 35 with DocumentModel

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));
}
Also used : CollectionManager(org.nuxeo.ecm.collections.api.CollectionManager) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7