Search in sources :

Example 1 with RepositoryManager

use of org.nuxeo.ecm.core.api.repository.RepositoryManager 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 RepositoryManager

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

the class NuxeoDriveGroupUpdateListener method handleUpdatedGroups.

protected void handleUpdatedGroups(List<String> groupNames) {
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    for (String repositoryName : repositoryManager.getRepositoryNames()) {
        CoreInstance.doPrivileged(repositoryName, (CoreSession session) -> {
            DocumentModelList impactedDocuments = getImpactedDocuments(session, groupNames);
            impactedDocuments.forEach(doc -> fireGroupUpdatedEvent(session, doc));
        });
    }
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) CoreSession(org.nuxeo.ecm.core.api.CoreSession)

Example 3 with RepositoryManager

use of org.nuxeo.ecm.core.api.repository.RepositoryManager 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 4 with RepositoryManager

use of org.nuxeo.ecm.core.api.repository.RepositoryManager 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 5 with RepositoryManager

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

the class NuxeoDriveManagerImpl method computeSynchronizationRoots.

protected Map<String, SynchronizationRoots> computeSynchronizationRoots(String query, Principal principal) {
    Map<String, SynchronizationRoots> syncRoots = new HashMap<String, SynchronizationRoots>();
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    for (String repositoryName : repositoryManager.getRepositoryNames()) {
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            syncRoots.putAll(queryAndFetchSynchronizationRoots(session, query));
        }
    }
    return syncRoots;
}
Also used : HashMap(java.util.HashMap) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) SynchronizationRoots(org.nuxeo.drive.service.SynchronizationRoots) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager)

Aggregations

RepositoryManager (org.nuxeo.ecm.core.api.repository.RepositoryManager)6 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)5 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)3 HashMap (java.util.HashMap)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)2 UserWorkspaceService (org.nuxeo.ecm.platform.userworkspace.api.UserWorkspaceService)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 UserSyncRootParentFolderItem (org.nuxeo.drive.hierarchy.permission.adapter.UserSyncRootParentFolderItem)1 UserWorkspaceTopLevelFolderItem (org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceTopLevelFolderItem)1 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)1 CoreSession (org.nuxeo.ecm.core.api.CoreSession)1 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)1 NuxeoPrincipal (org.nuxeo.ecm.core.api.NuxeoPrincipal)1 PageProvider (org.nuxeo.ecm.platform.query.api.PageProvider)1