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());
}
}
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());
}
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);
}
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);
}
}
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);
}
Aggregations