From f750d648fb9552dbef429c1c7742c17a0deaa602 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sun, 27 Feb 2022 11:57:37 +0100 Subject: [PATCH] Step in add of figures view. --- src/fr/devinsy/statoolinfos/core/Service.java | 123 ++++++++++++++++-- .../htmlize/FederationHeaderView.java | 1 + .../statoolinfos/htmlize/FederationPages.java | 1 + .../FederationServicesFiguresPage.java | 96 ++++++++++++++ .../htmlize/ServiceFigureView.java | 123 ++++++++++++++++++ .../htmlize/federationHeaderView.xhtml | 1 + .../htmlize/serviceFigureView.xhtml | 106 +++++++++++++++ 7 files changed, 440 insertions(+), 11 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/htmlize/FederationServicesFiguresPage.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/ServiceFigureView.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/serviceFigureView.xhtml diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index d75bec4..6948f32 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -447,6 +447,116 @@ public class Service extends PathPropertyList return this.metricsList; } + /** + * Gets the month account count. + * + * @return the month account count + */ + public long getMonthAccountCount(final YearMonth month) + { + long result; + + result = getMonthCount("metrics.service.accounts", month); + + // + return result; + } + + /** + * Gets the month active account count. + * + * @return the month active account count + */ + public long getMonthActiveAccountCount(final YearMonth month) + { + long result; + + result = getMonthCount("metrics.service.accounts.active", month); + + // + return result; + } + + /** + * Gets the month count. + * + * @param path + * the path + * @return the month count + */ + public long getMonthCount(final String path, final YearMonth month) + { + long result; + + MonthValues values = getMetricMonthValues(path); + values = values.extract(month, month); + + result = (long) values.sum(); + + // + return result; + } + + /** + * Gets the month hit count. + * + * @return the month hit count + */ + public long getMonthHitCount(final YearMonth month) + { + long result; + + result = getMonthCount("metrics.http.hits", month); + + // + return result; + } + + /** + * Gets the month user count. + * + * @return the month user count + */ + public long getMonthUserCount(final YearMonth month) + { + long result; + + result = getMonthCount("metrics.service.users", month); + + // + return result; + } + + /** + * Gets the month visit count. + * + * @return the month visit count + */ + public long getMonthVisitCount(final YearMonth month) + { + long result; + + result = getMonthCount("metrics.http.visits", month); + + // + return result; + } + + /** + * Gets the month visitor count. + * + * @return the month visitor count + */ + public long getMonthVisitorCount(final YearMonth month) + { + long result; + + result = getMonthCount("metrics.http.visitors", month); + + // + return result; + } + /** * Gets the name. * @@ -487,12 +597,7 @@ public class Service extends PathPropertyList { long result; - MonthValues values = getMetricMonthValues("metrics.service.users"); - - YearMonth previousMonth = YearMonth.now().minusMonths(1); - values = values.extract(previousMonth, previousMonth); - - result = (long) values.sum(); + result = getMonthUserCount(YearMonth.now().minusMonths(1)); // return result; @@ -507,11 +612,7 @@ public class Service extends PathPropertyList { long result; - MonthValues values = getMetricMonthValues("metrics.http.visits"); - - values = values.extract(YearMonth.now().minusMonths(1), YearMonth.now().minusMonths(1)); - - result = (long) values.sum(); + result = getMonthVisitCount(YearMonth.now().minusMonths(1)); // return result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java b/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java index d318e76..cd60b9d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java @@ -77,6 +77,7 @@ public class FederationHeaderView data.setAttribute("propertyCheckLink", "href", federation.getTechnicalName() + "-propertycheck.xhtml"); data.setAttribute("statsLink", "href", federation.getTechnicalName() + "-stats.xhtml"); data.setAttribute("metricsLink", "href", federation.getTechnicalName() + "-metrics-summary-months-last.xhtml"); + data.setAttribute("figuresLink", "href", federation.getTechnicalName() + "-services-figures.xhtml"); data.setAttribute("crawlLink", "href", federation.getTechnicalName() + "-crawl.xhtml"); data.setAttribute("uptimeLink", "href", federation.getLocalFileBaseName() + "-uptimes.xhtml"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPages.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPages.java index 0b71c27..1009d8c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPages.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPages.java @@ -69,6 +69,7 @@ public class FederationPages // FederationOrganizationsPage.build(); FederationServicesPage.build(); + FederationServicesFiguresPage.build(); FederationCrawlJournalPage.build(); FederationPropertyCheckPage.build(); FederationPropertyAlertPage.buildAll(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationServicesFiguresPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationServicesFiguresPage.java new file mode 100644 index 0000000..da322f2 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationServicesFiguresPage.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2022 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.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class FederationServicesFiguresPage. + */ +public class FederationServicesFiguresPage +{ + private static Logger logger = LoggerFactory.getLogger(FederationServicesFiguresPage.class); + + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + */ + public static void build() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + // + logger.info("PAGE FEDERATION services figures page: {}.", federation.getName()); + String page = htmlize(federation); + + FileUtils.write(new File(htmlizeDirectory, federation.getLocalFileBaseName() + "-services-figures.xhtml"), page, StandardCharsets.UTF_8); + } + + /** + * Builds the. + * + * @param federation + * the organization + * @return the string + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + */ + public static String htmlize(final Federation federation) throws StatoolInfosException, IOException + { + String result; + + try + { + TagDataManager data = new TagDataManager(); + + data.setContent("federationHeaderView", FederationHeaderView.htmlize(federation)); + data.setContent("serviceListView", ServiceFigureView.htmlize(federation.getServices())); + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationServices.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building federation services figures page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceFigureView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceFigureView.java new file mode 100644 index 0000000..e0eb0d6 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceFigureView.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2022 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.LocalDate; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.core.StatoolInfosUtils; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; +import fr.devinsy.xidyn.utils.XidynUtils; + +/** + * The Class ServiceFigureView. + */ +public class ServiceFigureView +{ + private static Logger logger = LoggerFactory.getLogger(ServiceFigureView.class); + + /** + * Builds the. + * + * @param services + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Services services) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building services figures view."); + + TagDataManager data = new TagDataManager(); + + data.setContent("serviceCount", services.size()); + + if (services.isEmpty()) + { + data.setAttribute("serviceListLine", "class", "xid:nodisplay"); + } + else + { + String monthLabel = LocalDate.now().minusMonths(1).format(DateTimeFormatter.ofPattern("MMMM yyyy")).replace(" ", " "); + data.setContent("monthLabel", monthLabel); + data.setAttribute("userCountHeaderColumn", "title", monthLabel); + data.setAttribute("visitCountHeaderColumn", "title", monthLabel); + + int index = 0; + for (Service service : services.sortByName()) + { + data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLink", "href", service.getOrganization().getTechnicalName() + ".xhtml"); + data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLogo", "src", service.getOrganization().getLogoFileName()); + data.setEscapedAttribute("serviceListLine", index, "serviceListLineOrganizationLogo", "title", service.getOrganization().getName()); + + data.setAttribute("serviceListLine", index, "serviceListLineLogo", "src", service.getLogoFileName()); + data.setEscapedContent("serviceListLine", index, "serviceListLineNameValue", service.getName()); + data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + + data.setAttribute("serviceListLine", index, "serviceStatusImg", "src", "status-" + service.getStatus().toString().toLowerCase() + ".png"); + data.setAttribute("serviceListLine", index, "serviceStatusImg", "title", StringUtils.defaultIfBlank(service.getStatusDescription(), service.getStatus().toString())); + + if (service.getWebsiteURL() != null) + { + data.setEscapedContent("serviceListLine", index, "serviceListLineUrlLink", service.getWebsiteURL().toString()); + data.setEscapedContent("serviceListLine", index, "serviceListLineWebsiteLink", service.getWebsiteURL().toString()); + data.setEscapedAttribute("serviceListLine", index, "serviceListLineWebsiteLink", "href", service.getWebsiteURL().toString()); + } + + data.setEscapedContent("serviceListLine", index, "serviceListLineSoftwareLink", service.getSoftwareName()); + data.setAttribute("serviceListLine", index, "serviceListLineSoftwareLink", "href", "software-" + service.getSoftwareTechnicalName() + ".xhtml"); + + YearMonth month = YearMonth.now(); + data.setContent("serviceListLine", index, "serviceListLineHitCount", StatoolInfosUtils.defaultIfZero(service.getMonthHitCount(month), "😢")); + data.setContent("serviceListLine", index, "serviceListLineVisitCount", StatoolInfosUtils.defaultIfZero(service.getMonthVisitCount(month), "😞")); + data.setContent("serviceListLine", index, "serviceListLineVisitorCount", StatoolInfosUtils.defaultIfZero(service.getMonthVisitorCount(month), "😞")); + data.setContent("serviceListLine", index, "serviceListLineUserCount", StatoolInfosUtils.defaultIfZero(service.getMonthUserCount(month), "😢")); + data.setContent("serviceListLine", index, "serviceListLineAccountCount", StatoolInfosUtils.defaultIfZero(service.getMonthAccountCount(month), "😇")); + data.setContent("serviceListLine", index, "serviceListLineActiveAccountCount", StatoolInfosUtils.defaultIfZero(service.getMonthActiveAccountCount(month), "😇")); + + index += 1; + } + } + result = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceFigureView.xhtml", data).toString(); + result = XidynUtils.extractBodyContent(result); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml index aa97549..0be754c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml @@ -35,6 +35,7 @@ Journal Stats Metriques + Chiffres Dispos diff --git a/src/fr/devinsy/statoolinfos/htmlize/serviceFigureView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/serviceFigureView.xhtml new file mode 100644 index 0000000..a80f10a --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/serviceFigureView.xhtml @@ -0,0 +1,106 @@ + + + + + StatoolInfos + + + + + + + +
+
+
Nombre de services : n/a
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
ServiceLogicielHitsVisitesVisiteursUtilisateursComptesComptes actifs
+ + + + + +  n/a + + + + n/a + n/an/an/an/an/an/a
+ + + +