Search in sources :

Example 1 with EventStreamException

use of org.xwiki.eventstream.EventStreamException in project xwiki-platform by xwiki.

the class DefaultModelBridge method findDocument.

private XWikiDocument findDocument(EntityReference entityReference) throws EventStreamException {
    XWikiContext context = contextProvider.get();
    XWiki xwiki = context.getWiki();
    try {
        return xwiki.getDocument(entityReference, context);
    } catch (XWikiException e) {
        throw new EventStreamException(String.format("Unable to retrieve the given document [%s] in the current context.", entityReference), e);
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) EventStreamException(org.xwiki.eventstream.EventStreamException) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with EventStreamException

use of org.xwiki.eventstream.EventStreamException in project xwiki-platform by xwiki.

the class DefaultUntypedRecordableEventDescriptor method setProperties.

/**
 * Set the object attributes by extracting their values from the given BaseObject.
 *
 * @param untypedEventObject the XObject that should contain the desired values
 * @throws EventStreamException if the properties could not be extracted
 */
private void setProperties(BaseObject untypedEventObject) throws EventStreamException {
    try {
        this.eventType = untypedEventObject.getStringValue(UNTYPED_EVENT_EVENT_TYPE);
        this.validationExpression = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_VALIDATION_EXPRESSION);
        this.target = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_TARGET);
        this.objectTypes = untypedEventObject.getListValue(UNTYPED_EVENT_DESCRIPTOR_OBJECT_TYPE);
        this.eventDescription = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_DESCRIPTION);
        this.eventTriggers = untypedEventObject.getListValue(UNTYPED_EVENT_DESCRIPTOR_EVENT_TRIGGERS);
        this.applicationName = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_APPLICATION_NAME);
        // If the applicationId property is not defined, fallback on the applicationName
        String rawApplicationIdProperty = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_APPLICATION_ID);
        this.applicationId = (rawApplicationIdProperty != null && StringUtils.isNotBlank(rawApplicationIdProperty)) ? rawApplicationIdProperty : this.applicationName;
        this.applicationIcon = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_APPLICATION_ICON);
        this.eventTypeIcon = untypedEventObject.getStringValue(UNTYPED_EVENT_DESCRIPTOR_EVENT_TYPE_ICON);
    } catch (Exception e) {
        throw new EventStreamException(String.format("Unable to extract the parameters of the [%s] EventClass.", untypedEventObject), e);
    }
}
Also used : EventStreamException(org.xwiki.eventstream.EventStreamException) EventStreamException(org.xwiki.eventstream.EventStreamException)

Example 3 with EventStreamException

use of org.xwiki.eventstream.EventStreamException in project xwiki-platform by xwiki.

the class DefaultRecordableEventDescriptorManager method getRecordableEventDescriptors.

@Override
public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException {
    try {
        // We use an hashSet to be sure we won't store the same descriptor twice (in case the same application
        // is installed on several wikis).
        Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>();
        // Load the component from the context component manager (root + wiki + user component managers, etc...)
        recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class));
        // Maybe add components of the other wikis too
        if (allWikis) {
            for (String wikiId : wikiDescriptorManager.getAllIds()) {
                recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId));
            }
        }
        return new ArrayList<>(recordableEventDescriptors);
    } catch (WikiManagerException | ComponentLookupException e) {
        throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e);
    }
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) ArrayList(java.util.ArrayList) EventStreamException(org.xwiki.eventstream.EventStreamException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) HashSet(java.util.HashSet)

Example 4 with EventStreamException

use of org.xwiki.eventstream.EventStreamException in project xwiki-platform by xwiki.

the class LiveNotificationEmailListener method onEvent.

@Override
public void onEvent(Event event, Object o, Object o1) {
    // notifications is enabled.
    if (this.notificationConfiguration.isEnabled() && this.notificationConfiguration.areEmailsEnabled()) {
        try {
            org.xwiki.eventstream.Event eventStreamEvent = (org.xwiki.eventstream.Event) o;
            // We can’t directly store a list of RecordableEventDescriptors as some of them can be
            // dynamically defined at runtime.
            List<RecordableEventDescriptor> descriptorList = this.recordableEventDescriptorManager.getRecordableEventDescriptors(true);
            // Try to match one of the given descriptors with the current event.
            for (RecordableEventDescriptor descriptor : descriptorList) {
                // Find a descriptor that corresponds to the given event
                if (descriptor.getEventType().equals(eventStreamEvent.getType())) {
                    // Add the event to the live notification email queue
                    this.liveNotificationEmailManager.addEvent(eventStreamEvent);
                    this.startNotificationThread();
                }
            }
        } catch (EventStreamException e) {
            logger.warn("Unable to retrieve a full list of RecordableEventDescriptor.", e);
        }
    }
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) Event(org.xwiki.observation.event.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) EventStreamException(org.xwiki.eventstream.EventStreamException)

Aggregations

EventStreamException (org.xwiki.eventstream.EventStreamException)4 RecordableEventDescriptor (org.xwiki.eventstream.RecordableEventDescriptor)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)1 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)1 Event (org.xwiki.observation.event.Event)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1