1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.observation.remote.converter

File ActionExecutionEventConverter.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

8
19
3
1
107
61
10
0.53
6.33
3
3.33

Classes

Class Line # Actions
ActionExecutionEventConverter 52 19 0% 10 19
0.3666666736.7%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Convert and filter action events for the network.
42    * <p>
43    * Currently only "upload" action is send (for attachments modifications).
44    *
45    * @todo make the list of actions to send configurable
46    * @version $Id: 0e7af3f2bfa1958cd23ebb2c26a8376fcd3ec667 $
47    * @since 2.0M4
48    */
49    @Component
50    @Singleton
51    @Named("action")
 
52    public class ActionExecutionEventConverter extends AbstractXWikiEventConverter
53    {
54    /**
55    * The events supported by this converter.
56    */
57    private Set<String> actions = new HashSet<String>()
58    {
 
59  8 toggle {
60  8 add("upload");
61    }
62    };
63   
 
64  1009 toggle @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    // fill the remote event
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   
 
84  0 toggle @Override
85    public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent)
86    {
87  0 if (remoteEvent.getEvent() instanceof ActionExecutedEvent
88    || remoteEvent.getEvent() instanceof ActionExecutingEvent) {
89    // fill the local event
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    }