Search in sources :

Example 16 with CloseableCoreSession

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

the class UserSyncRootParentFactory method getVirtualFolderItem.

/*------------------- VirtualFolderItemFactory ------------------- */
@Override
public FolderItem getVirtualFolderItem(Principal principal) {
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    // TODO: handle multiple repositories
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryManager.getDefaultRepositoryName(), principal)) {
        UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class);
        DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session);
        if (userWorkspace == null) {
            throw new NuxeoException(String.format("No personal workspace found for user %s.", principal.getName()));
        }
        return (FolderItem) getFileSystemItem(userWorkspace);
    }
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) UserSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.UserSyncRootParentFolderItem) UserWorkspaceService(org.nuxeo.ecm.platform.userworkspace.api.UserWorkspaceService) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 17 with CloseableCoreSession

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

the class UserWorkspaceTopLevelFolderItem method getChildren.

/*--------------------- FolderItem -----------------*/
@Override
public List<FileSystemItem> getChildren() {
    // already the case
    if (!getNuxeoDriveManager().isSynchronizationRoot(principal, userWorkspace)) {
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            getNuxeoDriveManager().registerSynchronizationRoot(principal, userWorkspace, session);
        }
    }
    List<FileSystemItem> children = new ArrayList<FileSystemItem>();
    // Add user workspace children
    children.addAll(super.getChildren());
    // Add synchronization root parent folder
    if (syncRootParentFactoryName == null) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No synchronization root parent factory name parameter for factory %s, the synchronization roots won't be synchronized client side.", factoryName));
        }
    } else {
        VirtualFolderItemFactory syncRootParentFactory = getFileSystemItemAdapterService().getVirtualFolderItemFactory(syncRootParentFactoryName);
        FolderItem syncRootParent = syncRootParentFactory.getVirtualFolderItem(principal);
        if (syncRootParent != null) {
            children.add(syncRootParent);
        }
    }
    return children;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) VirtualFolderItemFactory(org.nuxeo.drive.service.VirtualFolderItemFactory)

Example 18 with CloseableCoreSession

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

the class UserWorkspaceTopLevelFactory method getTopLevelFolderItem.

/*----------------------- TopLevelFolderItemFactory ---------------------*/
@Override
public FolderItem getTopLevelFolderItem(Principal principal) {
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    // TODO: handle multiple repositories
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryManager.getDefaultRepositoryName(), principal)) {
        UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class);
        DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session);
        if (userWorkspace == null) {
            throw new NuxeoException(String.format("No personal workspace found for user %s.", principal.getName()));
        }
        return (FolderItem) getFileSystemItem(userWorkspace);
    }
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) UserWorkspaceTopLevelFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceTopLevelFolderItem) UserWorkspaceService(org.nuxeo.ecm.platform.userworkspace.api.UserWorkspaceService) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 19 with CloseableCoreSession

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

the class DefaultTopLevelFolderItem method getChildren.

/*--------------------- FolderItem -----------------*/
@Override
public List<FileSystemItem> getChildren() {
    List<FileSystemItem> children = new ArrayList<FileSystemItem>();
    Map<String, SynchronizationRoots> syncRootsByRepo = Framework.getService(NuxeoDriveManager.class).getSynchronizationRoots(principal);
    for (String repositoryName : syncRootsByRepo.keySet()) {
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            Set<IdRef> syncRootRefs = syncRootsByRepo.get(repositoryName).getRefs();
            Iterator<IdRef> syncRootRefsIt = syncRootRefs.iterator();
            while (syncRootRefsIt.hasNext()) {
                IdRef idRef = syncRootRefsIt.next();
                // See https://jira.nuxeo.com/browse/NXP-11146
                if (!session.hasPermission(idRef, SecurityConstants.READ)) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("User %s has no READ access on synchronization root %s, not including it in children.", session.getPrincipal().getName(), idRef));
                    }
                    continue;
                }
                DocumentModel doc = session.getDocument(idRef);
                // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
                FileSystemItem child = getFileSystemItemAdapterService().getFileSystemItem(doc, this, false, false, false);
                if (child == null) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Synchronization root %s cannot be adapted as a FileSystemItem, not including it in children.", idRef));
                    }
                    continue;
                }
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Including synchronization root %s in children.", idRef));
                }
                children.add(child);
            }
        }
    }
    Collections.sort(children);
    return children;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) SynchronizationRoots(org.nuxeo.drive.service.SynchronizationRoots) IdRef(org.nuxeo.ecm.core.api.IdRef) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 20 with CloseableCoreSession

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

the class DocumentBackedFolderItem method doScrollDescendants.

@SuppressWarnings("unchecked")
protected ScrollFileSystemItemList doScrollDescendants(String scrollId, int batchSize, long keepAlive) {
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        // Limit batch size sent by the client
        checkBatchSize(batchSize);
        // Scroll through a batch of documents
        ScrollDocumentModelList descendantDocsBatch = getScrollBatch(scrollId, batchSize, session, keepAlive);
        String newScrollId = descendantDocsBatch.getScrollId();
        if (descendantDocsBatch.isEmpty()) {
            // No more descendants left to return
            return new ScrollFileSystemItemListImpl(newScrollId, 0);
        }
        // Adapt documents as FileSystemItems
        List<FileSystemItem> descendants = adaptDocuments(descendantDocsBatch, session);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Retrieved %d descendants of FolderItem %s (batchSize = %d)", descendants.size(), docPath, batchSize));
        }
        return new ScrollFileSystemItemListImpl(newScrollId, descendants);
    }
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession)

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