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

File WikiEventConverter.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

6
16
3
1
95
51
6
0.38
5.33
3
2

Classes

Class Line # Actions
WikiEventConverter 49 16 0% 6 14
0.4444%
 

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.io.Serializable;
23    import java.util.HashSet;
24    import java.util.Set;
25   
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.bridge.event.WikiCreatedEvent;
30    import org.xwiki.bridge.event.WikiDeletedEvent;
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   
38    /**
39    * Convert all document event to remote events and back to local events.
40    * <p>
41    * It also make sure the context contains the proper information like the user or the wiki.
42    *
43    * @version $Id: 368c738efff25acf18f736810d35b34fcba106f9 $
44    * @since 2.0M3
45    */
46    @Component
47    @Singleton
48    @Named("wiki")
 
49    public class WikiEventConverter extends AbstractXWikiEventConverter
50    {
51    /**
52    * The events supported by this converter.
53    */
54    private Set<Class<? extends Event>> events = new HashSet<Class<? extends Event>>()
55    {
 
56  8 toggle {
57  8 add(WikiDeletedEvent.class);
58  8 add(WikiCreatedEvent.class);
59    }
60    };
61   
 
62  1043 toggle @Override
63    public boolean toRemote(LocalEventData localEvent, RemoteEventData remoteEvent)
64    {
65  1042 if (this.events.contains(localEvent.getEvent().getClass())) {
66    // fill the remote event
67  0 remoteEvent.setEvent((Serializable) localEvent.getEvent());
68  0 remoteEvent.setSource((String) localEvent.getSource());
69  0 remoteEvent.setData(serializeXWikiContext((XWikiContext) localEvent.getData()));
70   
71  0 return true;
72    }
73   
74  1042 return false;
75    }
76   
 
77  1 toggle @Override
78    public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent)
79    {
80  1 if (this.events.contains(remoteEvent.getEvent().getClass())) {
81    // fill the local event
82  0 XWikiContext context = unserializeXWikiContext(remoteEvent.getData());
83   
84  0 if (context != null) {
85  0 localEvent.setEvent((Event) remoteEvent.getEvent());
86  0 localEvent.setSource(remoteEvent.getSource());
87  0 localEvent.setData(unserializeXWikiContext(remoteEvent.getData()));
88    }
89   
90  0 return true;
91    }
92   
93  1 return false;
94    }
95    }