1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal

File AbstractMailListener.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

10
16
9
1
113
73
14
0.88
1.78
9
1.56

Classes

Class Line # Actions
AbstractMailListener 35 16 0% 14 10
0.7142857371.4%
 

Contributing tests

This file is covered by 17 tests. .

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.mail.internal;
21   
22    import java.util.Map;
23   
24    import javax.inject.Inject;
25   
26    import org.slf4j.Logger;
27    import org.xwiki.mail.ExtendedMimeMessage;
28    import org.xwiki.mail.MailListener;
29   
30    /**
31    * Helper for implementation of {@link MailListener}.
32    *
33    * @version $Id: 24b1e199e98c72e8f1132041809dd1a24b2ee36b $
34    */
 
35    public abstract class AbstractMailListener implements MailListener
36    {
37    @Inject
38    protected Logger logger;
39   
40    private String batchId;
41   
 
42  46 toggle protected String getBatchId()
43    {
44  46 return batchId;
45    }
46   
 
47  53 toggle @Override
48    public void onPrepareBegin(String batchId, Map<String, Object> parameters)
49    {
50  53 if (this.batchId != null) {
51  0 throw new RuntimeException("A mail listener cannot be reused. This listener has been used for batch ["
52    + this.batchId + "] and is now called for batch [" + batchId + "].");
53    }
54   
55  53 logger.debug("Mail preparation begins for batch [{}].", batchId);
56   
57  53 this.batchId = batchId;
58    }
59   
 
60  29 toggle @Override
61    public void onPrepareMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters)
62    {
63  29 if (logger.isDebugEnabled()) {
64  0 logger.debug("Mail preparation succeed for message [{}] of batch [{}].",
65    message.getUniqueMessageId(), batchId);
66    }
67    }
68   
 
69  5 toggle @Override
70    public void onPrepareMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters)
71    {
72  5 if (logger.isDebugEnabled()) {
73  0 logger.debug("Mail preparation failed for message [{}] of batch [{}].",
74    message.getUniqueMessageId(), batchId, exception);
75    }
76    }
77   
 
78  1 toggle @Override
79    public void onPrepareFatalError(Exception exception, Map<String, Object> parameters)
80    {
81  1 logger.debug("Failure during preparation phase of thread [" + batchId + "]");
82    }
83   
 
84  42 toggle @Override
85    public void onPrepareEnd(Map<String, Object> parameters)
86    {
87  42 logger.debug("Mail preparation ended for batch [{}].", batchId);
88    }
89   
 
90  9 toggle @Override
91    public void onSendMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters)
92    {
93  9 if (logger.isDebugEnabled()) {
94  0 logger.debug("Mail sent successfully for message [{}] of batch [{}].",
95    message.getUniqueMessageId(), batchId);
96    }
97    }
98   
 
99  4 toggle @Override
100    public void onSendMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters)
101    {
102  4 if (logger.isDebugEnabled()) {
103  0 logger.debug("Mail sending failed for message [{}] of batch [{}].",
104    message.getUniqueMessageId(), batchId, exception);
105    }
106    }
107   
 
108  3 toggle @Override
109    public void onSendMessageFatalError(String uniqueMessageId, Exception exception, Map<String, Object> parameters)
110    {
111  3 logger.debug("Mail loading failed for message [{}] of batch [{}].", uniqueMessageId, batchId, exception);
112    }
113    }