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;
}
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;
}
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);
}
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;
}
Aggregations