use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveSyncRootVersioningListener method handleEvent.
@Override
public void handleEvent(Event event) {
EventContext context = event.getContext();
DocumentRef checkedInVersionRef = (DocumentRef) context.getProperty("checkedInVersionRef");
if (checkedInVersionRef == null) {
return;
}
CoreSession session = context.getCoreSession();
DocumentModel doc = session.getDocument(checkedInVersionRef);
if (!(doc.isVersion() && doc.hasFacet(NuxeoDriveManagerImpl.NUXEO_DRIVE_FACET))) {
return;
}
doc.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
doc.putContextData(CoreSession.ALLOW_VERSION_WRITE, Boolean.TRUE);
doc.putContextData("source", "drive");
doc.putContextData(CoreSession.SOURCE, "drive");
session.saveDocument(doc);
}
use of org.nuxeo.ecm.core.api.DocumentModel 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.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class AbstractDocumentBackedFileSystemItem method move.
@Override
public FileSystemItem move(FolderItem dest) {
DocumentRef sourceDocRef = new IdRef(docId);
AbstractDocumentBackedFileSystemItem docBackedDest = (AbstractDocumentBackedFileSystemItem) dest;
String destRepoName = docBackedDest.getRepositoryName();
DocumentRef destDocRef = new IdRef(docBackedDest.getDocId());
// create doc in destination
if (repositoryName.equals(destRepoName)) {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
DocumentModel movedDoc = session.move(sourceDocRef, destDocRef, null);
session.save();
return getFileSystemItemAdapterService().getFileSystemItem(movedDoc, dest);
}
} else {
// TODO: implement move to another repository
throw new UnsupportedOperationException("Multi repository move is not supported yet.");
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class DefaultSyncRootFolderItem method delete.
@Override
public void delete() {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
DocumentModel doc = getDocument(session);
Framework.getService(NuxeoDriveManager.class).unregisterSynchronizationRoot(principal, doc, session);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFileItem method rename.
/*--------------------- FileSystemItem ---------------------*/
@Override
public void rename(String name) {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
/* Update doc properties */
DocumentModel doc = getDocument(session);
BlobHolder bh = getBlobHolder(doc);
Blob blob = getBlob(bh);
blob.setFilename(name);
bh.setBlob(blob);
updateDocTitleIfNeeded(doc, name);
doc.putContextData(CoreSession.SOURCE, "drive");
doc = session.saveDocument(doc);
session.save();
/* Update FileSystemItem attributes */
this.name = name;
updateDownloadURL();
updateLastModificationDate(doc);
}
}
Aggregations