From 344e1bfa1c5016808993fce4ad366b940026780d Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 25 Sep 2020 15:46:30 +0200 Subject: [PATCH] Added softwares and software page. --- .../devinsy/statoolinfos/core/Categories.java | 37 ++++ .../devinsy/statoolinfos/core/Federation.java | 29 +++ .../devinsy/statoolinfos/core/Services.java | 29 +++ .../devinsy/statoolinfos/core/Software.java | 130 ++++++++++++ .../statoolinfos/core/SoftwareComparator.java | 110 ++++++++++ .../statoolinfos/core/SoftwareList.java | 89 ++++++++ .../devinsy/statoolinfos/core/Softwares.java | 85 ++++++++ .../statoolinfos/htmlize/CategoriesPage.java | 5 +- .../statoolinfos/htmlize/CategoryPage.java | 4 +- .../statoolinfos/htmlize/Htmlizer.java | 25 ++- .../statoolinfos/htmlize/SoftwarePage.java | 98 +++++++++ .../statoolinfos/htmlize/SoftwaresPage.java | 92 ++++++++ .../statoolinfos/htmlize/categories.xhtml | 8 +- .../statoolinfos/htmlize/software.xhtml | 53 +++++ .../statoolinfos/htmlize/softwares.xhtml | 46 ++++ .../statoolinfos/htmlize/webCharterView.xhtml | 3 +- .../devinsy/statoolinfos/stats/StatAgent.java | 50 ++++- .../stats/softwares/SoftwareStat.java | 141 +++++++++++++ .../softwares/SoftwareStatComparator.java | 198 ++++++++++++++++++ .../stats/softwares/SoftwareStats.java | 134 ++++++++++++ 20 files changed, 1355 insertions(+), 11 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/core/Software.java create mode 100644 src/fr/devinsy/statoolinfos/core/SoftwareComparator.java create mode 100644 src/fr/devinsy/statoolinfos/core/SoftwareList.java create mode 100644 src/fr/devinsy/statoolinfos/core/Softwares.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/software.xhtml create mode 100644 src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml create mode 100644 src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java create mode 100644 src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStatComparator.java create mode 100644 src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStats.java diff --git a/src/fr/devinsy/statoolinfos/core/Categories.java b/src/fr/devinsy/statoolinfos/core/Categories.java index d25fa62..c0cb228 100644 --- a/src/fr/devinsy/statoolinfos/core/Categories.java +++ b/src/fr/devinsy/statoolinfos/core/Categories.java @@ -37,6 +37,43 @@ public class Categories extends ArrayList super(); } + /** + * Find by software. + * + * @param name + * the name + * @return the category + */ + public Category findBySoftware(final String softwareName) + { + Category result; + + boolean ended = false; + Iterator iterator = this.iterator(); + result = null; + while (!ended) + { + if (iterator.hasNext()) + { + Category category = iterator.next(); + + if (category.getSoftwares().contains(softwareName)) + { + ended = true; + result = category; + } + } + else + { + ended = true; + result = null; + } + } + + // + return result; + } + /** * Matches. * diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index 4749fe6..58d7494 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -183,6 +183,35 @@ public class Federation extends PathPropertyList return result; } + /** + * Gets the software catalog. + * + * @return the software catalog + */ + public Softwares getSoftwares() + { + Softwares result; + + result = new Softwares(); + + for (Service service : getAllServices()) + { + if (StringUtils.isNotBlank(service.getSoftwareName())) + { + Software software = result.get(service.getSoftwareName()); + + if (software == null) + { + software = new Software(service.getSoftwareName(), service.get("software.description")); + result.put(software); + } + } + } + + // + return result; + } + /** * Gets the technical name. * diff --git a/src/fr/devinsy/statoolinfos/core/Services.java b/src/fr/devinsy/statoolinfos/core/Services.java index b8baed8..e955298 100644 --- a/src/fr/devinsy/statoolinfos/core/Services.java +++ b/src/fr/devinsy/statoolinfos/core/Services.java @@ -21,6 +21,8 @@ package fr.devinsy.statoolinfos.core; import java.util.ArrayList; import java.util.Collections; +import org.apache.commons.lang3.StringUtils; + /** * The Class Services. */ @@ -61,6 +63,33 @@ public class Services extends ArrayList return result; } + /** + * Gets the by. + * + * @param software + * the software + * @return the by + */ + public Services getBy(final Software software) + { + Services result; + + result = new Services(); + + for (Service service : this) + { + String serviceSoftwareName = StatoolInfosUtils.toTechnicalName(service.getSoftwareName()); + String softwareName = StatoolInfosUtils.toTechnicalName(software.getName()); + if (StringUtils.equals(serviceSoftwareName, softwareName)) + { + result.add(service); + } + } + + // + return result; + } + /** * Reverse. * diff --git a/src/fr/devinsy/statoolinfos/core/Software.java b/src/fr/devinsy/statoolinfos/core/Software.java new file mode 100644 index 0000000..198b03b --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/Software.java @@ -0,0 +1,130 @@ +/* + * 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.core; + +import fr.devinsy.strings.StringList; + +/** + * The Class Software. + */ +public class Software +{ + private String name; + private String description; + private StringList aliases; + + /** + * Instantiates a new software. + * + * @param name + * the name + */ + public Software(final String name) + { + this(name, ""); + } + + /** + * Instantiates a new software. + * + * @param name + * the name + * @param description + * the description + */ + public Software(final String name, final String description) + { + this.name = name; + this.description = description; + this.aliases = new StringList(name); + } + + /** + * Instantiates a new software. + * + * @param name + * the name + * @param description + * the description + * @param softwares + * the softwares + */ + public Software(final String name, final String description, final StringList softwares) + { + this.name = name; + this.description = description; + this.aliases = new StringList(softwares); + } + + public StringList getAliases() + { + return this.aliases; + } + + public String getDescription() + { + return this.description; + } + + public String getName() + { + return this.name; + } + + /** + * Gets the technical name. + * + * @return the technical name + */ + public String getTechnicalName() + { + String result; + + result = StatoolInfosUtils.toTechnicalName(getName()); + + // + return result; + } + + public void setDescription(final String description) + { + this.description = description; + } + + public void setName(final String name) + { + this.name = name; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() + { + String result; + + result = String.format("[name=%s][description=%s][aliases=%s]", this.name, this.description, this.aliases.toStringSeparatedBy(',')); + + // + return result; + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/core/SoftwareComparator.java b/src/fr/devinsy/statoolinfos/core/SoftwareComparator.java new file mode 100644 index 0000000..7af619c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/SoftwareComparator.java @@ -0,0 +1,110 @@ +/* + * + */ +package fr.devinsy.statoolinfos.core; + +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class SoftwareComparator. + */ +public class SoftwareComparator implements Comparator +{ + public enum Sorting + { + NAME + } + + private Sorting sorting; + + /** + * Instantiates a new organization comparator. + * + * @param sorting + * the sorting + */ + public SoftwareComparator(final Sorting sorting) + { + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final Software alpha, final Software bravo) + { + int result; + + result = compare(alpha, bravo, this.sorting); + + // + return result; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @param sorting + * the sorting + * @return the int + */ + public static int compare(final Software alpha, final Software bravo, final Sorting sorting) + { + int result; + + if (sorting == null) + { + result = 0; + } + else + { + switch (sorting) + { + default: + case NAME: + result = CompareUtils.compare(getName(alpha), getName(bravo)); + break; + } + } + + // + return result; + } + + /** + * Gets the name. + * + * @param source + * the source + * @return the name + */ + public static String getName(final Software source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.getName(); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/core/SoftwareList.java b/src/fr/devinsy/statoolinfos/core/SoftwareList.java new file mode 100644 index 0000000..e3ef66c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/SoftwareList.java @@ -0,0 +1,89 @@ +/* + * 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.core; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * The Class Categories. + */ +public class SoftwareList extends ArrayList +{ + private static final long serialVersionUID = -3197394621123996060L; + + /** + * Instantiates a new software list. + */ + public SoftwareList() + { + super(); + } + + /** + * Reverse. + * + * @return the software list + */ + public SoftwareList reverse() + { + SoftwareList result; + + Collections.reverse(this); + + result = this; + + // + return result; + } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the issues + */ + public SoftwareList sort(final SoftwareComparator.Sorting sorting) + { + SoftwareList result; + + sort(new SoftwareComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by name. + * + * @return the services + */ + public SoftwareList sortByName() + { + SoftwareList result; + + result = sort(SoftwareComparator.Sorting.NAME); + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/core/Softwares.java b/src/fr/devinsy/statoolinfos/core/Softwares.java new file mode 100644 index 0000000..595a5fa --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/Softwares.java @@ -0,0 +1,85 @@ +/* + * 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.core; + +import java.util.HashMap; + +/** + * The Class Softwares. + */ +public class Softwares extends HashMap +{ + private static final long serialVersionUID = 4780901718767657693L; + + /** + * Instantiates a new softwares. + */ + public Softwares() + { + super(); + } + + /** + * Builds the key. + * + * @param source + * the source + * @return the string + */ + private String buildKey(final String source) + { + String result; + + result = StatoolInfosUtils.toTechnicalName(source); + + // + return result; + } + + /** + * Gets the. + * + * @param key + * the key + * @return the software + */ + public Software get(final String key) + { + Software result; + + result = super.get(buildKey(key)); + + // + return result; + } + + /** + * Put. + * + * @param software + * the software + */ + public void put(final Software software) + { + for (String alias : software.getAliases()) + { + put(buildKey(alias), software); + } + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java index 0cd73c3..82d2388 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java @@ -29,7 +29,7 @@ import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; /** - * The Class ServicesPage. + * The Class CategoriesPage. */ public class CategoriesPage { @@ -62,6 +62,7 @@ public class CategoriesPage data.setEscapedContent("categoryListLine", index, "categoryListLineNameLink", stat.getCategory().getName()); data.setAttribute("categoryListLine", index, "categoryListLineNameLink", "href", "category-" + stat.getCategory().getTechnicalName() + ".xhtml"); data.setAttribute("categoryListLine", index, "categoryListLineNameLink", "title", stat.getCategory().getDescription()); + data.setEscapedContent("categoryListLine", index, "categoryListLineSoftwares", stat.getCategory().getSoftwares().toStringWithFrenchCommas()); data.setContent("categoryListLine", index, "categoryListLineOrganizationCount", stat.getOrganizationCount()); data.setContent("categoryListLine", index, "categoryListLineServiceCount", stat.getServiceCount()); @@ -78,7 +79,7 @@ public class CategoriesPage } catch (XidynException exception) { - throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + throw new StatoolInfosException("Error building categories page: " + exception.getMessage(), exception); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java index 7657a6f..93c82e8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java @@ -83,12 +83,12 @@ public class CategoryPage BreadcrumbTrail trail = new BreadcrumbTrail(); trail.add("Catégories", "categories.xhtml"); - trail.add("Catégorie", "category.xhtml"); + trail.add(category.getName(), "category-" + category.getTechnicalName() + ".xhtml"); result = WebCharterView.build(content, trail); } catch (XidynException exception) { - throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + throw new StatoolInfosException("Error building category page: " + exception.getMessage(), exception); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index b899c96..2b3d006 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -35,6 +35,8 @@ 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.Software; +import fr.devinsy.statoolinfos.core.Softwares; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.crawl.CrawlCache; @@ -42,6 +44,7 @@ import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.categories.CategoryStats; import fr.devinsy.statoolinfos.stats.properties.PropertyStats; import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats; +import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; /** * The Class Htmlizer. @@ -293,7 +296,7 @@ public class Htmlizer // { - logger.info("Htmlize category page."); + logger.info("Htmlize category pages."); for (Category category : categories) { Services services = federation.getAllServices().getBy(category); @@ -301,6 +304,26 @@ public class Htmlizer FileUtils.write(new File(htmlizeDirectory, "category-" + category.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); } } + + // + { + logger.info("Htmlize softwares page."); + SoftwareStats stats = StatAgent.statAllSoftwares(federation, categories); + page = SoftwaresPage.build(stats); + FileUtils.write(new File(htmlizeDirectory, "softwares.xhtml"), page, StandardCharsets.UTF_8); + } + + // + { + logger.info("Htmlize software pages."); + Softwares catalog = federation.getSoftwares(); + for (Software software : catalog.values()) + { + Services services = federation.getAllServices().getBy(software); + page = SoftwarePage.build(software, services); + FileUtils.write(new File(htmlizeDirectory, "software-" + software.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); + } + } } /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java b/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java new file mode 100644 index 0000000..ee5db22 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java @@ -0,0 +1,98 @@ +/* + * 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.Service; +import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.Software; +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 SoftwarePage. + */ +public class SoftwarePage +{ + private static Logger logger = LoggerFactory.getLogger(SoftwarePage.class); + + /** + * Builds the. + * + * @param software + * the software + * @param services + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final Software software, final Services services) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building services page."); + + TagDataManager data = new TagDataManager(); + + data.setContent("softwareName", software.getName()); + data.setContent("softwareDesciprtion", software.getDescription()); + data.setContent("serviceCount", services.size()); + + int index = 0; + for (Service service : services) + { + 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.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/software.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add("Logiciels", "softwares.xhtml"); + trail.add(software.getName(), "software-" + software.getTechnicalName() + ".xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building software page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java b/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java new file mode 100644 index 0000000..1b18bab --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java @@ -0,0 +1,92 @@ +/* + * 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.StatoolInfosException; +import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat; +import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServicesPage. + */ +public class SoftwaresPage +{ + private static Logger logger = LoggerFactory.getLogger(SoftwaresPage.class); + + /** + * Builds the. + * + * @param categories + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final SoftwareStats stats) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building softwares page."); + + TagDataManager data = new TagDataManager(); + + data.setContent("softwareCount", stats.size()); + + int index = 0; + for (SoftwareStat stat : stats) + { + data.setEscapedContent("softwareListLine", index, "softwareListLineNameLink", stat.getName()); + data.setAttribute("softwareListLine", index, "softwareListLineNameLink", "href", "software-" + stat.getTechnicalName() + ".xhtml"); + + data.setEscapedContent("softwareListLine", index, "softwareListLineCategoryLink", stat.getCategory().getName()); + data.setAttribute("softwareListLine", index, "softwareListLineCategoryLink", "href", "category-" + stat.getCategory().getTechnicalName() + ".xhtml"); + data.setAttribute("softwareListLine", index, "softwareListLineCategoryLink", "title", stat.getCategory().getDescription()); + + 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()); + + index += 1; + } + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/softwares.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add("Logiciels", "softwares.xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building softwares page: " + exception.getMessage(), exception); + } + + // + return result; + } + +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml b/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml index 21e5d76..6b24dd5 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml @@ -22,16 +22,18 @@ Nom de la catégorie Logiciels Services - Organizations + Organisations Utilisateurs mensuels - n/a + n/a + + + n/a - n/a n/a n/a n/a diff --git a/src/fr/devinsy/statoolinfos/htmlize/software.xhtml b/src/fr/devinsy/statoolinfos/htmlize/software.xhtml new file mode 100644 index 0000000..9495a0c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/software.xhtml @@ -0,0 +1,53 @@ + + + + + StatoolInfos + + + + + + + +
+

Logiciel n/a

+ +

Bla bla description

+
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/softwares.xhtml b/src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml new file mode 100644 index 0000000..d86b13f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/softwares.xhtml @@ -0,0 +1,46 @@ + + + + + StatoolInfos + + + + + + + +
+

Logiciels

+ +
Nombre de logiciels : n/a
+
+ + + + + + + + + + + + + + + + + + + +
NomCatégorieServicesOrganisationsUtilisateurs mensuels
+ n/a + + n/a + n/an/an/a
+
+
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml index 5132ee5..1e463f3 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml @@ -20,8 +20,7 @@ Propriétés Services Catégories - Logiciels - Candidats + Logiciels diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index 9421ae9..2fc6bd3 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -21,6 +21,9 @@ package fr.devinsy.statoolinfos.stats; import java.io.IOException; import java.net.MalformedURLException; +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.Federation; @@ -28,11 +31,15 @@ import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Organizations; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.Services; +import fr.devinsy.statoolinfos.core.Software; +import fr.devinsy.statoolinfos.core.Softwares; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.stats.categories.CategoryStat; import fr.devinsy.statoolinfos.stats.categories.CategoryStats; import fr.devinsy.statoolinfos.stats.properties.PropertyStats; import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats; +import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat; +import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.strings.StringSet; /** @@ -40,12 +47,13 @@ import fr.devinsy.strings.StringSet; */ public class StatAgent { + private static Logger logger = LoggerFactory.getLogger(StatAgent.class); + /** * Instantiates a new stat agent. */ private StatAgent() { - } /** @@ -144,6 +152,46 @@ public class StatAgent return result; } + /** + * Stat all softwares. + * + * @param federation + * the federation + * @return the software stats + */ + public static SoftwareStats statAllSoftwares(final Federation federation, final Categories categories) + { + SoftwareStats result; + + // Build catalog. + Softwares catalog = federation.getSoftwares(); + logger.info("CATALOG={}", catalog.size()); + + // Stat. + result = new SoftwareStats(); + for (Software software : catalog.values()) + { + SoftwareStat stat = new SoftwareStat(software.getName()); + StringSet organizations = new StringSet(); + for (Service service : federation.getAllServices()) + { + Software current = catalog.get(service.getSoftwareName()); + if (current == software) + { + stat.incServiceCount(); + stat.incUserCount(service.getUserCount()); + stat.setCategory(categories.findBySoftware(service.getSoftwareName())); + organizations.add(service.getOrganization().getName()); + } + } + stat.setOrganizationCount(organizations.size()); + result.add(stat); + } + + // + return result; + } + /** * Stat federation properties. * diff --git a/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java new file mode 100644 index 0000000..b76833c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStat.java @@ -0,0 +1,141 @@ +/* + * 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.stats.softwares; + +import fr.devinsy.statoolinfos.core.Category; +import fr.devinsy.statoolinfos.core.StatoolInfosUtils; + +/** + * The Class SoftwareStat. + */ +public class SoftwareStat +{ + private String name; + private Category category; + private int serviceCount; + private int organizationCount; + private int userCount; + + /** + * Instantiates a new software stat. + * + * @param name + * the name + */ + public SoftwareStat(final String name) + { + this.name = name; + this.category = null; + this.serviceCount = 0; + this.organizationCount = 0; + this.userCount = 0; + } + + public Category getCategory() + { + return this.category; + } + + public String getName() + { + return this.name; + } + + public int getOrganizationCount() + { + return this.organizationCount; + } + + public int getServiceCount() + { + return this.serviceCount; + } + + /** + * Gets the technical name. + * + * @return the technical name + */ + public String getTechnicalName() + { + String result; + + result = StatoolInfosUtils.toTechnicalName(this.name); + + // + return result; + } + + public int getUserCount() + { + return this.userCount; + } + + /** + * Inc service count. + */ + public void incServiceCount() + { + this.serviceCount += 1; + } + + /** + * Inc user count. + */ + public void incUserCount() + { + this.serviceCount += 1; + } + + /** + * Inc user count. + * + * @param value + * the value + */ + public void incUserCount(final int value) + { + this.userCount += value; + } + + public void setCategory(final Category category) + { + this.category = category; + } + + public void setName(final String name) + { + this.name = name; + } + + public void setOrganizationCount(final int organizationCount) + { + this.organizationCount = organizationCount; + } + + public void setServiceCount(final int serviceCount) + { + this.serviceCount = serviceCount; + } + + public void setUserCount(final int userCount) + { + this.userCount = userCount; + } +} diff --git a/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStatComparator.java b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStatComparator.java new file mode 100644 index 0000000..5cebfb1 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStatComparator.java @@ -0,0 +1,198 @@ +/* + * + */ +package fr.devinsy.statoolinfos.stats.softwares; + +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class SoftwareStatComparator. + */ +public class SoftwareStatComparator implements Comparator +{ + public enum Sorting + { + NAME, + SERVICE_COUNT, + ORGANIZATION_COUNT, + USER_COUNT + } + + private Sorting sorting; + + /** + * Instantiates a new category stat comparator. + * + * @param sorting + * the sorting + */ + public SoftwareStatComparator(final Sorting sorting) + { + // + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final SoftwareStat alpha, final SoftwareStat bravo) + { + int result; + + result = compare(alpha, bravo, this.sorting); + + // + return result; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @param sorting + * the sorting + * @return the int + */ + public static int compare(final SoftwareStat alpha, final SoftwareStat bravo, final Sorting sorting) + { + int result; + + if (sorting == null) + { + result = 0; + } + else + { + switch (sorting) + { + default: + case NAME: + result = CompareUtils.compare(getName(alpha), getName(bravo)); + break; + + case SERVICE_COUNT: + result = CompareUtils.compare(getServiceCount(alpha), getServiceCount(bravo)); + break; + + case ORGANIZATION_COUNT: + result = CompareUtils.compare(getOrganizationCount(alpha), getOrganizationCount(bravo)); + break; + + case USER_COUNT: + result = CompareUtils.compare(getUserCount(alpha), getUserCount(bravo)); + break; + } + } + + // + return result; + } + + /** + * Gets the name. + * + * @param source + * the source + * @return the name + */ + public static String getName(final SoftwareStat source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.getCategory().getName(); + } + + // + return result; + } + + /** + * Gets the organization count. + * + * @param source + * the source + * @return the organization count + */ + public static Long getOrganizationCount(final SoftwareStat source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = (long) source.getOrganizationCount(); + } + + // + return result; + } + + /** + * Gets the id. + * + * @param source + * the source + * @return the id + */ + public static Long getServiceCount(final SoftwareStat source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = (long) source.getServiceCount(); + } + + // + return result; + } + + /** + * Gets the user count. + * + * @param source + * the source + * @return the user count + */ + public static Long getUserCount(final SoftwareStat source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = (long) source.getUserCount(); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStats.java b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStats.java new file mode 100644 index 0000000..115d07c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/softwares/SoftwareStats.java @@ -0,0 +1,134 @@ +/* + * 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.stats.softwares; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * The Class SoftwareStats. + */ +public class SoftwareStats extends ArrayList +{ + private static final long serialVersionUID = 3512825968551889090L; + + /** + * Instantiates a new software stats. + */ + public SoftwareStats() + { + super(); + } + + /** + * Reverse. + * + * @return the software stats + */ + public SoftwareStats reverse() + { + SoftwareStats result; + + Collections.reverse(this); + + result = this; + + // + return result; + } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the issues + */ + public SoftwareStats sort(final SoftwareStatComparator.Sorting sorting) + { + SoftwareStats result; + + sort(new SoftwareStatComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by name. + * + * @return the software stats + */ + public SoftwareStats sortByName() + { + SoftwareStats result; + + result = sort(SoftwareStatComparator.Sorting.NAME); + + // + return result; + } + + /** + * Sort by organization count. + * + * @return the software stats + */ + public SoftwareStats sortByOrganizationCount() + { + SoftwareStats result; + + result = sort(SoftwareStatComparator.Sorting.ORGANIZATION_COUNT); + + // + return result; + } + + /** + * Sort by service count. + * + * @return the category stats + */ + public SoftwareStats sortByServiceCount() + { + SoftwareStats result; + + result = sort(SoftwareStatComparator.Sorting.SERVICE_COUNT); + + // + return result; + } + + /** + * Sort by user count. + * + * @return the category stats + */ + public SoftwareStats sortByUserCount() + { + SoftwareStats result; + + result = sort(SoftwareStatComparator.Sorting.USER_COUNT); + + // + return result; + } +}