Search in sources :

Example 31 with CloseableCoreSession

use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.

the class TestDriveVersioning method testAutomaticVersioning.

@Test
@Deploy({ "org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml" })
public void testAutomaticVersioning() throws Exception {
    FileItem fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
    // As a user with READ permission
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    // Under Oracle, the READ ACL optims are not visible from the
    // joe session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertFalse(fileItem.getCanUpdate());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertTrue(fileItem.getCanUpdate());
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        // ------------------------------------------------------
        // FileItem#getBlob
        // ------------------------------------------------------
        Blob fileItemBlob = fileItem.getBlob();
        assertEquals("Joe.odt", fileItemBlob.getFilename());
        assertEquals("Content of Joe's file.", fileItemBlob.getString());
        // Check initial version
        // A version with a minor increment is automatically created during creation for all File documents
        // by the "version-file" policy (automatic versioning),
        // see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
        assertEquals("0.1", file.getVersionLabel());
        // ------------------------------------------------------
        // 1. Change without delay
        // ------------------------------------------------------
        Blob newBlob = new StringBlob("This is a new file.");
        newBlob.setFilename("New blob.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        Blob updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("New blob.txt", updatedBlob.getFilename());
        assertEquals("This is a new file.", updatedBlob.getString());
        // Check versioning => should not be versioned since same contributor,
        // last modification was done before the versioning delay
        // and the "drive-force-versioning" policy prevents automatic versioning
        // from performing a minor increment,
        // see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
        // Should be checked out since not previously checked out
        assertEquals("0.1+", file.getVersionLabel());
        // ------------------------------------------------------
        // 2. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "versioning-delay" policy
        // since last modification was done after the versioning delay
        // and a minor increment by the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("1.1", file.getVersionLabel());
        List<DocumentModel> fileVersions = session.getVersions(file.getRef());
        assertEquals(3, fileVersions.size());
        DocumentModel firstMinorFileVersion = fileVersions.get(0);
        Blob versionedBlob = (Blob) firstMinorFileVersion.getPropertyValue("file:content");
        assertEquals("Joe.odt", versionedBlob.getFilename());
        DocumentModel lastMajorFileVersion = fileVersions.get(1);
        versionedBlob = (Blob) lastMajorFileVersion.getPropertyValue("file:content");
        assertEquals("New blob.txt", versionedBlob.getFilename());
        DocumentModel lastFileVersion = fileVersions.get(2);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 3. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified again.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("1.2", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(4, fileVersions.size());
        lastFileVersion = fileVersions.get(3);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 4. Change without delay
        // ------------------------------------------------------
        newBlob.setFilename("File name modified again as new draft.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again as new draft.txt", updatedBlob.getFilename());
        // Check versioning => should not be versioned since same contributor,
        // last modification was done before the versioning delay
        // and the "drive-force-versioning" policy prevents automatic versioning
        // from performing a minor increment,
        // see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
        // Should be checked out since not previously checked out
        assertEquals("1.2+", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(4, fileVersions.size());
        lastFileVersion = fileVersions.get(3);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 5. Change without delay with another user
        // ------------------------------------------------------
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "collaborative-save" policy
        // since updated by a different contributor
        // and a minor increment by the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("2.1", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(6, fileVersions.size());
        lastMajorFileVersion = fileVersions.get(4);
        versionedBlob = (Blob) lastMajorFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again as new draft.txt", versionedBlob.getFilename());
        lastFileVersion = fileVersions.get(5);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 6. Change with delay with the same user
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe again.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("2.2", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(7, fileVersions.size());
        lastFileVersion = fileVersions.get(6);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", versionedBlob.getFilename());
    }
    resetPermissions(rootDoc, "joe");
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test) Deploy(org.nuxeo.runtime.test.runner.Deploy)

Example 32 with CloseableCoreSession

use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.

the class TestDriveVersioning method testDefaultConfiguration.

@Test
public void testDefaultConfiguration() throws Exception {
    FileItem fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
    // As a user with READ permission
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    // Under Oracle, the READ ACL optims are not visible from the
    // joe session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertFalse(fileItem.getCanUpdate());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertTrue(fileItem.getCanUpdate());
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        // ------------------------------------------------------
        // FileItem#getBlob
        // ------------------------------------------------------
        Blob fileItemBlob = fileItem.getBlob();
        assertEquals("Joe.odt", fileItemBlob.getFilename());
        assertEquals("Content of Joe's file.", fileItemBlob.getString());
        // Check initial version
        assertEquals("0.0", file.getVersionLabel());
        // ------------------------------------------------------
        // 1. Change without delay
        // ------------------------------------------------------
        Blob newBlob = new StringBlob("This is a new file.");
        newBlob.setFilename("New blob.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        Blob updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("New blob.txt", updatedBlob.getFilename());
        assertEquals("This is a new file.", updatedBlob.getString());
        // Check versioning => should not be versioned since same contributor
        // and last modification was done before the versioning delay
        // Should not be checked out since previously checked out
        assertEquals("0.0", file.getVersionLabel());
        // ------------------------------------------------------
        // 2. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "versioning-delay" policy
        // since last modification was done after the versioning delay
        // Should be checked out since the "versioning-delay" policy is applied before update
        assertEquals("1.0+", file.getVersionLabel());
        List<DocumentModel> fileVersions = session.getVersions(file.getRef());
        assertEquals(1, fileVersions.size());
        DocumentModel lastFileVersion = fileVersions.get(0);
        Blob versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("New blob.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 3. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified again.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "versioning-delay" policy
        // since last modification was done after the versioning delay
        // Should be checked out since the "versioning-delay" policy is applied before update
        assertEquals("2.0+", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(2, fileVersions.size());
        lastFileVersion = fileVersions.get(1);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 4. Change without delay
        // ------------------------------------------------------
        newBlob.setFilename("File name modified again as draft.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again as draft.txt", updatedBlob.getFilename());
        // Check versioning => should not be versioned since same contributor
        // and last modification was done before the versioning delay
        // Should not be checked out since previously checked out
        assertEquals("2.0+", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(2, fileVersions.size());
        lastFileVersion = fileVersions.get(1);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 5. Change without delay with another user
        // ------------------------------------------------------
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "collaborative-save" policy
        // since updated by a different contributor
        // Should be checked out since the "collaborative-save" policy is applied before update
        assertEquals("3.0+", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(3, fileVersions.size());
        lastFileVersion = fileVersions.get(2);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again as draft.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 6. Change with delay with the same user
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe again.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", updatedBlob.getFilename());
        // Check versioning => should be versioned with a major increment by the "versioning-delay" policy
        // since last modification was done after the versioning delay
        // Should be checked out since the "versioning-delay" policy is applied before update
        assertEquals("4.0+", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(4, fileVersions.size());
        lastFileVersion = fileVersions.get(3);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", versionedBlob.getFilename());
    }
    resetPermissions(rootDoc, "joe");
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 33 with CloseableCoreSession

use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.

the class TestDriveVersioning method testAutomaticVersioningAndDriveForceVersionDisabled.

@Test
@Deploy({ "org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-versioning-file-policy-contrib.xml" })
public void testAutomaticVersioningAndDriveForceVersionDisabled() throws Exception {
    FileItem fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
    // As a user with READ permission
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    // Under Oracle, the READ ACL optims are not visible from the
    // joe session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertFalse(fileItem.getCanUpdate());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        assertTrue(fileItem.getCanUpdate());
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        // ------------------------------------------------------
        // FileItem#getBlob
        // ------------------------------------------------------
        Blob fileItemBlob = fileItem.getBlob();
        assertEquals("Joe.odt", fileItemBlob.getFilename());
        assertEquals("Content of Joe's file.", fileItemBlob.getString());
        // Check initial version
        // A version with a minor increment is automatically created during creation for all File documents
        // by the "version-file" policy (automatic versioning),
        // see test-nuxeodrive-versioning-file-policy-contrib.xml
        assertEquals("0.1", file.getVersionLabel());
        // ------------------------------------------------------
        // 1. Change without delay
        // ------------------------------------------------------
        Blob newBlob = new StringBlob("This is a new file.");
        newBlob.setFilename("New blob.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        Blob updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("New blob.txt", updatedBlob.getFilename());
        assertEquals("This is a new file.", updatedBlob.getString());
        // Check versioning => should be versioned with a minor increment by the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("0.2", file.getVersionLabel());
        // ------------------------------------------------------
        // 2. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("0.3", file.getVersionLabel());
        List<DocumentModel> fileVersions = session.getVersions(file.getRef());
        assertEquals(3, fileVersions.size());
        DocumentModel firstMinorFileVersion = fileVersions.get(0);
        Blob versionedBlob = (Blob) firstMinorFileVersion.getPropertyValue("file:content");
        assertEquals("Joe.odt", versionedBlob.getFilename());
        DocumentModel secondMinorFileVersion = fileVersions.get(1);
        versionedBlob = (Blob) secondMinorFileVersion.getPropertyValue("file:content");
        assertEquals("New blob.txt", versionedBlob.getFilename());
        DocumentModel lastFileVersion = fileVersions.get(2);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 3. Change with delay
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        newBlob.setFilename("File name modified again.txt");
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("0.4", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(4, fileVersions.size());
        lastFileVersion = fileVersions.get(3);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 4. Change without delay
        // ------------------------------------------------------
        newBlob.setFilename("File name modified again as draft.txt");
        ensureJustModified(file, session);
        fileItem.setBlob(newBlob);
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified again as draft.txt", updatedBlob.getFilename());
        // Check versioning => should not be versioned since last modification was done before the versioning delay
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("0.5", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(5, fileVersions.size());
        lastFileVersion = fileVersions.get(4);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified again as draft.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 5. Change without delay with another user
        // ------------------------------------------------------
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "collaborative-save" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("0.6", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(6, fileVersions.size());
        lastFileVersion = fileVersions.get(5);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe.txt", versionedBlob.getFilename());
        // ------------------------------------------------------
        // 6. Change with delay with the same user
        // ------------------------------------------------------
        // Wait for versioning delay
        Thread.sleep(VERSIONING_DELAY);
        file = joeSession.getDocument(file.getRef());
        fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
        newBlob.setFilename("File name modified by Joe again.txt");
        fileItem.setBlob(newBlob);
        // Re-fetch file with Administrator session
        file = session.getDocument(file.getRef());
        updatedBlob = (Blob) file.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", updatedBlob.getFilename());
        // Check versioning => no major increment by the "versioning-delay" policy
        // because the document is already checked in,
        // but versioned with a minor increment because of the "version-file" policy
        // Should not be checked out since the "version-file" policy is not applied before update
        assertEquals("0.7", file.getVersionLabel());
        fileVersions = session.getVersions(file.getRef());
        assertEquals(7, fileVersions.size());
        lastFileVersion = fileVersions.get(6);
        versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
        assertEquals("File name modified by Joe again.txt", versionedBlob.getFilename());
    }
    resetPermissions(rootDoc, "joe");
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test) Deploy(org.nuxeo.runtime.test.runner.Deploy)

Example 34 with CloseableCoreSession

use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.

the class DummyFolderItemFactory method getFileSystemItemById.

@Override
public FileSystemItem getFileSystemItemById(String id, Principal principal) {
    String[] idFragments = parseFileSystemId(id);
    String repositoryName = idFragments[1];
    String docId = idFragments[2];
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        DocumentModel doc = getDocumentById(docId, session);
        return new DummyFolderItem(name, doc);
    }
}
Also used : CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 35 with CloseableCoreSession

use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.

the class MockChangeFinder method getFileSystemChanges.

@Override
public List<FileSystemItemChange> getFileSystemChanges(CoreSession session, Set<IdRef> lastActiveRootRefs, SynchronizationRoots activeRoots, long lastSuccessfulSyncDate, long syncDate, int limit) throws TooManyChangesException {
    List<FileSystemItemChange> docChanges = new ArrayList<FileSystemItemChange>();
    if (!activeRoots.paths.isEmpty()) {
        StringBuilder querySb = new StringBuilder();
        querySb.append("SELECT * FROM Document WHERE (%s) AND (%s) ORDER BY dc:modified DESC");
        String query = String.format(querySb.toString(), getRootPathClause(activeRoots.paths), getDateClause(lastSuccessfulSyncDate, syncDate));
        if (log.isDebugEnabled()) {
            log.debug("Querying repository for document changes: " + query);
        }
        NuxeoPrincipal principal = (NuxeoPrincipal) session.getPrincipal();
        RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
        for (String repositoryName : repositoryManager.getRepositoryNames()) {
            try (CloseableCoreSession repoSession = CoreInstance.openCoreSession(repositoryName, principal)) {
                docChanges.addAll(getDocumentChanges(repoSession, query, limit));
            }
        }
    }
    return docChanges;
}
Also used : ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) NuxeoPrincipal(org.nuxeo.ecm.core.api.NuxeoPrincipal)

Aggregations

CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)35 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)25 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)9 FolderItem (org.nuxeo.drive.adapter.FolderItem)9 Blob (org.nuxeo.ecm.core.api.Blob)7 IdRef (org.nuxeo.ecm.core.api.IdRef)7 HashMap (java.util.HashMap)6 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)6 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)6 FileItem (org.nuxeo.drive.adapter.FileItem)5 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)5 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)5 RepositoryManager (org.nuxeo.ecm.core.api.repository.RepositoryManager)5 Serializable (java.io.Serializable)4 Deploy (org.nuxeo.runtime.test.runner.Deploy)4 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)3 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)3 PageProvider (org.nuxeo.ecm.platform.query.api.PageProvider)3