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

File AbstractMessageIterator.java

 

Coverage histogram

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

Code metrics

2
15
5
1
105
54
7
0.47
3
5
1.4

Classes

Class Line # Actions
AbstractMessageIterator 38 15 0% 7 6
0.7272727572.7%
 

Contributing tests

This file is covered by 4 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.factory;
21   
22    import java.util.Iterator;
23    import java.util.Map;
24   
25    import javax.mail.MessagingException;
26    import javax.mail.internet.MimeMessage;
27   
28    import org.slf4j.Logger;
29    import org.xwiki.mail.ExtendedMimeMessage;
30    import org.xwiki.mail.MimeMessageFactory;
31   
32    /**
33    * Abstract class to generate iterator of MimeMessage.
34    *
35    * @version $Id: 59e1cafed9576696ae3b3b7ce1e61d3121634fbf $
36    * @since 6.4M3
37    */
 
38    public abstract class AbstractMessageIterator implements Iterator<MimeMessage>, Iterable<MimeMessage>
39    {
40    protected MimeMessageFactory<MimeMessage> factory;
41   
42    protected int position;
43   
44    protected int iteratorSize;
45   
46    protected Map<String, Object> parameters;
47   
48    /**
49    * @return the MimeMessage as the current element of Iterator.
50    * @throws MessagingException when an error occurs
51    */
52    protected abstract ExtendedMimeMessage createMessageInternal() throws MessagingException;
53   
54    protected abstract Logger getLogger();
55   
56    /**
57    * @return the MimeMessage as the current element of Iterator.
58    * @throws MessagingException when an error occurs
59    */
 
60  10 toggle public ExtendedMimeMessage createMessage() throws MessagingException
61    {
62  10 ExtendedMimeMessage message = createMessageInternal();
63   
64    // Set the Message type if passed in parameters
65  9 String type = (String) parameters.get("type");
66  9 if (type != null) {
67  0 message.setType(type);
68    }
69   
70  9 return message;
71    }
72   
 
73  10 toggle @Override
74    public MimeMessage next()
75    {
76  10 MimeMessage mimeMessage;
77  10 try {
78  10 mimeMessage = createMessage();
79    } catch (Exception e) {
80    //TODO We need to save all the errors and display them in the status of all emails in the admin UI.
81  1 getLogger().error("Failed to create Mime Message", e);
82  1 mimeMessage = null;
83    }
84  10 this.position++;
85  10 return mimeMessage;
86    }
87   
 
88  12 toggle @Override
89    public boolean hasNext()
90    {
91  12 return this.iteratorSize != this.position;
92    }
93   
 
94  0 toggle @Override
95    public void remove()
96    {
97  0 throw new UnsupportedOperationException();
98    }
99   
 
100  0 toggle @Override
101    public Iterator<MimeMessage> iterator()
102    {
103  0 return this;
104    }
105    }