Search in sources :

Example 46 with FileSystemItem

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

the class AuditChangeFinder method getFileSystemItemChange.

protected FileSystemItemChange getFileSystemItemChange(CoreSession session, DocumentRef docRef, LogEntry entry, String expectedFileSystemItemId) {
    DocumentModel doc = session.getDocument(docRef);
    // TODO: check the facet, last root change and list of roots
    // to have a special handling for the roots.
    FileSystemItem fsItem = null;
    try {
        // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
        fsItem = Framework.getService(FileSystemItemAdapterService.class).getFileSystemItem(doc, false, false, false);
    } catch (RootlessItemException e) {
        // be adapted as a FileSystemItem: nothing to do.
        if (log.isDebugEnabled()) {
            log.debug(String.format("RootlessItemException thrown while trying to adapt document %s (%s) as a FileSystemItem.", entry.getDocPath(), docRef));
        }
    }
    if (fsItem == null) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Document %s (%s) is not adaptable as a FileSystemItem, returning null.", entry.getDocPath(), docRef));
        }
        return null;
    }
    if (expectedFileSystemItemId != null && !fsItem.getId().endsWith(AbstractFileSystemItem.FILE_SYSTEM_ITEM_ID_SEPARATOR + expectedFileSystemItemId)) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Id %s of FileSystemItem adapted from document %s (%s) doesn't match expected FileSystemItem id %s, returning null.", fsItem.getId(), entry.getDocPath(), docRef, expectedFileSystemItemId));
        }
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug(String.format("Document %s (%s) is adaptable as a FileSystemItem, providing it to the FileSystemItemChange entry.", entry.getDocPath(), docRef));
    }
    // guarantee when facing long transactions.
    return new FileSystemItemChangeImpl(entry.getEventId(), entry.getEventDate().getTime(), entry.getRepositoryId(), entry.getDocUUID(), fsItem);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) AbstractFileSystemItem(org.nuxeo.drive.adapter.impl.AbstractFileSystemItem) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 47 with FileSystemItem

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

the class NuxeoDriveGetFileSystemItem method run.

@OperationMethod
public Blob run() throws IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FileSystemItem fsItem;
    if (parentId == null) {
        fsItem = fileSystemItemManager.getFileSystemItemById(id, ctx.getPrincipal());
    } else {
        fsItem = fileSystemItemManager.getFileSystemItemById(id, parentId, ctx.getPrincipal());
    }
    return Blobs.createJSONBlobFromValue(fsItem);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 48 with FileSystemItem

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

the class NuxeoDriveGetTopLevelChildren method run.

@OperationMethod
public Blob run() throws IOException {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    List<FileSystemItem> children = fileSystemItemManager.getTopLevelChildren(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)

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