diff --git a/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java b/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java index f81105c..56061b1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java @@ -32,6 +32,8 @@ import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.io.CSVFile; import fr.devinsy.statoolinfos.io.JSONFile; import fr.devinsy.statoolinfos.io.ODSFile; +import fr.devinsy.statoolinfos.uptime.ServiceUptimes; +import fr.devinsy.statoolinfos.uptime.ServiceUptimesFile; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -92,6 +94,19 @@ public class ExportsPage logger.error("Error during JSON export: " + exception.getMessage(), exception); } + // + try + { + logger.info("EXPORTS SERVICE UPTIME JOURNAL."); + ServiceUptimes uptimes = ServiceUptimes.of(federation.getServicesAll(), HtmlizerContext.instance().getUptimeJournal()); + ServiceUptimesFile.saveCSV(new File(htmlizeDirectory, "serviceUptimeJournal.csv"), uptimes); + ServiceUptimesFile.saveODS(new File(htmlizeDirectory, "serviceUptimeJournal.ods"), uptimes); + } + catch (Exception exception) + { + logger.error("Error during JSON export: " + exception.getMessage(), exception); + } + // try { diff --git a/src/fr/devinsy/statoolinfos/htmlize/exports.xhtml b/src/fr/devinsy/statoolinfos/htmlize/exports.xhtml index fec50ba..37bc43f 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/exports.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/exports.xhtml @@ -17,9 +17,9 @@
La fédération :
-
+
-
+

@@ -35,6 +35,13 @@
+
+
+
Disponibilités services :
+
+
+
+
diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/log-icon.svg b/src/fr/devinsy/statoolinfos/htmlize/stuff/log-icon.svg new file mode 100644 index 0000000..e08edd3 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/stuff/log-icon.svg @@ -0,0 +1,372 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LOG + + + LOG + + + + + + \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/io/CSVFile.java b/src/fr/devinsy/statoolinfos/io/CSVFile.java index 1400d66..0eb9af6 100644 --- a/src/fr/devinsy/statoolinfos/io/CSVFile.java +++ b/src/fr/devinsy/statoolinfos/io/CSVFile.java @@ -42,7 +42,6 @@ public class CSVFile { private static final Logger logger = LoggerFactory.getLogger(CSVFile.class); - public static final String DEFAULT_CHARSET_NAME = "UTF-8"; public static final int MAX_LINE_SIZE = 4096; public static final String SEPARATOR = ";"; diff --git a/src/fr/devinsy/statoolinfos/io/JSONFile.java b/src/fr/devinsy/statoolinfos/io/JSONFile.java index 154c9c0..fe8c7c5 100644 --- a/src/fr/devinsy/statoolinfos/io/JSONFile.java +++ b/src/fr/devinsy/statoolinfos/io/JSONFile.java @@ -46,8 +46,6 @@ public class JSONFile { private static final Logger logger = LoggerFactory.getLogger(JSONFile.class); - public static final String DEFAULT_CHARSET_NAME = "UTF-8"; - /** * Escape. * diff --git a/src/fr/devinsy/statoolinfos/uptime/ServiceUptime.java b/src/fr/devinsy/statoolinfos/uptime/ServiceUptime.java new file mode 100644 index 0000000..525be1a --- /dev/null +++ b/src/fr/devinsy/statoolinfos/uptime/ServiceUptime.java @@ -0,0 +1,55 @@ +/* + * 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.uptime; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Service; + +/** + * The Class ServiceUptime. + */ +public class ServiceUptime extends Uptime +{ + private static Logger logger = LoggerFactory.getLogger(ServiceUptime.class); + + private Service service; + + /** + * Instantiates a new service uptime. + * + * @param service + * the service + * @param uptime + * the uptime + */ + public ServiceUptime(final Service service, final Uptime uptime) + { + // final URL url, final LocalDateTime datetime, final UptimeStatus + // status, final int code + super(uptime.getURL(), uptime.getDateTime(), uptime.getStatus(), uptime.getCode()); + this.service = service; + } + + public Service getService() + { + return this.service; + } +} diff --git a/src/fr/devinsy/statoolinfos/uptime/ServiceUptimes.java b/src/fr/devinsy/statoolinfos/uptime/ServiceUptimes.java new file mode 100644 index 0000000..3ebe860 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/uptime/ServiceUptimes.java @@ -0,0 +1,129 @@ +/* + * 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.uptime; + +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.strings.StringList; + +/** + * The Class ServiceUptimes. + */ +public class ServiceUptimes extends ArrayList +{ + private static final long serialVersionUID = -4077776702697960767L; + private static Logger logger = LoggerFactory.getLogger(ServiceUptimes.class); + + /** + * Instantiates a new service uptimes. + */ + public ServiceUptimes() + { + } + + /** + * Adds the. + * + * @param serviceName + * the service name + * @param organizationName + * the organization name + * @param uptime + * the uptime + */ + public void add(final Service service, final Uptime uptime) + { + ServiceUptime target = new ServiceUptime(service, uptime); + add(target); + } + + /* (non-Javadoc) + * @see java.util.ArrayList#add(java.lang.Object) + */ + @Override + public boolean add(final ServiceUptime uptime) + { + boolean result; + + if (uptime == null) + { + result = false; + } + else + { + result = super.add(uptime); + } + + // + return result; + } + + /** + * To time list. + * + * @return the string list + */ + public StringList toTimeList() + { + StringList result; + + result = new StringList(); + for (Uptime uptime : this) + { + String line = String.format("%s %s %s %03d %s", uptime.getDateTime().format(DateTimeFormatter.ofPattern("HH:mm")), uptime.getCode(), uptime.getStatus().name()); + result.append(line); + } + + // + return result; + } + + /** + * Of. + * + * @param services + * the services + * @param journal + * the journal + * @return the service uptimes + */ + public static ServiceUptimes of(final Services services, final UptimeJournal journal) + { + ServiceUptimes result; + + result = new ServiceUptimes(); + + for (Service service : services) + { + for (Uptime uptime : journal.getUptimes(service.getWebsiteURL())) + { + result.add(service, uptime); + } + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/uptime/ServiceUptimesFile.java b/src/fr/devinsy/statoolinfos/uptime/ServiceUptimesFile.java new file mode 100644 index 0000000..0fed216 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/uptime/ServiceUptimesFile.java @@ -0,0 +1,127 @@ +/* + * 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.uptime; + +import java.io.File; +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.io.CSVWriter; +import fr.devinsy.statoolinfos.io.ODSWriter; +import fr.devinsy.statoolinfos.io.SpreadsheetWriter; + +/** + * The Class ServiceUptimesFile. + */ +public class ServiceUptimesFile +{ + private static final Logger logger = LoggerFactory.getLogger(ServiceUptimesFile.class); + + /** + * Save CSV. + * + * @param file + * the file + * @param source + * the source + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void saveCSV(final File file, final ServiceUptimes source) throws IOException + { + CSVWriter out = null; + try + { + out = new CSVWriter(file, ';'); + write(out, source); + } + finally + { + out.close(); + } + } + + /** + * Save ODS. + * + * @param file + * the file + * @param source + * the source + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void saveODS(final File file, final ServiceUptimes source) throws IOException + { + ODSWriter out = null; + try + { + out = new ODSWriter(file); + write(out, source); + } + finally + { + out.close(); + } + } + + /** + * Write. + * + * @param out + * the out + * @param organizations + * the organizations + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void write(final SpreadsheetWriter out, final ServiceUptimes uptimes) throws IOException + { + // Write label line. + out.writeCell("serviceName"); + out.writeCell("organizationName"); + out.writeCell("DateTime"); + out.writeCell("Status"); + out.writeCell("Code"); + out.writeCell("URL"); + out.writeEndRow(); + + // Write organization lines. + for (ServiceUptime uptime : uptimes) + { + out.writeCell(uptime.getService().getName()); + out.writeCell(uptime.getService().getOrganization().getName()); + out.writeCell(uptime.getDateTime().toString()); + out.writeCell(uptime.getStatus().toString()); + out.writeCell(String.valueOf(uptime.getCode())); + if (uptime.getURL() == null) + { + out.writeCell(""); + } + else + { + out.writeCell(uptime.getURL().toString()); + } + + out.writeEndRow(); + } + } +} diff --git a/src/fr/devinsy/statoolinfos/uptime/Uptime.java b/src/fr/devinsy/statoolinfos/uptime/Uptime.java index 69a91d3..f86bd73 100644 --- a/src/fr/devinsy/statoolinfos/uptime/Uptime.java +++ b/src/fr/devinsy/statoolinfos/uptime/Uptime.java @@ -87,7 +87,7 @@ public class Uptime return this.status; } - public URL getUrl() + public URL getURL() { return this.url; } diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java index 96d4226..072dfad 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java @@ -58,12 +58,12 @@ public class UptimeJournal { if (uptime != null) { - Uptimes uptimes = this.map.get(uptime.getUrl().toString()); + Uptimes uptimes = this.map.get(uptime.getURL().toString()); if (uptimes == null) { uptimes = new Uptimes(); - this.map.put(uptime.getUrl().toString(), uptimes); + this.map.put(uptime.getURL().toString(), uptimes); } uptimes.add(uptime); diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java index 99812b6..d789de1 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java @@ -223,7 +223,7 @@ public class UptimeJournalFile { for (Uptime uptime : journal.getUptimesAll()) { - String line = String.format("%s %s %d %s", uptime.getDateTime().toString(), uptime.getStatus(), uptime.getCode(), uptime.getUrl()); + String line = String.format("%s %s %d %s", uptime.getDateTime().toString(), uptime.getStatus(), uptime.getCode(), uptime.getURL()); out.write(line); out.write("\n"); } diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java b/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java index c8845f2..f0179a3 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java @@ -138,9 +138,9 @@ public class UptimeSurveyor System.out.println("Survey of " + result.size()); for (Uptime uptime : result) { - int code = survey(uptime.getUrl()); + int code = survey(uptime.getURL()); uptime.update(code); - System.out.println("Uptime: " + uptime.getStatus().toString() + " " + uptime.getUrl().toString()); + System.out.println("Uptime: " + uptime.getStatus().toString() + " " + uptime.getURL().toString()); } //