use of org.nuxeo.ecm.core.api.CloseableCoreSession 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.CloseableCoreSession 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.CloseableCoreSession 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);
}
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFileItem method setBlob.
@Override
public void setBlob(Blob blob) {
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
/* Update doc properties */
DocumentModel doc = getDocument(session);
// If blob's filename is empty, set it to the current name
String blobFileName = blob.getFilename();
if (StringUtils.isEmpty(blobFileName)) {
blob.setFilename(name);
} else {
updateDocTitleIfNeeded(doc, blobFileName);
name = blobFileName;
updateDownloadURL();
}
BlobHolder bh = getBlobHolder(doc);
bh.setBlob(blob);
doc.putContextData(CoreSession.SOURCE, "drive");
doc = session.saveDocument(doc);
session.save();
/* Update FileSystemItem attributes */
updateLastModificationDate(doc);
updateDigest(getBlob(doc));
}
}
use of org.nuxeo.ecm.core.api.CloseableCoreSession 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;
}
}
Aggregations