diff --git a/src/fr/devinsy/statoolinfos/HtmlizerContext.java b/src/fr/devinsy/statoolinfos/HtmlizerContext.java index bafd15a..31ca656 100644 --- a/src/fr/devinsy/statoolinfos/HtmlizerContext.java +++ b/src/fr/devinsy/statoolinfos/HtmlizerContext.java @@ -27,6 +27,7 @@ import fr.devinsy.statoolinfos.core.Factory; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.crawl.CrawlCache; +import fr.devinsy.statoolinfos.uptime.UptimeJournal; /** * The Class Manager. @@ -44,6 +45,7 @@ public class HtmlizerContext private Federation federation; private Categories categories; private CrawlCache cache; + private UptimeJournal uptimeJournal; /** * Instantiates a new manager. @@ -89,6 +91,7 @@ public class HtmlizerContext { this.federation = Factory.loadFederation(this.configuration.getHtmlizeInputURL(), this.cache); this.categories = Factory.loadCategories(this.configuration.getCategoryFile(), this.federation); + this.uptimeJournal = this.cache.restoreUptimeJournal(); } else { @@ -172,6 +175,11 @@ public class HtmlizerContext return result; } + public UptimeJournal getUptimeJournal() + { + return this.uptimeJournal; + } + /** * Instance. * diff --git a/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java b/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java index 4b6137b..705cbbd 100644 --- a/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java +++ b/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java @@ -117,6 +117,7 @@ public final class StatoolInfosCLI message.appendln(" statoolinfos stat ua [-bot|-nobot] generate stats about user agent from log file"); message.appendln(" statoolinfos stat visitors [-bot|-nobot] generate stats about visitors (ip+ua) from log file"); message.appendln(" statoolinfos tagdate update the file.datetime file"); + message.appendln(" statoolinfos uptime update uptime journal"); System.out.println(message.toString()); } @@ -461,6 +462,24 @@ public final class StatoolInfosCLI } } } + else if (isMatching(args, "uptime", "\\s*.+\\s*")) + { + Chrono chrono = new Chrono().start(); + Files inputs = convertPath(StringUtils.trim(args[1])); + for (File input : inputs) + { + try + { + StatoolInfos.uptime(input); + } + catch (Exception exception) + { + logger.error("Error with [{}]: {}", input.getAbsoluteFile(), exception.getMessage()); + exception.printStackTrace(); + } + } + System.out.println(chrono.format()); + } else { System.out.println("Bad usage."); diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index d6d5599..8d1100d 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -33,6 +33,7 @@ import fr.devinsy.statoolinfos.crawl.CrawlJournal; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathPropertyUtils; +import fr.devinsy.statoolinfos.util.Chrono; import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringSet; @@ -167,6 +168,7 @@ public class Factory Federation result; System.out.println("Loading federation " + inputURL); + Chrono chrono = new Chrono().start(); if (inputURL == null) { @@ -220,9 +222,10 @@ public class Factory } // - result.getCrawlJournal().addAll(cache.restoreJournal()); + result.getCrawlJournal().addAll(cache.restoreCrawlJournal()); } } + System.out.println("Federation loaded in " + chrono.format()); // return result; @@ -329,7 +332,7 @@ public class Factory } // - CrawlJournal journal = cache.restoreJournal(); + CrawlJournal journal = cache.restoreCrawlJournal(); result.getCrawlJournal().add(journal.getByUrl(inputURL)); result.getCrawlJournal().addAll(journal.searchByParent(result.getInputURL())); for (Service service : result.getServices()) @@ -398,7 +401,7 @@ public class Factory result.getInputChecks().addAll(checks); // - CrawlJournal journal = cache.restoreJournal(); + CrawlJournal journal = cache.restoreCrawlJournal(); result.getCrawlJournal().add(journal.getByUrl(inputURL)); result.getCrawlJournal().addAll(journal.searchByParent(result.getInputURL())); diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index 1f7b933..7d8e5d5 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -32,6 +32,7 @@ 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; +import fr.devinsy.statoolinfos.uptime.URLSet; import fr.devinsy.statoolinfos.util.URLUtils; /** @@ -80,26 +81,6 @@ public class Federation extends PathPropertyList } } - /** - * Gets the all services. - * - * @return the all services - */ - public Services getAllServices() - { - Services result; - - result = new Services(); - - for (Organization organization : this.organizations) - { - result.addAll(organization.getServices()); - } - - // - return result; - } - /** * Gets the contact email. * @@ -278,9 +259,8 @@ public class Federation extends PathPropertyList * Gets the logo URL. * * @return the logo URL - * @throws MalformedURLException */ - public URL getLogoURL() throws MalformedURLException + public URL getLogoURL() { URL result; @@ -425,6 +405,26 @@ public class Federation extends PathPropertyList return result; } + /** + * Gets the all services. + * + * @return the all services + */ + public Services getServicesAll() + { + Services result; + + result = new Services(); + + for (Organization organization : this.organizations) + { + result.addAll(organization.getServices()); + } + + // + return result; + } + /** * Gets the software catalog. * @@ -436,7 +436,7 @@ public class Federation extends PathPropertyList result = new Softwares(); - for (Service service : getAllServices()) + for (Service service : getServicesAll()) { if (StringUtils.isNotBlank(service.getSoftwareName())) { @@ -501,6 +501,54 @@ public class Federation extends PathPropertyList return result; } + /** + * Gets the URL all. + * + * @return the URL all + */ + public URLSet getURLAll() + { + URLSet result; + + result = new URLSet(); + + // + result.add(getContactURL()); + result.add(getLegalURL()); + result.add(getLogoURL()); + result.add(getTechnicalGuideURL()); + result.add(getUserGuideURL()); + result.add(getWebsiteURL()); + + // + for (Organization organization : getOrganizations()) + { + result.add(organization.getContactURL()); + result.add(organization.getLegalURL()); + result.add(organization.getLogoURL()); + result.add(organization.getTechnicalGuideURL()); + result.add(organization.getUserGuideURL()); + result.add(organization.getWebsiteURL()); + + // + for (Service service : organization.getServices()) + { + result.add(service.getContactURL()); + result.add(service.getLegalURL()); + result.add(service.getLogoURL()); + result.add(service.getSoftwareWebsite()); + result.add(service.getSoftwareLicenseURL()); + result.add(service.getSoftwareSourceURL()); + result.add(service.getTechnicalGuideURL()); + result.add(service.getUserGuideURL()); + result.add(service.getWebsiteURL()); + } + } + + // + return result; + } + /** * Gets the user doc website. * diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index b5eef5d..6e0e2c2 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -19,7 +19,6 @@ package fr.devinsy.statoolinfos.core; import java.io.File; -import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; @@ -431,10 +430,8 @@ public class Service extends PathPropertyList * Gets the logo URL. * * @return the logo URL - * @throws MalformedURLException - * the malformed URL exception */ - public URL getLogoURL() throws MalformedURLException + public URL getLogoURL() { URL result; diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java index 8e711bb..9d7174f 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.build.Builder; import fr.devinsy.statoolinfos.crawl.Crawler; import fr.devinsy.statoolinfos.htmlize.Htmlizer; @@ -42,6 +43,8 @@ import fr.devinsy.statoolinfos.stats.useragent.UserAgentStat; import fr.devinsy.statoolinfos.stats.useragent.UserAgentStator; import fr.devinsy.statoolinfos.stats.visitor.VisitorStat; import fr.devinsy.statoolinfos.stats.visitor.VisitorStator; +import fr.devinsy.statoolinfos.uptime.UptimeJournal; +import fr.devinsy.statoolinfos.uptime.UptimeSurveyor; import fr.devinsy.statoolinfos.util.Chrono; import fr.devinsy.statoolinfos.util.LineIterator; import fr.devinsy.strings.StringList; @@ -527,4 +530,24 @@ public class StatoolInfos StringsUtils.save(inputFile, lines); } } + + /** + * Uptime. + * + * @param configurationFile + * the configuration file + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void uptime(final File configurationFile) throws StatoolInfosException, IOException + { + HtmlizerContext.instance().configure(configurationFile); + + UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal(); + Federation federation = HtmlizerContext.instance().getFederation(); + UptimeSurveyor.survey(journal, federation.getURLAll()); + HtmlizerContext.instance().getCache().storeUptimeJournal(journal); + } } diff --git a/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java b/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java index ede5177..5cf8b11 100644 --- a/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java +++ b/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java @@ -37,6 +37,8 @@ import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyUtils; +import fr.devinsy.statoolinfos.uptime.UptimeJournal; +import fr.devinsy.statoolinfos.uptime.UptimeJournalFile; import fr.devinsy.statoolinfos.util.URLUtils; /** @@ -144,6 +146,22 @@ public class CrawlCache return result; } + /** + * @return + * @throws IOException + */ + public CrawlJournal restoreCrawlJournal() throws IOException + { + CrawlJournal result; + + File journalFile = restoreFile(getCrawlJournalURL()); + + result = CrawlJournalFile.load(journalFile); + + // + return result; + } + /** * Restore file. * @@ -191,22 +209,6 @@ public class CrawlCache } } - /** - * @return - * @throws IOException - */ - public CrawlJournal restoreJournal() throws IOException - { - CrawlJournal result; - - File journalFile = restoreFile(getJournalURL()); - - result = CrawlJournalFile.load(journalFile); - - // - return result; - } - /** * Restore logo to. * @@ -281,6 +283,32 @@ public class CrawlCache return result; } + /** + * Restore uptime journal. + * + * @return the crawl journal + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public UptimeJournal restoreUptimeJournal() throws IOException + { + UptimeJournal result; + + File journalFile = restoreFile(getUptimeJournalURL()); + + if (journalFile == null) + { + result = new UptimeJournal(); + } + else + { + result = UptimeJournalFile.load(journalFile); + } + + // + return result; + } + /** * Store. * @@ -311,15 +339,18 @@ public class CrawlCache } /** - * Store journal. + * Store crawl journal. + * + * @param journal + * the journal */ - public void storeJournal(final CrawlJournal journal) + public void storeCrawlJournal(final CrawlJournal journal) { try { File file = Files.createTempFile("tmp-", ".statoolsinfos").toFile(); CrawlJournalFile.save(file, journal); - store(getJournalURL(), file); + store(getCrawlJournalURL(), file); file.delete(); } catch (IOException exception) @@ -393,13 +424,34 @@ public class CrawlCache return result; } + /** + * Store journal. + * + * @param journal + * the journal + */ + public void storeUptimeJournal(final UptimeJournal journal) + { + try + { + File file = Files.createTempFile("tmp-", ".statoolsinfos").toFile(); + UptimeJournalFile.save(file, journal); + store(getUptimeJournalURL(), file); + file.delete(); + } + catch (IOException exception) + { + exception.printStackTrace(); + } + } + /** * Gets the journal URL. * * @return the journal URL * @throws MalformedURLException */ - public static URL getJournalURL() throws MalformedURLException + public static URL getCrawlJournalURL() throws MalformedURLException { URL result; @@ -408,4 +460,21 @@ public class CrawlCache // return result; } + + /** + * Gets the uptimes journal URL. + * + * @return the uptimes journal URL + * @throws MalformedURLException + * the malformed URL exception + */ + public static URL getUptimeJournalURL() throws MalformedURLException + { + URL result; + + result = new URL("http://localhost/uptimes.journal"); + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/crawl/Crawler.java b/src/fr/devinsy/statoolinfos/crawl/Crawler.java index 0152dca..6ee7e05 100644 --- a/src/fr/devinsy/statoolinfos/crawl/Crawler.java +++ b/src/fr/devinsy/statoolinfos/crawl/Crawler.java @@ -341,7 +341,7 @@ public class Crawler logger.info("Restoring crawl journal."); - result = this.cache.restoreJournal(); + result = this.cache.restoreCrawlJournal(); // return result; @@ -353,6 +353,6 @@ public class Crawler public void storeJournal() { logger.info("Storing crawl journal."); - this.cache.storeJournal(this.journal); + this.cache.storeCrawlJournal(this.journal); } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java index 4de32e5..b9eeadb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java @@ -60,7 +60,7 @@ public class CategoryPage logger.info("Htmlize category pages."); for (Category category : categories) { - Services services = federation.getAllServices().getBy(category); + Services services = federation.getServicesAll().getBy(category); String page = CategoryPage.htmlize(category, services); FileUtils.write(new File(htmlizeDirectory, "category-" + category.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); } diff --git a/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java index c17bada..4889ad5 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ChartHtmlizer.java @@ -620,8 +620,6 @@ public class ChartHtmlizer * the dataset * @param color * the color - * @param animated - * the animated * @return the string * @throws StatoolInfosException * the statool infos exception @@ -1078,7 +1076,7 @@ public class ChartHtmlizer { String result; - result = htmlizeServiceCountMonthChart(federation.getAllServices(), + result = htmlizeServiceCountMonthChart(federation.getServicesAll(), YearMonth.from(StatoolInfosUtils.parseDate(federation.getStartDate()))); // @@ -1264,7 +1262,7 @@ public class ChartHtmlizer { String result; - result = htmlizeServiceCountYearChart(federation.getAllServices(), + result = htmlizeServiceCountYearChart(federation.getServicesAll(), StatoolInfosUtils.parseDate(federation.getStartDate()).getYear()); // diff --git a/src/fr/devinsy/statoolinfos/htmlize/CrawlJournalPage.java b/src/fr/devinsy/statoolinfos/htmlize/CrawlJournalPage.java index acf6af1..45828da 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CrawlJournalPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CrawlJournalPage.java @@ -69,7 +69,7 @@ public class CrawlJournalPage FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-crawl.xhtml"), page, StandardCharsets.UTF_8); } - for (Service service : federation.getAllServices()) + for (Service service : federation.getServicesAll()) { page = htmlize("Journal des téléchargements de " + service.getName(), service.getCrawlJournal()); FileUtils.write(new File(htmlizeDirectory, service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-crawl.xhtml"), page, StandardCharsets.UTF_8); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java b/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java index 23018d1..f81105c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java @@ -60,7 +60,7 @@ public class ExportsPage { logger.info("EXPORTS CSV."); CSVFile.save(new File(htmlizeDirectory, "organizations.csv"), federation.getOrganizations()); - CSVFile.save(new File(htmlizeDirectory, "services.csv"), federation.getAllServices()); + CSVFile.save(new File(htmlizeDirectory, "services.csv"), federation.getServicesAll()); } catch (IOException exception) { @@ -73,7 +73,7 @@ public class ExportsPage logger.info("EXPORTS JSON."); JSONFile.save(new File(htmlizeDirectory, "federation.json"), federation); JSONFile.save(new File(htmlizeDirectory, "organizations.json"), federation.getOrganizations()); - JSONFile.save(new File(htmlizeDirectory, "services.json"), federation.getAllServices()); + JSONFile.save(new File(htmlizeDirectory, "services.json"), federation.getServicesAll()); } catch (IOException exception) { @@ -85,7 +85,7 @@ public class ExportsPage { logger.info("EXPORTS ODS."); ODSFile.save(new File(htmlizeDirectory, "organizations.ods"), federation.getOrganizations()); - ODSFile.save(new File(htmlizeDirectory, "services.ods"), federation.getAllServices()); + ODSFile.save(new File(htmlizeDirectory, "services.ods"), federation.getServicesAll()); } catch (Exception exception) { diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java b/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java index f303d04..d111a3a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java @@ -77,6 +77,8 @@ public class FederationHeaderView data.setAttribute("metricsLink", "href", federation.getTechnicalName() + "-metrics-summary-months-last.xhtml"); data.setAttribute("crawlLink", "href", federation.getTechnicalName() + "-crawl.xhtml"); + data.setAttribute("uptimeLink", "href", federation.getLocalFileBaseName() + "-uptimes.xhtml"); + if (federation.getCrawlJournal().getErrors().isEmpty()) { data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java index d287f00..680efdc 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationStatsPage.java @@ -69,14 +69,14 @@ public class FederationStatsPage data.setContent("organizationCountChart", ChartHtmlizer.htmlizeOrganizationCountChart(federation)); data.setContent("organizationInOutChart", ChartHtmlizer.htmlizeOrganizationInOutChart(federation)); - data.setContent("hostServerTypeChart", ChartHtmlizer.htmlizeHostServerTypeChart(federation.getAllServices())); - data.setContent("hostProviderTypeChart", ChartHtmlizer.htmlizeHostProviderTypeChart(federation.getAllServices())); - data.setContent("serviceInstallTypeChart", ChartHtmlizer.htmlizeServiceInstallTypeChart(federation.getAllServices())); - data.setContent("serviceCountryChart", ChartHtmlizer.htmlizeServiceCountryChart(federation.getAllServices())); + data.setContent("hostServerTypeChart", ChartHtmlizer.htmlizeHostServerTypeChart(federation.getServicesAll())); + data.setContent("hostProviderTypeChart", ChartHtmlizer.htmlizeHostProviderTypeChart(federation.getServicesAll())); + data.setContent("serviceInstallTypeChart", ChartHtmlizer.htmlizeServiceInstallTypeChart(federation.getServicesAll())); + data.setContent("serviceCountryChart", ChartHtmlizer.htmlizeServiceCountryChart(federation.getServicesAll())); // { - RegistrationStats stats = StatAgent.statRegistrationTypes(federation.getAllServices()); + RegistrationStats stats = StatAgent.statRegistrationTypes(federation.getServicesAll()); data.setContent("registrationTypeChart", ChartHtmlizer.htmlizeRegistrationBarChart(stats)); data.setContent("registrationNoneTypeChart", ChartHtmlizer.htmlizeRegistrationNonePieChart(stats)); @@ -86,14 +86,14 @@ public class FederationStatsPage } data.setContent("serviceCountYearChart", ChartHtmlizer.htmlizeServiceCountYearChart(federation)); - data.setContent("serviceDateStatusChart", ChartHtmlizer.htmlizeServiceDateStatusChart(federation.getAllServices())); + data.setContent("serviceDateStatusChart", ChartHtmlizer.htmlizeServiceDateStatusChart(federation.getServicesAll())); data.setContent("softwareDistributionChart", ChartHtmlizer.htmlizeSoftwareDistributionChart()); - data.setContent("softwareDistributionPieChart", ChartHtmlizer.htmlizeSoftwareDistributionPieChart(federation.getAllServices())); + data.setContent("softwareDistributionPieChart", ChartHtmlizer.htmlizeSoftwareDistributionPieChart(federation.getServicesAll())); data.setContent("categoryDistributionChart", ChartHtmlizer.htmlizeCategoryDistributionChart()); - data.setContent("categoryDistributionPieChart", ChartHtmlizer.htmlizeCatergoryDistributionPieChart(federation.getAllServices())); + data.setContent("categoryDistributionPieChart", ChartHtmlizer.htmlizeCatergoryDistributionPieChart(federation.getServicesAll())); - data.setContent("hostNameChart", ChartHtmlizer.htmlizeHostNamePieChart(federation.getAllServices())); + data.setContent("hostNameChart", ChartHtmlizer.htmlizeHostNamePieChart(federation.getServicesAll())); // String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml", data).toString(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java new file mode 100644 index 0000000..a6c4419 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java @@ -0,0 +1,99 @@ +/* + * 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.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.statoolinfos.uptime.UptimeJournal; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class FederationUptimePage. + */ +public class FederationUptimePage +{ + private static Logger logger = LoggerFactory.getLogger(FederationUptimePage.class); + + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void build() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal(); + + String page = htmlize(federation, journal); + FileUtils.write(new File(htmlizeDirectory, federation.getLocalFileBaseName() + "-uptimes.xhtml"), page, StandardCharsets.UTF_8); + } + + /** + * Htmlize. + * + * @param services + * the services + * @param journal + * the journal + * @return the string + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + */ + public static String htmlize(final Federation federation, final UptimeJournal journal) throws StatoolInfosException, IOException + { + String result; + + try + { + TagDataManager data = new TagDataManager(); + + data.setContent("headerView", FederationHeaderView.htmlize(federation)); + data.setContent("uptimeView", UptimeView.htmlize(federation.getServicesAll(), journal)); + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add("Disponibilités", federation.getLocalFileBaseName() + "-uptimes.xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building FederationUptime page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index cbc9a27..206f12e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -165,11 +165,14 @@ public class Htmlizer ExportsPage.build(); FederationPage.build(); FederationStatsPage.build(); + FederationUptimePage.build(); OrganizationPage.buildAll(); + OrganizationUptimePage.buildAll(); PropertyFileCheckPage.buildAll(); PropertiesFilesPage.build(); PropertyStatsPage.buildAll(); ServicePage.buildAll(); + ServiceUptimePage.buildAll(); ServicesPage.build(); SoftwaresPage.build(); SoftwarePage.buildAll(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationHeaderView.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationHeaderView.java index b436a75..846f7f8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationHeaderView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationHeaderView.java @@ -103,6 +103,8 @@ public class OrganizationHeaderView data.setAttribute("metricsLink", "href", organization.getTechnicalName() + "-metrics-summary-months-last.xhtml"); data.setAttribute("crawlLink", "href", organization.getTechnicalName() + "-crawl.xhtml"); + data.setAttribute("uptimeLink", "href", organization.getLocalFileBaseName() + "-uptimes.xhtml"); + if (organization.getCrawlJournal().getErrors().isEmpty()) { data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationUptimePage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationUptimePage.java new file mode 100644 index 0000000..3e373ca --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationUptimePage.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 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.Organization; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.uptime.UptimeJournal; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class OrganizationUptimePage. + */ +public class OrganizationUptimePage +{ + private static Logger logger = LoggerFactory.getLogger(OrganizationUptimePage.class); + + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void build(final Organization organization) throws StatoolInfosException, IOException + { + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal(); + + String page = htmlize(organization, journal); + FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-uptimes.xhtml"), page, StandardCharsets.UTF_8); + } + + /** + * Builds the all. + * + * @throws IOException + * @throws StatoolInfosException + */ + public static void buildAll() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + + for (Organization organization : federation.getOrganizations()) + { + build(organization); + } + } + + /** + * Htmlize. + * + * @param organization + * the organization + * @param journal + * the journal + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Organization organization, final UptimeJournal journal) throws StatoolInfosException + { + String result; + + try + { + TagDataManager data = new TagDataManager(); + + data.setContent("headerView", OrganizationHeaderView.htmlize(organization)); + data.setContent("uptimeView", UptimeView.htmlize(organization.getServices(), journal)); + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(organization.getName(), organization.getLocalFileBaseName() + ".xhtml"); + trail.add("Disponibilités", organization.getLocalFileBaseName() + "-uptimes.xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building about page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java index 4e563ee..d8b55bf 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java @@ -74,7 +74,7 @@ public class PropertyStatsPage page = PropertyStatsPage.htmlize("Les propriétés des organizations", organizationsStats); FileUtils.write(new File(htmlizeDirectory, "propertyStats-organizations.xhtml"), page, StandardCharsets.UTF_8); - PropertyStats servicesStats = StatAgent.statServicesProperties(federation.getAllServices()); + PropertyStats servicesStats = StatAgent.statServicesProperties(federation.getServicesAll()); page = PropertyStatsPage.htmlize("Les propriétés des services", servicesStats); FileUtils.write(new File(htmlizeDirectory, "propertyStats-services.xhtml"), page, StandardCharsets.UTF_8); } diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java index 488cb8e..e0b4b29 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceHeaderView.java @@ -180,6 +180,7 @@ public class ServiceHeaderView { data.setAttribute("crawlLinkImg", "src", "circle-icons/download.svg"); } + data.setAttribute("uptimeLink", "href", service.getLocalFileBaseName() + "-uptimes.xhtml"); { PropertyChecks checks = service.getInputChecksAll(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index 90bfcba..b5dc908 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -107,7 +107,7 @@ public class ServicePage */ public static void buildAll() throws IOException, StatoolInfosException { - for (Service service : HtmlizerContext.instance().getFederation().getAllServices()) + for (Service service : HtmlizerContext.instance().getFederation().getServicesAll()) { build(service); } diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceUptimePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceUptimePage.java new file mode 100644 index 0000000..00377e3 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceUptimePage.java @@ -0,0 +1,122 @@ +/* + * 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.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.Service; +import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.uptime.UptimeJournal; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServiceUptimePage. + */ +public class ServiceUptimePage +{ + private static Logger logger = LoggerFactory.getLogger(ServiceUptimePage.class); + + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void build(final Service service) throws StatoolInfosException, IOException + { + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal(); + + String page = htmlize(service, journal); + FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-uptimes.xhtml"), page, StandardCharsets.UTF_8); + } + + /** + * Builds the all. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void buildAll() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + + for (Service service : federation.getServicesAll()) + { + build(service); + } + } + + /** + * Htmlize. + * + * @param service + * the service + * @param journal + * the journal + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Service service, final UptimeJournal journal) throws StatoolInfosException + { + String result; + + try + { + TagDataManager data = new TagDataManager(); + + data.setContent("headerView", ServiceHeaderView.htmlize(service)); + + Services services = new Services(); + services.add(service); + data.setContent("uptimeView", UptimeView.htmlize(services, journal)); + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(service.getOrganization().getName(), service.getOrganization().getLocalFileBaseName() + ".xhtml"); + trail.add(service.getName(), service.getLocalFileBaseName() + ".xhtml"); + trail.add("Disponibilités", service.getLocalFileBaseName() + "-uptimes.xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building about page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java index b08f460..4199843 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java @@ -53,7 +53,7 @@ public class ServicesPage File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); logger.info("Htmlize services page."); - String page = ServicesPage.htmlize(federation.getAllServices()); + String page = ServicesPage.htmlize(federation.getServicesAll()); FileUtils.write(new File(htmlizeDirectory, "services.xhtml"), page, StandardCharsets.UTF_8); } diff --git a/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java b/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java index da70e31..75dffbc 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java @@ -58,7 +58,7 @@ public class SoftwarePage Softwares catalog = federation.getSoftwares(); for (Software software : catalog.values()) { - Services services = federation.getAllServices().getBy(software); + Services services = federation.getServicesAll().getBy(software); String page = SoftwarePage.htmlize(software, services); FileUtils.write(new File(htmlizeDirectory, "software-" + software.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); } diff --git a/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java new file mode 100644 index 0000000..e54fa3b --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java @@ -0,0 +1,121 @@ +/* + * 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.DayOfWeek; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +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.uptime.UptimeJournal; +import fr.devinsy.statoolinfos.uptime.UptimeStat; +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 UptimeView. + */ +public class UptimeView +{ + private static Logger logger = LoggerFactory.getLogger(UptimeView.class); + + /** + * Htmlize. + * + * @param services + * the services + * @param journal + * the journal + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String htmlize(final Services services, final UptimeJournal journal) throws StatoolInfosException + { + String result; + + try + { + TagDataManager data = new TagDataManager(); + + int index = 0; + for (Service service : services.sortByName()) + { + // + data.setAttribute("line", index, "lineLogo", "src", service.getLogoFileName()); + data.setEscapedContent("line", index, "lineNameValue", service.getName()); + data.setAttribute("line", index, "lineNameLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + + data.setAttribute("line", index, "lineOrganizationLink", "href", service.getOrganization().getTechnicalName() + ".xhtml"); + data.setAttribute("line", index, "lineOrganizationLogo", "src", service.getOrganization().getLogoFileName()); + data.setEscapedContent("line", index, "lineOrganizationValue", service.getOrganization().getName()); + + // + LocalDate now = LocalDate.now(); + for (int dayCount = 0; dayCount < 22; dayCount++) + { + LocalDate date = now.minusDays(dayCount); + + // + data.setContent("lineHeader-" + dayCount, StringUtils.capitalize(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.FRENCH)).substring(0, 2))); + data.setAttribute("lineHeader-" + dayCount, "title", date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); + + DayOfWeek weekDay = date.getDayOfWeek(); + if ((weekDay == DayOfWeek.SUNDAY) || (weekDay == DayOfWeek.SATURDAY)) + { + data.setAttribute("lineHeader-" + dayCount, "style", "background-color: gainsboro;"); + data.setAttribute("line", index, "uptime-" + dayCount, "style", "background-color: gainsboro;"); + } + else + { + data.setAttribute("lineHeader-" + dayCount, "style", "background-color: #ececec;"); + } + + // + UptimeStat stat = journal.getStat(service.getWebsiteURL(), date); + data.setAttribute("line", index, "statusImg-" + dayCount, "src", "status-" + stat.getStatus().toString().toLowerCase() + ".png"); + String title = String.format("%d ok + %d err %s", stat.getOkCount(), stat.getErrorCount(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); + data.setAttribute("line", index, "statusImg-" + dayCount, "title", title); + } + + // + index += 1; + } + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimeView.xhtml", data).toString(); + result = XidynUtils.extractBodyContent(content); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building about 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 7c37cff..beb4a88 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml @@ -23,7 +23,6 @@

Description absente…

Depuis n/a