use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFolderItem method getChildren.
/*--------------------- FolderItem -----------------*/
@Override
@SuppressWarnings("unchecked")
public List<FileSystemItem> getChildren() {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
PageProviderService pageProviderService = Framework.getService(PageProviderService.class);
Map<String, Serializable> props = new HashMap<>();
props.put(CORE_SESSION_PROPERTY, (Serializable) session);
PageProvider<DocumentModel> childrenPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(FOLDER_ITEM_CHILDREN_PAGE_PROVIDER, null, null, 0L, props, docId);
long pageSize = childrenPageProvider.getPageSize();
List<FileSystemItem> children = new ArrayList<>();
int nbChildren = 0;
boolean reachedPageSize = false;
boolean hasNextPage = true;
// FileSystemItems
while (nbChildren < pageSize && hasNextPage) {
List<DocumentModel> dmChildren = childrenPageProvider.getCurrentPage();
for (DocumentModel dmChild : dmChildren) {
// NXP-19442: Avoid useless and costly call to DocumentModel#getLockInfo
FileSystemItem child = getFileSystemItemAdapterService().getFileSystemItem(dmChild, this, false, false, false);
if (child != null) {
children.add(child);
nbChildren++;
if (nbChildren == pageSize) {
reachedPageSize = true;
break;
}
}
}
if (!reachedPageSize) {
hasNextPage = childrenPageProvider.isNextPageAvailable();
if (hasNextPage) {
childrenPageProvider.nextPage();
}
}
}
return children;
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFolderItem method populateAncestorCache.
protected FolderItem populateAncestorCache(Map<DocumentRef, FolderItem> cache, DocumentModel doc, CoreSession session, boolean cacheItem) {
DocumentRef parentDocRef = session.getParentDocumentRef(doc.getRef());
if (parentDocRef == null) {
throw new RootlessItemException("Reached repository root");
}
FolderItem parentItem = cache.get(parentDocRef);
if (parentItem != null) {
if (log.isTraceEnabled()) {
log.trace(String.format("Found parent FolderItem in cache for doc %s: %s", doc.getPathAsString(), parentItem.getPath()));
}
return getFolderItem(cache, doc, parentItem, cacheItem);
}
if (log.isTraceEnabled()) {
log.trace(String.format("No parent FolderItem found in cache for doc %s, computing ancestor cache", doc.getPathAsString()));
}
DocumentModel parentDoc;
try {
parentDoc = session.getDocument(parentDocRef);
} catch (DocumentSecurityException e) {
throw new RootlessItemException(String.format("User %s has no READ access on parent of document %s (%s).", principal.getName(), doc.getPathAsString(), doc.getId()), e);
}
parentItem = populateAncestorCache(cache, parentDoc, session, true);
if (parentItem == null) {
return null;
}
return getFolderItem(cache, doc, parentItem, cacheItem);
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFolderItem method rename.
/*--------------------- FileSystemItem ---------------------*/
@Override
public void rename(String name) {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
// Update doc properties
DocumentModel doc = getDocument(session);
doc.setPropertyValue("dc:title", name);
doc.putContextData(CoreSession.SOURCE, "drive");
doc = session.saveDocument(doc);
session.save();
// Update FileSystemItem attributes
this.docTitle = name;
this.name = name;
updateLastModificationDate(doc);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class SharedSyncRootParentFolderItem method getChildren.
@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);
// principal)
if (!session.getPrincipal().getName().equals(doc.getPropertyValue("dc:creator"))) {
// 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, maybe because user %s doesn't have the required permission on it (default required permission is ReadWrite). Not including it in children.", idRef, session.getPrincipal().getName()));
}
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.DocumentModel in project nuxeo-drive-server by nuxeo.
the class AbstractDocumentBackedFileSystemItem method handleCollectionMember.
protected boolean handleCollectionMember(DocumentModel doc, CoreSession session, boolean relaxSyncRootConstraint, boolean getLockInfo) {
if (!doc.hasSchema(CollectionConstants.COLLECTION_MEMBER_SCHEMA_NAME)) {
return false;
}
CollectionManager cm = Framework.getService(CollectionManager.class);
List<DocumentModel> docCollections = cm.getVisibleCollection(doc, session);
if (docCollections.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace(String.format("Doc %s (%s) is not member of any collection", doc.getPathAsString(), doc.getId()));
}
return false;
} else {
FileSystemItem parent = null;
DocumentModel collection = null;
Iterator<DocumentModel> it = docCollections.iterator();
while (it.hasNext() && parent == null) {
collection = it.next();
// as a FileSystemItem and this collection is not a synchronization root for the current user
if (collection.getPathAsString().startsWith(doc.getPathAsString() + "/") && !Framework.getService(NuxeoDriveManager.class).isSynchronizationRoot(session.getPrincipal(), collection)) {
continue;
}
try {
parent = getFileSystemItemAdapterService().getFileSystemItem(collection, true, relaxSyncRootConstraint, getLockInfo);
} catch (RootlessItemException e) {
if (log.isTraceEnabled()) {
log.trace(String.format("The collection %s (%s) of which doc %s (%s) is a member cannot be adapted as a FileSystemItem.", collection.getPathAsString(), collection.getId(), doc.getPathAsString(), doc.getId()));
}
continue;
}
}
if (parent == null) {
if (log.isTraceEnabled()) {
log.trace(String.format("None of the collections of which doc %s (%s) is a member can be adapted as a FileSystemItem.", doc.getPathAsString(), doc.getId()));
}
return false;
}
if (log.isTraceEnabled()) {
log.trace(String.format("Using first collection %s (%s) of which doc %s (%s) is a member and that is adaptable as a FileSystemItem as a parent FileSystemItem.", collection.getPathAsString(), collection.getId(), doc.getPathAsString(), doc.getId()));
}
parentId = parent.getId();
path = parent.getPath() + '/' + id;
return true;
}
}
Aggregations