Search in sources :

Example 21 with FolderItem

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

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

Example 23 with FolderItem

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

the class FileSystemItemManagerImpl method move.

@Override
public FileSystemItem move(String srcId, String destId, Principal principal) {
    FileSystemItem srcFsItem = getFileSystemItemById(srcId, principal);
    if (srcFsItem == null) {
        throw new NuxeoException(String.format("Cannot move file system item with id %s because it doesn't exist.", srcId));
    }
    FileSystemItem destFsItem = getFileSystemItemById(destId, principal);
    if (destFsItem == null) {
        throw new NuxeoException(String.format("Cannot move a file system item to file system item with id %s because it doesn't exist.", destId));
    }
    if (!(destFsItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot move a file system item to file system item with id %s because it is not a folder.", destId));
    }
    return srcFsItem.move((FolderItem) destFsItem);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 24 with FolderItem

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

the class FileSystemItemManagerImpl method scrollDescendants.

@Override
public ScrollFileSystemItemList scrollDescendants(String id, Principal principal, String scrollId, int batchSize, long keepAlive) {
    FileSystemItem fileSystemItem = getFileSystemItemById(id, principal);
    if (fileSystemItem == null) {
        throw new NuxeoException(String.format("Cannot get the descendants of file system item with id %s because it doesn't exist.", id));
    }
    if (!(fileSystemItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot get the descendants of file system item with id %s because it is not a folder.", id));
    }
    FolderItem folderItem = (FolderItem) fileSystemItem;
    return folderItem.scrollDescendants(scrollId, batchSize, keepAlive);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 25 with FolderItem

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

the class FileSystemItemManagerImpl method createFile.

@Override
public FileItem createFile(String parentId, Blob blob, Principal principal, boolean overwrite) {
    FileSystemItem parentFsItem = getFileSystemItemById(parentId, principal);
    if (parentFsItem == null) {
        throw new NuxeoException(String.format("Cannot create a file in file system item with id %s because it doesn't exist.", parentId));
    }
    if (!(parentFsItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot create a file in file system item with id %s because it is not a folder but is: %s", parentId, parentFsItem));
    }
    FolderItem parentFolder = (FolderItem) parentFsItem;
    return parentFolder.createFile(blob, overwrite);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

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