Search in sources :

Example 1 with DocumentEventContext

use of org.nuxeo.ecm.core.event.impl.DocumentEventContext in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveCacheInvalidationListener method handleEvent.

@Override
public void handleEvent(Event event) {
    DocumentEventContext docCtx;
    if (event.getContext() instanceof DocumentEventContext) {
        docCtx = (DocumentEventContext) event.getContext();
    } else {
        // not interested in event that are not related to documents
        return;
    }
    String transition = (String) docCtx.getProperty(LifeCycleConstants.TRANSTION_EVENT_OPTION_TRANSITION);
    if (transition != null && !(LifeCycleConstants.DELETE_TRANSITION.equals(transition) || LifeCycleConstants.UNDELETE_TRANSITION.equals(transition))) {
        // document deletion
        return;
    }
    NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
    if (CollectionConstants.ADDED_TO_COLLECTION.equals(event.getName()) || CollectionConstants.REMOVED_FROM_COLLECTION.equals(event.getName())) {
        driveManager.invalidateCollectionSyncRootMemberCache();
    } else {
        driveManager.handleFolderDeletion((IdRef) docCtx.getSourceDocument().getRef());
    }
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager)

Example 2 with DocumentEventContext

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

Example 3 with DocumentEventContext

use of org.nuxeo.ecm.core.event.impl.DocumentEventContext in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveGroupUpdateListener method fireGroupUpdatedEvent.

protected void fireGroupUpdatedEvent(CoreSession session, DocumentModel source) {
    EventContext context = new DocumentEventContext(session, session.getPrincipal(), source);
    Event event = context.newEvent(NuxeoDriveEvents.GROUP_UPDATED);
    Framework.getService(EventService.class).fireEvent(event);
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) EventContext(org.nuxeo.ecm.core.event.EventContext) DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) Event(org.nuxeo.ecm.core.event.Event) EventService(org.nuxeo.ecm.core.event.EventService)

Example 4 with DocumentEventContext

use of org.nuxeo.ecm.core.event.impl.DocumentEventContext 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 5 with DocumentEventContext

use of org.nuxeo.ecm.core.event.impl.DocumentEventContext in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveManagerImpl method fireEvent.

protected void fireEvent(DocumentModel sourceDocument, CoreSession session, String eventName, String impactedUserName) {
    EventService eventService = Framework.getService(EventService.class);
    DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), sourceDocument);
    ctx.setProperty(CoreEventConstants.REPOSITORY_NAME, session.getRepositoryName());
    ctx.setProperty(CoreEventConstants.SESSION_ID, session.getSessionId());
    ctx.setProperty("category", NuxeoDriveEvents.EVENT_CATEGORY);
    ctx.setProperty(NuxeoDriveEvents.IMPACTED_USERNAME_PROPERTY, impactedUserName);
    Event event = ctx.newEvent(eventName);
    eventService.fireEvent(event);
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) Event(org.nuxeo.ecm.core.event.Event) EventService(org.nuxeo.ecm.core.event.EventService)

Aggregations

DocumentEventContext (org.nuxeo.ecm.core.event.impl.DocumentEventContext)5 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)2 Event (org.nuxeo.ecm.core.event.Event)2 EventContext (org.nuxeo.ecm.core.event.EventContext)2 EventService (org.nuxeo.ecm.core.event.EventService)2 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)1 CoreSession (org.nuxeo.ecm.core.api.CoreSession)1 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)1 ConfigurationService (org.nuxeo.runtime.services.config.ConfigurationService)1