1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.component.internal

File WikiDeletedListener.java

 

Coverage histogram

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

Code metrics

2
8
3
1
93
51
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 76 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.namespace.WikiNamespace;
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: 3e00bffe9b890c0ae5a2839c561c55cfd99bd4d5 $
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  757 toggle @Override
66    public String getName()
67    {
68  757 return "component.multi.WikiDeletedListener";
69    }
70   
 
71  223 toggle @Override
72    public List<Event> getEvents()
73    {
74  223 return EVENTS;
75    }
76   
 
77  1 toggle @Override
78    public void onEvent(Event event, Object o, Object context)
79    {
80  1 String wiki = ((WikiDeletedEvent) event).getWikiId();
81   
82  1 ComponentManager componentManager =
83    this.componentManagerManager.getComponentManager(new WikiNamespace(wiki).serialize(), false);
84   
85  1 if (componentManager instanceof Disposable) {
86  1 try {
87  1 ((Disposable) componentManager).dispose();
88    } catch (ComponentLifecycleException e) {
89  0 this.logger.error(String.format("Failed to dispose component manager for wiki [%s]", wiki), e);
90    }
91    }
92    }
93    }