1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.messagestream.script; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.context.Execution; |
28 |
|
import org.xwiki.context.ExecutionContext; |
29 |
|
import org.xwiki.messagestream.MessageStream; |
30 |
|
import org.xwiki.model.EntityType; |
31 |
|
import org.xwiki.model.reference.DocumentReference; |
32 |
|
import org.xwiki.model.reference.EntityReference; |
33 |
|
import org.xwiki.script.service.ScriptService; |
34 |
|
import org.xwiki.stability.Unstable; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWiki; |
37 |
|
import com.xpn.xwiki.XWikiContext; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.objects.BaseObject; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("messageStream") |
48 |
|
@Singleton |
|
|
| 92.5% |
Uncovered Elements: 4 (53) |
Complexity: 16 |
Complexity Density: 0.39 |
|
49 |
|
public class MessageStreamScriptService implements ScriptService |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
static final String ERROR_KEY = "scriptservice.messageStream.error"; |
55 |
|
|
56 |
|
private static final EntityReference CONFIG_DOCUMENT_REFERENCE = |
57 |
|
new EntityReference("MessageStreamConfig", EntityType.DOCUMENT, |
58 |
|
new EntityReference("XWiki", EntityType.SPACE)); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@Inject |
64 |
|
protected Execution execution; |
65 |
|
|
66 |
|
|
67 |
|
@Inject |
68 |
|
private MessageStream stream; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@return |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
76 |
2 |
public boolean postPublicMessage(String message)... |
77 |
|
{ |
78 |
2 |
try { |
79 |
2 |
this.stream.postPublicMessage(message); |
80 |
1 |
return true; |
81 |
|
} catch (Exception e) { |
82 |
1 |
setError(e); |
83 |
1 |
return false; |
84 |
|
} |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
@return |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
94 |
2 |
public boolean postPersonalMessage(String message)... |
95 |
|
{ |
96 |
2 |
try { |
97 |
2 |
this.stream.postPersonalMessage(message); |
98 |
1 |
return true; |
99 |
|
} catch (Exception e) { |
100 |
1 |
setError(e); |
101 |
1 |
return false; |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
@param |
110 |
|
@return |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
112 |
2 |
public boolean postDirectMessageToUser(String message, DocumentReference user)... |
113 |
|
{ |
114 |
2 |
try { |
115 |
2 |
this.stream.postDirectMessageToUser(message, user); |
116 |
1 |
return true; |
117 |
|
} catch (Exception e) { |
118 |
1 |
setError(e); |
119 |
1 |
return false; |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
@param |
128 |
|
@return |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
130 |
2 |
public boolean postMessageToGroup(String message, DocumentReference group)... |
131 |
|
{ |
132 |
2 |
try { |
133 |
2 |
this.stream.postMessageToGroup(message, group); |
134 |
1 |
return true; |
135 |
|
} catch (Exception e) { |
136 |
1 |
setError(e); |
137 |
1 |
return false; |
138 |
|
} |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
@return |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
147 |
2 |
public boolean deleteMessage(String id)... |
148 |
|
{ |
149 |
2 |
try { |
150 |
2 |
this.stream.deleteMessage(id); |
151 |
1 |
return true; |
152 |
|
} catch (Exception e) { |
153 |
1 |
setError(e); |
154 |
1 |
return false; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
@return |
160 |
|
@since |
161 |
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0.29 |
|
162 |
80 |
@Unstable... |
163 |
|
public boolean isActive() |
164 |
|
{ |
165 |
80 |
boolean result = false; |
166 |
|
|
167 |
|
|
168 |
80 |
try { |
169 |
80 |
ExecutionContext ec = this.execution.getContext(); |
170 |
80 |
if (ec != null) { |
171 |
80 |
XWikiContext xcontext = (XWikiContext) ec.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY); |
172 |
80 |
if (xcontext != null) { |
173 |
80 |
XWiki xwiki = xcontext.getWiki(); |
174 |
80 |
XWikiDocument configDocument = xwiki.getDocument(CONFIG_DOCUMENT_REFERENCE, xcontext); |
175 |
80 |
BaseObject configObject = configDocument.getXObject(CONFIG_DOCUMENT_REFERENCE); |
176 |
80 |
int active = configObject.getIntValue("active"); |
177 |
80 |
result = (active == 1); |
178 |
|
} |
179 |
|
} |
180 |
|
} catch (Exception e) { |
181 |
0 |
setError(e); |
182 |
0 |
return false; |
183 |
|
} |
184 |
|
|
185 |
80 |
return result; |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
@return |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
193 |
4 |
public Exception getLastError()... |
194 |
|
{ |
195 |
4 |
return (Exception) this.execution.getContext().getProperty(ERROR_KEY); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
@link |
200 |
|
|
201 |
|
@param |
202 |
|
@see |
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
5 |
protected void setError(Exception e)... |
205 |
|
{ |
206 |
5 |
this.execution.getContext().setProperty(ERROR_KEY, e); |
207 |
|
} |
208 |
|
} |