use of org.nuxeo.drive.adapter.FileSystemItem 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.drive.adapter.FileSystemItem 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.drive.adapter.FileSystemItem 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);
}
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class PermissionTopLevelFolderItem method getChildren.
@Override
public List<FileSystemItem> getChildren() {
List<FileSystemItem> children = new ArrayList<FileSystemItem>();
for (String childFactoryName : childrenFactoryNames) {
VirtualFolderItemFactory factory = getFileSystemItemAdapterService().getVirtualFolderItemFactory(childFactoryName);
FolderItem child = factory.getVirtualFolderItem(principal);
if (child != null) {
children.add(child);
}
}
return children;
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class AbstractFileSystemItemFactory method getFileSystemItemById.
@Override
public FileSystemItem getFileSystemItemById(String id, String parentId, Principal principal) {
String[] idFragments = parseFileSystemId(id);
String repositoryName = idFragments[1];
String docId = idFragments[2];
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
FileSystemItem parentItem = Framework.getService(FileSystemItemAdapterService.class).getFileSystemItemFactoryForId(parentId).getFileSystemItemById(parentId, principal);
if (!(parentItem instanceof FolderItem)) {
throw new NuxeoException(String.format("FileSystemItem with id %s should be a FolderItem", parentId));
}
DocumentModel doc = getDocumentById(docId, session);
return getFileSystemItem(doc, (FolderItem) parentItem);
} catch (DocumentNotFoundException e) {
if (log.isDebugEnabled()) {
log.debug(String.format("No doc related to id %s, returning null.", docId));
}
return null;
} catch (DocumentSecurityException e) {
if (log.isDebugEnabled()) {
log.debug(String.format("User %s cannot access doc %s, returning null.", principal.getName(), docId));
}
return null;
}
}
Aggregations