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.usersandgroups; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import javax.mail.Address; |
28 |
|
import javax.mail.MessagingException; |
29 |
|
import javax.mail.internet.InternetAddress; |
30 |
|
|
31 |
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.text.XWikiToStringBuilder; |
34 |
|
|
35 |
|
|
36 |
|
@link |
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
@since |
42 |
|
|
|
|
| 86% |
Uncovered Elements: 7 (50) |
Complexity: 12 |
Complexity Density: 0.34 |
|
43 |
|
public class UsersAndGroupsSource |
44 |
|
{ |
45 |
|
private List<DocumentReference> includedUserAndGroupReferences; |
46 |
|
|
47 |
|
private List<DocumentReference> excludedUserAndGroupReferences; |
48 |
|
|
49 |
|
private List<Address> includedAddresses; |
50 |
|
|
51 |
|
private List<Address> excludedAdresses; |
52 |
|
|
53 |
|
|
54 |
|
@param@link |
55 |
|
@param@link |
56 |
|
@param@link |
57 |
|
@param@link |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
59 |
4 |
public UsersAndGroupsSource(List<DocumentReference> includedUserAndGroupReferences,... |
60 |
|
List<DocumentReference> excludedUserAndGroupReferences, List<Address> includedAddresses, |
61 |
|
List<Address> excludedAddresses) |
62 |
|
{ |
63 |
4 |
this.includedUserAndGroupReferences = includedUserAndGroupReferences; |
64 |
4 |
this.excludedUserAndGroupReferences = excludedUserAndGroupReferences; |
65 |
4 |
this.includedAddresses = includedAddresses; |
66 |
4 |
this.excludedAdresses = excludedAddresses; |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
@return |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
4 |
public List<DocumentReference> getIncludedUserAndGroupReferences()... |
73 |
|
{ |
74 |
4 |
return this.includedUserAndGroupReferences; |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
@return |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
4 |
public List<DocumentReference> getExcludedUserAndGroupReferences()... |
81 |
|
{ |
82 |
4 |
return this.excludedUserAndGroupReferences; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@return |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
4 |
public List<Address> getIncludedAddresses()... |
89 |
|
{ |
90 |
4 |
return this.includedAddresses; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@return |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
4 |
public List<Address> getExcludedAddresses()... |
97 |
|
{ |
98 |
4 |
return this.excludedAdresses; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
|
104 |
|
|
105 |
|
@return |
106 |
|
@throws |
107 |
|
|
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
109 |
4 |
public static UsersAndGroupsSource parse(Map<String, Object> sourceMap) throws MessagingException... |
110 |
|
{ |
111 |
4 |
List<DocumentReference> includedUserAndGroupReferences = |
112 |
|
extractUserAndGroupReferences("users", "groups", sourceMap); |
113 |
4 |
List<DocumentReference> excludedUserAndGroupReferences = |
114 |
|
extractUserAndGroupReferences("excludedUsers", "excludedGroups", sourceMap); |
115 |
|
|
116 |
4 |
List<Address> includedAddresses = extractAddresses("emails", sourceMap); |
117 |
4 |
List<Address> excludedAddresses = extractAddresses("excludedEmails", sourceMap); |
118 |
|
|
119 |
4 |
return new UsersAndGroupsSource(includedUserAndGroupReferences, excludedUserAndGroupReferences, |
120 |
|
includedAddresses, excludedAddresses); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
123 |
8 |
private static List<Address> extractAddresses(String key, Map<String, Object> sourceMap) throws MessagingException... |
124 |
|
{ |
125 |
8 |
List<Address> addresses; |
126 |
8 |
List<String> emails = (List<String>) sourceMap.get(key); |
127 |
8 |
if (emails != null) { |
128 |
1 |
addresses = new ArrayList<>(); |
129 |
1 |
for (String email : emails) { |
130 |
1 |
addresses.add(InternetAddress.parse(email)[0]); |
131 |
|
} |
132 |
|
} else { |
133 |
7 |
addresses = Collections.emptyList(); |
134 |
|
} |
135 |
8 |
return addresses; |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
138 |
8 |
private static List<DocumentReference> extractUserAndGroupReferences(String userKey, String groupKey,... |
139 |
|
Map<String, Object> sourceMap) |
140 |
|
{ |
141 |
8 |
List<DocumentReference> userAndGroupReferences = new ArrayList<>(); |
142 |
8 |
List<DocumentReference> userReferences = (List<DocumentReference>) sourceMap.get(userKey); |
143 |
8 |
if (userReferences != null) { |
144 |
4 |
userAndGroupReferences.addAll(userReferences); |
145 |
|
} |
146 |
8 |
List<DocumentReference> groupReferences = (List<DocumentReference>) sourceMap.get(groupKey); |
147 |
8 |
if (groupReferences != null) { |
148 |
1 |
userAndGroupReferences.addAll(groupReferences); |
149 |
|
} |
150 |
8 |
return userAndGroupReferences; |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
153 |
0 |
@Override... |
154 |
|
public String toString() |
155 |
|
{ |
156 |
0 |
ToStringBuilder builder = new XWikiToStringBuilder(this); |
157 |
0 |
builder.append("includedUserAndGroupsReferences", getIncludedUserAndGroupReferences()); |
158 |
0 |
builder.append("excludedUserAndGroupsReferences", getExcludedUserAndGroupReferences()); |
159 |
0 |
builder.append("includedAddresses", getIncludedAddresses()); |
160 |
0 |
builder.append("excludedAddresses", getExcludedAddresses()); |
161 |
0 |
return builder.toString(); |
162 |
|
} |
163 |
|
} |