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

File InstalledExtensionSynchronizer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
14
3
1
111
59
6
0.43
4.67
3
2

Classes

Class Line # Actions
InstalledExtensionSynchronizer 51 14 0% 6 1
0.9523809695.2%
 

Contributing tests

This file is covered by 21 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.extension.xar.internal.repository;
21   
22    import java.util.Collection;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.slf4j.Logger;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.extension.InstalledExtension;
31    import org.xwiki.extension.event.ExtensionEvent;
32    import org.xwiki.extension.event.ExtensionInstalledEvent;
33    import org.xwiki.extension.event.ExtensionUninstalledEvent;
34    import org.xwiki.extension.event.ExtensionUpgradedEvent;
35    import org.xwiki.extension.repository.InstalledExtensionRepository;
36    import org.xwiki.extension.xar.internal.handler.UnsupportedNamespaceException;
37    import org.xwiki.extension.xar.internal.handler.XarExtensionHandler;
38    import org.xwiki.observation.AbstractEventListener;
39    import org.xwiki.observation.event.Event;
40   
41    /**
42    * Maintain extension stored in {@link XarInstalledExtensionRepository} in sync with the standard
43    * {@link InstalledExtensionRepository} component.
44    *
45    * @version $Id: 1cb88995bef17516d4b34538b4f8cbea82c6ad0d $
46    * @since 8.1M2
47    */
48    @Component
49    @Named("org.xwiki.extension.xar.internal.repository.InstalledExtensionSynchronizer")
50    @Singleton
 
51    public class InstalledExtensionSynchronizer extends AbstractEventListener
52    {
53    @Inject
54    @Named(XarExtensionHandler.TYPE)
55    private InstalledExtensionRepository xarRepository;
56   
57    @Inject
58    private Logger logger;
59   
60    /**
61    * Default constructor.
62    */
 
63  26 toggle public InstalledExtensionSynchronizer()
64    {
65  26 super(InstalledExtensionSynchronizer.class.getName(), new ExtensionInstalledEvent(),
66    new ExtensionUninstalledEvent(), new ExtensionUpgradedEvent());
67    }
68   
 
69  176 toggle private XarInstalledExtensionRepository getXarRepository()
70    {
71  176 return (XarInstalledExtensionRepository) this.xarRepository;
72    }
73   
 
74  82 toggle @Override
75    public void onEvent(Event event, Object source, Object data)
76    {
77  82 ExtensionEvent extensionEvent = (ExtensionEvent) event;
78   
79  82 try {
80  82 if (extensionEvent instanceof ExtensionUninstalledEvent) {
81    // Update documents index
82  19 getXarRepository().pagesRemoved(extensionEvent.getExtensionId(), extensionEvent.getNamespace());
83   
84    // Update extension cache
85  19 getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId());
86    } else {
87    // Previous extensions
88   
89  63 if (data != null) {
90  6 for (InstalledExtension installedExtension : (Collection<InstalledExtension>) data) {
91    // Update documents index
92  6 getXarRepository().pagesRemoved(installedExtension.getId(), extensionEvent.getNamespace());
93   
94    // Update extension cache
95  6 getXarRepository().updateCachedXarExtension(installedExtension.getId());
96    }
97    }
98   
99    // New extension
100   
101    // Update extension cache
102  63 getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId());
103   
104    // Update documents index
105  63 getXarRepository().pagesAdded(extensionEvent.getExtensionId(), extensionEvent.getNamespace());
106    }
107    } catch (UnsupportedNamespaceException e) {
108  0 logger.error("Failed to extract wiki from namespace [{}]", extensionEvent.getNamespace());
109    }
110    }
111    }