Search in sources :

Example 6 with RootlessItemException

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

the class NuxeoDriveCanMove method run.

@OperationMethod
public Blob run() throws IOException {
    boolean canMove = false;
    try {
        FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
        canMove = fileSystemItemManager.canMove(srcId, destId, ctx.getPrincipal());
    } catch (RootlessItemException e) {
        // active sync root: just return false in that case.
        if (log.isDebugEnabled()) {
            log.debug(String.format("Cannot move %s to %s: %s", srcId, destId, e.getMessage()), e);
        }
    }
    return Blobs.createJSONBlobFromValue(canMove);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 7 with RootlessItemException

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

Aggregations

RootlessItemException (org.nuxeo.drive.adapter.RootlessItemException)7 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)5 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)5 Test (org.junit.Test)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 Blob (org.nuxeo.ecm.core.api.Blob)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)1 AbstractFileSystemItem (org.nuxeo.drive.adapter.impl.AbstractFileSystemItem)1 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)1 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)1 OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)1 CollectionManager (org.nuxeo.ecm.collections.api.CollectionManager)1 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)1 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)1 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)1 DocumentSecurityException (org.nuxeo.ecm.core.api.DocumentSecurityException)1 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)1