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