1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal.factory.users; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.mail.Message; |
26 |
|
import javax.mail.MessagingException; |
27 |
|
import javax.mail.internet.InternetAddress; |
28 |
|
import javax.mail.internet.MimeMessage; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.slf4j.LoggerFactory; |
32 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
33 |
|
import org.xwiki.component.manager.ComponentLookupException; |
34 |
|
import org.xwiki.component.manager.ComponentManager; |
35 |
|
import org.xwiki.mail.ExtendedMimeMessage; |
36 |
|
import org.xwiki.mail.MimeMessageFactory; |
37 |
|
import org.xwiki.mail.internal.factory.AbstractMessageIterator; |
38 |
|
import org.xwiki.model.reference.DocumentReference; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
@deprecated |
46 |
|
|
47 |
|
@Deprecated |
|
|
| 79.3% |
Uncovered Elements: 6 (29) |
Complexity: 6 |
Complexity Density: 0.26 |
|
48 |
|
public class UsersMimeMessageIterator extends AbstractMessageIterator |
49 |
|
{ |
50 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(UsersMimeMessageIterator.class); |
51 |
|
|
52 |
|
private DocumentAccessBridge documentAccessBridge; |
53 |
|
|
54 |
|
private final List<DocumentReference> users; |
55 |
|
|
56 |
|
private ComponentManager componentManager; |
57 |
|
|
58 |
|
|
59 |
|
@param |
60 |
|
@param |
61 |
|
@param |
62 |
|
@param |
63 |
|
@throws |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
65 |
1 |
public UsersMimeMessageIterator(List<DocumentReference> userReferences,... |
66 |
|
MimeMessageFactory<MimeMessage> factory, Map<String, Object> parameters, |
67 |
|
ComponentManager componentManager) throws MessagingException |
68 |
|
{ |
69 |
1 |
this.factory = factory; |
70 |
1 |
this.parameters = parameters; |
71 |
1 |
this.iteratorSize = userReferences.size(); |
72 |
1 |
this.users = userReferences; |
73 |
1 |
this.componentManager = componentManager; |
74 |
1 |
this.documentAccessBridge = getAccessBridge(); |
75 |
|
} |
76 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
77 |
1 |
private DocumentAccessBridge getAccessBridge() throws MessagingException... |
78 |
|
{ |
79 |
1 |
DocumentAccessBridge accessBridge; |
80 |
1 |
try { |
81 |
1 |
accessBridge = this.componentManager.getInstance(DocumentAccessBridge.class); |
82 |
|
} catch (ComponentLookupException e) { |
83 |
0 |
throw new MessagingException("Failed to find default Document bridge ", e); |
84 |
|
} |
85 |
1 |
return accessBridge; |
86 |
|
} |
87 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
88 |
3 |
@Override... |
89 |
|
protected ExtendedMimeMessage createMessageInternal() throws MessagingException |
90 |
|
{ |
91 |
3 |
ExtendedMimeMessage mimeMessage; |
92 |
|
|
93 |
3 |
DocumentReference userReference = users.get(this.position); |
94 |
|
|
95 |
|
|
96 |
3 |
Object emailObject = this.documentAccessBridge.getProperty(userReference, new DocumentReference(userReference |
97 |
|
.getWikiReference().getName(), "XWiki", "XWikiUsers"), "email"); |
98 |
3 |
if (emailObject != null) { |
99 |
3 |
String email = emailObject.toString(); |
100 |
|
|
101 |
3 |
Map<String, Object> parameters = (Map<String, Object>) this.parameters.get("parameters"); |
102 |
|
|
103 |
3 |
mimeMessage = |
104 |
|
ExtendedMimeMessage.wrap(this.factory.createMessage(this.parameters.get("source"), parameters)); |
105 |
3 |
mimeMessage.addRecipient(Message.RecipientType.TO, InternetAddress.parse(email)[0]); |
106 |
|
} else { |
107 |
0 |
getLogger().warn("User [{}] has no email defined. Email has not been sent to that user.", userReference); |
108 |
0 |
mimeMessage = null; |
109 |
|
} |
110 |
|
|
111 |
3 |
return mimeMessage; |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
@Override... |
115 |
|
protected Logger getLogger() |
116 |
|
{ |
117 |
0 |
return LOGGER; |
118 |
|
} |
119 |
|
} |