Search in sources :

Example 26 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem 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 27 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem 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 28 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem 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)

Example 29 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class PermissionTopLevelFolderItem method getChildren.

@Override
public List<FileSystemItem> getChildren() {
    List<FileSystemItem> children = new ArrayList<FileSystemItem>();
    for (String childFactoryName : childrenFactoryNames) {
        VirtualFolderItemFactory factory = getFileSystemItemAdapterService().getVirtualFolderItemFactory(childFactoryName);
        FolderItem child = factory.getVirtualFolderItem(principal);
        if (child != null) {
            children.add(child);
        }
    }
    return children;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) AbstractVirtualFolderItem(org.nuxeo.drive.adapter.impl.AbstractVirtualFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) ArrayList(java.util.ArrayList) VirtualFolderItemFactory(org.nuxeo.drive.service.VirtualFolderItemFactory)

Example 30 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class AbstractFileSystemItemFactory method getFileSystemItemById.

@Override
public FileSystemItem getFileSystemItemById(String id, String parentId, Principal principal) {
    String[] idFragments = parseFileSystemId(id);
    String repositoryName = idFragments[1];
    String docId = idFragments[2];
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        FileSystemItem parentItem = Framework.getService(FileSystemItemAdapterService.class).getFileSystemItemFactoryForId(parentId).getFileSystemItemById(parentId, principal);
        if (!(parentItem instanceof FolderItem)) {
            throw new NuxeoException(String.format("FileSystemItem with id %s should be a FolderItem", parentId));
        }
        DocumentModel doc = getDocumentById(docId, session);
        return getFileSystemItem(doc, (FolderItem) parentItem);
    } catch (DocumentNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No doc related to id %s, returning null.", docId));
        }
        return null;
    } catch (DocumentSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("User %s cannot access doc %s, returning null.", principal.getName(), docId));
        }
        return null;
    }
}
Also used : AbstractFileSystemItem(org.nuxeo.drive.adapter.impl.AbstractFileSystemItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)48 FolderItem (org.nuxeo.drive.adapter.FolderItem)24 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)22 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)12 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)12 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)10 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)9 Blob (org.nuxeo.ecm.core.api.Blob)8 FileItem (org.nuxeo.drive.adapter.FileItem)7 IdRef (org.nuxeo.ecm.core.api.IdRef)7 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)6 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)6 RootlessItemException (org.nuxeo.drive.adapter.RootlessItemException)5 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)5 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)5 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)5 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)5 OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)5 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)4