Search in sources :

Example 1 with CoreSession

use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveGroupUpdateListener method handleUpdatedGroups.

protected void handleUpdatedGroups(List<String> groupNames) {
    RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
    for (String repositoryName : repositoryManager.getRepositoryNames()) {
        CoreInstance.doPrivileged(repositoryName, (CoreSession session) -> {
            DocumentModelList impactedDocuments = getImpactedDocuments(session, groupNames);
            impactedDocuments.forEach(doc -> fireGroupUpdatedEvent(session, doc));
        });
    }
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) RepositoryManager(org.nuxeo.ecm.core.api.repository.RepositoryManager) CoreSession(org.nuxeo.ecm.core.api.CoreSession)

Example 2 with CoreSession

use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveSyncRootCopyListener method handleEvent.

@Override
public void handleEvent(Event event) {
    if (Framework.getService(ConfigurationService.class).isBooleanPropertyFalse(RESET_SYNC_ROOTS_ON_COPY_CONFIGURATION_PROPERTY)) {
        return;
    }
    EventContext context = event.getContext();
    if (!(context instanceof DocumentEventContext)) {
        return;
    }
    DocumentModel doc = ((DocumentEventContext) context).getSourceDocument();
    CoreSession session = context.getCoreSession();
    DocumentModelList syncRoots = getSyncRoots(doc, session);
    for (DocumentModel syncRoot : syncRoots) {
        syncRoot.setPropertyValue(NuxeoDriveManagerImpl.DRIVE_SUBSCRIPTIONS_PROPERTY, null);
        syncRoot.putContextData("source", "drive");
        syncRoot.putContextData(CoreSession.SOURCE, "drive");
        session.saveDocument(syncRoot);
    }
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) EventContext(org.nuxeo.ecm.core.event.EventContext) DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) ConfigurationService(org.nuxeo.runtime.services.config.ConfigurationService) CoreSession(org.nuxeo.ecm.core.api.CoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 3 with CoreSession

use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method getSession.

@Deprecated
@Override
public CoreSession getSession(String repositoryName, Principal principal) {
    final String sessionKey = repositoryName + "/" + principal.getName();
    CoreSession session = openedSessions.get().get(sessionKey);
    if (session == null) {
        Map<String, Serializable> context = new HashMap<String, Serializable>();
        context.put("principal", (Serializable) principal);
        final CloseableCoreSession newSession = CoreInstance.openCoreSession(repositoryName, principal);
        openedSessions.get().put(sessionKey, newSession);
        try {
            Transaction t = TransactionHelper.lookupTransactionManager().getTransaction();
            if (t == null) {
                throw new RuntimeException("FileSystemItemManagerImpl requires an active transaction.");
            }
            t.registerSynchronization(new SessionCloser(newSession, sessionKey));
        } catch (SystemException | NamingException | RollbackException e) {
            throw new NuxeoException(e);
        }
        session = newSession;
    }
    return session;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) RollbackException(javax.transaction.RollbackException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NamingException(javax.naming.NamingException) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) CoreSession(org.nuxeo.ecm.core.api.CoreSession) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 4 with CoreSession

use of org.nuxeo.ecm.core.api.CoreSession in project nuxeo-drive-server by nuxeo.

the class PermissionSyncRootFactory method isFileSystemItem.

/**
 * Checks if the given {@link DocumentModel} is adaptable as a {@link FileSystemItem}. The permission
 * synchronization root factory considers that a {@link DocumentModel} is adaptable as a {@link FileSystemItem} if:
 * <ul>
 * <li>It is Folderish</li>
 * <li>AND it is not a version nor a proxy</li>
 * <li>AND it is not HiddenInNavigation</li>
 * <li>AND it is not in the trash, unless {@code includeDeleted} is true</li>
 * <li>AND it is a synchronization root registered for the current user, unless {@code relaxSyncRootConstraint} is
 * true</li>
 * <li>AND the current user has the {@link #getRequiredPermission()} permission on the document</li>
 * </ul>
 */
@Override
public boolean isFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint) {
    // Check required permission
    CoreSession session = doc.getCoreSession();
    boolean hasRequiredPermission = session.hasPermission(doc.getRef(), requiredPermission);
    if (!hasRequiredPermission) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Required permission %s is not granted on document %s to user %s, it cannot be adapted as a FileSystemItem.", requiredPermission, doc.getId(), session.getPrincipal().getName()));
        }
        return false;
    }
    return super.isFileSystemItem(doc, includeDeleted, relaxSyncRootConstraint) && hasRequiredPermission;
}
Also used : CoreSession(org.nuxeo.ecm.core.api.CoreSession)

Example 5 with CoreSession

use of org.nuxeo.ecm.core.api.CoreSession 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);
}
Also used : EventContext(org.nuxeo.ecm.core.event.EventContext) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CoreSession(org.nuxeo.ecm.core.api.CoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

CoreSession (org.nuxeo.ecm.core.api.CoreSession)7 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)2 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)2 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)2 EventContext (org.nuxeo.ecm.core.event.EventContext)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 NamingException (javax.naming.NamingException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 Transaction (javax.transaction.Transaction)1 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)1 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)1 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)1 RepositoryManager (org.nuxeo.ecm.core.api.repository.RepositoryManager)1 DocumentEventContext (org.nuxeo.ecm.core.event.impl.DocumentEventContext)1 WebContext (org.nuxeo.ecm.webengine.model.WebContext)1 ConfigurationService (org.nuxeo.runtime.services.config.ConfigurationService)1