use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testScrollDescendantsIncludingCollections.
@Test
public void testScrollDescendantsIncludingCollections() {
log.trace("Add a document to a new collection \"testCollection\" created in \"/default-domain/UserWorkspaces/Administrator/Collections\"");
collectionManager.addToNewCollection("testCollection", null, file, session);
DocumentModel userCollections = collectionManager.getUserDefaultCollections(null, session);
DocumentModel userWorkspace = session.getParentDocument(userCollections.getRef());
log.trace("Create \"testFolder\" in \"/default-domain/UserWorkspaces/Administrator\"");
DocumentModel testFolder = session.createDocumentModel(userWorkspace.getPathAsString(), "testFolder", "Folder");
testFolder = session.createDocument(testFolder);
log.trace("Register \"/default-domain/UserWorkspaces/Administrator\" as a synchronization root for Administrator");
nuxeoDriveManager.registerSynchronizationRoot(principal, userWorkspace, session);
log.trace("Scroll through the descendants of \"/default-domain/UserWorkspaces/Administrator\", expecting one: \"testFolder\", " + "the \"Collections\" folder and its descendants being ignored");
FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
FolderItem userWorkspaceFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(userWorkspace);
ScrollFileSystemItemList descendants = userWorkspaceFolderItem.scrollDescendants(null, 10, 1000);
assertEquals(1, descendants.size());
FileSystemItem descendant = descendants.get(0);
assertTrue(descendant.isFolder());
assertEquals("testFolder", descendant.getName());
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class UserSyncRootParentFolderItem method getChildren.
@Override
public List<FileSystemItem> getChildren() {
if (isUserWorkspaceSyncRoot) {
return super.getChildren();
} else {
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 UserWorkspaceSyncRootParentFolderItem 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);
// registered as a synchronization root to avoid recursion
if (!UserWorkspaceHelper.isUserWorkspace(doc)) {
// 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 NuxeoDriveFileSystemDeletionListener method fireVirtualEventLogEntries.
protected void fireVirtualEventLogEntries(DocumentModel doc, String eventName, Principal principal, String impactedUserName, CoreSession session) {
if (Framework.getService(AuditLogger.class) == null) {
// The log is not deployed (probably in unittest)
return;
}
List<LogEntry> entries = new ArrayList<>();
// XXX: shall we use the server local for the event date or UTC?
Date currentDate = Calendar.getInstance(NuxeoDriveManagerImpl.UTC).getTime();
FileSystemItem fsItem = getFileSystemItem(doc, eventName);
if (fsItem == null) {
// roots in order to make Drive add / remove them if needed
if (NuxeoDriveEvents.SECURITY_UPDATED_EVENT.equals(eventName)) {
for (DocumentModel childSyncRoot : getChildSyncRoots(doc, session)) {
FileSystemItem childSyncRootFSItem = getFileSystemItem(childSyncRoot, eventName);
if (childSyncRootFSItem != null) {
entries.add(computeLogEntry(eventName, currentDate, childSyncRoot.getId(), childSyncRoot.getPathAsString(), principal.getName(), childSyncRoot.getType(), childSyncRoot.getRepositoryName(), childSyncRoot.getCurrentLifeCycleState(), impactedUserName, childSyncRootFSItem));
}
}
}
} else {
entries.add(computeLogEntry(eventName, currentDate, doc.getId(), doc.getPathAsString(), principal.getName(), doc.getType(), doc.getRepositoryName(), doc.getCurrentLifeCycleState(), impactedUserName, fsItem));
}
if (!entries.isEmpty()) {
EventContext eventContext = new EventContextImpl(entries.toArray());
Event event = eventContext.newEvent(NuxeoDriveEvents.VIRTUAL_EVENT_CREATED);
Framework.getService(EventProducer.class).fireEvent(event);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveFileSystemDeletionListener method handleEvent.
@Override
public void handleEvent(Event event) {
DocumentEventContext ctx;
if (event.getContext() instanceof DocumentEventContext) {
ctx = (DocumentEventContext) event.getContext();
} else {
// Not interested in events that are not related to documents
return;
}
DocumentModel doc = ctx.getSourceDocument();
if (doc.hasFacet(FacetNames.SYSTEM_DOCUMENT)) {
// Not interested in system documents
return;
}
DocumentModel docForLogEntry = doc;
if (DocumentEventTypes.BEFORE_DOC_UPDATE.equals(event.getName())) {
docForLogEntry = handleBeforeDocUpdate(ctx, doc);
if (docForLogEntry == null) {
return;
}
}
if (LifeCycleConstants.TRANSITION_EVENT.equals(event.getName()) && !handleLifeCycleTransition(ctx)) {
return;
}
if (DocumentEventTypes.ABOUT_TO_REMOVE.equals(event.getName()) && !handleAboutToRemove(doc)) {
return;
}
if (log.isDebugEnabled()) {
log.debug(String.format("NuxeoDriveFileSystemDeletionListener handling %s event for %s", event.getName(), doc));
}
// Virtual event name
String virtualEventName;
if (DocumentEventTypes.BEFORE_DOC_SECU_UPDATE.equals(event.getName()) || NuxeoDriveEvents.GROUP_UPDATED.equals(event.getName())) {
virtualEventName = NuxeoDriveEvents.SECURITY_UPDATED_EVENT;
} else if (DocumentEventTypes.ABOUT_TO_MOVE.equals(event.getName())) {
virtualEventName = NuxeoDriveEvents.MOVED_EVENT;
} else {
virtualEventName = NuxeoDriveEvents.DELETED_EVENT;
}
// Some events will only impact a specific user (e.g. root
// unregistration)
String impactedUserName = (String) ctx.getProperty(NuxeoDriveEvents.IMPACTED_USERNAME_PROPERTY);
fireVirtualEventLogEntries(docForLogEntry, virtualEventName, ctx.getPrincipal(), impactedUserName, ctx.getCoreSession());
}
Aggregations