Search in sources :

Example 16 with StringBlob

use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.

the class TestESSyncRootFolderItem method buildTree.

protected void buildTree(String parentPath, int maxLevel, int level, int fileCount, int folderCount) {
    if (level > maxLevel) {
        return;
    }
    for (int i = 0; i < fileCount; i++) {
        String name = "file-" + level + "-" + i;
        DocumentModel file = session.createDocumentModel(parentPath, name, "File");
        file.setPropertyValue("dc:title", name);
        Blob blob = new StringBlob("Content of Joe's file.");
        blob.setFilename("Joe.odt");
        file.setPropertyValue("file:content", (Serializable) blob);
        session.createDocument(file);
    }
    for (int i = 0; i < folderCount; i++) {
        String name = "folder-" + level + "-" + i;
        DocumentModel folder = session.createDocumentModel(parentPath, name, "Folder");
        folder.setPropertyValue("dc:title", name);
        session.createDocument(folder);
        buildTree(parentPath + "/" + name, maxLevel, level + 1, fileCount, folderCount);
    }
}
Also used : 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) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 17 with StringBlob

use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.

the class TestOperationHelper method testNormalizeMimeTypeAndEncoding.

@Test
public void testNormalizeMimeTypeAndEncoding() throws Exception {
    Blob blob = new StringBlob("Joe's blob content.", null, null);
    NuxeoDriveOperationHelper.normalizeMimeTypeAndEncoding(blob);
    assertNull(blob.getMimeType());
    assertNull(blob.getEncoding());
    blob.setMimeType("application/text");
    NuxeoDriveOperationHelper.normalizeMimeTypeAndEncoding(blob);
    assertEquals("application/text", blob.getMimeType());
    assertNull(blob.getEncoding());
    blob.setMimeType("application/text; charset=utf-8");
    NuxeoDriveOperationHelper.normalizeMimeTypeAndEncoding(blob);
    assertEquals("application/text", blob.getMimeType());
    assertEquals("utf-8", blob.getEncoding());
    blob.setMimeType("application/text; charset=iso8859_1");
    NuxeoDriveOperationHelper.normalizeMimeTypeAndEncoding(blob);
    assertEquals("application/text", blob.getMimeType());
    assertEquals("utf-8", blob.getEncoding());
}
Also used : 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) Test(org.junit.Test)

Example 18 with StringBlob

use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testFolderishCollection3.

/**
 * <pre>
 * /folder1                 -> isMemberOf(collectionFolder)
 *   |-- collectionFolder   -> synchronization root
 * /collectionSyncRoot      -> synchronization root
 * /testDoc                 -> isMemberOf(collectionFolder, collectionSyncRoot)
 * </pre>
 */
@Test
public void testFolderishCollection3() throws Exception {
    DocumentModel collectionFolder;
    DocumentModel collectionSyncRoot;
    DocumentModel testDoc;
    List<FileSystemItemChange> changes;
    try {
        log.trace("testFolderishCollection3():" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside a folder (\"folder1\") and register it as a sycnhronization root;" + "\nAdd \"folder1\" to the \"collectionFolder\" collection;" + "\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);
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionFolder, session);
        collectionManager.addToCollection(collectionFolder, 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
        // - addedToCollection for folder1
        // - documentModified for collectionFolder
        // - rootRegistered 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(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with StringBlob

use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testFolderishCollection4.

/**
 * <pre>
 * /collectionSyncRoot1     -> synchronization root
 * /folder1                 -> isMemberOf(collectionSyncRoot1)
 *   |-- collectionFolder
 * /collectionSyncRoot2     -> synchronization root
 * /testDoc                 -> isMemberOf(collectionFolder, collectionSyncRoot2)
 * </pre>
 */
@Test
public void testFolderishCollection4() throws Exception {
    DocumentModel collectionSyncRoot1;
    DocumentModel collectionSyncRoot2;
    DocumentModel testDoc;
    List<FileSystemItemChange> changes;
    try {
        log.trace("testFolderishCollection4():" + "\nCreate a collection \"collectionSyncRoot1\" and register it as a synchronization root;" + "\nAdd \"folder1\" to the \"collectionSyncRoot1\" collection;" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside (\"folder1\");" + "\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");
        collectionSyncRoot1 = collectionManager.createCollection(session, "collectionSyncRoot1", null, "/");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot1, session);
        collectionManager.addToCollection(collectionSyncRoot1, folder1, session);
        DocumentModel collectionFolder = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
        collectionFolder = session.createDocument(collectionFolder);
        collectionSyncRoot2 = collectionManager.createCollection(session, "collectionSyncRoot2", null, "/");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot2, 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(collectionSyncRoot2, testDoc, session);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Expecting 11 (among which 10 distinct) changes:
        // - addedToCollection for testDoc
        // - documentModified for collectionSyncRoot2
        // - addedToCollection for testDoc
        // - documentCreated for testDoc
        // - rootRegistered for collectionSyncRoot2
        // - documentCreated for collectionSyncRoot2
        // - addedToCollection for folder1
        // - documentModified for collectionSyncRoot1
        // - rootRegistered for collectionSyncRoot1
        // - documentCreated for collectionSyncRoot1
        // - documentCreated for folder1
        changes = getChanges(session.getPrincipal());
        assertEquals(11, changes.size());
        Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
        expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "documentModified"));
        expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "addedToCollection"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "documentModified"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "rootRegistered"));
        expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "documentCreated"));
        expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
        assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with StringBlob

use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.

the class AuditChangeFinderTestSuite method testLockUnlock.

@Test
public void testLockUnlock() throws Exception {
    DocumentModel doc;
    List<FileSystemItemChange> changes;
    try {
        log.trace("Register a sync root and create a document inside it");
        nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
        doc = session.createDocumentModel("/folder1", "doc", "File");
        doc.setPropertyValue("file:content", new StringBlob("The file content"));
        doc = session.createDocument(doc);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 3:
        // - documentCreated for doc
        // - rootRegistered for folder1
        // - documentCreated for folder1
        changes = getChanges(session.getPrincipal());
        assertEquals(3, changes.size());
        log.trace("Lock doc");
        session.setLock(doc.getRef());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 1:
        // - documentLocked for doc
        changes = getChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "documentLocked", "test", "defaultFileSystemItemFactory#test#" + doc.getId(), "doc"), toSimpleFileSystemItemChange(changes.get(0)));
        log.trace("Unlock doc");
        session.removeLock(doc.getRef());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        // Check changes, expecting 1:
        // - documentUnlocked for doc
        changes = getChanges();
        assertEquals(1, changes.size());
        assertEquals(new SimpleFileSystemItemChange(doc.getId(), "documentUnlocked", "test", "defaultFileSystemItemFactory#test#" + doc.getId(), "doc"), toSimpleFileSystemItemChange(changes.get(0)));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)32 Test (org.junit.Test)24 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)24 Blob (org.nuxeo.ecm.core.api.Blob)17 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)13 HashSet (java.util.HashSet)12 FileItem (org.nuxeo.drive.adapter.FileItem)7 Principal (java.security.Principal)5 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)5 FolderItem (org.nuxeo.drive.adapter.FolderItem)5 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)5 Before (org.junit.Before)4 FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)4 RootlessItemException (org.nuxeo.drive.adapter.RootlessItemException)2 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)2 SimpleFileSystemItemChange (org.nuxeo.drive.fixtures.SimpleFileSystemItemChange)2 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)2 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)2 PathRef (org.nuxeo.ecm.core.api.PathRef)2 Deploy (org.nuxeo.runtime.test.runner.Deploy)2