use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveRename method run.
@OperationMethod
public Blob run() throws InvalidOperationException, IOException {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
FileSystemItem fsItem;
try {
fsItem = fileSystemItemManager.rename(id, name, ctx.getPrincipal());
} catch (UnsupportedOperationException e) {
throw new InvalidOperationException(e);
}
return Blobs.createJSONBlobFromValue(fsItem);
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveGetChildren method run.
@OperationMethod
public Blob run() throws IOException {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
List<FileSystemItem> children = fileSystemItemManager.getChildren(id, ctx.getPrincipal());
return Blobs.createJSONBlobFromValue(children);
}
use of org.nuxeo.drive.adapter.FileSystemItem 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.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFolderItem method getFolderItem.
protected FolderItem getFolderItem(Map<DocumentRef, FolderItem> cache, DocumentModel doc, FolderItem parentItem, boolean cacheItem) {
if (cacheItem) {
// NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
FileSystemItem fsItem = getFileSystemItemAdapterService().getFileSystemItem(doc, parentItem, true, false, false);
if (fsItem == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Reached document %s that cannot be adapted as a (possibly virtual) descendant of the top level folder item.", doc.getPathAsString()));
}
return null;
}
FolderItem folderItem = (FolderItem) fsItem;
if (log.isTraceEnabled()) {
log.trace(String.format("Caching FolderItem for doc %s: %s", doc.getPathAsString(), folderItem.getPath()));
}
cache.put(doc.getRef(), folderItem);
return folderItem;
} else {
return parentItem;
}
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFolderItem method adaptDocuments.
/**
* Adapts the given {@link DocumentModelList} as {@link FileSystemItem}s using a cache for the {@link FolderItem}
* ancestors.
*/
protected List<FileSystemItem> adaptDocuments(DocumentModelList docs, CoreSession session) {
Map<DocumentRef, FolderItem> ancestorCache = new HashMap<>();
if (log.isTraceEnabled()) {
log.trace(String.format("Caching current FolderItem for doc %s: %s", docPath, getPath()));
}
ancestorCache.put(new IdRef(docId), this);
List<FileSystemItem> descendants = new ArrayList<>(docs.size());
for (DocumentModel doc : docs) {
FolderItem parent = populateAncestorCache(ancestorCache, doc, session, false);
if (parent == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Cannot adapt parent document of %s as a FileSystemItem, skipping descendant document", doc.getPathAsString()));
continue;
}
}
// NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
FileSystemItem descendant = getFileSystemItemAdapterService().getFileSystemItem(doc, parent, false, false, false);
if (descendant != null) {
if (descendant.isFolder()) {
if (log.isTraceEnabled()) {
log.trace(String.format("Caching descendant FolderItem for doc %s: %s", doc.getPathAsString(), descendant.getPath()));
}
ancestorCache.put(doc.getRef(), (FolderItem) descendant);
}
descendants.add(descendant);
}
}
return descendants;
}
Aggregations