Search in sources :

Example 21 with FileSystemItem

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

the class DocumentBackedFolderItem method getChildren.

/*--------------------- FolderItem -----------------*/
@Override
@SuppressWarnings("unchecked")
public List<FileSystemItem> getChildren() {
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        PageProviderService pageProviderService = Framework.getService(PageProviderService.class);
        Map<String, Serializable> props = new HashMap<>();
        props.put(CORE_SESSION_PROPERTY, (Serializable) session);
        PageProvider<DocumentModel> childrenPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(FOLDER_ITEM_CHILDREN_PAGE_PROVIDER, null, null, 0L, props, docId);
        long pageSize = childrenPageProvider.getPageSize();
        List<FileSystemItem> children = new ArrayList<>();
        int nbChildren = 0;
        boolean reachedPageSize = false;
        boolean hasNextPage = true;
        // FileSystemItems
        while (nbChildren < pageSize && hasNextPage) {
            List<DocumentModel> dmChildren = childrenPageProvider.getCurrentPage();
            for (DocumentModel dmChild : dmChildren) {
                // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
                FileSystemItem child = getFileSystemItemAdapterService().getFileSystemItem(dmChild, this, false, false, false);
                if (child != null) {
                    children.add(child);
                    nbChildren++;
                    if (nbChildren == pageSize) {
                        reachedPageSize = true;
                        break;
                    }
                }
            }
            if (!reachedPageSize) {
                hasNextPage = childrenPageProvider.isNextPageAvailable();
                if (hasNextPage) {
                    childrenPageProvider.nextPage();
                }
            }
        }
        return children;
    }
}
Also used : Serializable(java.io.Serializable) PageProviderService(org.nuxeo.ecm.platform.query.api.PageProviderService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) PageProvider(org.nuxeo.ecm.platform.query.api.PageProvider)

Example 22 with FileSystemItem

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

the class ScrollFileSystemItemListDeserializer method deserialize.

@Override
public ScrollFileSystemItemList deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
    JsonNode rootNode = jp.readValueAsTree();
    String scrollId = ((TextNode) rootNode.get("scrollId")).textValue();
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode fileSystemItemNodes = (ArrayNode) rootNode.get("fileSystemItems");
    List<FileSystemItem> fileSystemItems = new ArrayList<>(fileSystemItemNodes.size());
    for (JsonNode fileSystemItemNode : fileSystemItemNodes) {
        boolean folderish = ((BooleanNode) fileSystemItemNode.get("folder")).booleanValue();
        if (folderish) {
            fileSystemItems.add(readValue(mapper, fileSystemItemNode, DocumentBackedFolderItem.class));
        } else {
            fileSystemItems.add(readValue(mapper, fileSystemItemNode, DocumentBackedFileItem.class));
        }
    }
    return new ScrollFileSystemItemListImpl(scrollId, fileSystemItems);
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with FileSystemItem

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

the class SharedSyncRootParentFolderItem method getChildren.

@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);
                // principal)
                if (!session.getPrincipal().getName().equals(doc.getPropertyValue("dc:creator"))) {
                    // 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, maybe because user %s doesn't have the required permission on it (default required permission is ReadWrite). Not including it in children.", idRef, session.getPrincipal().getName()));
                        }
                        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 24 with FileSystemItem

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

the class AbstractDocumentBackedFileSystemItem method handleCollectionMember.

protected boolean handleCollectionMember(DocumentModel doc, CoreSession session, boolean relaxSyncRootConstraint, boolean getLockInfo) {
    if (!doc.hasSchema(CollectionConstants.COLLECTION_MEMBER_SCHEMA_NAME)) {
        return false;
    }
    CollectionManager cm = Framework.getService(CollectionManager.class);
    List<DocumentModel> docCollections = cm.getVisibleCollection(doc, session);
    if (docCollections.isEmpty()) {
        if (log.isTraceEnabled()) {
            log.trace(String.format("Doc %s (%s) is not member of any collection", doc.getPathAsString(), doc.getId()));
        }
        return false;
    } else {
        FileSystemItem parent = null;
        DocumentModel collection = null;
        Iterator<DocumentModel> it = docCollections.iterator();
        while (it.hasNext() && parent == null) {
            collection = it.next();
            // as a FileSystemItem and this collection is not a synchronization root for the current user
            if (collection.getPathAsString().startsWith(doc.getPathAsString() + "/") && !Framework.getService(NuxeoDriveManager.class).isSynchronizationRoot(session.getPrincipal(), collection)) {
                continue;
            }
            try {
                parent = getFileSystemItemAdapterService().getFileSystemItem(collection, true, relaxSyncRootConstraint, getLockInfo);
            } catch (RootlessItemException e) {
                if (log.isTraceEnabled()) {
                    log.trace(String.format("The collection %s (%s) of which doc %s (%s) is a member cannot be adapted as a FileSystemItem.", collection.getPathAsString(), collection.getId(), doc.getPathAsString(), doc.getId()));
                }
                continue;
            }
        }
        if (parent == null) {
            if (log.isTraceEnabled()) {
                log.trace(String.format("None of the collections of which doc %s (%s) is a member can be adapted as a FileSystemItem.", doc.getPathAsString(), doc.getId()));
            }
            return false;
        }
        if (log.isTraceEnabled()) {
            log.trace(String.format("Using first collection %s (%s) of which doc %s (%s) is a member and that is adaptable as a FileSystemItem as a parent FileSystemItem.", collection.getPathAsString(), collection.getId(), doc.getPathAsString(), doc.getId()));
        }
        parentId = parent.getId();
        path = parent.getPath() + '/' + id;
        return true;
    }
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) CollectionManager(org.nuxeo.ecm.collections.api.CollectionManager) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager)

Example 25 with FileSystemItem

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

the class CollectionSyncRootFolderItem method getChildren.

@Override
@SuppressWarnings("unchecked")
public List<FileSystemItem> getChildren() {
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        PageProviderService pageProviderService = Framework.getService(PageProviderService.class);
        Map<String, Serializable> props = new HashMap<String, Serializable>();
        props.put(CORE_SESSION_PROPERTY, (Serializable) session);
        PageProvider<DocumentModel> childrenPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER, null, null, 0L, props, docId);
        List<DocumentModel> dmChildren = childrenPageProvider.getCurrentPage();
        List<FileSystemItem> children = new ArrayList<FileSystemItem>(dmChildren.size());
        for (DocumentModel dmChild : dmChildren) {
            // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
            FileSystemItem child = getFileSystemItemAdapterService().getFileSystemItem(dmChild, this, false, false, false);
            if (child != null) {
                children.add(child);
            }
        }
        return children;
    }
}
Also used : Serializable(java.io.Serializable) PageProviderService(org.nuxeo.ecm.platform.query.api.PageProviderService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) PageProvider(org.nuxeo.ecm.platform.query.api.PageProvider)

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