use of org.nuxeo.ecm.core.api.CloseableCoreSession 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.CloseableCoreSession 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.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class AbstractDocumentBackedFileSystemItem method canMove.
@Override
public boolean canMove(FolderItem dest) {
// Check source doc deletion
if (!canDelete) {
return false;
}
// Check add children on destination doc
AbstractDocumentBackedFileSystemItem docBackedDest = (AbstractDocumentBackedFileSystemItem) dest;
String destRepoName = docBackedDest.getRepositoryName();
DocumentRef destDocRef = new IdRef(docBackedDest.getDocId());
String sessionRepo = repositoryName;
// session bound to the destination repository
if (!repositoryName.equals(destRepoName)) {
sessionRepo = destRepoName;
}
try (CloseableCoreSession session = CoreInstance.openCoreSession(sessionRepo, principal)) {
if (!session.hasPermission(destDocRef, SecurityConstants.ADD_CHILDREN)) {
return false;
}
return true;
}
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class AbstractDocumentBackedFileSystemItem method delete.
/*--------------------- FileSystemItem ---------------------*/
@Override
public void delete() {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
DocumentModel doc = getDocument(session);
FileSystemItemFactory parentFactory = getFileSystemItemAdapterService().getFileSystemItemFactoryForId(parentId);
// Handle removal from a collection sync root
if (CollectionSyncRootFolderItemFactory.FACTORY_NAME.equals(parentFactory.getName())) {
String[] idFragments = parseFileSystemId(parentId);
String parentRepositoryName = idFragments[1];
String parentDocId = idFragments[2];
if (!parentRepositoryName.equals(repositoryName)) {
throw new UnsupportedOperationException(String.format("Found collection member: %s [repo=%s] in a different repository from the collection one: %s [repo=%s].", doc, repositoryName, parentDocId, parentRepositoryName));
}
DocumentModel collection = getDocumentById(parentDocId, session);
Framework.getService(CollectionManager.class).removeFromCollection(collection, doc, session);
} else {
List<DocumentModel> docs = new ArrayList<DocumentModel>();
docs.add(doc);
getTrashService().trashDocuments(docs);
}
}
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class CollectionSyncRootFolderItem method getChildren.
@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<String, Serializable>();
props.put(CORE_SESSION_PROPERTY, (Serializable) session);
PageProvider<DocumentModel> childrenPageProvider = (PageProvider<DocumentModel>) pageProviderService.getPageProvider(CollectionConstants.COLLECTION_CONTENT_PAGE_PROVIDER, null, null, 0L, props, docId);
List<DocumentModel> dmChildren = childrenPageProvider.getCurrentPage();
List<FileSystemItem> children = new ArrayList<FileSystemItem>(dmChildren.size());
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);
}
}
return children;
}
}
Aggregations