Search in sources :

Example 51 with DocumentModel

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

the class TestPermissionHierarchyFileSystemChanges method testRegisteredSyncRootChildChange.

@Test
public void testRegisteredSyncRootChildChange() throws InterruptedException {
    commitAndWaitForAsyncCompletion();
    DocumentModel folderA;
    DocumentModel folderC;
    // Create the tree structure
    try {
        createFolderTree(session1, userWorkspace1.getPathAsString(), 5);
        folderA = session1.getChild(userWorkspace1.getRef(), "Folder A");
        DocumentModel folderB = session1.getChild(folderA.getRef(), "Folder B");
        folderC = session1.getChild(folderB.getRef(), "Folder C");
        setPermission(session1, folderA, "user2", SecurityConstants.EVERYTHING, true);
        setPermission(session1, folderC, "user2", SecurityConstants.READ, true);
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
    // Register FolderA as a synchronization root for user2
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), folderA, session2);
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderA.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("rootRegistered", change.getEventId());
        assertEquals("Folder A", change.getFileSystemItemName());
        assertNotNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    try {
        resetPermissions(session1, folderA.getRef(), "user2");
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("securityUpdated", change.getEventId());
        assertNull(change.getFileSystemItemName());
        assertNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Register Folder C as a synchronization root for user2
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), folderC, session2);
        assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderA.getId())));
        assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderC.getId())));
    } finally {
        commitAndWaitForAsyncCompletion();
    }
    // Check file system item change
    try {
        assertEquals(1, session2.getChildren(folderC.getRef()).size());
        List<FileSystemItemChange> changes = getChanges(principal2);
        assertEquals(1, changes.size());
        FileSystemItemChange change = changes.get(0);
        assertEquals("rootRegistered", change.getEventId());
        assertEquals("Folder C", change.getFileSystemItemName());
        assertNotNull(change.getFileSystemItem());
    } finally {
        commitAndWaitForAsyncCompletion();
    }
}
Also used : FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 52 with DocumentModel

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

the class NuxeoDriveIntegrationTestsHelper method cleanUp.

public static void cleanUp(CoreSession session) {
    // Delete test users and their personal workspace if exist
    UserManager userManager = Framework.getService(UserManager.class);
    DocumentModelList testUsers = userManager.searchUsers(TEST_USER_NAME_PREFIX);
    for (DocumentModel testUser : testUsers) {
        String testUserName = (String) testUser.getPropertyValue(userManager.getUserSchemaName() + ":" + userManager.getUserIdField());
        if (userManager.getPrincipal(testUserName) != null) {
            userManager.deleteUser(testUserName);
        }
        String testUserWorkspaceName = IdUtils.generateId(testUserName, "-", false, 30);
        String testUserWorkspacePath = getDefaultDomainPath(session) + "/" + USER_WORKSPACE_PARENT_NAME + "/" + testUserWorkspaceName;
        DocumentRef testUserWorkspaceRef = new PathRef(testUserWorkspacePath);
        if (session.exists(testUserWorkspaceRef)) {
            session.removeDocument(testUserWorkspaceRef);
            session.save();
        }
    }
    // Delete test workspace if exists
    String testWorkspacePath = getDefaultDomainPath(session) + "/" + TEST_WORKSPACE_PARENT_NAME + "/" + TEST_WORKSPACE_NAME;
    DocumentRef testWorkspaceDocRef = new PathRef(testWorkspacePath);
    if (session.exists(testWorkspaceDocRef)) {
        session.removeDocument(testWorkspaceDocRef);
        session.save();
    }
    // Invalidate user profile cache
    Framework.getService(UserProfileService.class).clearCache();
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) UserProfileService(org.nuxeo.ecm.user.center.profile.UserProfileService) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 53 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel 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 54 with DocumentModel

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

the class MockChangeFinder method getDocumentChanges.

protected List<FileSystemItemChange> getDocumentChanges(CoreSession session, String query, int limit) throws TooManyChangesException {
    List<FileSystemItemChange> docChanges = new ArrayList<FileSystemItemChange>();
    DocumentModelList queryResult = session.query(query, limit);
    if (queryResult.size() >= limit) {
        throw new TooManyChangesException("Too many document changes found in the repository.");
    }
    for (DocumentModel doc : queryResult) {
        String repositoryId = session.getRepositoryName();
        String eventId = "documentChanged";
        long eventDate = ((Calendar) doc.getPropertyValue("dc:modified")).getTimeInMillis();
        String docUuid = doc.getId();
        FileSystemItem fsItem = doc.getAdapter(FileSystemItem.class);
        if (fsItem != null) {
            docChanges.add(new FileSystemItemChangeImpl(eventId, eventDate, repositoryId, docUuid, fsItem));
        }
    }
    return docChanges;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileSystemItemChangeImpl(org.nuxeo.drive.service.impl.FileSystemItemChangeImpl)

Example 55 with DocumentModel

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

the class DocumentBackedFolderItem method adaptDocuments.

/**
 * Adapts the given {@link DocumentModelList} as {@link FileSystemItem}s using a cache for the {@link FolderItem}
 * ancestors.
 */
protected List<FileSystemItem> adaptDocuments(DocumentModelList docs, CoreSession session) {
    Map<DocumentRef, FolderItem> ancestorCache = new HashMap<>();
    if (log.isTraceEnabled()) {
        log.trace(String.format("Caching current FolderItem for doc %s: %s", docPath, getPath()));
    }
    ancestorCache.put(new IdRef(docId), this);
    List<FileSystemItem> descendants = new ArrayList<>(docs.size());
    for (DocumentModel doc : docs) {
        FolderItem parent = populateAncestorCache(ancestorCache, doc, session, false);
        if (parent == null) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Cannot adapt parent document of %s as a FileSystemItem, skipping descendant document", doc.getPathAsString()));
                continue;
            }
        }
        // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
        FileSystemItem descendant = getFileSystemItemAdapterService().getFileSystemItem(doc, parent, false, false, false);
        if (descendant != null) {
            if (descendant.isFolder()) {
                if (log.isTraceEnabled()) {
                    log.trace(String.format("Caching descendant FolderItem for doc %s: %s", doc.getPathAsString(), descendant.getPath()));
                }
                ancestorCache.put(doc.getRef(), (FolderItem) descendant);
            }
            descendants.add(descendant);
        }
    }
    return descendants;
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

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