diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index c750ab0..901f1dc 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -81,6 +81,60 @@ public class Federation extends PathPropertyList } } + /** + * Gets the organizations active. + * + * @return the organizations active + */ + public Organizations getActiveOrganizations() + { + Organizations result; + + result = this.organizations.filterActiveFor(getTechnicalName()); + + // + return result; + } + + /** + * Gets the active services. + * + * @return the active services + */ + public Services getActiveServices() + { + Services result; + + result = new Services(); + + for (Organization organization : getActiveOrganizations()) + { + result.addAll(organization.getActiveServices()); + } + + // + return result; + } + + /** + * Gets the active services. + * + * @return the active services + */ + public long getActiveServiceCount() + { + long result; + + result = 0; + for (Organization organization : getActiveOrganizations()) + { + result += organization.getActiveServiceCount(); + } + + // + return result; + } + /** * Gets the contact email. * @@ -386,21 +440,6 @@ public class Federation extends PathPropertyList return this.organizations; } - /** - * Gets the organizations active. - * - * @return the organizations active - */ - public Organizations getActiveOrganizations() - { - Organizations result; - - result = this.organizations.filterActiveFor(getTechnicalName()); - - // - return result; - } - /** * Gets the service count. * @@ -411,7 +450,7 @@ public class Federation extends PathPropertyList int result; result = 0; - for (Organization organization : this.organizations) + for (Organization organization : getActiveOrganizations()) { result += organization.getServiceCount(); } @@ -420,6 +459,26 @@ public class Federation extends PathPropertyList return result; } + /** + * Gets the all services. + * + * @return the all services + */ + public Services getServices() + { + Services result; + + result = new Services(); + + for (Organization organization : getActiveOrganizations()) + { + result.addAll(organization.getServices()); + } + + // + return result; + } + /** * Gets the all services. * diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index 73f89e9..e7ace71 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -86,6 +86,51 @@ public class Organization extends PathPropertyList this.crawlJournal = new CrawlJournal(); } + /** + * Gets the active services. + * + * @return the active services + */ + public Services getActiveServices() + { + Services result; + + result = new Services(); + + for (Service service : this.services) + { + if (service.isActive()) + { + result.add(service); + } + } + + // + return result; + } + + /** + * Gets the service active count. + * + * @return the service active count + */ + public int getActiveServiceCount() + { + int result; + + result = 0; + for (Service service : this.services) + { + if (service.isActive()) + { + result += 1; + } + } + + // + return result; + } + /** * Gets the age. * @@ -665,21 +710,6 @@ public class Organization extends PathPropertyList return result; } - /** - * Gets the service active count. - * - * @return the service active count - */ - public int getServiceActiveCount() - { - int result; - - result = this.services.getBy(Service.Status.OK).size(); - - // - return result; - } - /** * Gets the service count. * diff --git a/src/fr/devinsy/statoolinfos/core/Organizations.java b/src/fr/devinsy/statoolinfos/core/Organizations.java index db20ddb..7153a7b 100644 --- a/src/fr/devinsy/statoolinfos/core/Organizations.java +++ b/src/fr/devinsy/statoolinfos/core/Organizations.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -110,18 +110,18 @@ public class Organizations extends ArrayList } /** - * Gets the service active count. + * Gets the active service count. * - * @return the service active count + * @return the active service count */ - public int getServiceActiveCount() + public int getActiveServiceCount() { int result; result = 0; for (Organization organization : this) { - result += organization.getServiceCount(); + result += organization.getActiveServiceCount(); } // diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index 7c673a6..d75bec4 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -860,6 +860,59 @@ public class Service extends PathPropertyList return result; } + /** + * Checks if is active. + * + * @return true, if is active + */ + public boolean isActive() + { + boolean result; + + if (((getStatus() == Service.Status.OK) || (getStatus() == Status.WARNING) || (getStatus() == Status.ERROR)) && (!isAway())) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /** + * Checks if is away. + * + * @return true, if is away + */ + public boolean isAway() + { + boolean result; + + if (getEndDate() == null) + { + result = false; + } + else + { + LocalDate endDate = getDate("service.enddate"); + + if ((endDate == null) || (endDate.isAfter(LocalDate.now()))) + { + result = false; + } + else + { + result = true; + } + } + + // + return result; + } + /** * Checks if is registration client. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java index b9eeadb..fa77af1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -60,7 +60,7 @@ public class CategoryPage logger.info("Htmlize category pages."); for (Category category : categories) { - Services services = federation.getServicesAll().getBy(category); + Services services = federation.getServices().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/FederationOrganizationsPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java index ec46bda..3c52e1e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationOrganizationsPage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationServicesPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationServicesPage.java index f8cdbe0..f406ee4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationServicesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationServicesPage.java @@ -78,7 +78,7 @@ public class FederationServicesPage TagDataManager data = new TagDataManager(); data.setContent("federationHeaderView", FederationHeaderView.htmlize(federation)); - data.setContent("serviceListView", ServiceListView.htmlize(federation.getServicesAll())); + data.setContent("serviceListView", ServiceListView.htmlize(federation.getServices())); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationServices.xhtml", data).toString(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java index 6d9c586..b6eca45 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationUptimePage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Christian Pierre MOMON + * Copyright (C) 2021-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -81,7 +81,7 @@ public class FederationUptimePage TagDataManager data = new TagDataManager(); data.setContent("headerView", FederationHeaderView.htmlize(federation)); - data.setContent("uptimeView", UptimeView.htmlize(federation.getServicesAll(), journal)); + data.setContent("uptimeView", UptimeView.htmlize(federation.getActiveServices(), journal)); String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString(); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationListView.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationListView.java index 84252f5..f9a2a63 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationListView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationListView.java @@ -61,7 +61,7 @@ public class OrganizationListView TagDataManager data = new TagDataManager(); data.setContent("organizationCount", organizations.size()); - data.setContent("serviceCount", organizations.getServiceCount()); + data.setContent("serviceCount", organizations.getActiveServiceCount()); String monthLabel = LocalDate.now().minusMonths(1).format(DateTimeFormatter.ofPattern("MMMM yyyy")).replace(" ", " "); data.setContent("monthLabel", monthLabel); @@ -81,7 +81,7 @@ public class OrganizationListView data.setEscapedContent("organizationListLine", index, "organizationListLineUrlLink", organization.getWebsiteURL().toString()); data.setEscapedAttribute("organizationListLine", index, "organizationListLineUrlLink", "href", organization.getWebsiteURL().toString()); } - data.setContent("organizationListLine", index, "organizationListLineServiceCount", StatoolInfosUtils.defaultIfZero(organization.getServiceActiveCount(), "😿")); + data.setContent("organizationListLine", index, "organizationListLineServiceCount", StatoolInfosUtils.defaultIfZero(organization.getActiveServiceCount(), "😿")); data.setContent("organizationListLine", index, "organizationListLineUserCount", StatoolInfosUtils.defaultIfZero(organization.getPreviousMonthUserCount(), "😢")); data.setContent("organizationListLine", index, "organizationListLineVisitCount", StatoolInfosUtils.defaultIfZero(organization.getPreviousMonthVisitCount(), "😞")); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java index 5bcf5e4..13f4527 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -95,8 +95,8 @@ public class ServiceListView data.setEscapedContent("serviceListLine", index, "serviceListLineSoftwareLink", service.getSoftwareName()); data.setAttribute("serviceListLine", index, "serviceListLineSoftwareLink", "href", "software-" + service.getSoftwareTechnicalName() + ".xhtml"); - data.setContent("serviceListLine", index, "serviceListLineUserCount", StatoolInfosUtils.defaultIfZero(service.getPreviousMonthUserCount(), "😞")); - data.setContent("serviceListLine", index, "serviceListLineVisitCount", StatoolInfosUtils.defaultIfZero(service.getPreviousMonthVisitCount(), "😢")); + data.setContent("serviceListLine", index, "serviceListLineUserCount", StatoolInfosUtils.defaultIfZero(service.getPreviousMonthUserCount(), "😢")); + data.setContent("serviceListLine", index, "serviceListLineVisitCount", StatoolInfosUtils.defaultIfZero(service.getPreviousMonthVisitCount(), "😞")); data.setEscapedContent("serviceListLine", index, "serviceListLineDate", service.getCrawledDate().format(DateTimeFormatter.ofPattern("dd/MM/YYYY"))); data.setEscapedAttribute("serviceListLine", index, "serviceListLineDate", "title", service.getCrawledDate().format(DateTimeFormatter.ofPattern("HH:mm:ss"))); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java index 4199843..5554ac4 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.getServicesAll()); + String page = ServicesPage.htmlize(federation.getServices()); 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 75dffbc..cc218dc 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.getServicesAll().getBy(software); + Services services = federation.getServices().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 index 71bbfc4..60b1fdb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Christian Pierre MOMON + * Copyright (C) 2021-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -156,7 +156,7 @@ public class UptimeView } int index = 0; - for (Service service : services.getBy(Service.Status.OK).sortByName()) + for (Service service : services.sortByName()) { // data.setAttribute("line", index, "lineLogo", "src", service.getLogoFileName());