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; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Iterator; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.slf4j.LoggerFactory; |
29 |
|
import org.xwiki.mail.MailState; |
30 |
|
import org.xwiki.mail.MailStatus; |
31 |
|
import org.xwiki.mail.MailStatusStore; |
32 |
|
import org.xwiki.mail.MailStoreException; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 72.4% |
Uncovered Elements: 8 (29) |
Complexity: 10 |
Complexity Density: 0.53 |
|
41 |
|
public class DatabaseMailStatusResult extends AbstractMailStatusResult |
42 |
|
{ |
43 |
|
private static final String BATCHID_KEY = "batchId"; |
44 |
|
|
45 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseMailStatusResult.class); |
46 |
|
|
47 |
|
private static final String DATE_FIELD = "date"; |
48 |
|
|
49 |
|
private MailStatusStore mailStatusStore; |
50 |
|
|
51 |
|
private String batchId; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
43 |
public DatabaseMailStatusResult(MailStatusStore mailStatusStore)... |
58 |
|
{ |
59 |
43 |
this.mailStatusStore = mailStatusStore; |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
43 |
public void setBatchId(String batchId)... |
68 |
|
{ |
69 |
43 |
this.batchId = batchId; |
70 |
|
} |
71 |
|
|
|
|
| 50% |
Uncovered Elements: 4 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
72 |
1 |
@Override... |
73 |
|
public Iterator<MailStatus> getAll() |
74 |
|
{ |
75 |
1 |
if (this.batchId == null) { |
76 |
0 |
return Collections.emptyIterator(); |
77 |
|
} |
78 |
|
|
79 |
1 |
try { |
80 |
1 |
return this.mailStatusStore.load(Collections.<String, Object>singletonMap(BATCHID_KEY, this.batchId), |
81 |
|
0, 0, DATE_FIELD, true).iterator(); |
82 |
|
} catch (MailStoreException e) { |
83 |
0 |
LOGGER.error("Failed to get all results. Returning an empty result.", e); |
84 |
0 |
return Collections.emptyIterator(); |
85 |
|
} |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
2 |
@Override... |
89 |
|
public Iterator<MailStatus> getAllErrors() |
90 |
|
{ |
91 |
2 |
return getFilteredState("%_error"); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
2 |
@Override... |
95 |
|
public Iterator<MailStatus> getByState(MailState state) |
96 |
|
{ |
97 |
2 |
return getFilteredState(state.toString()); |
98 |
|
} |
99 |
|
|
|
|
| 63.6% |
Uncovered Elements: 4 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
100 |
4 |
private Iterator<MailStatus> getFilteredState(String state)... |
101 |
|
{ |
102 |
4 |
if (this.batchId == null) { |
103 |
0 |
return Collections.emptyIterator(); |
104 |
|
} |
105 |
|
|
106 |
4 |
try { |
107 |
4 |
Map<String, Object> filterMap = new HashMap<>(); |
108 |
4 |
filterMap.put(BATCHID_KEY, this.batchId); |
109 |
4 |
filterMap.put("state", state); |
110 |
4 |
return this.mailStatusStore.load(filterMap, 0, 0, DATE_FIELD, true).iterator(); |
111 |
|
} catch (MailStoreException e) { |
112 |
0 |
LOGGER.error("Failed to get results by state. Returning an empty result.", e); |
113 |
0 |
return Collections.emptyIterator(); |
114 |
|
} |
115 |
|
} |
116 |
|
} |