From b3b6404c36ba320baa27cc6980511f94395d50e9 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 24 Feb 2015 16:23:45 +0100 Subject: Fixed possible Null pointer error, Added source entry to csv file --- .../gv/egiz/pdfas/web/stats/StatisticFrontend.java | 72 ++++++++++++---------- .../pdfas/web/stats/impl/StatisticFileBackend.java | 1 + 2 files changed, 39 insertions(+), 34 deletions(-) (limited to 'pdf-as-web/src/main/java/at/gv/egiz') diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticFrontend.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticFrontend.java index 3c59a7cc..f006be54 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticFrontend.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/StatisticFrontend.java @@ -39,36 +39,41 @@ public class StatisticFrontend implements StatisticBackend { while (statisticIterator.hasNext()) { StatisticBackend statisticBackend = statisticIterator.next(); - - if(enabledBackends == null || enabledBackends.contains(statisticBackend - .getName())) { + + if (enabledBackends == null + || enabledBackends.contains(statisticBackend.getName())) { logger.info("adding Statistic Logger {} [{}]", statisticBackend .getName(), statisticBackend.getClass().getName()); - - statisticBackends.add(statisticBackend); + + statisticBackends.add(statisticBackend); } else { - logger.info("skipping Statistic Logger {} [{}]", statisticBackend - .getName(), statisticBackend.getClass().getName()); + logger.info("skipping Statistic Logger {} [{}]", + statisticBackend.getName(), statisticBackend.getClass() + .getName()); } } - - - Iterator enabledBackendsIterator = enabledBackends - .iterator(); - while (enabledBackendsIterator.hasNext()) { - String enabledBackend = enabledBackendsIterator.next(); - statisticIterator = statisticBackends.iterator(); - boolean found = false; - while (statisticIterator.hasNext()) { - StatisticBackend statisticBackend = statisticIterator.next(); - if(statisticBackend.getName().equals(enabledBackend)) { - found = true; - break; + + if (enabledBackends != null) { + Iterator enabledBackendsIterator = enabledBackends + .iterator(); + while (enabledBackendsIterator.hasNext()) { + String enabledBackend = enabledBackendsIterator.next(); + statisticIterator = statisticBackends.iterator(); + boolean found = false; + while (statisticIterator.hasNext()) { + StatisticBackend statisticBackend = statisticIterator + .next(); + if (statisticBackend.getName().equals(enabledBackend)) { + found = true; + break; + } + } + + if (!found) { + logger.warn( + "Failed to load statistic backend {}. Not in classpath?", + enabledBackend); } - } - - if(!found) { - logger.warn("Failed to load statistic backend {}. Not in classpath?", enabledBackend); } } } @@ -80,29 +85,28 @@ public class StatisticFrontend implements StatisticBackend { return _instance; } - @Override public String getName() { return StatisticFrontend.class.getSimpleName(); } - @Override public void storeEvent(StatisticEvent statisticEvent) { - - if(statisticEvent == null) { + + if (statisticEvent == null) { logger.warn("Tried to log null as statisticEvent!"); return; } - - if(statisticEvent.isLogged()) { + + if (statisticEvent.isLogged()) { logger.warn("Tried to relog statisticEvent!"); return; } - - Iterator statisticBackendIterator = statisticBackends.iterator(); - - while(statisticBackendIterator.hasNext()) { + + Iterator statisticBackendIterator = statisticBackends + .iterator(); + + while (statisticBackendIterator.hasNext()) { StatisticBackend statisticBackend = statisticBackendIterator.next(); statisticBackend.storeEvent(statisticEvent); } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/impl/StatisticFileBackend.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/impl/StatisticFileBackend.java index 531c47bf..997bcfdd 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/impl/StatisticFileBackend.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/stats/impl/StatisticFileBackend.java @@ -30,6 +30,7 @@ public class StatisticFileBackend implements StatisticBackend { addCSVValue(String.valueOf(statisticEvent.getTimestamp()), sb); addCSVValue(statisticEvent.getOperation().getName(), sb); addCSVValue(statisticEvent.getDevice(), sb); + addCSVValue(statisticEvent.getSource().getName(), sb); addCSVValue(statisticEvent.getProfileId(), sb); addCSVValue(String.valueOf(statisticEvent.getFilesize()), sb); addCSVValue(statisticEvent.getUserAgent(), sb); -- cgit v1.2.3