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