From 53732f23af0cb48bbbe41bc21681c8b3f7270654 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 25 Sep 2020 05:44:40 +0200 Subject: [PATCH] Added Category page. --- .../devinsy/statoolinfos/core/Category.java | 24 +++++ src/fr/devinsy/statoolinfos/core/Factory.java | 35 +++++++ .../devinsy/statoolinfos/core/Services.java | 25 +++++ .../statoolinfos/htmlize/CategoryPage.java | 97 +++++++++++++++++++ .../statoolinfos/htmlize/Htmlizer.java | 15 ++- .../statoolinfos/htmlize/ServicesPage.java | 5 +- .../statoolinfos/htmlize/category.xhtml | 54 +++++++++++ .../statoolinfos/htmlize/organization.xhtml | 44 ++++----- .../htmlize/propertiesFiles.xhtml | 2 +- .../statoolinfos/htmlize/services.xhtml | 65 +++++++------ .../devinsy/statoolinfos/stats/StatAgent.java | 16 --- 11 files changed, 312 insertions(+), 70 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/category.xhtml diff --git a/src/fr/devinsy/statoolinfos/core/Category.java b/src/fr/devinsy/statoolinfos/core/Category.java index a0aa755..c290a84 100644 --- a/src/fr/devinsy/statoolinfos/core/Category.java +++ b/src/fr/devinsy/statoolinfos/core/Category.java @@ -86,6 +86,30 @@ public class Category return result; } + /** + * Matches. + * + * @param service + * the service + * @return true, if successful + */ + public boolean matches(final Service service) + { + boolean result; + + if (this.softwares.contains(service.getSoftwareName())) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + public void setDescription(final String description) { this.description = description; diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index 4435358..e6d6e9d 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -50,8 +50,11 @@ public class Factory /** * Load categories. * + * @param source + * the source * @return the categories * @throws IOException + * Signals that an I/O exception has occurred. */ public static Categories loadCategories(final File source) throws IOException { @@ -85,6 +88,38 @@ public class Factory return result; } + /** + * Load categories. + * + * @param source + * the source + * @param federation + * the federation + * @return the categories + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static Categories loadCategories(final File source, final Federation federation) throws IOException + { + Categories result; + + result = loadCategories(source); + + Category other = new Category("{Autres}", "Qui ne rentre pas dans une catégorie existante."); + result.add(other); + + for (Service service : federation.getAllServices()) + { + if (!result.matches(service.getSoftwareName())) + { + other.getSoftwares().add(service.getSoftwareName()); + } + } + + // + return result; + } + /** * Load configuration. * diff --git a/src/fr/devinsy/statoolinfos/core/Services.java b/src/fr/devinsy/statoolinfos/core/Services.java index 0381fd1..b8baed8 100644 --- a/src/fr/devinsy/statoolinfos/core/Services.java +++ b/src/fr/devinsy/statoolinfos/core/Services.java @@ -36,6 +36,31 @@ public class Services extends ArrayList super(); } + /** + * Gets the by. + * + * @param category + * the category + * @return the by + */ + public Services getBy(final Category category) + { + Services result; + + result = new Services(); + + for (Service service : this) + { + if (category.matches(service)) + { + result.add(service); + } + } + + // + return result; + } + /** * Reverse. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java new file mode 100644 index 0000000..7657a6f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2020 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.Category; +import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServicesPage. + */ +public class CategoryPage +{ + private static Logger logger = LoggerFactory.getLogger(CategoryPage.class); + + /** + * Builds the. + * + * @param categories + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final Category category, final Services services) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building category page."); + + TagDataManager data = new TagDataManager(); + + data.setContent("categoryName", category.getName()); + data.setContent("categoryDescription", category.getDescription()); + data.setContent("categorySoftwares", category.getSoftwares().toStringWithFrenchCommas()); + data.setContent("serviceCount", services.size()); + + int index = 0; + for (Service service : services.sortByName()) + { + data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + data.setAttribute("serviceListLine", index, "serviceListLineLogo", "src", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-logo.png"); + data.setEscapedContent("serviceListLine", index, "serviceListLineNameValue", service.getName()); + + data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLink", "href", service.getOrganization().getTechnicalName() + ".xhtml"); + data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLogo", "src", service.getOrganization().getTechnicalName() + "-logo.png"); + data.setEscapedContent("serviceListLine", index, "serviceListLineOrganizationValue", service.getOrganization().getName()); + + data.setEscapedContent("serviceListLine", index, "serviceListLineUrlLink", service.getWebsite()); + data.setEscapedContent("serviceListLine", index, "serviceListLineWebsiteLink", service.getWebsite()); + data.setAttribute("serviceListLine", index, "serviceListLineWebsiteLink", "href", service.getWebsite()); + data.setEscapedContent("serviceListLine", index, "serviceListLineSoftware", service.getSoftwareName()); + + index += 1; + } + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/category.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add("Catégories", "categories.xhtml"); + trail.add("Catégorie", "category.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/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 2c5ed2d..b899c96 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -28,11 +28,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.Categories; +import fr.devinsy.statoolinfos.core.Category; import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Factory; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.crawl.CrawlCache; @@ -209,6 +211,7 @@ public class Htmlizer File htmlizeDirectory = configuration.getHtmlizeDirectory(); Federation federation = Factory.loadFederation(htmlizeInput, cache); + Categories categories = Factory.loadCategories(configuration.getCategoryFile(), federation); copyStuff(htmlizeDirectory); @@ -283,11 +286,21 @@ public class Htmlizer // { logger.info("Htmlize categories page."); - Categories categories = Factory.loadCategories(configuration.getCategoryFile()); CategoryStats stats = StatAgent.statAllCategories(federation, categories); page = CategoriesPage.build(stats); FileUtils.write(new File(htmlizeDirectory, "categories.xhtml"), page, StandardCharsets.UTF_8); } + + // + { + logger.info("Htmlize category page."); + for (Category category : categories) + { + Services services = federation.getAllServices().getBy(category); + page = CategoryPage.build(category, services); + FileUtils.write(new File(htmlizeDirectory, "category-" + category.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); + } + } } /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java index 57177b1..53f4ae5 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java @@ -62,8 +62,11 @@ public class ServicesPage data.setAttribute("serviceListLine", index, "serviceListLineLogo", "src", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-logo.png"); data.setEscapedContent("serviceListLine", index, "serviceListLineNameValue", service.getName()); data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); - data.setEscapedContent("serviceListLine", index, "serviceListLineOrganizationLink", service.getOrganization().getName()); + data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLink", "href", service.getOrganization().getTechnicalName() + ".xhtml"); + data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLogo", "src", service.getOrganization().getTechnicalName() + "-logo.png"); + data.setEscapedContent("serviceListLine", index, "serviceListLineOrganizationValue", service.getOrganization().getName()); + data.setEscapedContent("serviceListLine", index, "serviceListLineUrlLink", service.getWebsite()); data.setEscapedContent("serviceListLine", index, "serviceListLineWebsiteLink", service.getWebsite()); data.setAttribute("serviceListLine", index, "serviceListLineWebsiteLink", "href", service.getWebsite()); diff --git a/src/fr/devinsy/statoolinfos/htmlize/category.xhtml b/src/fr/devinsy/statoolinfos/htmlize/category.xhtml new file mode 100644 index 0000000..d5f0476 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/category.xhtml @@ -0,0 +1,54 @@ + + + + + StatoolInfos + + + + + + + +
+

Catégorie n/a

+ +

Bla bla description

+
Logiciels : Bla bla logiciels
+
Nombre de services : n/a
+
+ + + + + + + + + + + + + + + + + + + +
Nom du serviceOrganisationURLLogicielUtilisateurs mensuels
+ + +  n/a + + + + +  n/a + + n/an/an/a
+
+
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml index 13f905f..f0d0035 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml @@ -22,28 +22,28 @@
Nombre de services : n/a
- - - - - - - - - - - - - - - - -
Nom du serviceURLLogicielUtilisateurs mensuels
- - -  n/a - - n/an/an/a
+ + + Nom du service + URL + Logiciel + Utilisateurs mensuels + + + + + + + +  n/a + + + n/a + n/a + n/a + + +
diff --git a/src/fr/devinsy/statoolinfos/htmlize/propertiesFiles.xhtml b/src/fr/devinsy/statoolinfos/htmlize/propertiesFiles.xhtml index c5666ad..3a472f8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/propertiesFiles.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/propertiesFiles.xhtml @@ -18,7 +18,7 @@ - + diff --git a/src/fr/devinsy/statoolinfos/htmlize/services.xhtml b/src/fr/devinsy/statoolinfos/htmlize/services.xhtml index 04794a4..1805ccb 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/services.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/services.xhtml @@ -11,35 +11,42 @@ -

Tous les services

- -
Nombre de services : n/a
-
-
NomNom local Organisation Lignes Propriétés
- - - - - - - - - - - - - - - - - - -
Nom du serviceOrganisationURLLogicielUtilisateurs mensuels
- - -  n/a - - n/an/an/an/a
+
+

Tous les services

+ +
Nombre de services : n/a
+
+ + + + + + + + + + + + + + + + + + + +
Nom du serviceOrganisationURLLogicielUtilisateurs mensuels
+ + +  n/a + + + + +  n/a + + n/an/an/a
+
diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index 6679aeb..9421ae9 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -83,22 +83,6 @@ public class StatAgent result.add(stat); } - Category other = new Category("{Autres}", "Qui ne rentre pas dans une catégorie existante."); - CategoryStat stat = new CategoryStat(other); - StringSet organizations = new StringSet(); - for (Service service : federation.getAllServices()) - { - if (!categories.matches(service.getSoftwareName())) - { - stat.incServiceCount(); - stat.incUserCount(service.getUserCount()); - organizations.add(service.getOrganization().getName()); - other.getSoftwares().add(service.getSoftwareName()); - } - } - stat.setOrganizationCount(organizations.size()); - result.add(stat); - // return result; }