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.HashMap; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Provider; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.xwiki.activeinstalls.internal.client.PingDataProvider; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.extension.CoreExtension; |
34 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
35 |
|
import org.xwiki.extension.version.Version; |
36 |
|
import org.xwiki.instance.InstanceIdManager; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Named("distribution") |
46 |
|
@Singleton |
|
|
| 91.2% |
Uncovered Elements: 3 (34) |
Complexity: 6 |
Complexity Density: 0.25 |
|
47 |
|
public class DistributionPingDataProvider implements PingDataProvider |
48 |
|
{ |
49 |
|
private static final String PROPERTY_INSTANCE_ID = "instanceId"; |
50 |
|
|
51 |
|
private static final String PROPERTY_DISTRIBUTION_VERSION = "distributionVersion"; |
52 |
|
|
53 |
|
private static final String PROPERTY_DISTRIBUTION_ID = "distributionId"; |
54 |
|
|
55 |
|
private static final String PROPERTY_DISTRIBUTION_FEATURES = "distributionFeatures"; |
56 |
|
|
57 |
|
@Inject |
58 |
|
private CoreExtensionRepository coreExtensionRepository; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Inject |
65 |
|
private Provider<InstanceIdManager> instanceIdManagerProvider; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
67 |
2 |
@Override... |
68 |
|
public Map<String, Object> provideMapping() |
69 |
|
{ |
70 |
2 |
Map<String, Object> map = new HashMap<>(); |
71 |
2 |
map.put("type", "string"); |
72 |
2 |
map.put("index", "not_analyzed"); |
73 |
|
|
74 |
2 |
Map<String, Object> propertiesMap = new HashMap<>(); |
75 |
2 |
propertiesMap.put(PROPERTY_INSTANCE_ID, map); |
76 |
2 |
propertiesMap.put(PROPERTY_DISTRIBUTION_VERSION, map); |
77 |
2 |
propertiesMap.put(PROPERTY_DISTRIBUTION_ID, map); |
78 |
2 |
propertiesMap.put(PROPERTY_DISTRIBUTION_FEATURES, map); |
79 |
|
|
80 |
2 |
return propertiesMap; |
81 |
|
} |
82 |
|
|
|
|
| 87% |
Uncovered Elements: 3 (23) |
Complexity: 5 |
Complexity Density: 0.33 |
|
83 |
2 |
@Override... |
84 |
|
public Map<String, Object> provideData() |
85 |
|
{ |
86 |
2 |
Map<String, Object> jsonMap = new HashMap<>(); |
87 |
|
|
88 |
2 |
String instanceId = this.instanceIdManagerProvider.get().getInstanceId().toString(); |
89 |
2 |
jsonMap.put(PROPERTY_INSTANCE_ID, instanceId); |
90 |
|
|
91 |
2 |
CoreExtension distributionExtension = this.coreExtensionRepository.getEnvironmentExtension(); |
92 |
2 |
if (distributionExtension != null) { |
93 |
2 |
String distributionId = distributionExtension.getId().getId(); |
94 |
2 |
if (distributionId != null) { |
95 |
2 |
jsonMap.put(PROPERTY_DISTRIBUTION_ID, distributionId); |
96 |
|
} |
97 |
2 |
Version distributionVersion = distributionExtension.getId().getVersion(); |
98 |
2 |
if (distributionVersion != null) { |
99 |
2 |
jsonMap.put(PROPERTY_DISTRIBUTION_VERSION, distributionVersion.toString()); |
100 |
|
} |
101 |
2 |
Collection<String> features = distributionExtension.getFeatures(); |
102 |
2 |
if (!features.isEmpty()) { |
103 |
1 |
jsonMap.put(PROPERTY_DISTRIBUTION_FEATURES, distributionExtension.getFeatures().toArray()); |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
2 |
return jsonMap; |
108 |
|
} |
109 |
|
} |