1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.observation.remote.converter; |
21 |
|
|
22 |
|
import java.util.HashSet; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.bridge.event.AbstractActionExecutionEvent; |
29 |
|
import org.xwiki.bridge.event.ActionExecutedEvent; |
30 |
|
import org.xwiki.bridge.event.ActionExecutingEvent; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.observation.event.Event; |
33 |
|
import org.xwiki.observation.remote.LocalEventData; |
34 |
|
import org.xwiki.observation.remote.RemoteEventData; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Singleton |
51 |
|
@Named("action") |
|
|
| 36.7% |
Uncovered Elements: 19 (30) |
Complexity: 10 |
Complexity Density: 0.53 |
|
52 |
|
public class ActionExecutionEventConverter extends AbstractXWikiEventConverter |
53 |
|
{ |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private Set<String> actions = new HashSet<String>() |
58 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
8 |
{... |
60 |
8 |
add("upload"); |
61 |
|
} |
62 |
|
}; |
63 |
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
64 |
1009 |
@Override... |
65 |
|
public boolean toRemote(LocalEventData localEvent, RemoteEventData remoteEvent) |
66 |
|
{ |
67 |
1009 |
if (localEvent.getEvent() instanceof ActionExecutedEvent |
68 |
|
|| localEvent.getEvent() instanceof ActionExecutingEvent) { |
69 |
32 |
AbstractActionExecutionEvent event = (AbstractActionExecutionEvent) localEvent.getEvent(); |
70 |
|
|
71 |
32 |
if (this.actions.contains(event.getActionName())) { |
72 |
|
|
73 |
0 |
remoteEvent.setEvent(event); |
74 |
0 |
remoteEvent.setSource(serializeXWikiDocument((XWikiDocument) localEvent.getSource())); |
75 |
0 |
remoteEvent.setData(serializeXWikiContext((XWikiContext) localEvent.getData())); |
76 |
|
} |
77 |
|
|
78 |
32 |
return true; |
79 |
|
} |
80 |
|
|
81 |
977 |
return false; |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
84 |
0 |
@Override... |
85 |
|
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) |
86 |
|
{ |
87 |
0 |
if (remoteEvent.getEvent() instanceof ActionExecutedEvent |
88 |
|
|| remoteEvent.getEvent() instanceof ActionExecutingEvent) { |
89 |
|
|
90 |
0 |
XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData()); |
91 |
|
|
92 |
0 |
try { |
93 |
0 |
if (xcontext != null) { |
94 |
0 |
localEvent.setSource(unserializeDocument(remoteEvent.getSource())); |
95 |
0 |
localEvent.setData(xcontext); |
96 |
0 |
localEvent.setEvent((Event) remoteEvent.getEvent()); |
97 |
|
} |
98 |
|
} catch (XWikiException e) { |
99 |
0 |
this.logger.error("Failed to convert remote event [{}]", remoteEvent, e); |
100 |
|
} |
101 |
|
|
102 |
0 |
return true; |
103 |
|
} |
104 |
|
|
105 |
0 |
return false; |
106 |
|
} |
107 |
|
} |