Search in sources :

Example 16 with FolderItem

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

the class DocumentBackedFolderItem method populateAncestorCache.

protected FolderItem populateAncestorCache(Map<DocumentRef, FolderItem> cache, DocumentModel doc, CoreSession session, boolean cacheItem) {
    DocumentRef parentDocRef = session.getParentDocumentRef(doc.getRef());
    if (parentDocRef == null) {
        throw new RootlessItemException("Reached repository root");
    }
    FolderItem parentItem = cache.get(parentDocRef);
    if (parentItem != null) {
        if (log.isTraceEnabled()) {
            log.trace(String.format("Found parent FolderItem in cache for doc %s: %s", doc.getPathAsString(), parentItem.getPath()));
        }
        return getFolderItem(cache, doc, parentItem, cacheItem);
    }
    if (log.isTraceEnabled()) {
        log.trace(String.format("No parent FolderItem found in cache for doc %s, computing ancestor cache", doc.getPathAsString()));
    }
    DocumentModel parentDoc;
    try {
        parentDoc = session.getDocument(parentDocRef);
    } catch (DocumentSecurityException e) {
        throw new RootlessItemException(String.format("User %s has no READ access on parent of document %s (%s).", principal.getName(), doc.getPathAsString(), doc.getId()), e);
    }
    parentItem = populateAncestorCache(cache, parentDoc, session, true);
    if (parentItem == null) {
        return null;
    }
    return getFolderItem(cache, doc, parentItem, cacheItem);
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 17 with FolderItem

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

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

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

the class UserWorkspaceSyncRootParentFactory method getVirtualFolderItem.

@Override
public FolderItem getVirtualFolderItem(Principal principal) {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(principal);
    if (topLevelFolder == null) {
        throw new NuxeoException("Found no top level folder item. Please check your contribution to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"topLevelFolderItemFactory\">.");
    }
    return new UserWorkspaceSyncRootParentFolderItem(getName(), principal, topLevelFolder.getId(), topLevelFolder.getPath(), folderName);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) UserWorkspaceSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) UserWorkspaceSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 20 with FolderItem

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

Aggregations

FolderItem (org.nuxeo.drive.adapter.FolderItem)43 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)24 Test (org.junit.Test)22 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)16 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)14 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)10 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)10 FileItem (org.nuxeo.drive.adapter.FileItem)8 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)8 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)8 Blob (org.nuxeo.ecm.core.api.Blob)8 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)7 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)7 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)6 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)4 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)4 Deploy (org.nuxeo.runtime.test.runner.Deploy)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)3