1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Named("extensions") |
47 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
61 |
2 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
77 |
2 |
@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 |
|
} |