Search in sources :

Example 16 with FileSystemItem

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

the class NuxeoDriveRename method run.

@OperationMethod
public Blob run() throws InvalidOperationException, IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FileSystemItem fsItem;
    try {
        fsItem = fileSystemItemManager.rename(id, name, ctx.getPrincipal());
    } catch (UnsupportedOperationException e) {
        throw new InvalidOperationException(e);
    }
    return Blobs.createJSONBlobFromValue(fsItem);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) InvalidOperationException(org.nuxeo.ecm.automation.InvalidOperationException) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 17 with FileSystemItem

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

the class NuxeoDriveGetChildren method run.

@OperationMethod
public Blob run() throws IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    List<FileSystemItem> children = fileSystemItemManager.getChildren(id, ctx.getPrincipal());
    return Blobs.createJSONBlobFromValue(children);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 18 with FileSystemItem

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

the class MockChangeFinder method getDocumentChanges.

protected List<FileSystemItemChange> getDocumentChanges(CoreSession session, String query, int limit) throws TooManyChangesException {
    List<FileSystemItemChange> docChanges = new ArrayList<FileSystemItemChange>();
    DocumentModelList queryResult = session.query(query, limit);
    if (queryResult.size() >= limit) {
        throw new TooManyChangesException("Too many document changes found in the repository.");
    }
    for (DocumentModel doc : queryResult) {
        String repositoryId = session.getRepositoryName();
        String eventId = "documentChanged";
        long eventDate = ((Calendar) doc.getPropertyValue("dc:modified")).getTimeInMillis();
        String docUuid = doc.getId();
        FileSystemItem fsItem = doc.getAdapter(FileSystemItem.class);
        if (fsItem != null) {
            docChanges.add(new FileSystemItemChangeImpl(eventId, eventDate, repositoryId, docUuid, fsItem));
        }
    }
    return docChanges;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileSystemItemChangeImpl(org.nuxeo.drive.service.impl.FileSystemItemChangeImpl)

Example 19 with FileSystemItem

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

the class DocumentBackedFolderItem method getFolderItem.

protected FolderItem getFolderItem(Map<DocumentRef, FolderItem> cache, DocumentModel doc, FolderItem parentItem, boolean cacheItem) {
    if (cacheItem) {
        // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
        FileSystemItem fsItem = getFileSystemItemAdapterService().getFileSystemItem(doc, parentItem, true, false, false);
        if (fsItem == null) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Reached document %s that cannot be  adapted as a (possibly virtual) descendant of the top level folder item.", doc.getPathAsString()));
            }
            return null;
        }
        FolderItem folderItem = (FolderItem) fsItem;
        if (log.isTraceEnabled()) {
            log.trace(String.format("Caching FolderItem for doc %s: %s", doc.getPathAsString(), folderItem.getPath()));
        }
        cache.put(doc.getRef(), folderItem);
        return folderItem;
    } else {
        return parentItem;
    }
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem)

Example 20 with FileSystemItem

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

the class DocumentBackedFolderItem method adaptDocuments.

/**
 * Adapts the given {@link DocumentModelList} as {@link FileSystemItem}s using a cache for the {@link FolderItem}
 * ancestors.
 */
protected List<FileSystemItem> adaptDocuments(DocumentModelList docs, CoreSession session) {
    Map<DocumentRef, FolderItem> ancestorCache = new HashMap<>();
    if (log.isTraceEnabled()) {
        log.trace(String.format("Caching current FolderItem for doc %s: %s", docPath, getPath()));
    }
    ancestorCache.put(new IdRef(docId), this);
    List<FileSystemItem> descendants = new ArrayList<>(docs.size());
    for (DocumentModel doc : docs) {
        FolderItem parent = populateAncestorCache(ancestorCache, doc, session, false);
        if (parent == null) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Cannot adapt parent document of %s as a FileSystemItem, skipping descendant document", doc.getPathAsString()));
                continue;
            }
        }
        // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
        FileSystemItem descendant = getFileSystemItemAdapterService().getFileSystemItem(doc, parent, false, false, false);
        if (descendant != null) {
            if (descendant.isFolder()) {
                if (log.isTraceEnabled()) {
                    log.trace(String.format("Caching descendant FolderItem for doc %s: %s", doc.getPathAsString(), descendant.getPath()));
                }
                ancestorCache.put(doc.getRef(), (FolderItem) descendant);
            }
            descendants.add(descendant);
        }
    }
    return descendants;
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

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