Search in sources :

Example 1 with DocumentModelList

use of org.nuxeo.ecm.core.api.DocumentModelList in project nuxeo-filesystem-connectors by nuxeo.

the class SearchVirtualBackend method init.

@Override
protected void init() {
    DocumentModelList docs = getSession().query(query);
    registerSimpleBackends(docs);
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList)

Example 2 with DocumentModelList

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

the class NuxeoDriveGroupUpdateListener method handleUpdatedGroups.

protected void handleUpdatedGroups(List<String> groupNames) {
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    for (String repositoryName : repositoryManager.getRepositoryNames()) {
        CoreInstance.doPrivileged(repositoryName, (CoreSession session) -> {
            DocumentModelList impactedDocuments = getImpactedDocuments(session, groupNames);
            impactedDocuments.forEach(doc -> fireGroupUpdatedEvent(session, doc));
        });
    }
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) CoreSession(org.nuxeo.ecm.core.api.CoreSession)

Example 3 with DocumentModelList

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

the class NuxeoDriveSyncRootCopyListener method handleEvent.

@Override
public void handleEvent(Event event) {
    if (Framework.getService(ConfigurationService.class).isBooleanPropertyFalse(RESET_SYNC_ROOTS_ON_COPY_CONFIGURATION_PROPERTY)) {
        return;
    }
    EventContext context = event.getContext();
    if (!(context instanceof DocumentEventContext)) {
        return;
    }
    DocumentModel doc = ((DocumentEventContext) context).getSourceDocument();
    CoreSession session = context.getCoreSession();
    DocumentModelList syncRoots = getSyncRoots(doc, session);
    for (DocumentModel syncRoot : syncRoots) {
        syncRoot.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
        syncRoot.putContextData("source", "drive");
        syncRoot.putContextData(CoreSession.SOURCE, "drive");
        session.saveDocument(syncRoot);
    }
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) EventContext(org.nuxeo.ecm.core.event.EventContext) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) ConfigurationService(org.nuxeo.runtime.services.config.ConfigurationService) CoreSession(org.nuxeo.ecm.core.api.CoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 4 with DocumentModelList

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

the class NuxeoDriveSyncRootCopyListener method getSyncRoots.

protected DocumentModelList getSyncRoots(DocumentModel doc, CoreSession session) {
    String nxql = "SELECT * FROM Document WHERE ecm:mixinType = '" + NuxeoDriveManagerImpl.NUXEO_DRIVE_FACET + "' AND ecm:isVersion = 0 AND ecm:path STARTSWITH " + NXQL.escapeString(doc.getPathAsString());
    DocumentModelList syncRoots = session.query(nxql);
    if (doc.hasFacet(NuxeoDriveManagerImpl.NUXEO_DRIVE_FACET)) {
        syncRoots.add(doc);
    }
    return syncRoots;
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList)

Example 5 with DocumentModelList

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

the class DefaultFileSystemItemFactoryFixture method testFolderItem.

@Test
public void testFolderItem() throws Exception {
    // ------------------------------------------------------
    // FolderItem#canCreateChild
    // ------------------------------------------------------
    // As Administrator
    FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
    assertTrue(folderItem.getCanCreateChild());
    // As a user with READ permission
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    // Under Oracle, the READ ACL optims are not visible from the joe
    // session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        folder = joeSession.getDocument(folder.getRef());
        // should not be mappable as an fs item.
        try {
            defaultFileSystemItemFactory.getFileSystemItem(folder);
            fail("Should have raised RootlessItemException as ");
        } catch (RootlessItemException e) {
        // expected
        }
        // Register the sync root for Joe's account
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
        folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
        assertFalse(folderItem.getCanCreateChild());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
        assertTrue(folderItem.getCanCreateChild());
    }
    resetPermissions(rootDoc, "joe");
    // ------------------------------------------------------
    // FolderItem#createFile and FolderItem#createFolder
    // ------------------------------------------------------
    folder = session.getDocument(folder.getRef());
    folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
    // Note
    Blob childBlob = new StringBlob("This is the Note child.");
    childBlob.setFilename("Note child.txt");
    folderItem.createFile(childBlob);
    // File
    childBlob = new StringBlob("This is the File child.");
    childBlob.setFilename("File child.odt");
    childBlob.setMimeType("application/vnd.oasis.opendocument.text");
    folderItem.createFile(childBlob);
    // Folder
    folderItem.createFolder("Sub-folder");
    DocumentModelList children = session.query(String.format("select * from Document where ecm:parentId = '%s' order by ecm:primaryType asc", folder.getId()));
    assertEquals(3, children.size());
    // Check File
    DocumentModel file = children.get(0);
    assertEquals("File", file.getType());
    assertEquals("File child.odt", file.getTitle());
    childBlob = (Blob) file.getPropertyValue("file:content");
    assertEquals("File child.odt", childBlob.getFilename());
    assertEquals("This is the File child.", childBlob.getString());
    // Check Folder
    DocumentModel subFolder = children.get(1);
    assertEquals("Folder", subFolder.getType());
    assertEquals("Sub-folder", subFolder.getTitle());
    // Check Note
    DocumentModel note = children.get(2);
    assertEquals("Note", note.getType());
    assertEquals("Note child.txt", note.getTitle());
    childBlob = note.getAdapter(BlobHolder.class).getBlob();
    assertEquals("Note child.txt", childBlob.getFilename());
    assertEquals("This is the Note child.", childBlob.getString());
    // --------------------------------------------------------------------------------------------
    // FolderItem#getChildren, FolderItem#getCanScrollDescendants and
    // FolderItem#scrollDescendants
    // --------------------------------------------------------------------------------------------
    // Create another child adaptable as a FileSystemItem => should be
    // retrieved
    DocumentModel adaptableChild = session.createDocumentModel("/syncRoot/aFolder", "adaptableChild", "File");
    Blob adaptableChildBlob = new StringBlob("Content of another file.");
    adaptableChildBlob.setFilename("Another file.odt");
    adaptableChild.setPropertyValue("file:content", (Serializable) adaptableChildBlob);
    adaptableChild = session.createDocument(adaptableChild);
    // Create another child not adaptable as a FileSystemItem => should
    // not be retrieved
    session.createDocument(session.createDocumentModel("/syncRoot/aFolder", "notAdaptableChild", "NotSynchronizable"));
    session.save();
    // Check getChildren
    List<FileSystemItem> folderChildren = folderItem.getChildren();
    assertEquals(4, folderChildren.size());
    // Ordered
    checkChildren(folderChildren, folder.getId(), note.getId(), file.getId(), subFolder.getId(), adaptableChild.getId(), true);
    // Check scrollDescendants
    assertTrue(folderItem.getCanScrollDescendants());
    // Scroll through all descendants in one breath
    ScrollFileSystemItemList folderDescendants = folderItem.scrollDescendants(null, 10, 1000);
    String scrollId = folderDescendants.getScrollId();
    assertNotNull(scrollId);
    assertEquals(4, folderDescendants.size());
    // Order is not determined
    checkChildren(folderDescendants, folder.getId(), note.getId(), file.getId(), subFolder.getId(), adaptableChild.getId(), false);
    // Check that next call to scrollDescendants returns an empty list
    assertTrue(folderItem.scrollDescendants(scrollId, 10, 1000).isEmpty());
    // Scroll through descendants in several steps
    folderDescendants.clear();
    ScrollFileSystemItemList descendantsBatch;
    int batchSize = 2;
    scrollId = null;
    while (!(descendantsBatch = folderItem.scrollDescendants(scrollId, batchSize, 1000)).isEmpty()) {
        assertTrue(descendantsBatch.size() > 0);
        scrollId = descendantsBatch.getScrollId();
        folderDescendants.addAll(descendantsBatch);
    }
    assertEquals(4, folderDescendants.size());
    // Order is not determined
    checkChildren(folderDescendants, folder.getId(), note.getId(), file.getId(), subFolder.getId(), adaptableChild.getId(), false);
    // Check batch size limit
    try {
        folderItem.scrollDescendants(null, 10000, 1000);
        fail("Should not be able to scroll through more descendants than the maximum batch size allowed.");
    } catch (NuxeoException e) {
        log.trace(e);
    }
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) Test(org.junit.Test)

Aggregations

DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)14 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)7 IdRef (org.nuxeo.ecm.core.api.IdRef)4 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)4 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)3 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)3 Map (java.util.Map)2 Test (org.junit.Test)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 Blob (org.nuxeo.ecm.core.api.Blob)2 CoreSession (org.nuxeo.ecm.core.api.CoreSession)2 PathRef (org.nuxeo.ecm.core.api.PathRef)2 DocumentModelListImpl (org.nuxeo.ecm.core.api.impl.DocumentModelListImpl)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 FacesContext (javax.faces.context.FacesContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LogFactory (org.apache.commons.logging.LogFactory)1