Search in sources :

Example 21 with CompositeEvent

use of org.xwiki.notifications.CompositeEvent in project xwiki-platform by xwiki.

the class DefaultCompositeEventStatusManager method getCompositeEventStatuses.

@Override
public List<CompositeEventStatus> getCompositeEventStatuses(List<CompositeEvent> compositeEvents, String entityId) throws Exception {
    // Creating a list of all events to avoid multiple calls to getEventStatuses() and so multiple calls to the
    // database.
    List<Event> allEvents = new ArrayList<>();
    // But maintain a mapping between eventId and their composite event status
    Map<String, CompositeEventStatus> map = new HashMap<>();
    for (CompositeEvent compositeEvent : compositeEvents) {
        CompositeEventStatus compositeEventStatus = new CompositeEventStatus(compositeEvent);
        for (Event event : compositeEvent.getEvents()) {
            map.put(event.getId(), compositeEventStatus);
        }
        allEvents.addAll(compositeEvent.getEvents());
    }
    // Put the event statuses into the composite events statuses
    for (EventStatus eventStatus : getEventStatuses(allEvents, entityId)) {
        map.get(eventStatus.getEvent().getId()).add(eventStatus);
    }
    List<CompositeEventStatus> results = new ArrayList<>();
    // Keep the same order than inputs
    for (CompositeEvent event : compositeEvents) {
        results.add(map.get(event.getEvents().get(0).getId()));
    }
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompositeEventStatus(org.xwiki.notifications.CompositeEventStatus) EventStatus(org.xwiki.eventstream.EventStatus) CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) CompositeEventStatus(org.xwiki.notifications.CompositeEventStatus)

Example 22 with CompositeEvent

use of org.xwiki.notifications.CompositeEvent in project xwiki-platform by xwiki.

the class DefaultNotificationRSSRendererTest method mockEvent.

private void mockEvent(CompositeEvent testCompositeEvent) throws Exception {
    Event testEvent1 = mock(Event.class);
    Date testEventDate = mock(Date.class);
    when(testEvent1.getTitle()).thenReturn("EventTitle");
    when(testEvent1.getDocumentTitle()).thenReturn("EventDocumentTitle");
    when(this.contextualLocalizationManager.getTranslationPlain("EventTitle", "EventDocumentTitle")).thenReturn("TranslatedEventTitle");
    DocumentReference testEventAuthor1 = new DocumentReference("xwiki", "XWiki", "AuthorName");
    when(this.templateManager.getTemplate(ArgumentMatchers.any())).thenReturn(Mockito.mock(Template.class));
    when(testCompositeEvent.getEvents()).thenReturn(Arrays.asList(testEvent1));
    when(testCompositeEvent.getUsers()).thenReturn(new HashSet<>(Arrays.asList(testEventAuthor1)));
    when(testCompositeEvent.getEventIds()).thenReturn(Arrays.asList("id1"));
    when(testCompositeEvent.getType()).thenReturn("eventType");
    when(testCompositeEvent.getDates()).thenReturn(Arrays.asList(testEventDate));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) Template(org.xwiki.template.Template)

Example 23 with CompositeEvent

use of org.xwiki.notifications.CompositeEvent in project xwiki-platform by xwiki.

the class LiveNotificationEmailSenderTest method testSendMail.

@Test
public void testSendMail() throws Exception {
    CompositeEvent event1 = mock(CompositeEvent.class);
    when(this.wikiDescriptorManager.getCurrentWikiId()).thenReturn("xwiki");
    when(this.notificationUserIteratorProvider.get()).thenReturn(Mockito.mock(NotificationUserIterator.class));
    when(this.liveMimeMessageIteratorProvider.get()).thenReturn(Mockito.mock(LiveMimeMessageIterator.class));
    when(this.sessionFactory.create(ArgumentMatchers.any())).thenReturn(null);
    when(this.mailListenerProvider.get()).thenReturn(Mockito.mock(MailListener.class));
    this.mocker.getComponentUnderTest().sendEmails(event1);
    verify(this.mailSender, times(1)).sendAsynchronously(any(LiveMimeMessageIterator.class), any(), any(MailListener.class));
}
Also used : MailListener(org.xwiki.mail.MailListener) NotificationUserIterator(org.xwiki.notifications.notifiers.internal.email.NotificationUserIterator) LiveMimeMessageIterator(org.xwiki.notifications.notifiers.internal.email.live.LiveMimeMessageIterator) CompositeEvent(org.xwiki.notifications.CompositeEvent) Test(org.junit.Test)

Aggregations

CompositeEvent (org.xwiki.notifications.CompositeEvent)23 DocumentReference (org.xwiki.model.reference.DocumentReference)15 Event (org.xwiki.eventstream.Event)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)5 Date (java.util.Date)3 NotificationException (org.xwiki.notifications.NotificationException)3 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)2 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)1 Attachment (com.xpn.xwiki.api.Attachment)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AddressException (javax.mail.internet.AddressException)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1 ScriptContext (javax.script.ScriptContext)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1