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

File MemoryMailListener.java

 

Coverage histogram

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

Code metrics

2
28
7
1
125
77
8
0.29
4
7
1.14

Classes

Class Line # Actions
MemoryMailListener 43 28 0% 8 2
0.945945994.6%
 

Contributing tests

This file is covered by 10 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.Named;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.annotation.InstantiationStrategy;
28    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
29    import org.xwiki.mail.ExtendedMimeMessage;
30    import org.xwiki.mail.MailState;
31    import org.xwiki.mail.MailStatus;
32    import org.xwiki.mail.MailStatusResult;
33   
34    /**
35    * Saves errors when sending messages, in a local variable.
36    *
37    * @version $Id: a303255e80204dccdc5bde4f88bd271692dd9e64 $
38    * @since 6.4M3
39    */
40    @Component
41    @Named("memory")
42    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
43    public class MemoryMailListener extends AbstractMailListener
44    {
45    private MemoryMailStatusResult mailStatusResult = new MemoryMailStatusResult();
46   
 
47  12 toggle @Override
48    public void onPrepareMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters)
49    {
50  12 super.onPrepareMessageSuccess(message, parameters);
51   
52  12 MailStatus status = new MailStatus(getBatchId(), message, MailState.PREPARE_SUCCESS);
53  12 this.mailStatusResult.setStatus(status);
54    }
55   
 
56  4 toggle @Override
57    public void onPrepareMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters)
58    {
59  4 super.onPrepareMessageError(message, exception, parameters);
60   
61  4 MailStatus status = new MailStatus(getBatchId(), message, MailState.PREPARE_ERROR);
62  4 status.setError(exception);
63  4 this.mailStatusResult.setStatus(status);
64   
65    // This mail will not reach the send queue, so its processing is done now.
66  4 this.mailStatusResult.incrementCurrentSize();
67    }
68   
 
69  1 toggle @Override
70    public void onPrepareFatalError(Exception exception, Map<String, Object> parameters)
71    {
72  1 super.onPrepareFatalError(exception, parameters);
73   
74    //TODO: Store failure exception
75  1 logger.error("Failure during preparation phase of thread [" + getBatchId() + "]");
76    }
77   
 
78  8 toggle @Override
79    public void onSendMessageSuccess(ExtendedMimeMessage message, Map<String, Object> parameters)
80    {
81  8 super.onPrepareMessageSuccess(message, parameters);
82   
83  8 MailStatus status = new MailStatus(getBatchId(), message, MailState.SEND_SUCCESS);
84  8 this.mailStatusResult.setStatus(status);
85  8 this.mailStatusResult.incrementCurrentSize();
86    }
87   
 
88  2 toggle @Override
89    public void onSendMessageFatalError(String uniqueMessageId, Exception exception, Map<String, Object> parameters)
90    {
91  2 super.onSendMessageFatalError(uniqueMessageId, exception, parameters);
92   
93  2 MailStatus status = this.mailStatusResult.getStatus(uniqueMessageId);
94  2 if (status != null) {
95  2 status.setState(MailState.SEND_FATAL_ERROR);
96  2 status.setError(exception);
97  2 this.mailStatusResult.setStatus(status);
98    } else {
99  0 this.logger.error("Failed to find a previous mail status for message id [{}] of batch [{}]. "
100    + "Unable to report the fatal error encountered during mail sending.", uniqueMessageId, getBatchId(),
101    exception);
102    }
103   
104  2 this.mailStatusResult.incrementCurrentSize();
105    }
106   
 
107  2 toggle @Override
108    public void onSendMessageError(ExtendedMimeMessage message, Exception exception, Map<String, Object> parameters)
109    {
110  2 super.onSendMessageError(message, exception, parameters);
111   
112  2 MailStatus status = new MailStatus(getBatchId(), message, MailState.SEND_ERROR);
113  2 status.setError(exception);
114  2 this.mailStatusResult.setStatus(status);
115   
116    // This mail will not reach the send queue, so its processing is done now.
117  2 this.mailStatusResult.incrementCurrentSize();
118    }
119   
 
120  34 toggle @Override
121    public MailStatusResult getMailStatusResult()
122    {
123  34 return this.mailStatusResult;
124    }
125    }