use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.
the class UserWorkspaceSyncRootParentFactory method getVirtualFolderItem.
@Override
public FolderItem getVirtualFolderItem(Principal principal) {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(principal);
if (topLevelFolder == null) {
throw new NuxeoException("Found no top level folder item. Please check your contribution to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"topLevelFolderItemFactory\">.");
}
return new UserWorkspaceSyncRootParentFolderItem(getName(), principal, topLevelFolder.getId(), topLevelFolder.getPath(), folderName);
}
use of org.nuxeo.ecm.core.api.NuxeoException 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.NuxeoException 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.NuxeoException 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;
}
}
use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.
the class FileSystemItemManagerImpl method move.
@Override
public FileSystemItem move(String srcId, String destId, Principal principal) {
FileSystemItem srcFsItem = getFileSystemItemById(srcId, principal);
if (srcFsItem == null) {
throw new NuxeoException(String.format("Cannot move file system item with id %s because it doesn't exist.", srcId));
}
FileSystemItem destFsItem = getFileSystemItemById(destId, principal);
if (destFsItem == null) {
throw new NuxeoException(String.format("Cannot move a file system item to file system item with id %s because it doesn't exist.", destId));
}
if (!(destFsItem instanceof FolderItem)) {
throw new NuxeoException(String.format("Cannot move a file system item to file system item with id %s because it is not a folder.", destId));
}
return srcFsItem.move((FolderItem) destFsItem);
}
Aggregations