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

File DistributionPingDataProvider.java

 

Coverage histogram

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

Code metrics

8
24
2
1
109
64
6
0.25
12
2
3

Classes

Class Line # Actions
DistributionPingDataProvider 47 24 0% 6 3
0.911764791.2%
 

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.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    * Provide the instance's unique id and distribution id and version.
40    *
41    * @version $Id: 0c1c6b2836eb06b4e91dc8033a83988024b4e6e0 $
42    * @since 6.1M1
43    */
44    @Component
45    @Named("distribution")
46    @Singleton
 
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    * Note that we use a Provider to make sure that the Instance Manager is initialized as late as possible (it
62    * requires the database to be ready for its initialization).
63    */
64    @Inject
65    private Provider<InstanceIdManager> instanceIdManagerProvider;
66   
 
67  2 toggle @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   
 
83  2 toggle @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    }