use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class UserSyncRootParentFactory method getVirtualFolderItem.
/*------------------- VirtualFolderItemFactory ------------------- */
@Override
public FolderItem getVirtualFolderItem(Principal principal) {
RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
// TODO: handle multiple repositories
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryManager.getDefaultRepositoryName(), principal)) {
UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class);
DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session);
if (userWorkspace == null) {
throw new NuxeoException(String.format("No personal workspace found for user %s.", principal.getName()));
}
return (FolderItem) getFileSystemItem(userWorkspace);
}
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class UserWorkspaceTopLevelFolderItem method getChildren.
/*--------------------- FolderItem -----------------*/
@Override
public List<FileSystemItem> getChildren() {
// already the case
if (!getNuxeoDriveManager().isSynchronizationRoot(principal, userWorkspace)) {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
getNuxeoDriveManager().registerSynchronizationRoot(principal, userWorkspace, session);
}
}
List<FileSystemItem> children = new ArrayList<FileSystemItem>();
// Add user workspace children
children.addAll(super.getChildren());
// Add synchronization root parent folder
if (syncRootParentFactoryName == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("No synchronization root parent factory name parameter for factory %s, the synchronization roots won't be synchronized client side.", factoryName));
}
} else {
VirtualFolderItemFactory syncRootParentFactory = getFileSystemItemAdapterService().getVirtualFolderItemFactory(syncRootParentFactoryName);
FolderItem syncRootParent = syncRootParentFactory.getVirtualFolderItem(principal);
if (syncRootParent != null) {
children.add(syncRootParent);
}
}
return children;
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class UserWorkspaceTopLevelFactory method getTopLevelFolderItem.
/*----------------------- TopLevelFolderItemFactory ---------------------*/
@Override
public FolderItem getTopLevelFolderItem(Principal principal) {
RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
// TODO: handle multiple repositories
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryManager.getDefaultRepositoryName(), principal)) {
UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class);
DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session);
if (userWorkspace == null) {
throw new NuxeoException(String.format("No personal workspace found for user %s.", principal.getName()));
}
return (FolderItem) getFileSystemItem(userWorkspace);
}
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession 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;
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFolderItem method doScrollDescendants.
@SuppressWarnings("unchecked")
protected ScrollFileSystemItemList doScrollDescendants(String scrollId, int batchSize, long keepAlive) {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
// Limit batch size sent by the client
checkBatchSize(batchSize);
// Scroll through a batch of documents
ScrollDocumentModelList descendantDocsBatch = getScrollBatch(scrollId, batchSize, session, keepAlive);
String newScrollId = descendantDocsBatch.getScrollId();
if (descendantDocsBatch.isEmpty()) {
// No more descendants left to return
return new ScrollFileSystemItemListImpl(newScrollId, 0);
}
// Adapt documents as FileSystemItems
List<FileSystemItem> descendants = adaptDocuments(descendantDocsBatch, session);
if (log.isDebugEnabled()) {
log.debug(String.format("Retrieved %d descendants of FolderItem %s (batchSize = %d)", descendants.size(), docPath, batchSize));
}
return new ScrollFileSystemItemListImpl(newScrollId, descendants);
}
}
Aggregations