use of org.nuxeo.ecm.core.api.DocumentModel 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.DocumentModel 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;
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class UserSyncRootParentFactory method getVirtualFolderItem.
/*------------------- VirtualFolderItemFactory ------------------- */
@Override
public FolderItem getVirtualFolderItem(Principal principal) {
RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
// TODO: handle multiple repositories
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryManager.getDefaultRepositoryName(), principal)) {
UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class);
DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session);
if (userWorkspace == null) {
throw new NuxeoException(String.format("No personal workspace found for user %s.", principal.getName()));
}
return (FolderItem) getFileSystemItem(userWorkspace);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class UserWorkspaceTopLevelFactory method getTopLevelFolderItem.
/*----------------------- TopLevelFolderItemFactory ---------------------*/
@Override
public FolderItem getTopLevelFolderItem(Principal principal) {
RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
// TODO: handle multiple repositories
try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryManager.getDefaultRepositoryName(), principal)) {
UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class);
DocumentModel userWorkspace = userWorkspaceService.getCurrentUserPersonalWorkspace(session);
if (userWorkspace == null) {
throw new NuxeoException(String.format("No personal workspace found for user %s.", principal.getName()));
}
return (FolderItem) getFileSystemItem(userWorkspace);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveFileSystemDeletionListener method handleBeforeDocUpdate.
protected DocumentModel handleBeforeDocUpdate(DocumentEventContext ctx, DocumentModel doc) {
// Interested in update of a BlobHolder whose blob has been removed
boolean blobRemoved = false;
DocumentModel previousDoc = (DocumentModel) ctx.getProperty(CoreEventConstants.PREVIOUS_DOCUMENT_MODEL);
if (previousDoc != null) {
BlobHolder previousBh = previousDoc.getAdapter(BlobHolder.class);
if (previousBh != null) {
BlobHolder bh = doc.getAdapter(BlobHolder.class);
if (bh != null) {
blobRemoved = previousBh.getBlob() != null && bh.getBlob() == null;
}
}
}
if (blobRemoved) {
// FileSystemItem
return previousDoc;
} else {
return null;
}
}
Aggregations