1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.component.internal

File WikiDeletedListener.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
8
3
1
94
52
5
0.62
2.67
3
1.67

Classes

Class Line # Actions
WikiDeletedListener 49 8 0% 5 2
0.8461538684.6%
 

Contributing tests

This file is covered by 72 tests. .

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 org.xwiki.component.internal;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.slf4j.Logger;
30    import org.xwiki.bridge.event.WikiDeletedEvent;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.internal.multi.ComponentManagerManager;
33    import org.xwiki.component.manager.ComponentLifecycleException;
34    import org.xwiki.component.manager.ComponentManager;
35    import org.xwiki.component.phase.Disposable;
36    import org.xwiki.model.EntityType;
37    import org.xwiki.observation.EventListener;
38    import org.xwiki.observation.event.Event;
39   
40    /**
41    * Make sure to dispose the {@link ComponentManager} associated to a deleted wiki.
42    *
43    * @version $Id: fc8f38c5bebd584ea097d7c840761eb08891f8ac $
44    * @since 5.2RC1
45    */
46    @Component
47    @Singleton
48    @Named("component.multi.WikiDeletedListener")
 
49    public class WikiDeletedListener implements EventListener
50    {
51    /**
52    * The list of events observed.
53    */
54    private static final List<Event> EVENTS = Arrays.<Event> asList(new WikiDeletedEvent());
55   
56    /**
57    * Store and provide {@link ComponentManager} instances.
58    */
59    @Inject
60    private ComponentManagerManager componentManagerManager;
61   
62    @Inject
63    private Logger logger;
64   
 
65  657 toggle @Override
66    public String getName()
67    {
68  657 return "component.multi.WikiDeletedListener";
69    }
70   
 
71  199 toggle @Override
72    public List<Event> getEvents()
73    {
74  199 return EVENTS;
75    }
76   
 
77  4 toggle @Override
78    public void onEvent(Event event, Object o, Object context)
79    {
80  4 String wiki = ((WikiDeletedEvent) event).getWikiId();
81   
82  4 ComponentManager componentManager =
83    this.componentManagerManager.getComponentManager(EntityType.WIKI.toString().toLowerCase() + ':' + wiki,
84    false);
85   
86  4 if (componentManager instanceof Disposable) {
87  4 try {
88  4 ((Disposable) componentManager).dispose();
89    } catch (ComponentLifecycleException e) {
90  0 this.logger.error(String.format("Failed to dispose component manager for wiki [%s]", wiki), e);
91    }
92    }
93    }
94    }