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

File UsersAndGroupsMimeMessageFactory.java

 

Coverage histogram

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

Code metrics

0
6
1
1
80
38
1
0.17
6
1
1

Classes

Class Line # Actions
UsersAndGroupsMimeMessageFactory 49 6 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 5 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.usersandgroups;
21   
22    import java.util.Iterator;
23    import java.util.Map;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28    import javax.mail.MessagingException;
29    import javax.mail.internet.MimeMessage;
30   
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.context.Execution;
33    import org.xwiki.mail.MimeMessageFactory;
34    import org.xwiki.mail.internal.factory.AbstractIteratorMimeMessageFactory;
35    import org.xwiki.model.reference.DocumentReferenceResolver;
36   
37    /**
38    * Generate one {@link MimeMessage} per user found in the passed Groups and per user passed too (and preventing
39    * duplicates), using the passed parameters to define the {@link MimeMessageFactory} to call to generate the message $
40    * for each user. Also handles an optional list of users to exclude.
41    *
42    * @version $Id: 41c28e65c5b3e2bb3393ae043a1d1960062e6594 $
43    * @since 6.4.2
44    * @since 7.0M2
45    */
46    @Component
47    @Named("usersandgroups")
48    @Singleton
 
49    public class UsersAndGroupsMimeMessageFactory extends AbstractIteratorMimeMessageFactory
50    {
51    private static final String HINT = "hint";
52   
53    private static final String SOURCE = "source";
54   
55    @Inject
56    @Named("explicit")
57    private DocumentReferenceResolver<String> explicitDocumentReferenceResolver;
58   
59    @Inject
60    private Execution execution;
61   
 
62  6 toggle @Override
63    public Iterator<MimeMessage> createMessage(Object sourceObject, Map<String, Object> parameters)
64    throws MessagingException
65    {
66  6 Map<String, Object> source = getTypedSource(sourceObject, Map.class);
67   
68    // We verify that we have both a Factory hint specified but also the source for the Factory.
69  6 validateParameters(parameters, HINT, SOURCE);
70   
71    // Extract from the passed parameters the MimeMessageFactory to use to create a single mail
72  3 String factoryHint = (String) parameters.get(HINT);
73   
74  3 MimeMessageFactory factory = getInternalMimeMessageFactory(factoryHint);
75   
76  2 UsersAndGroupsMimeMessageIterator iterator = new UsersAndGroupsMimeMessageIterator(source, factory, parameters,
77    this.explicitDocumentReferenceResolver, this.execution);
78  2 return iterator;
79    }
80    }