From 66c7a9132edc40e7d266fc6376a1683676e86584 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 2 Jun 2021 18:36:02 +0200 Subject: [PATCH] Refactored organization metric generate. --- .../statoolinfos/core/Organization.java | 46 ++++++ .../statoolinfos/htmlize/MetricHtmlizer.java | 92 +++++++++++ ...ava => OrganizationMetricGenericPage.java} | 11 +- ...va => OrganizationMetricSpecificPage.java} | 9 +- ...ava => OrganizationMetricSummaryPage.java} | 32 +--- .../htmlize/OrganizationMetricWebPage.java | 115 +++++++++++++ .../htmlize/OrganizationPage.java | 8 +- .../htmlize/OrganizationWebMetricPage.java | 155 ------------------ .../properties/PathPropertyList.java | 7 + 9 files changed, 280 insertions(+), 195 deletions(-) rename src/fr/devinsy/statoolinfos/htmlize/{OrganizationGenericMetricPage.java => OrganizationMetricGenericPage.java} (83%) rename src/fr/devinsy/statoolinfos/htmlize/{OrganizationSpecificMetricPage.java => OrganizationMetricSpecificPage.java} (93%) rename src/fr/devinsy/statoolinfos/htmlize/{OrganizationSummaryMetricPage.java => OrganizationMetricSummaryPage.java} (65%) create mode 100644 src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java delete mode 100644 src/fr/devinsy/statoolinfos/htmlize/OrganizationWebMetricPage.java diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index c4c8e2a..decc441 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -30,6 +30,8 @@ import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.crawl.CrawlJournal; import fr.devinsy.statoolinfos.htmlize.charts.MonthValues; +import fr.devinsy.statoolinfos.htmlize.charts.WeekValues; +import fr.devinsy.statoolinfos.htmlize.charts.YearValues; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; @@ -466,6 +468,50 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the metric week values all. + * + * @param path + * the path + * @return the metric week values all + */ + public WeekValues getMetricWeekValuesAll(final String path) + { + WeekValues result; + + result = getMetricWeekValues(path); + + for (Service service : getServices()) + { + result.addAll(service.getMetricWeekValues(path)); + } + + // + return result; + } + + /** + * Gets the metric year values all. + * + * @param path + * the path + * @return the metric year values all + */ + public YearValues getMetricYearValuesAll(final String path) + { + YearValues result; + + result = getMetricYearValues(path); + + for (Service service : getServices()) + { + result.addAll(service.getMetricYearValues(path)); + } + + // + return result; + } + /** * Gets the mobilizon webpage. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java index 4d385c1..d57ec3a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/MetricHtmlizer.java @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.threeten.extra.YearWeek; +import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; @@ -126,6 +127,97 @@ public class MetricHtmlizer return result; } + /** + * Htmlize data. + * + * @param data + * the data + * @param metricId + * the metric id + * @param organization + * the organization + * @param metricPath + * the metric path + * @param color + * the color + * @throws StatoolInfosException + * the statool infos exception + */ + public static void htmlizeData(final TagDataManager data, final String metricId, final Organization organization, final String metricPath, final ChartColor color) throws StatoolInfosException + { + YearValues yearMetric = organization.getMetricYearValuesAll(metricPath); + data.setContent("charts", CHART_YEARS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, yearMetric, color)); + + MonthValues monthMetric = organization.getMetricMonthValuesAll(metricPath); + data.setContent("charts", CHART_MONTHS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, monthMetric, color)); + data.setContent("charts", CHART_MONTHS_LAST, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.now().minusMonths(11), YearMonth.now(), monthMetric, color)); + data.setContent("charts", CHART_MONTHS_2020, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(2020, 01), YearMonth.of(2020, 12), monthMetric, color)); + data.setContent("charts", CHART_MONTHS_2021, metricId, ChartHtmlizer.htmlizeMetricsChart(YearMonth.of(2021, 01), YearMonth.of(2021, 12), monthMetric, color)); + + WeekValues weekMetric = organization.getMetricWeekValuesAll(metricPath); + data.setContent("charts", CHART_WEEKS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(null, null, weekMetric, color)); + data.setContent("charts", CHART_WEEKS_LAST, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.now().minusYears(1), YearWeek.now(), weekMetric, color)); + data.setContent("charts", CHART_WEEKS_2020, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(2020, 01), YearWeek.of(2020, 53), weekMetric, color)); + data.setContent("charts", CHART_WEEKS_2021, metricId, ChartHtmlizer.htmlizeMetricsChart(YearWeek.of(2021, 01), YearWeek.of(2021, 53), weekMetric, color)); + } + + /** + * Htmlize data. + * + * @param data + * the data + * @param metricId + * the metric id + * @param organization + * the organization + * @param metricLabel + * the metric label + * @param metricPath1 + * the metric path 1 + * @param color1 + * the color 1 + * @param metricPath2 + * the metric path 2 + * @param color2 + * the color 2 + * @throws StatoolInfosException + * the statool infos exception + */ + public static void htmlizeData(final TagDataManager data, final String metricId, final Organization organization, final String metricLabel, final String metricPath1, + final ChartColor color1, + final String metricPath2, + final ChartColor color2) throws StatoolInfosException + { + // + YearValues yearMetric1 = organization.getMetricYearValuesAll(metricPath1); + YearValues yearMetric2 = organization.getMetricYearValuesAll(metricPath2); + data.setContent("charts", CHART_YEARS_FULL, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, yearMetric1, yearMetric2)); + + // + MonthValues monthMetric1 = organization.getMetricMonthValuesAll(metricPath1); + MonthValues monthMetric2 = organization.getMetricMonthValuesAll(metricPath2); + data.setContent("charts", CHART_MONTHS_FULL, metricId, ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2)); + data.setContent("charts", CHART_MONTHS_LAST, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.now().minusMonths(11), YearMonth.now(), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2)); + data.setContent("charts", CHART_MONTHS_2020, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(2020, 01), YearMonth.of(2020, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2)); + data.setContent("charts", CHART_MONTHS_2021, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearMonth.of(2021, 01), YearMonth.of(2021, 12), new ChartColor[] { color1, color2 }, monthMetric1, monthMetric2)); + + // + WeekValues weekMetric1 = organization.getMetricWeekValuesAll(metricPath1); + WeekValues weekMetric2 = organization.getMetricWeekValuesAll(metricPath2); + data.setContent("charts", CHART_WEEKS_FULL, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, null, null, new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2)); + data.setContent("charts", CHART_WEEKS_LAST, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.now().minusYears(1), YearWeek.now(), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2)); + data.setContent("charts", CHART_WEEKS_2020, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(2020, 01), YearWeek.of(2020, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2)); + data.setContent("charts", CHART_WEEKS_2021, metricId, + ChartHtmlizer.htmlizeMetricsChart(metricLabel, YearWeek.of(2021, 01), YearWeek.of(2021, 53), new ChartColor[] { color1, color2 }, weekMetric1, weekMetric2)); + } + /** * Htmlize data. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationGenericMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricGenericPage.java similarity index 83% rename from src/fr/devinsy/statoolinfos/htmlize/OrganizationGenericMetricPage.java rename to src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricGenericPage.java index 2034242..45ba9e2 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationGenericMetricPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricGenericPage.java @@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem; +import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -31,9 +32,9 @@ import fr.devinsy.xidyn.presenters.PresenterUtils; /** * The Class OrganizationGenericMetricPage. */ -public class OrganizationGenericMetricPage +public class OrganizationMetricGenericPage { - private static Logger logger = LoggerFactory.getLogger(OrganizationGenericMetricPage.class); + private static Logger logger = LoggerFactory.getLogger(OrganizationMetricGenericPage.class); /** * Builds the. @@ -59,10 +60,12 @@ public class OrganizationGenericMetricPage data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, MenuItem.GENERIC)); // - int graphicIndex = 0; + MetricHtmlizer.htmlizeData(data, "users.count", organization, "metrics.users.count", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "database.bytes", organization, "metrics.database.bytes", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "files.bytes", organization, "metrics.http.visits.visitors", ChartColor.GREEN); // - String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/organizationMetricView.xhtml", data).toString(); + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml", data).toString(); BreadcrumbTrail trail = new BreadcrumbTrail(); trail.add(organization.getName(), organization.getTechnicalName() + ".xhtml"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationSpecificMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSpecificPage.java similarity index 93% rename from src/fr/devinsy/statoolinfos/htmlize/OrganizationSpecificMetricPage.java rename to src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSpecificPage.java index d939a88..8d7b355 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationSpecificMetricPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSpecificPage.java @@ -31,9 +31,9 @@ import fr.devinsy.xidyn.presenters.PresenterUtils; /** * The Class OrganizationSpecificMetricPage. */ -public class OrganizationSpecificMetricPage +public class OrganizationMetricSpecificPage { - private static Logger logger = LoggerFactory.getLogger(OrganizationSpecificMetricPage.class); + private static Logger logger = LoggerFactory.getLogger(OrganizationMetricSpecificPage.class); /** * Builds the. @@ -59,10 +59,7 @@ public class OrganizationSpecificMetricPage data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, MenuItem.SPECIFIC)); // - int graphicIndex = 0; - - // - String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/organizationMetricView.xhtml", data).toString(); + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml", data).toString(); BreadcrumbTrail trail = new BreadcrumbTrail(); trail.add(organization.getName(), organization.getTechnicalName() + ".xhtml"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java similarity index 65% rename from src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java rename to src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java index 0581ad6..687b5e6 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationSummaryMetricPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricSummaryPage.java @@ -19,7 +19,6 @@ package fr.devinsy.statoolinfos.htmlize; import java.io.IOException; -import java.time.YearMonth; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +27,6 @@ import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem; import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; -import fr.devinsy.statoolinfos.htmlize.charts.MonthValues; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -36,9 +34,9 @@ import fr.devinsy.xidyn.presenters.PresenterUtils; /** * The Class OrganizationGeneralStatsPage. */ -public class OrganizationSummaryMetricPage +public class OrganizationMetricSummaryPage { - private static Logger logger = LoggerFactory.getLogger(OrganizationSummaryMetricPage.class); + private static Logger logger = LoggerFactory.getLogger(OrganizationMetricSummaryPage.class); /** * Htmlize. @@ -65,30 +63,12 @@ public class OrganizationSummaryMetricPage data.setContent("headerView", OrganizationHeaderView.htmlize(organization)); data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, MenuItem.SUMMARY)); - String tagIds[] = { "fullChart", "lastChart", "2020Chart", "2021Chart" }; - YearMonth starts[] = { null, YearMonth.now().minusMonths(11), YearMonth.of(2020, 01), YearMonth.of(2021, 01) }; - YearMonth ends[] = { null, YearMonth.now(), YearMonth.of(2020, 12), YearMonth.of(2021, 12) }; - - for (int index = 0; index < tagIds.length; index++) - { - String tagId = tagIds[index]; - YearMonth start = starts[index]; - YearMonth end = ends[index]; - - int graphicIndex = 0; - - MonthValues metric = organization.getMetricMonthValuesAll("metrics.http.hits.visitors"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN)); - - metric = organization.getMetricMonthValuesAll("metrics.http.ip.visitors"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN)); - - metric = organization.getMetricMonthValuesAll("metrics.http.visits.visitors"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN)); - } + MetricHtmlizer.htmlizeData(data, "http.hits.visitors", organization, "metrics.http.hits.visitors", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "http.ip.visitors", organization, "metrics.http.ip.visitors", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "http.visits.visitors", organization, "metrics.http.visits.visitors", ChartColor.GREEN); // - String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/organizationMetricView.xhtml", data).toString(); + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricSummaryView.xhtml", data).toString(); // BreadcrumbTrail trail = new BreadcrumbTrail(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java new file mode 100644 index 0000000..ef6a82f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationMetricWebPage.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.htmlize; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Organization; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem; +import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class OrganizationWebMetricPage. + */ +public class OrganizationMetricWebPage +{ + private static Logger logger = LoggerFactory.getLogger(OrganizationMetricWebPage.class); + + /** + * Builds the. + * + * @param organization + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Organization organization) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building oranization web metric page {}…", organization.get("service.name")); + + TagDataManager data = new TagDataManager(); + + // + data.setContent("headerView", OrganizationHeaderView.htmlize(organization)); + data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, MenuItem.WEB)); + + // + MetricHtmlizer.htmlizeData(data, "http.hits", organization, "metrics.http.hits", ChartColor.BLUE); + + MetricHtmlizer.htmlizeData(data, "http.hits-ipv4ipv6", organization, "http.hits (ipv4 + ipv6)", "metrics.http.hits.ipv4", ChartColor.YELLOW, "metrics.http.hits.ipv6", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "http.hits.ipv4", organization, "metrics.http.hits.ipv4", ChartColor.YELLOW); + MetricHtmlizer.htmlizeData(data, "http.hits.ipv6", organization, "metrics.http.hits.ipv6", ChartColor.GREEN); + + MetricHtmlizer.htmlizeData(data, "http.hits-visitorsbots", organization, "http.hits (visitors + bots)", "metrics.http.hits.visitors", ChartColor.GREEN, "metrics.http.hits.bots", + ChartColor.YELLOW); + MetricHtmlizer.htmlizeData(data, "http.hits.visitors", organization, "metrics.http.hits.visitors", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "http.hits.bots", organization, "metrics.http.hits.bots", ChartColor.YELLOW); + + MetricHtmlizer.htmlizeData(data, "http.errors", organization, "metrics.http.errors", ChartColor.RED); + MetricHtmlizer.htmlizeData(data, "http.errors.php", organization, "metrics.http.errors.php", ChartColor.RED); + + MetricHtmlizer.htmlizeData(data, "http.files", organization, "metrics.http.files", ChartColor.BLUE); + MetricHtmlizer.htmlizeData(data, "http.pages", organization, "metrics.http.pages", ChartColor.BLUE); + MetricHtmlizer.htmlizeData(data, "http.bytes", organization, "metrics.http.bytes", ChartColor.BLUE); + + MetricHtmlizer.htmlizeData(data, "http.ip", organization, "metrics.http.ip", ChartColor.BLUE); + + MetricHtmlizer.htmlizeData(data, "http.ip-visitorsbots", organization, "http.ip (visitors + bots)", "metrics.http.ip.visitors", ChartColor.GREEN, "metrics.http.ip.bots", + ChartColor.YELLOW); + MetricHtmlizer.htmlizeData(data, "http.ip.visitors", organization, "metrics.http.ip.visitors", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "http.ip.bots", organization, "metrics.http.ip.bots", ChartColor.YELLOW); + + MetricHtmlizer.htmlizeData(data, "http.ip-ipv4ipv6", organization, "http.ip (ipv4 + ipv6)", "metrics.http.ip.ipv4", ChartColor.YELLOW, "metrics.http.ip.ipv6", ChartColor.GREEN); + MetricHtmlizer.htmlizeData(data, "http.ip.ipv4", organization, "metrics.http.ip.ipv4", ChartColor.YELLOW); + MetricHtmlizer.htmlizeData(data, "http.ip.ipv6", organization, "metrics.http.ip.ipv6", ChartColor.GREEN); + + MetricHtmlizer.htmlizeData(data, "http.visits", organization, "metrics.http.visits", ChartColor.BLUE); + + MetricHtmlizer.htmlizeData(data, "http.visits-visitorsbots", organization, "http.visits (visitors + bots)", "metrics.http.visits.visitors", ChartColor.GREEN, "metrics.http.visits.bots", + ChartColor.YELLOW); + MetricHtmlizer.htmlizeData(data, "http.visits.bots", organization, "metrics.http.visits.bots", ChartColor.YELLOW); + MetricHtmlizer.htmlizeData(data, "http.visits.visitors", organization, "metrics.http.visits.visitors", ChartColor.GREEN); + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricWebView.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(organization.getName(), organization.getTechnicalName() + ".xhtml"); + trail.add(organization.getName(), organization.getTechnicalName() + "-" + organization.getTechnicalName() + ".xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building organization web metric page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java index 01b4e68..8027d14 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java @@ -78,19 +78,19 @@ public class OrganizationPage FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-stats.xhtml"), page, StandardCharsets.UTF_8); logger.info("Htmlize organization summarty metric page: {}.", organization.getName()); - page = OrganizationSummaryMetricPage.htmlize(organization); + page = OrganizationMetricSummaryPage.htmlize(organization); FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-metrics.xhtml"), page, StandardCharsets.UTF_8); logger.info("Htmlize organization generic metric page: {}.", organization.getName()); - page = OrganizationGenericMetricPage.htmlize(organization); + page = OrganizationMetricGenericPage.htmlize(organization); FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-metrics-generic.xhtml"), page, StandardCharsets.UTF_8); logger.info("Htmlize organization web metric page: {}.", organization.getName()); - page = OrganizationWebMetricPage.htmlize(organization); + page = OrganizationMetricWebPage.htmlize(organization); FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-metrics-web.xhtml"), page, StandardCharsets.UTF_8); logger.info("Htmlize service specific metric page: {}.", organization.getName()); - page = OrganizationSpecificMetricPage.htmlize(organization); + page = OrganizationMetricSpecificPage.htmlize(organization); FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-metrics-specific.xhtml"), page, StandardCharsets.UTF_8); } diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationWebMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationWebMetricPage.java deleted file mode 100644 index 7c76cb1..0000000 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationWebMetricPage.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2021 Christian Pierre MOMON - * - * This file is part of StatoolInfos, simple service statistics tool. - * - * StatoolInfos is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * StatoolInfos is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with StatoolInfos. If not, see . - */ -package fr.devinsy.statoolinfos.htmlize; - -import java.time.YearMonth; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fr.devinsy.statoolinfos.core.Organization; -import fr.devinsy.statoolinfos.core.StatoolInfosException; -import fr.devinsy.statoolinfos.htmlize.OrganizationMetricMenuView.MenuItem; -import fr.devinsy.statoolinfos.htmlize.charts.ChartColor; -import fr.devinsy.statoolinfos.htmlize.charts.MonthValues; -import fr.devinsy.xidyn.XidynException; -import fr.devinsy.xidyn.data.TagDataManager; -import fr.devinsy.xidyn.presenters.PresenterUtils; - -/** - * The Class OrganizationWebMetricPage. - */ -public class OrganizationWebMetricPage -{ - private static Logger logger = LoggerFactory.getLogger(OrganizationWebMetricPage.class); - - /** - * Builds the. - * - * @param organization - * the service - * @return the string - * @throws StatoolInfosException - * the statool infos exception - */ - public static String htmlize(final Organization organization) throws StatoolInfosException - { - String result; - - try - { - logger.debug("Building oranization web metric page {}…", organization.get("service.name")); - - TagDataManager data = new TagDataManager(); - - // - data.setContent("headerView", OrganizationHeaderView.htmlize(organization)); - data.setContent("metricMenuView", OrganizationMetricMenuView.htmlize(organization, MenuItem.WEB)); - - // - String tagIds[] = { "fullChart", "lastChart", "2020Chart", "2021Chart" }; - YearMonth starts[] = { null, YearMonth.now().minusMonths(11), YearMonth.of(2020, 01), YearMonth.of(2021, 01) }; - YearMonth ends[] = { null, YearMonth.now(), YearMonth.of(2020, 12), YearMonth.of(2021, 12) }; - - for (int index = 0; index < tagIds.length; index++) - { - String tagId = tagIds[index]; - YearMonth start = starts[index]; - YearMonth end = ends[index]; - - int graphicIndex = 0; - - MonthValues metric = organization.getMetricMonthValuesAll("metrics.http.hits"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); - - MonthValues metric4 = organization.getMetricMonthValuesAll("metrics.http.hits.ipv4"); - MonthValues metric6 = organization.getMetricMonthValuesAll("metrics.http.hits.ipv6"); - data.setContent(tagId, graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.hits (ipv4 + ipv6)", start, end, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN)); - - metric4 = organization.getMetricMonthValuesAll("metrics.http.hits.bots"); - metric6 = organization.getMetricMonthValuesAll("metrics.http.hits.visitors"); - data.setContent(tagId, graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.hits (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW)); - - metric = organization.getMetricMonthValuesAll("metrics.http.errors"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED)); - - metric = organization.getMetricMonthValuesAll("metrics.http.errors.php"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED)); - - metric = organization.getMetricMonthValuesAll("metrics.http.files"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); - - metric = organization.getMetricMonthValuesAll("metrics.http.pages"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); - - metric = organization.getMetricMonthValuesAll("metrics.http.bytes"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); - - metric = organization.getMetricMonthValuesAll("metrics.http.ip"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); - - metric4 = organization.getMetricMonthValuesAll("metrics.http.ip.bots"); - metric6 = organization.getMetricMonthValuesAll("metrics.http.ip.visitors"); - data.setContent(tagId, graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.ip (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW)); - - metric4 = organization.getMetricMonthValuesAll("metrics.http.ip.ipv4"); - metric6 = organization.getMetricMonthValuesAll("metrics.http.ip.ipv6"); - data.setContent(tagId, graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.ip (ipv4 + ipv6)", start, end, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN)); - - metric = organization.getMetricMonthValuesAll("metrics.http.visits"); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); - - metric4 = organization.getMetricMonthValuesAll("metrics.http.visits.bots"); - metric6 = organization.getMetricMonthValuesAll("metrics.http.visits.visitors"); - data.setContent(tagId, graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.visits (visitors + bots)", start, end, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); - - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN)); - data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric4, ChartColor.YELLOW)); - } - - // - String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/organizationMetricView.xhtml", data).toString(); - - BreadcrumbTrail trail = new BreadcrumbTrail(); - trail.add(organization.getName(), organization.getTechnicalName() + ".xhtml"); - trail.add(organization.getName(), organization.getTechnicalName() + "-" + organization.getTechnicalName() + ".xhtml"); - result = WebCharterView.build(content, trail); - } - catch (XidynException exception) - { - throw new StatoolInfosException("Error building organization web metric page: " + exception.getMessage(), exception); - } - - // - return result; - } -} diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index 6de0d10..835655a 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -361,6 +361,13 @@ public class PathPropertyList extends ArrayList implements PathPro return result; } + /** + * Gets the metric month values. + * + * @param path + * the path + * @return the metric month values + */ public MonthValues getMetricMonthValues(final String path) { MonthValues result;