Search in sources :

Example 1 with EventContext

use of org.nuxeo.ecm.core.event.EventContext 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);
    }
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) EventContext(org.nuxeo.ecm.core.event.EventContext) AuditLogger(org.nuxeo.ecm.platform.audit.api.AuditLogger) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) EventContextImpl(org.nuxeo.ecm.core.event.impl.EventContextImpl) ArrayList(java.util.ArrayList) EventProducer(org.nuxeo.ecm.core.event.EventProducer) Event(org.nuxeo.ecm.core.event.Event) LogEntry(org.nuxeo.ecm.platform.audit.api.LogEntry) Date(java.util.Date) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 2 with EventContext

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

the class NuxeoDriveGroupUpdateListener method handleEvent.

@Override
public void handleEvent(EventBundle events) {
    for (Event event : events) {
        EventContext context = event.getContext();
        if (context == null) {
            continue;
        }
        String groupName = (String) context.getProperty(UserManagerImpl.ID_PROPERTY_KEY);
        if (groupName == null) {
            continue;
        }
        if (log.isDebugEnabled()) {
            log.debug(String.format("NuxeoDriveGroupUpdateListener handling %s event for group %s", event.getName(), groupName));
        }
        List<String> groupNames = getAllGroupNames(groupName, context);
        handleUpdatedGroups(groupNames);
    }
}
Also used : DocumentEventContext(org.nuxeo.ecm.core.event.impl.DocumentEventContext) EventContext(org.nuxeo.ecm.core.event.EventContext) Event(org.nuxeo.ecm.core.event.Event)

Example 3 with EventContext

use of org.nuxeo.ecm.core.event.EventContext 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 EventContext

use of org.nuxeo.ecm.core.event.EventContext 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 EventContext

use of org.nuxeo.ecm.core.event.EventContext 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

EventContext (org.nuxeo.ecm.core.event.EventContext)6 Event (org.nuxeo.ecm.core.event.Event)4 DocumentEventContext (org.nuxeo.ecm.core.event.impl.DocumentEventContext)4 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)3 ArrayList (java.util.ArrayList)2 CoreSession (org.nuxeo.ecm.core.api.CoreSession)2 AuditLogger (org.nuxeo.ecm.platform.audit.api.AuditLogger)2 LogEntry (org.nuxeo.ecm.platform.audit.api.LogEntry)2 Date (java.util.Date)1 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)1 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)1 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)1 EventProducer (org.nuxeo.ecm.core.event.EventProducer)1 EventService (org.nuxeo.ecm.core.event.EventService)1 EventContextImpl (org.nuxeo.ecm.core.event.impl.EventContextImpl)1 ConfigurationService (org.nuxeo.runtime.services.config.ConfigurationService)1