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

File ExtensionPingDataProvider.java

 

Coverage histogram

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

Code metrics

2
21
2
1
95
57
3
0.14
10.5
2
1.5

Classes

Class Line # Actions
ExtensionPingDataProvider 48 21 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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.activeinstalls.internal.client.data;
21   
22    import java.util.Collection;
23    import java.util.Collections;
24    import java.util.HashMap;
25    import java.util.Iterator;
26    import java.util.Map;
27   
28    import javax.inject.Inject;
29    import javax.inject.Named;
30    import javax.inject.Singleton;
31   
32    import org.xwiki.activeinstalls.internal.client.PingDataProvider;
33    import org.xwiki.component.annotation.Component;
34    import org.xwiki.extension.InstalledExtension;
35    import org.xwiki.extension.repository.InstalledExtensionRepository;
36   
37    import net.sf.json.JSONObject;
38   
39    /**
40    * Provide the list of installed extensions and their versions.
41    *
42    * @version $Id: dfff706228050ff6ecf2fdbb0ddb4cbf5c982822 $
43    * @since 6.1M1
44    */
45    @Component
46    @Named("extensions")
47    @Singleton
 
48    public class ExtensionPingDataProvider implements PingDataProvider
49    {
50    private static final String PROPERTY_ID = "id";
51   
52    private static final String PROPERTY_VERSION = "version";
53   
54    private static final String PROPERTY_FEATURES = "features";
55   
56    private static final String PROPERTY_EXTENSIONS = "extensions";
57   
58    @Inject
59    private InstalledExtensionRepository extensionRepository;
60   
 
61  2 toggle @Override
62    public Map<String, Object> provideMapping()
63    {
64  2 Map<String, Object> map = new HashMap<>();
65  2 map.put("type", "string");
66  2 map.put("index", "not_analyzed");
67   
68  2 Map<String, Object> propertiesMap = new HashMap<>();
69  2 propertiesMap.put(PROPERTY_ID, map);
70  2 propertiesMap.put(PROPERTY_VERSION, map);
71  2 propertiesMap.put(PROPERTY_FEATURES, map);
72   
73  2 return Collections.singletonMap(PROPERTY_EXTENSIONS,
74    (Object) Collections.singletonMap("properties", propertiesMap));
75    }
76   
 
77  2 toggle @Override
78    public Map<String, Object> provideData()
79    {
80  2 Collection<InstalledExtension> installedExtensions = this.extensionRepository.getInstalledExtensions();
81  2 JSONObject[] extensions = new JSONObject[installedExtensions.size()];
82  2 Iterator<InstalledExtension> it = installedExtensions.iterator();
83  2 int i = 0;
84  3 while (it.hasNext()) {
85  1 InstalledExtension extension = it.next();
86  1 Map<String, Object> extensionMap = new HashMap<>();
87  1 extensionMap.put(PROPERTY_ID, extension.getId().getId());
88  1 extensionMap.put(PROPERTY_VERSION, extension.getId().getVersion().toString());
89  1 extensionMap.put(PROPERTY_FEATURES, extension.getFeatures().toArray());
90  1 extensions[i] = JSONObject.fromObject(extensionMap);
91  1 i++;
92    }
93  2 return Collections.singletonMap(PROPERTY_EXTENSIONS, (Object) extensions);
94    }
95    }