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

File NotificationEmailSender.java

 

Coverage histogram

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

Code metrics

0
7
1
1
93
48
1
0.14
7
1
1

Classes

Class Line # Actions
NotificationEmailSender 51 7 0% 1 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24    import java.util.Date;
25    import java.util.HashMap;
26    import java.util.Map;
27   
28    import javax.inject.Inject;
29    import javax.inject.Named;
30    import javax.inject.Provider;
31    import javax.mail.Session;
32   
33    import org.quartz.JobExecutionException;
34    import org.xwiki.component.annotation.Component;
35    import org.xwiki.component.annotation.InstantiationStrategy;
36    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
37    import org.xwiki.mail.MailListener;
38    import org.xwiki.mail.MailSender;
39    import org.xwiki.mail.SessionFactory;
40    import org.xwiki.model.reference.DocumentReference;
41    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
42   
43    /**
44    * Send notifications emails for specified users.
45    *
46    * @version $Id: aa1aa1c6e3c66aa60470e9f03819728a33646a13 $
47    * @since 9.5RC1
48    */
49    @Component(roles = NotificationEmailSender.class)
50    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
51    public class NotificationEmailSender
52    {
53    @Inject
54    private MailSender mailSender;
55   
56    @Inject
57    private SessionFactory sessionFactory;
58   
59    @Inject
60    @Named("database")
61    private Provider<MailListener> mailListenerProvider;
62   
63    @Inject
64    private Provider<PeriodicMimeMessageIterator> notificationMimeMessageIteratorProvider;
65   
66    @Inject
67    private WikiDescriptorManager wikiDescriptorManager;
68   
69    /**
70    * Send notifications emails for specified users.
71    * @param fromDate only send notifications about events that happened after this date
72    * @param notificationUserIterator iterator for users interested in the notifications emails
73    * @throws JobExecutionException if error happens
74    */
 
75  4 toggle public void sendEmails(Date fromDate, NotificationUserIterator notificationUserIterator)
76    throws JobExecutionException
77    {
78  4 Map<String, Object> emailFactoryParameters = new HashMap<>();
79   
80  4 DocumentReference templateReference = new DocumentReference(wikiDescriptorManager.getCurrentWikiId(),
81    Arrays.asList("XWiki", "Notifications"), "MailTemplate");
82   
83  4 PeriodicMimeMessageIterator periodicMimeMessageIterator = notificationMimeMessageIteratorProvider.get();
84  4 periodicMimeMessageIterator.initialize(notificationUserIterator, emailFactoryParameters, fromDate,
85    templateReference);
86   
87  4 Session session = this.sessionFactory.create(Collections.emptyMap());
88  4 MailListener mailListener = mailListenerProvider.get();
89   
90    // Pass it to the message sender to send it asynchronously.
91  4 mailSender.sendAsynchronously(periodicMimeMessageIterator, session, mailListener);
92    }
93    }