From be6c6e164340f02dbf6caf3302f897d4de6bfebb Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 19 Oct 2020 02:17:57 +0200 Subject: [PATCH] Added multi categories for software. --- .../devinsy/statoolinfos/core/Categories.java | 26 ++--- src/fr/devinsy/statoolinfos/core/Factory.java | 6 +- .../devinsy/statoolinfos/core/Federation.java | 2 +- src/fr/devinsy/statoolinfos/core/Service.java | 15 +++ .../statoolinfos/htmlize/CategoriesView.java | 103 ++++++++++++++++++ .../statoolinfos/htmlize/SoftwaresPage.java | 7 +- .../statoolinfos/htmlize/categoriesView.xhtml | 19 ++++ .../statoolinfos/htmlize/softwares.xhtml | 9 +- .../devinsy/statoolinfos/stats/StatAgent.java | 2 +- .../stats/softwares/SoftwareStat.java | 15 +-- 10 files changed, 158 insertions(+), 46 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/htmlize/CategoriesView.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml diff --git a/src/fr/devinsy/statoolinfos/core/Categories.java b/src/fr/devinsy/statoolinfos/core/Categories.java index ff06843..6781833 100644 --- a/src/fr/devinsy/statoolinfos/core/Categories.java +++ b/src/fr/devinsy/statoolinfos/core/Categories.java @@ -44,29 +44,17 @@ public class Categories extends ArrayList * the software name * @return the category */ - public Category findBySoftware(final String softwareName) + public Categories findBySoftware(final String softwareName) { - Category result; + Categories result; - boolean ended = false; - Iterator iterator = this.iterator(); - result = null; - while (!ended) + result = new Categories(); + + for (Category category : this) { - if (iterator.hasNext()) + if (category.getSoftwares().containsAnyIgnoreCase(softwareName)) { - Category category = iterator.next(); - - if (category.getSoftwares().contains(softwareName)) - { - ended = true; - result = category; - } - } - else - { - ended = true; - result = null; + result.add(category); } } diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index 25badcf..03906cb 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -112,11 +112,11 @@ public class Factory Category other = new Category("Autres", "Qui ne rentre pas dans une catégorie existante."); result.add(other); - for (Service service : federation.getAllServices()) + for (Software software : federation.getSoftwares().values()) { - if (!result.matches(service.getSoftwareName())) + if (!result.matches(software.getName())) { - other.getSoftwares().add(service.getSoftwareName()); + other.getSoftwares().add(software.getName()); } } diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index ba858ae..ed9e74a 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -263,7 +263,7 @@ public class Federation extends PathPropertyList if (software == null) { - software = new Software(service.getSoftwareName(), service.get("software.description")); + software = new Software(service.getSoftwareName(), service.getSoftwareDescription()); result.put(software); } } diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index eef7b20..254948c 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -317,6 +317,21 @@ public class Service extends PathPropertyList return result; } + /** + * Gets the software description. + * + * @return the software description + */ + public String getSoftwareDescription() + { + String result; + + result = get("software.description"); + + // + return result; + } + /** * Gets the software license name. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoriesView.java b/src/fr/devinsy/statoolinfos/htmlize/CategoriesView.java new file mode 100644 index 0000000..3f82e9c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoriesView.java @@ -0,0 +1,103 @@ +/* + * 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.Categories; +import fr.devinsy.statoolinfos.core.Category; +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 CategoriesView. + */ +public class CategoriesView +{ + private static Logger logger = LoggerFactory.getLogger(CategoriesView.class); + + public enum Mode + { + ALL, + ICONS_ONLY, + LABELS_ONLY + } + + /** + * Builds the. + * + * @param stats + * the stats + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final Categories categories, final Mode mode) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building categories view."); + + TagDataManager data = new TagDataManager(); + + int index = 0; + for (Category category : categories) + { + data.setAttribute("category", index, "categoryLink", "href", "category-" + category.getTechnicalName() + ".xhtml"); + data.setAttribute("category", index, "categoryLink", "title", category.getDescription()); + + if ((mode == Mode.ALL) || (mode == Mode.ICONS_ONLY)) + { + data.setAttribute("category", index, "categoryLogo", "src", category.getLogoPath()); + } + else + { + data.setAttribute("category", index, "categoryLogo", "class", "xid:nodisplay"); + } + + if ((mode == Mode.ALL) || (mode == Mode.LABELS_ONLY)) + { + data.setEscapedContent("category", index, "categoryName", category.getName()); + } + else + { + data.setAttribute("category", index, "categoryName", "class", "xid:nodisplay"); + } + + index += 1; + } + + String page = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml", data).toString(); + result = XidynUtils.extractBodyContent(page.replaceAll("id=\"[^\"]*\"", "")); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building categories view: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java b/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java index 868875f..ac88b64 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java @@ -22,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.htmlize.CategoriesView.Mode; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.xidyn.XidynException; @@ -62,12 +63,8 @@ public class SoftwaresPage data.setEscapedContent("softwareListLine", index, "softwareListLineNameLink", stat.getName()); data.setAttribute("softwareListLine", index, "softwareListLineNameLink", "href", "software-" + stat.getTechnicalName() + ".xhtml"); - data.setEscapedContent("softwareListLine", index, "softwareListLineCategoryName", stat.getCategory().getName()); - data.setAttribute("softwareListLine", index, "softwareListLineCategoryLink", "href", "category-" + stat.getCategory().getTechnicalName() + ".xhtml"); - data.setAttribute("softwareListLine", index, "softwareListLineCategoryLink", "title", stat.getCategory().getDescription()); - data.setAttribute("softwareListLine", index, "softwareListLineCategoryLogo", "src", stat.getCategory().getLogoPath()); + data.setContent("softwareListLine", index, "softwareListLineCategory", CategoriesView.build(stat.getCategories(), Mode.ALL)); - data.setEscapedContent("softwareListLine", index, "softwareListLineSoftwares", stat.getCategory().getName()); data.setContent("softwareListLine", index, "softwareListLineOrganizationCount", stat.getOrganizationCount()); data.setContent("softwareListLine", index, "softwareListLineServiceCount", stat.getServiceCount()); data.setContent("softwareListLine", index, "categoryListLineUserCount", stat.getUserCount()); diff --git a/src/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml new file mode 100644 index 0000000..bf77deb --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml @@ -0,0 +1,19 @@ + + + + + StatoolInfos + + + + + + + + + + n/a + + + + diff --git a/src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml b/src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml index 24b3ebd..058b482 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml @@ -21,7 +21,7 @@ Nom - Catégorie + Catégories Services Organisations Utilisateurs mensuels @@ -32,12 +32,7 @@ n/a - - - -  n/a - - + n/a n/a n/a n/a diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index 2fc6bd3..4a22830 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -172,6 +172,7 @@ public class StatAgent for (Software software : catalog.values()) { SoftwareStat stat = new SoftwareStat(software.getName()); + stat.getCategories().addAll(categories.findBySoftware(software.getName())); StringSet organizations = new StringSet(); for (Service service : federation.getAllServices()) { @@ -180,7 +181,6 @@ public class StatAgent { stat.incServiceCount(); stat.incUserCount(service.getUserCount()); - stat.setCategory(categories.findBySoftware(service.getSoftwareName())); organizations.add(service.getOrganization().getName()); } } diff --git a/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java index b76833c..2c9c82f 100644 --- a/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java +++ b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java @@ -18,7 +18,7 @@ */ package fr.devinsy.statoolinfos.stats.softwares; -import fr.devinsy.statoolinfos.core.Category; +import fr.devinsy.statoolinfos.core.Categories; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; /** @@ -27,7 +27,7 @@ import fr.devinsy.statoolinfos.core.StatoolInfosUtils; public class SoftwareStat { private String name; - private Category category; + private Categories categories; private int serviceCount; private int organizationCount; private int userCount; @@ -41,15 +41,15 @@ public class SoftwareStat public SoftwareStat(final String name) { this.name = name; - this.category = null; + this.categories = new Categories(); this.serviceCount = 0; this.organizationCount = 0; this.userCount = 0; } - public Category getCategory() + public Categories getCategories() { - return this.category; + return this.categories; } public String getName() @@ -114,11 +114,6 @@ public class SoftwareStat this.userCount += value; } - public void setCategory(final Category category) - { - this.category = category; - } - public void setName(final String name) { this.name = name;