@@ -80,6 +80,10 @@ public class StatsCollector extends Task {
8080
8181 private static String productName = "LogicalDOC Community" ;
8282
83+ private boolean uploadStatistics = true ;
84+
85+ private List <NameValuePair > statistics = new ArrayList <>();
86+
8387 public StatsCollector () {
8488 super (NAME );
8589 log = LoggerFactory .getLogger (StatsCollector .class );
@@ -240,48 +244,48 @@ protected void runTask() throws TaskException {
240244 log .debug ("Package collected statistics" );
241245
242246 // Prepare the post parameters
243- List < NameValuePair > postParams = new ArrayList <> ();
247+ statistics . clear ();
244248
245249 // Add all statistics as parameters
246- postParams .add (new BasicNameValuePair ("id" , StringUtils .defaultString (id )));
247- postParams .add (new BasicNameValuePair ("userno" , StringUtils .defaultString (userno )));
248- postParams .add (new BasicNameValuePair ("sid" , StringUtils .defaultString (sid )));
249-
250- postParams .add (new BasicNameValuePair ("product_release" , StringUtils .defaultString (release )));
251- postParams .add (new BasicNameValuePair ("email" , StringUtils .defaultString (email )));
252- postParams .add (new BasicNameValuePair ("product" , StringUtils .defaultString (StatsCollector .product )));
253- postParams
250+ statistics .add (new BasicNameValuePair ("id" , StringUtils .defaultString (id )));
251+ statistics .add (new BasicNameValuePair ("userno" , StringUtils .defaultString (userno )));
252+ statistics .add (new BasicNameValuePair ("sid" , StringUtils .defaultString (sid )));
253+
254+ statistics .add (new BasicNameValuePair ("product_release" , StringUtils .defaultString (release )));
255+ statistics .add (new BasicNameValuePair ("email" , StringUtils .defaultString (email )));
256+ statistics .add (new BasicNameValuePair ("product" , StringUtils .defaultString (StatsCollector .product )));
257+ statistics
254258 .add (new BasicNameValuePair ("product_name" , StringUtils .defaultString (StatsCollector .productName )));
255259
256- postParams .add (new BasicNameValuePair ("java_version" , StringUtils .defaultString (javaversion )));
257- postParams .add (new BasicNameValuePair ("java_vendor" , StringUtils .defaultString (javavendor )));
258- postParams .add (new BasicNameValuePair ("java_arch" , StringUtils .defaultString (javaarch )));
259- postParams .add (new BasicNameValuePair ("dbms" , StringUtils .defaultString (dbms )));
260+ statistics .add (new BasicNameValuePair ("java_version" , StringUtils .defaultString (javaversion )));
261+ statistics .add (new BasicNameValuePair ("java_vendor" , StringUtils .defaultString (javavendor )));
262+ statistics .add (new BasicNameValuePair ("java_arch" , StringUtils .defaultString (javaarch )));
263+ statistics .add (new BasicNameValuePair ("dbms" , StringUtils .defaultString (dbms )));
260264
261- postParams .add (new BasicNameValuePair ("os_name" , StringUtils .defaultString (osname )));
262- postParams .add (new BasicNameValuePair ("os_version" , StringUtils .defaultString (osversion )));
263- postParams .add (new BasicNameValuePair ("file_encoding" , StringUtils .defaultString (fileencoding )));
265+ statistics .add (new BasicNameValuePair ("os_name" , StringUtils .defaultString (osname )));
266+ statistics .add (new BasicNameValuePair ("os_version" , StringUtils .defaultString (osversion )));
267+ statistics .add (new BasicNameValuePair ("file_encoding" , StringUtils .defaultString (fileencoding )));
264268
265- postParams .add (new BasicNameValuePair ("user_language" , StringUtils .defaultString (userlanguage )));
266- postParams .add (new BasicNameValuePair ("user_country" , StringUtils .defaultString (usercountry )));
269+ statistics .add (new BasicNameValuePair ("user_language" , StringUtils .defaultString (userlanguage )));
270+ statistics .add (new BasicNameValuePair ("user_country" , StringUtils .defaultString (usercountry )));
267271
268272 // Sizing
269- postParams .add (new BasicNameValuePair ("users" , Integer .toString (users )));
270- postParams .add (new BasicNameValuePair ("guests" , Integer .toString (guests )));
271- postParams .add (new BasicNameValuePair ("groups" , Integer .toString (groups )));
272- postParams .add (new BasicNameValuePair ("docs" , Long .toString (totaldocs )));
273- postParams .add (new BasicNameValuePair ("pages" , Long .toString (totalpages )));
274-
275- postParams .add (new BasicNameValuePair ("archived_docs" , Long .toString (archiveddocs )));
276- postParams .add (new BasicNameValuePair ("folders" , Long .toString (withdocs + empty + deletedfolders )));
277- postParams .add (new BasicNameValuePair ("tags" , Long .toString (tags )));
278- postParams .add (new BasicNameValuePair ("versions" , Long .toString (versions )));
279- postParams .add (new BasicNameValuePair ("histories" , Long .toString (histories )));
280- postParams .add (new BasicNameValuePair ("user_histories" , Long .toString (userHistories )));
281- postParams .add (new BasicNameValuePair ("votes" , Long .toString (votes )));
282- postParams .add (new BasicNameValuePair ("wscalls" , Long .toString (wsCalls )));
283-
284- collectFeatureUsageStats (postParams );
273+ statistics .add (new BasicNameValuePair ("users" , Integer .toString (users )));
274+ statistics .add (new BasicNameValuePair ("guests" , Integer .toString (guests )));
275+ statistics .add (new BasicNameValuePair ("groups" , Integer .toString (groups )));
276+ statistics .add (new BasicNameValuePair ("docs" , Long .toString (totaldocs )));
277+ statistics .add (new BasicNameValuePair ("pages" , Long .toString (totalpages )));
278+
279+ statistics .add (new BasicNameValuePair ("archived_docs" , Long .toString (archiveddocs )));
280+ statistics .add (new BasicNameValuePair ("folders" , Long .toString (withdocs + empty + deletedfolders )));
281+ statistics .add (new BasicNameValuePair ("tags" , Long .toString (tags )));
282+ statistics .add (new BasicNameValuePair ("versions" , Long .toString (versions )));
283+ statistics .add (new BasicNameValuePair ("histories" , Long .toString (histories )));
284+ statistics .add (new BasicNameValuePair ("user_histories" , Long .toString (userHistories )));
285+ statistics .add (new BasicNameValuePair ("votes" , Long .toString (votes )));
286+ statistics .add (new BasicNameValuePair ("wscalls" , Long .toString (wsCalls )));
287+
288+ collectFeatureUsageStats (statistics );
285289 next ();
286290 if (interruptRequested )
287291 return ;
@@ -290,29 +294,29 @@ protected void runTask() throws TaskException {
290294 * General usage
291295 */
292296 Date lastLogin = findLastLogin ();
293- postParams .add (new BasicNameValuePair ("last_login" , formatDate (lastLogin )));
297+ statistics .add (new BasicNameValuePair ("last_login" , formatDate (lastLogin )));
294298
295299 Date lastCreation = findLastCreation ();
296- postParams .add (new BasicNameValuePair ("last_creation" , formatDate (lastCreation )));
300+ statistics .add (new BasicNameValuePair ("last_creation" , formatDate (lastCreation )));
297301
298302 /*
299303 * Quotas
300304 */
301- postParams .add (new BasicNameValuePair ("docdir" , Long .toString (docdir )));
302- postParams .add (new BasicNameValuePair ("trash" , Long .toString (trash )));
303- postParams .add (new BasicNameValuePair ("indexdir" , Long .toString (indexdir )));
304- postParams .add (new BasicNameValuePair ("quota" ,
305+ statistics .add (new BasicNameValuePair ("docdir" , Long .toString (docdir )));
306+ statistics .add (new BasicNameValuePair ("trash" , Long .toString (trash )));
307+ statistics .add (new BasicNameValuePair ("indexdir" , Long .toString (indexdir )));
308+ statistics .add (new BasicNameValuePair ("quota" ,
305309 Long .toString (docdir + indexdir + userdir + importdir + exportdir + plugindir + dbdir + logdir )));
306310
307311 /*
308312 * Registration
309313 */
310- postParams .add (new BasicNameValuePair ("reg_name" , regName != null ? regName : "" ));
311- postParams .add (new BasicNameValuePair ("reg_email" , regEmail != null ? regEmail : "" ));
312- postParams .add (new BasicNameValuePair ("reg_organization" , regOrganization != null ? regOrganization : "" ));
313- postParams .add (new BasicNameValuePair ("reg_website" , regWebsite != null ? regWebsite : "" ));
314+ statistics .add (new BasicNameValuePair ("reg_name" , regName != null ? regName : "" ));
315+ statistics .add (new BasicNameValuePair ("reg_email" , regEmail != null ? regEmail : "" ));
316+ statistics .add (new BasicNameValuePair ("reg_organization" , regOrganization != null ? regOrganization : "" ));
317+ statistics .add (new BasicNameValuePair ("reg_website" , regWebsite != null ? regWebsite : "" ));
314318
315- postStatistics ( postParams );
319+ uploadStatistics ( statistics );
316320
317321 next ();
318322 } catch (PersistenceException e ) {
@@ -325,14 +329,16 @@ private String formatDate(Date lastLogin) {
325329 return lastLogin != null ? isoDf .format (lastLogin ) : "" ;
326330 }
327331
328- private void postStatistics (List <NameValuePair > postParams ) {
332+ private void uploadStatistics (List <NameValuePair > postParams ) {
329333 try {
330334 // Execute request
331335 try (CloseableHttpClient httpClient = HttpUtil .getNotValidatingClient (60 )) {
332336 HttpPost post = new HttpPost ("http://stat.logicaldoc.com/stats/collect" );
333337 UrlEncodedFormEntity entity = new UrlEncodedFormEntity (postParams , StandardCharsets .UTF_8 );
334338 post .setEntity (entity );
335- httpClient .execute (post , new StringHttpClientResponseHandler ());
339+
340+ if (uploadStatistics )
341+ httpClient .execute (post , new StringHttpClientResponseHandler ());
336342 }
337343 log .info ("Statistics packaged" );
338344 } catch (IOException e ) {
@@ -851,4 +857,12 @@ public static void setProduct(String product) {
851857 public static void setProductName (String productName ) {
852858 StatsCollector .productName = productName ;
853859 }
860+
861+ void setUploadStatistics (boolean uploadStatistics ) {
862+ this .uploadStatistics = uploadStatistics ;
863+ }
864+
865+ List <NameValuePair > getStatistics () {
866+ return statistics ;
867+ }
854868}
0 commit comments