diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index 8075069..c4c8e2a 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -29,6 +29,7 @@ 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.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; @@ -443,6 +444,28 @@ public class Organization extends PathPropertyList return result; } + /** + * Gets the metric month values all. + * + * @param path + * the path + * @return the metric month values all + */ + public MonthValues getMetricMonthValuesAll(final String path) + { + MonthValues result; + + result = getMetricMonthValues(path); + + for (Service service : getServices()) + { + result.addAll(service.getMetricMonthValues(path)); + } + + // + return result; + } + /** * Gets the mobilizon webpage. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceGenericMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceGenericMetricPage.java new file mode 100644 index 0000000..f5b4442 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceGenericMetricPage.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020-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.Service; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServicePage. + */ +public class ServiceGenericMetricPage +{ + private static Logger logger = LoggerFactory.getLogger(ServiceGenericMetricPage.class); + + /** + * Builds the. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building service page {}…", service.get("service.name")); + + TagDataManager data = new TagDataManager(); + + // + data.setContent("headerView", ServiceHeaderView.htmlize(service)); + data.setContent("serviceMetricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.GENERIC)); + + // + int graphicIndex = 0; + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/service.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); + trail.add(service.getName(), service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java new file mode 100644 index 0000000..d0d707f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2020-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.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.checker.PropertyChecks; +import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.DisplayMode; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; +import fr.devinsy.xidyn.utils.XidynUtils; + +/** + * The Class ServiceHeaderView. + */ +public class ServiceHeaderView +{ + private static Logger logger = LoggerFactory.getLogger(ServiceHeaderView.class); + + /** + * Htmlize. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service) throws StatoolInfosException + { + String result; + + try + { + logger.debug("htmlizing service header page {}…", service.get("service.name")); + + TagDataManager data = new TagDataManager(); + + data.setAttribute("serviceLogo", "src", service.getLogoFileName()); + + data.setEscapedContent("serviceName", service.getName()); + data.setEscapedAttribute("serviceName", "href", service.getWebsite()); + + data.setEscapedContent("serviceURL", service.getWebsite()); + data.setEscapedAttribute("serviceURL", "href", service.getWebsite()); + + data.setEscapedContent("serviceDescription", StringUtils.defaultIfBlank(service.getDescription(), "n/a")); + + data.setContent("serviceStartDate", StringUtils.defaultIfBlank(service.getStartDate(), "n/a")); + data.setContent("serviceEndDate", StringUtils.defaultIfBlank(service.getEndDate(), "n/a")); + data.setContent("serviceAge", StringUtils.defaultIfBlank(service.getAge(), "n/a")); + if (StringUtils.isBlank(service.getEndDate())) + { + data.setAttribute("serviceEndDateData", "style", "display: none;"); + } + else + { + data.setAttribute("serviceStartDateWord", "style", "display: none;"); + } + + data.setAttribute("serviceStatusImg", "src", "status-" + service.getStatus().toString().toLowerCase() + ".png"); + data.setAttribute("serviceStatusImg", "title", StringUtils.defaultIfBlank(service.getStatusDescription(), service.getStatus().toString())); + + data.setAttribute("rawLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".properties"); + data.setAttribute("rawCheckLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"); + + data.setAttribute("statsLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + + if (StringUtils.isNotBlank(service.getLegalWebsite())) + { + data.setEscapedAttribute("legalLink", "href", service.getLegalWebsite()); + data.setAttribute("legalLinkImg", "class", ""); + data.getIdData("legalLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (StringUtils.isNotBlank(service.getContactWebsite())) + { + data.setEscapedAttribute("contactLink", "href", service.getContactWebsite()); + data.setAttribute("contactLinkImg", "class", ""); + data.getIdData("contactLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (StringUtils.isNotBlank(service.getContactEmail())) + { + data.setEscapedAttribute("emailLink", "href", "mailto:" + service.getContactEmail()); + data.setAttribute("emailLinkImg", "class", ""); + data.getIdData("emailLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (StringUtils.isNotBlank(service.getUserDocWebsite())) + { + data.setEscapedAttribute("userDocLink", "href", service.getUserDocWebsite()); + data.setAttribute("userDocLinkImg", "class", ""); + data.getIdData("userDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (StringUtils.isNotBlank(service.getTechnicalDocWebsite())) + { + data.setEscapedAttribute("technicalDocLink", "href", service.getTechnicalDocWebsite()); + data.setAttribute("technicalDocLinkImg", "class", ""); + data.getIdData("technicalDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + + // + if (service.isRegistrationNone()) + { + data.setAttribute("registrationNoneImg", "class", ""); + data.getIdData("registrationNoneImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (service.isRegistrationFree()) + { + data.setAttribute("registrationFreeImg", "class", ""); + data.getIdData("registrationFreeImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (service.isRegistrationMember()) + { + data.setAttribute("registrationMemberImg", "class", ""); + data.getIdData("registrationMemberImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (service.isRegistrationClient()) + { + data.setAttribute("registrationClientImg", "class", ""); + data.getIdData("registrationClientImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (service.isRegistrationLoadFull()) + { + data.setAttribute("registrationLoadImg", "class", ""); + data.getIdData("registrationLoadImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + + // + data.setEscapedContent("softwareName", StringUtils.defaultIfBlank(service.getSoftwareName(), "n/a")); + data.setContent("softwareVersion", StringUtils.defaultIfBlank(service.getSoftwareVersion(), "n/a")); + data.setEscapedContent("softwareLicenseName", StringUtils.defaultIfBlank(service.getSoftwareLicenseName(), "n/a")); + if (StringUtils.isNotBlank(service.getSoftwareWebsite())) + { + data.setEscapedAttribute("softwareWebsiteLink", "href", service.getSoftwareWebsite()); + data.setAttribute("softwareWebsiteLinkImg", "class", ""); + data.getIdData("softwareWebsiteLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (StringUtils.isNotBlank(service.getSoftwareLicenseWebpage())) + { + data.setEscapedAttribute("softwareLicenseLink", "href", service.getSoftwareLicenseWebpage()); + data.setAttribute("softwareLicenseLinkImg", "class", ""); + data.getIdData("softwareLicenseLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + if (StringUtils.isNotBlank(service.getSoftwareSourceWebsite())) + { + data.setEscapedAttribute("softwareSourceLink", "href", service.getSoftwareSourceWebsite()); + data.setAttribute("softwareSourceLinkImg", "class", ""); + data.getIdData("softwareSourceLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); + } + + data.setAttribute("crawlLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-crawl.xhtml"); + if (service.getCrawlJournal().getErrors().isEmpty()) + { + data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg"); + } + else + { + data.setAttribute("crawlLinkImg", "src", "circle-icons/download.svg"); + } + + { + PropertyChecks checks = service.getInputChecksAll(); + data.setContent("errorCount", checks.getErrorCount()); + data.setContent("warningCount", checks.getWarningCount()); + data.setContent("voidCount", checks.getVoidCount()); + + data.setAttribute("alertLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml#alerts"); + } + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceHeaderView.xhtml", data).toString(); + + result = XidynUtils.extractBodyContent(content); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service header view: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java new file mode 100644 index 0000000..ae29301 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceMetricMenuView.java @@ -0,0 +1,97 @@ +/* + * 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.Service; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +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 ServiceMetricMenuView. + */ +public class ServiceMetricMenuView +{ + private static Logger logger = LoggerFactory.getLogger(ServiceMetricMenuView.class); + + public enum MenuItem + { + SUMMARY, + GENERIC, + WEB, + SPECIFIC + } + + /** + * Htmlize. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service, final MenuItem item) throws StatoolInfosException + { + String result; + + try + { + TagDataManager data = new TagDataManager(); + + data.setAttribute("summaryCategoryButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + data.setAttribute("genericCategoryButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-generic.xhtml"); + data.setAttribute("webCategoryButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-web.xhtml"); + data.setAttribute("specificCategoryButton", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-metrics-specific.xhtml"); + + if ((item == null) || (item == MenuItem.SUMMARY)) + { + data.appendAttribute("summaryCategoryButton", "class", "button selected"); + } + else if (item == MenuItem.GENERIC) + { + data.appendAttribute("genericCategoryButton", "class", "button selected"); + } + else if (item == MenuItem.WEB) + { + data.appendAttribute("webCategoryButton", "class", "button selected"); + } + else if (item == MenuItem.SPECIFIC) + { + data.appendAttribute("specificCategoryButton", "class", "button selected"); + } + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/serviceMetricMenuView.xhtml", data).toString(); + result = XidynUtils.extractBodyContent(content); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service metric menu view: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index a1508d0..54aca11 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -21,24 +21,22 @@ package fr.devinsy.statoolinfos.htmlize; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.time.YearMonth; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.catgenerator.core.BirdGenerator; import fr.devinsy.statoolinfos.HtmlizerContext; -import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.core.Metrics; -import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.crawl.CrawlCache; +import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.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.DisplayMode; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -78,8 +76,21 @@ public class ServicePage // logger.info("Htmlize service page: {}.", service.getName()); - String page = ServicePage.htmlize(service.getOrganization(), service); + String page = ServicePage.htmlize(service); FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + ".xhtml"), page, StandardCharsets.UTF_8); + + // + logger.info("Htmlize service generic metric page: {}.", service.getName()); + page = ServiceGenericMetricPage.htmlize(service); + FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-metrics-generic.xhtml"), page, StandardCharsets.UTF_8); + + logger.info("Htmlize service web metric page: {}.", service.getName()); + page = ServiceWebMetricPage.htmlize(service); + FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-metrics-web.xhtml"), page, StandardCharsets.UTF_8); + + logger.info("Htmlize service specific metric page: {}.", service.getName()); + page = ServiceSpecificMetricPage.htmlize(service); + FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-metrics-specific.xhtml"), page, StandardCharsets.UTF_8); } /** @@ -107,7 +118,7 @@ public class ServicePage * @throws StatoolInfosException * the statool infos exception */ - public static String htmlize(final Organization organization, final Service service) throws StatoolInfosException + public static String htmlize(final Service service) throws StatoolInfosException { String result; @@ -117,202 +128,37 @@ public class ServicePage TagDataManager data = new TagDataManager(); - data.setAttribute("serviceLogo", "src", service.getLogoFileName()); - - data.setEscapedContent("serviceName", service.getName()); - data.setEscapedAttribute("serviceName", "href", service.getWebsite()); - - data.setEscapedContent("serviceURL", service.getWebsite()); - data.setEscapedAttribute("serviceURL", "href", service.getWebsite()); - - data.setEscapedContent("serviceDescription", StringUtils.defaultIfBlank(service.getDescription(), "n/a")); - - data.setContent("serviceStartDate", StringUtils.defaultIfBlank(service.getStartDate(), "n/a")); - data.setContent("serviceEndDate", StringUtils.defaultIfBlank(service.getEndDate(), "n/a")); - data.setContent("serviceAge", StringUtils.defaultIfBlank(service.getAge(), "n/a")); - if (StringUtils.isBlank(service.getEndDate())) - { - data.setAttribute("serviceEndDateData", "style", "display: none;"); - } - else - { - data.setAttribute("serviceStartDateWord", "style", "display: none;"); - } - - data.setAttribute("serviceStatusImg", "src", "status-" + service.getStatus().toString().toLowerCase() + ".png"); - data.setAttribute("serviceStatusImg", "title", StringUtils.defaultIfBlank(service.getStatusDescription(), service.getStatus().toString())); - - data.setAttribute("rawLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + ".properties"); - data.setAttribute("rawCheckLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"); - - data.setAttribute("statsLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); - - if (StringUtils.isNotBlank(service.getLegalWebsite())) - { - data.setEscapedAttribute("legalLink", "href", service.getLegalWebsite()); - data.setAttribute("legalLinkImg", "class", ""); - data.getIdData("legalLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (StringUtils.isNotBlank(service.getContactWebsite())) - { - data.setEscapedAttribute("contactLink", "href", service.getContactWebsite()); - data.setAttribute("contactLinkImg", "class", ""); - data.getIdData("contactLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (StringUtils.isNotBlank(service.getContactEmail())) - { - data.setEscapedAttribute("emailLink", "href", "mailto:" + service.getContactEmail()); - data.setAttribute("emailLinkImg", "class", ""); - data.getIdData("emailLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (StringUtils.isNotBlank(service.getUserDocWebsite())) - { - data.setEscapedAttribute("userDocLink", "href", service.getUserDocWebsite()); - data.setAttribute("userDocLinkImg", "class", ""); - data.getIdData("userDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (StringUtils.isNotBlank(service.getTechnicalDocWebsite())) - { - data.setEscapedAttribute("technicalDocLink", "href", service.getTechnicalDocWebsite()); - data.setAttribute("technicalDocLinkImg", "class", ""); - data.getIdData("technicalDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } + // + data.setContent("headerView", ServiceHeaderView.htmlize(service)); + data.setContent("serviceMetricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SUMMARY)); // - if (service.isRegistrationNone()) - { - data.setAttribute("registrationNoneImg", "class", ""); - data.getIdData("registrationNoneImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (service.isRegistrationFree()) - { - data.setAttribute("registrationFreeImg", "class", ""); - data.getIdData("registrationFreeImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (service.isRegistrationMember()) - { - data.setAttribute("registrationMemberImg", "class", ""); - data.getIdData("registrationMemberImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (service.isRegistrationClient()) - { - data.setAttribute("registrationClientImg", "class", ""); - data.getIdData("registrationClientImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (service.isRegistrationLoadFull()) - { - data.setAttribute("registrationLoadImg", "class", ""); - data.getIdData("registrationLoadImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - - // - data.setEscapedContent("softwareName", StringUtils.defaultIfBlank(service.getSoftwareName(), "n/a")); - data.setContent("softwareVersion", StringUtils.defaultIfBlank(service.getSoftwareVersion(), "n/a")); - data.setEscapedContent("softwareLicenseName", StringUtils.defaultIfBlank(service.getSoftwareLicenseName(), "n/a")); - if (StringUtils.isNotBlank(service.getSoftwareWebsite())) - { - data.setEscapedAttribute("softwareWebsiteLink", "href", service.getSoftwareWebsite()); - data.setAttribute("softwareWebsiteLinkImg", "class", ""); - data.getIdData("softwareWebsiteLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (StringUtils.isNotBlank(service.getSoftwareLicenseWebpage())) - { - data.setEscapedAttribute("softwareLicenseLink", "href", service.getSoftwareLicenseWebpage()); - data.setAttribute("softwareLicenseLinkImg", "class", ""); - data.getIdData("softwareLicenseLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - if (StringUtils.isNotBlank(service.getSoftwareSourceWebsite())) - { - data.setEscapedAttribute("softwareSourceLink", "href", service.getSoftwareSourceWebsite()); - data.setAttribute("softwareSourceLinkImg", "class", ""); - data.getIdData("softwareSourceLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE); - } - - data.setAttribute("crawlLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-crawl.xhtml"); - if (service.getCrawlJournal().getErrors().isEmpty()) - { - data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg"); - } - else - { - data.setAttribute("crawlLinkImg", "src", "circle-icons/download.svg"); - } - - { - PropertyChecks checks = service.getInputChecksAll(); - data.setContent("errorCount", checks.getErrorCount()); - data.setContent("warningCount", checks.getWarningCount()); - data.setContent("voidCount", checks.getVoidCount()); - - data.setAttribute("alertLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml#alerts"); - } - - // - int graphicIndex = 0; // data.setContent("fooChart", graphicIndex++, // LineMonthsChartView.build()); // service.getPrefixes(); - MonthValues metric = service.getMetricMonthValues("metrics.http.hits"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.BLUE)); + 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) }; - MonthValues metric4 = service.getMetricMonthValues("metrics.http.hits.ipv4"); - MonthValues metric6 = service.getMetricMonthValues("metrics.http.hits.ipv6"); - data.setContent("fooChart", graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.hits (ipv4 + ipv6)", null, null, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric4, ChartColor.YELLOW)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric6, ChartColor.GREEN)); + for (int index = 0; index < tagIds.length; index++) + { + String tagId = tagIds[index]; + YearMonth start = starts[index]; + YearMonth end = ends[index]; - metric4 = service.getMetricMonthValues("metrics.http.hits.bots"); - metric6 = service.getMetricMonthValues("metrics.http.hits.visitors"); - data.setContent("fooChart", graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.hits (visitors + bots)", null, null, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric4, ChartColor.YELLOW)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric6, ChartColor.GREEN)); + int graphicIndex = 0; - metric = service.getMetricMonthValues("metrics.http.errors"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.RED)); + MonthValues metric = service.getMetricMonthValues("metrics.http.hits.visitors"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN)); - metric = service.getMetricMonthValues("metrics.http.errors.php"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.RED)); + metric = service.getMetricMonthValues("metrics.http.ip.visitors"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN)); - metric = service.getMetricMonthValues("metrics.http.files"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.BLUE)); - - metric = service.getMetricMonthValues("metrics.http.pages"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.BLUE)); - - metric = service.getMetricMonthValues("metrics.http.bytes"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.BLUE)); - - metric = service.getMetricMonthValues("metrics.http.ip"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.BLUE)); - - metric4 = service.getMetricMonthValues("metrics.http.ip.bots"); - metric6 = service.getMetricMonthValues("metrics.http.ip.visitors"); - data.setContent("fooChart", graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.ip (visitors + bots)", null, null, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric6, ChartColor.GREEN)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric4, ChartColor.YELLOW)); - - metric4 = service.getMetricMonthValues("metrics.http.ip.ipv4"); - metric6 = service.getMetricMonthValues("metrics.http.ip.ipv6"); - data.setContent("fooChart", graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.ip (ipv4 + ipv6)", null, null, new ChartColor[] { ChartColor.YELLOW, ChartColor.GREEN }, metric4, metric6)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric4, ChartColor.YELLOW)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric6, ChartColor.GREEN)); - - metric = service.getMetricMonthValues("metrics.http.visits"); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric, ChartColor.BLUE)); - - metric4 = service.getMetricMonthValues("metrics.http.visits.bots"); - metric6 = service.getMetricMonthValues("metrics.http.visits.visitors"); - data.setContent("fooChart", graphicIndex++, - ChartHtmlizer.htmlizeMetricsChart("http.visits (visitors + bots)", null, null, new ChartColor[] { ChartColor.GREEN, ChartColor.YELLOW }, metric6, metric4)); - - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric6, ChartColor.GREEN)); - data.setContent("fooChart", graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(null, null, metric4, ChartColor.YELLOW)); + metric = service.getMetricMonthValues("metrics.http.visits.visitors"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.GREEN)); + } // String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/service.xhtml", data).toString(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceSpecificMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceSpecificMetricPage.java new file mode 100644 index 0000000..c1fb2a7 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceSpecificMetricPage.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020-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.Service; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.MenuItem; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServicePage. + */ +public class ServiceSpecificMetricPage +{ + private static Logger logger = LoggerFactory.getLogger(ServiceSpecificMetricPage.class); + + /** + * Builds the. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building service specific page {}…", service.get("service.name")); + + TagDataManager data = new TagDataManager(); + + // + data.setContent("headerView", ServiceHeaderView.htmlize(service)); + data.setContent("serviceMetricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.SPECIFIC)); + + // + int graphicIndex = 0; + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/service.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); + trail.add(service.getName(), service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceWebMetricPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceWebMetricPage.java new file mode 100644 index 0000000..30bf382 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceWebMetricPage.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2020-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.Service; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.ServiceMetricMenuView.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 ServicePage. + */ +public class ServiceWebMetricPage +{ + private static Logger logger = LoggerFactory.getLogger(ServiceWebMetricPage.class); + + /** + * Builds the. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building service generic metric page {}…", service.get("service.name")); + + TagDataManager data = new TagDataManager(); + + // + data.setContent("headerView", ServiceHeaderView.htmlize(service)); + data.setContent("serviceMetricMenuView", ServiceMetricMenuView.htmlize(service, MenuItem.WEB)); + + // service.getPrefixes(); + + 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 = service.getMetricMonthValues("metrics.http.hits"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); + + MonthValues metric4 = service.getMetricMonthValues("metrics.http.hits.ipv4"); + MonthValues metric6 = service.getMetricMonthValues("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 = service.getMetricMonthValues("metrics.http.hits.bots"); + metric6 = service.getMetricMonthValues("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, metric4, ChartColor.YELLOW)); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric6, ChartColor.GREEN)); + + metric = service.getMetricMonthValues("metrics.http.errors"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED)); + + metric = service.getMetricMonthValues("metrics.http.errors.php"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.RED)); + + metric = service.getMetricMonthValues("metrics.http.files"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); + + metric = service.getMetricMonthValues("metrics.http.pages"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); + + metric = service.getMetricMonthValues("metrics.http.bytes"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); + + metric = service.getMetricMonthValues("metrics.http.ip"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); + + metric4 = service.getMetricMonthValues("metrics.http.ip.bots"); + metric6 = service.getMetricMonthValues("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 = service.getMetricMonthValues("metrics.http.ip.ipv4"); + metric6 = service.getMetricMonthValues("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 = service.getMetricMonthValues("metrics.http.visits"); + data.setContent(tagId, graphicIndex++, ChartHtmlizer.htmlizeMetricsChart(start, end, metric, ChartColor.BLUE)); + + metric4 = service.getMetricMonthValues("metrics.http.visits.bots"); + metric6 = service.getMetricMonthValues("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/service.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(service.getOrganization().getName(), service.getOrganization().getTechnicalName() + ".xhtml"); + trail.add(service.getName(), service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java index b13042a..7bb892b 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/charts/BarChartView.java @@ -21,6 +21,7 @@ package fr.devinsy.statoolinfos.htmlize.charts; import java.io.IOException; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,7 +55,7 @@ public class BarChartView String source = XidynUtils.load(BarChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/barChartView.xhtml")); result = XidynUtils.extractBodyContent(source); - result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(chart.getTitle() + "barChart")); + result = result.replace("myChart", "myChart_" + DigestUtils.sha1Hex(chart.getTitle() + "barChart" + RandomStringUtils.random(10))); StringList lines = new StringList(); lines.append("{\n"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/service.xhtml b/src/fr/devinsy/statoolinfos/htmlize/service.xhtml index d42c82d..8128a01 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/service.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/service.xhtml @@ -11,57 +11,21 @@ -
-
-
- -
- -

Description absente…

+
+
+
+