Search in sources :

Example 11 with DocumentModelList

use of org.nuxeo.ecm.core.api.DocumentModelList 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 12 with DocumentModelList

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

the class DocumentBackedFolderItem method fetchFromVCS.

protected DocumentModelList fetchFromVCS(List<String> ids, CoreSession session) {
    DocumentModelList res = null;
    int size = ids.size();
    int start = 0;
    int end = Math.min(VCS_CHUNK_SIZE, size);
    boolean done = false;
    while (!done) {
        DocumentModelList docs = fetchFromVcsChunk(ids.subList(start, end), session);
        if (res == null) {
            res = docs;
        } else {
            res.addAll(docs);
        }
        if (end >= ids.size()) {
            done = true;
        } else {
            start = end;
            end = Math.min(start + VCS_CHUNK_SIZE, size);
        }
    }
    return res;
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList)

Example 13 with DocumentModelList

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

the class DocumentBackedFolderItem method getScrollBatch.

@SuppressWarnings("unchecked")
protected ScrollDocumentModelList getScrollBatch(String scrollId, int batchSize, CoreSession session, long keepAlive) {
    Cache scrollingCache = Framework.getService(CacheService.class).getCache(DESCENDANTS_SCROLL_CACHE);
    if (scrollingCache == null) {
        throw new NuxeoException("Cache not found: " + DESCENDANTS_SCROLL_CACHE);
    }
    String newScrollId;
    List<String> descendantIds;
    if (StringUtils.isEmpty(scrollId)) {
        // Perform initial query to fetch ids of all the descendant documents and put the result list in a
        // cache, aka "search context"
        descendantIds = new ArrayList<>();
        StringBuilder sb = new StringBuilder(String.format("SELECT ecm:uuid FROM Document WHERE ecm:ancestorId = '%s'", docId));
        sb.append(" AND ecm:isTrashed = 0");
        sb.append(" AND ecm:mixinType != 'HiddenInNavigation'");
        // Don't need to add ecm:isVersion = 0 because versions are already excluded by the
        // ecm:ancestorId clause since they have no path
        String query = sb.toString();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Executing initial query to scroll through the descendants of %s: %s", docPath, query));
        }
        try (IterableQueryResult res = session.queryAndFetch(sb.toString(), NXQL.NXQL)) {
            Iterator<Map<String, Serializable>> it = res.iterator();
            while (it.hasNext()) {
                descendantIds.add((String) it.next().get(NXQL.ECM_UUID));
            }
        }
        // Generate a scroll id
        newScrollId = UUID.randomUUID().toString();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Put initial query result list (search context) in the %s cache at key (scrollId) %s", DESCENDANTS_SCROLL_CACHE, newScrollId));
        }
        scrollingCache.put(newScrollId, (Serializable) descendantIds);
    } else {
        // Get the descendant ids from the cache
        descendantIds = (List<String>) scrollingCache.get(scrollId);
        if (descendantIds == null) {
            throw new NuxeoException(String.format("No search context found in the %s cache for scrollId [%s]", DESCENDANTS_SCROLL_CACHE, scrollId));
        }
        newScrollId = scrollId;
    }
    if (descendantIds.isEmpty()) {
        return new ScrollDocumentModelList(newScrollId, 0);
    }
    // Extract a batch of descendant ids
    List<String> descendantIdsBatch = getBatch(descendantIds, batchSize);
    // Update descendant ids in the cache
    scrollingCache.put(newScrollId, (Serializable) descendantIds);
    // Fetch documents from VCS
    DocumentModelList descendantDocsBatch = fetchFromVCS(descendantIdsBatch, session);
    return new ScrollDocumentModelList(newScrollId, descendantDocsBatch);
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) IterableQueryResult(org.nuxeo.ecm.core.api.IterableQueryResult) HashMap(java.util.HashMap) Map(java.util.Map) Cache(org.nuxeo.ecm.core.cache.Cache) CacheService(org.nuxeo.ecm.core.cache.CacheService)

Example 14 with DocumentModelList

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

the class NuxeoDriveIntegrationTestsHelper method getDefaultDomainPath.

public static String getDefaultDomainPath(CoreSession session) {
    String query = "SELECT * FROM Document where ecm:primaryType = 'Domain'";
    DocumentModelList results = session.query(query);
    if (results.isEmpty()) {
        throw new NuxeoException(String.format("Found no domains in repository %s", session.getRepositoryName()));
    }
    if (results.size() > 1) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Found more than one domain in repository %s, using first one.", session.getRepositoryName()));
        }
    }
    DocumentModel defaultDomain = results.get(0);
    String defaultDomainPath = defaultDomain.getPathAsString();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Using default domain %s", defaultDomainPath));
    }
    return defaultDomainPath;
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

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