Search in sources :

Example 1 with PageProviderService

use of org.nuxeo.ecm.platform.query.api.PageProviderService in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveManagerImpl method computeCollectionSyncRootMemberIds.

@SuppressWarnings("unchecked")
protected Map<String, Set<String>> computeCollectionSyncRootMemberIds(Principal principal) {
    Map<String, Set<String>> collectionSyncRootMemberIds = new HashMap<String, Set<String>>();
    PageProviderService pageProviderService = Framework.getService(PageProviderService.class);
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    for (String repositoryName : repositoryManager.getRepositoryNames()) {
        Set<String> collectionMemberIds = new HashSet<String>();
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            Map<String, Serializable> props = new HashMap<String, Serializable>();
            props.put(CORE_SESSION_PROPERTY, (Serializable) session);
            PageProvider<DocumentModel> collectionPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(CollectionConstants.ALL_COLLECTIONS_PAGE_PROVIDER, null, null, 0L, props);
            List<DocumentModel> collections = collectionPageProvider.getCurrentPage();
            for (DocumentModel collection : collections) {
                if (isSynchronizationRoot(principal, collection)) {
                    PageProvider<DocumentModel> collectionMemberPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER, null, COLLECTION_CONTENT_PAGE_SIZE, 0L, props, collection.getId());
                    List<DocumentModel> collectionMembers = collectionMemberPageProvider.getCurrentPage();
                    for (DocumentModel collectionMember : collectionMembers) {
                        collectionMemberIds.add(collectionMember.getId());
                    }
                }
            }
            collectionSyncRootMemberIds.put(repositoryName, collectionMemberIds);
        }
    }
    return collectionSyncRootMemberIds;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) PageProviderService(org.nuxeo.ecm.platform.query.api.PageProviderService) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) PageProvider(org.nuxeo.ecm.platform.query.api.PageProvider) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with PageProviderService

use of org.nuxeo.ecm.platform.query.api.PageProviderService 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 3 with PageProviderService

use of org.nuxeo.ecm.platform.query.api.PageProviderService 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

Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)3 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)3 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)3 PageProvider (org.nuxeo.ecm.platform.query.api.PageProvider)3 PageProviderService (org.nuxeo.ecm.platform.query.api.PageProviderService)3 ArrayList (java.util.ArrayList)2 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 RepositoryManager (org.nuxeo.ecm.core.api.repository.RepositoryManager)1