1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.notifications.notifiers.internal.email.live

File LiveNotificationEmailSender.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
8
1
1
96
49
1
0.12
8
1
1

Classes

Class Line # Actions
LiveNotificationEmailSender 52 8 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.notifications.notifiers.internal.email.live;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24    import java.util.HashMap;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Provider;
29    import javax.mail.Session;
30   
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.annotation.InstantiationStrategy;
33    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
34    import org.xwiki.mail.MailListener;
35    import org.xwiki.mail.MailSender;
36    import org.xwiki.mail.SessionFactory;
37    import org.xwiki.model.reference.DocumentReference;
38    import org.xwiki.notifications.CompositeEvent;
39    import org.xwiki.notifications.notifiers.email.NotificationEmailInterval;
40    import org.xwiki.notifications.notifiers.internal.email.NotificationUserIterator;
41    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
42   
43    /**
44    * Sends live email notifications regarding a given composite event against every user that have set their preferences
45    * to receive live email notifications for this kind of events.
46    *
47    * @since 9.6RC1
48    * @version $Id: 1d799c709dbcb4da475cc67292ef535e986f8296 $
49    */
50    @Component(roles = LiveNotificationEmailSender.class)
51    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
52    public class LiveNotificationEmailSender
53    {
54    @Inject
55    private MailSender mailSender;
56   
57    @Inject
58    private SessionFactory sessionFactory;
59   
60    @Inject
61    @Named("database")
62    private Provider<MailListener> mailListenerProvider;
63   
64    @Inject
65    private Provider<NotificationUserIterator> notificationUserIteratorProvider;
66   
67    @Inject
68    private Provider<LiveMimeMessageIterator> liveMimeMessageIteratorProvider;
69   
70    @Inject
71    private WikiDescriptorManager wikiDescriptorManager;
72   
73    /**
74    * Send live notification e-mails regarding the given event for the users that are concerned by this event and that
75    * have enabled live notifications.
76    * @param event the event that should be sent to the users
77    */
 
78  368 toggle public void sendEmails(CompositeEvent event)
79    {
80  368 DocumentReference templateReference = new DocumentReference(this.wikiDescriptorManager.getCurrentWikiId(),
81    Arrays.asList("XWiki", "Notifications"), "MailTemplate");
82   
83    // Get a list of users that have enabled the live e-mail notifications.
84  368 NotificationUserIterator notificationUserIterator = this.notificationUserIteratorProvider.get();
85  368 notificationUserIterator.initialize(NotificationEmailInterval.LIVE);
86   
87  368 LiveMimeMessageIterator liveNotificationMessageIterator = this.liveMimeMessageIteratorProvider.get();
88  368 liveNotificationMessageIterator.initialize(notificationUserIterator, new HashMap<>(), event, templateReference);
89   
90  368 Session session = this.sessionFactory.create(Collections.emptyMap());
91  368 MailListener mailListener = mailListenerProvider.get();
92   
93    // Pass it to the message sender to send it asynchronously.
94  368 mailSender.sendAsynchronously(liveNotificationMessageIterator, session, mailListener);
95    }
96    }