Search in sources :

Example 66 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveSyncRootVersioningListener method handleEvent.

@Override
public void handleEvent(Event event) {
    EventContext context = event.getContext();
    DocumentRef checkedInVersionRef = (DocumentRef) context.getProperty("checkedInVersionRef");
    if (checkedInVersionRef == null) {
        return;
    }
    CoreSession session = context.getCoreSession();
    DocumentModel doc = session.getDocument(checkedInVersionRef);
    if (!(doc.isVersion() && doc.hasFacet(NuxeoDriveManagerImpl.NUXEO_DRIVE_FACET))) {
        return;
    }
    doc.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
    doc.putContextData(CoreSession.ALLOW_VERSION_WRITE, Boolean.TRUE);
    doc.putContextData("source", "drive");
    doc.putContextData(CoreSession.SOURCE, "drive");
    session.saveDocument(doc);
}
Also used : EventContext(org.nuxeo.ecm.core.event.EventContext) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CoreSession(org.nuxeo.ecm.core.api.CoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 67 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class DefaultTopLevelFolderItem method getChildren.

/*--------------------- FolderItem -----------------*/
@Override
public List<FileSystemItem> getChildren() {
    List<FileSystemItem> children = new ArrayList<FileSystemItem>();
    Map<String, SynchronizationRoots> syncRootsByRepo = Framework.getService(NuxeoDriveManager.class).getSynchronizationRoots(principal);
    for (String repositoryName : syncRootsByRepo.keySet()) {
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            Set<IdRef> syncRootRefs = syncRootsByRepo.get(repositoryName).getRefs();
            Iterator<IdRef> syncRootRefsIt = syncRootRefs.iterator();
            while (syncRootRefsIt.hasNext()) {
                IdRef idRef = syncRootRefsIt.next();
                // See https://jira.nuxeo.com/browse/NXP-11146
                if (!session.hasPermission(idRef, SecurityConstants.READ)) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("User %s has no READ access on synchronization root %s, not including it in children.", session.getPrincipal().getName(), idRef));
                    }
                    continue;
                }
                DocumentModel doc = session.getDocument(idRef);
                // NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
                FileSystemItem child = getFileSystemItemAdapterService().getFileSystemItem(doc, this, false, false, false);
                if (child == null) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Synchronization root %s cannot be adapted as a FileSystemItem, not including it in children.", idRef));
                    }
                    continue;
                }
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Including synchronization root %s in children.", idRef));
                }
                children.add(child);
            }
        }
    }
    Collections.sort(children);
    return children;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) SynchronizationRoots(org.nuxeo.drive.service.SynchronizationRoots) IdRef(org.nuxeo.ecm.core.api.IdRef) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 68 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class AbstractDocumentBackedFileSystemItem method move.

@Override
public FileSystemItem move(FolderItem dest) {
    DocumentRef sourceDocRef = new IdRef(docId);
    AbstractDocumentBackedFileSystemItem docBackedDest = (AbstractDocumentBackedFileSystemItem) dest;
    String destRepoName = docBackedDest.getRepositoryName();
    DocumentRef destDocRef = new IdRef(docBackedDest.getDocId());
    // create doc in destination
    if (repositoryName.equals(destRepoName)) {
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            DocumentModel movedDoc = session.move(sourceDocRef, destDocRef, null);
            session.save();
            return getFileSystemItemAdapterService().getFileSystemItem(movedDoc, dest);
        }
    } else {
        // TODO: implement move to another repository
        throw new UnsupportedOperationException("Multi repository move is not supported yet.");
    }
}
Also used : DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 69 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class DefaultSyncRootFolderItem method delete.

@Override
public void delete() {
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        DocumentModel doc = getDocument(session);
        Framework.getService(NuxeoDriveManager.class).unregisterSynchronizationRoot(principal, doc, session);
    }
}
Also used : CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager)

Example 70 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class DocumentBackedFileItem method rename.

/*--------------------- FileSystemItem ---------------------*/
@Override
public void rename(String name) {
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        /* Update doc properties */
        DocumentModel doc = getDocument(session);
        BlobHolder bh = getBlobHolder(doc);
        Blob blob = getBlob(bh);
        blob.setFilename(name);
        bh.setBlob(blob);
        updateDocTitleIfNeeded(doc, name);
        doc.putContextData(CoreSession.SOURCE, "drive");
        doc = session.saveDocument(doc);
        session.save();
        /* Update FileSystemItem attributes */
        this.name = name;
        updateDownloadURL();
        updateLastModificationDate(doc);
    }
}
Also used : Blob(org.nuxeo.ecm.core.api.Blob) BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7