diff --git a/src/fr/devinsy/statoolinfos/core/Categories.java b/src/fr/devinsy/statoolinfos/core/Categories.java new file mode 100644 index 0000000..e64b848 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/Categories.java @@ -0,0 +1,75 @@ +/* + * 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.Iterator; + +/** + * The Class Categories. + */ +public class Categories extends ArrayList +{ + private static final long serialVersionUID = -221887756635386650L; + + /** + * Instantiates a new categories. + */ + public Categories() + { + super(); + } + + /** + * Matches. + * + * @param softwareName + * the software name + * @return true, if successful + */ + public boolean matches(final String softwareName) + { + boolean result; + + boolean ended = false; + Iterator iterator = this.iterator(); + result = false; + while (!ended) + { + if (iterator.hasNext()) + { + Category category = iterator.next(); + + if (category.getSoftwares().contains(softwareName)) + { + ended = true; + result = true; + } + } + else + { + ended = true; + result = false; + } + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/core/Category.java b/src/fr/devinsy/statoolinfos/core/Category.java new file mode 100644 index 0000000..a0aa755 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/Category.java @@ -0,0 +1,114 @@ +/* + * 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 Category. + */ +public class Category +{ + private String name; + private String description; + private StringList softwares; + + /** + * Instantiates a new category. + */ + public Category(final String name, final String description) + { + this.name = name; + this.description = description; + this.softwares = new StringList(); + } + + /** + * Instantiates a new category. + * + * @param name + * the name + * @param description + * the description + * @param softwares + * the softwares + */ + public Category(final String name, final String description, final StringList softwares) + { + this.name = name; + this.description = description; + this.softwares = new StringList(softwares); + } + + public String getDescription() + { + return this.description; + } + + public String getName() + { + return this.name; + } + + public StringList getSoftwares() + { + return this.softwares; + } + + /** + * 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][softwares=%s]", this.name, this.description, this.softwares.toStringSeparatedBy(',')); + + // + return result; + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/core/Configuration.java b/src/fr/devinsy/statoolinfos/core/Configuration.java index 7e3b678..80355f9 100644 --- a/src/fr/devinsy/statoolinfos/core/Configuration.java +++ b/src/fr/devinsy/statoolinfos/core/Configuration.java @@ -136,6 +136,30 @@ public class Configuration extends PathPropertyList return result; } + /** + * Gets the category file. + * + * @return the category file + * @throws StatoolInfosException + */ + public File getCategoryFile() throws StatoolInfosException + { + File result; + + String path = get("conf.htmlize.categories"); + if (StringUtils.isBlank(path)) + { + throw new StatoolInfosException("Entry conf.htmlize.categories is missing in configuration file."); + } + else + { + result = new File(path); + } + + // + return result; + } + /** * Gets the class name. * diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index db150c1..4435358 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -30,6 +30,8 @@ import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathPropertyUtils; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringSet; /** * The Class PathProperty. @@ -45,6 +47,44 @@ public class Factory { } + /** + * Load categories. + * + * @return the categories + * @throws IOException + */ + public static Categories loadCategories(final File source) throws IOException + { + Categories result; + + result = new Categories(); + + PathProperties properties = PathPropertyUtils.load(source); + + StringSet prefixes = properties.getSubPrefixes(); + for (String prefix : prefixes) + { + String name = properties.get(prefix + ".name"); + String description = properties.get(prefix + ".description"); + String softwares = properties.get(prefix + ".softwares"); + + StringList softwareList = new StringList(); + if (StringUtils.isNotBlank(softwares)) + { + for (String string : softwares.split("[;,]")) + { + softwareList.add(string.trim()); + } + } + + Category category = new Category(name, description, softwareList); + result.add(category); + } + + // + return result; + } + /** * Load configuration. * diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index be1d945..4749fe6 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -192,7 +192,7 @@ public class Federation extends PathPropertyList { String result; - result = StatoolInfosUtils.buildTechnicalName(getName()); + result = StatoolInfosUtils.toTechnicalName(getName()); // return result; diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index 508a374..6344086 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -171,7 +171,22 @@ public class Organization extends PathPropertyList { String result; - result = StatoolInfosUtils.buildTechnicalName(getName()); + result = StatoolInfosUtils.toTechnicalName(getName()); + + // + return result; + } + + /** + * Gets the user count. + * + * @return the user count + */ + public int getUserCount() + { + int result; + + result = 0; // return result; diff --git a/src/fr/devinsy/statoolinfos/core/OrganizationComparator.java b/src/fr/devinsy/statoolinfos/core/OrganizationComparator.java new file mode 100644 index 0000000..0321b2c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/OrganizationComparator.java @@ -0,0 +1,169 @@ +/* + * + */ +package fr.devinsy.statoolinfos.core; + +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class OrganizationComparator. + */ +public class OrganizationComparator implements Comparator +{ + public enum Sorting + { + NAME, + SERVICE_COUNT, + USER_COUNT + } + + private Sorting sorting; + + /** + * Instantiates a new organization comparator. + * + * @param sorting + * the sorting + */ + public OrganizationComparator(final Sorting sorting) + { + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final Organization alpha, final Organization 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 Organization alpha, final Organization 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 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 Organization source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.getName(); + } + + // + return result; + } + + /** + * Gets the service count. + * + * @param source + * the source + * @return the service count + */ + public static Long getServiceCount(final Organization 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 Organization source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = (long) source.getUserCount(); + } + + // + return result; + } + +} diff --git a/src/fr/devinsy/statoolinfos/core/Organizations.java b/src/fr/devinsy/statoolinfos/core/Organizations.java index 66e64ad..75bc4a0 100644 --- a/src/fr/devinsy/statoolinfos/core/Organizations.java +++ b/src/fr/devinsy/statoolinfos/core/Organizations.java @@ -19,6 +19,7 @@ package fr.devinsy.statoolinfos.core; import java.util.ArrayList; +import java.util.Collections; /** * The Class Organizations. @@ -34,4 +35,71 @@ public class Organizations extends ArrayList { super(); } + + /** + * Reverse. + * + * @return the services + */ + public Organizations reverse() + { + Organizations result; + + Collections.reverse(this); + + result = this; + + // + return result; + } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the issues + */ + public Organizations sort(final OrganizationComparator.Sorting sorting) + { + Organizations result; + + sort(new OrganizationComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by name. + * + * @return the services + */ + public Organizations sortByName() + { + Organizations result; + + result = sort(OrganizationComparator.Sorting.NAME); + + // + return result; + } + + /** + * Sort by service count. + * + * @return the organizations + */ + public Organizations sortByServiceCount() + { + Organizations result; + + result = sort(OrganizationComparator.Sorting.USER_COUNT); + + // + return result; + } + } diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index e746bc2..f60951f 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -126,7 +126,12 @@ public class Service extends PathPropertyList return this.organization; } - public String getSoftware() + /** + * Gets the software name. + * + * @return the software name + */ + public String getSoftwareName() { String result; @@ -145,7 +150,22 @@ public class Service extends PathPropertyList { String result; - result = StatoolInfosUtils.buildTechnicalName(getName()); + result = StatoolInfosUtils.toTechnicalName(getName()); + + // + return result; + } + + /** + * User count. + * + * @return the int + */ + public int getUserCount() + { + int result; + + result = 0; // return result; diff --git a/src/fr/devinsy/statoolinfos/core/ServiceComparator.java b/src/fr/devinsy/statoolinfos/core/ServiceComparator.java new file mode 100644 index 0000000..cdc4145 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/core/ServiceComparator.java @@ -0,0 +1,139 @@ +/* + * + */ +package fr.devinsy.statoolinfos.core; + +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class CategoryStatComparator. + */ +public class ServiceComparator implements Comparator +{ + public enum Sorting + { + NAME, + USER_COUNT + } + + private Sorting sorting; + + /** + * Instantiates a new category stat comparator. + * + * @param sorting + * the sorting + */ + public ServiceComparator(final Sorting sorting) + { + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final Service alpha, final Service 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 Service alpha, final Service 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 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 Service source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.getName(); + } + + // + return result; + } + + /** + * Gets the user count. + * + * @param source + * the source + * @return the user count + */ + public static Long getUserCount(final Service source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = (long) source.getUserCount(); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/core/Services.java b/src/fr/devinsy/statoolinfos/core/Services.java index 0932023..0381fd1 100644 --- a/src/fr/devinsy/statoolinfos/core/Services.java +++ b/src/fr/devinsy/statoolinfos/core/Services.java @@ -19,6 +19,7 @@ package fr.devinsy.statoolinfos.core; import java.util.ArrayList; +import java.util.Collections; /** * The Class Services. @@ -34,4 +35,55 @@ public class Services extends ArrayList { super(); } + + /** + * Reverse. + * + * @return the services + */ + public Services reverse() + { + Services result; + + Collections.reverse(this); + + result = this; + + // + return result; + } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the issues + */ + public Services sort(final ServiceComparator.Sorting sorting) + { + Services result; + + sort(new ServiceComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by name. + * + * @return the services + */ + public Services sortByName() + { + Services result; + + result = sort(ServiceComparator.Sorting.NAME); + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java index c49a2f6..92557e5 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java @@ -56,28 +56,6 @@ public class StatoolInfosUtils public static final DateTimeFormatter PATTERN_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE); public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE); - /** - * Builds the technical name. - * - * @return the string - */ - public static String buildTechnicalName(final String source) - { - String result; - - if (source == null) - { - result = null; - } - else - { - result = source.toLowerCase().replaceAll("[^a-z_0-9]", ""); - } - - // - return result; - } - /** * Copy ressource. * @@ -386,7 +364,7 @@ public class StatoolInfosUtils } else { - result = StringUtils.stripAccents(source).replaceAll("[^A-Za-z0-9]+", ""); + result = StringUtils.stripAccents(source.toLowerCase()).replaceAll("[^a-z0-9]+", ""); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/Breadcrumb.java b/src/fr/devinsy/statoolinfos/htmlize/Breadcrumb.java index 71d1d4a..ee494d8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Breadcrumb.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Breadcrumb.java @@ -18,6 +18,9 @@ */ package fr.devinsy.statoolinfos.htmlize; +/** + * The Class Breadcrumb. + */ public class Breadcrumb { private String label; diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java new file mode 100644 index 0000000..6dac1ac --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java @@ -0,0 +1,87 @@ +/* + * 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.categories.CategoryStat; +import fr.devinsy.statoolinfos.stats.categories.CategoryStats; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class ServicesPage. + */ +public class CategoriesPage +{ + private static Logger logger = LoggerFactory.getLogger(CategoriesPage.class); + + /** + * Builds the. + * + * @param categories + * the services + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final CategoryStats stats) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building categories page."); + + TagDataManager data = new TagDataManager(); + + data.setContent("categoryCount", stats.size()); + + int index = 0; + for (CategoryStat stat : stats.sortByName()) + { + 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()); + data.setContent("categoryListLine", index, "categoryListLineUserCount", stat.getUserCount()); + + index += 1; + } + + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/categories.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add("Catégories", "categories.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/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java index 1bf0b36..0ca72e3 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -62,7 +62,7 @@ public class FederationPage data.setContent("serviceCount", federation.getServiceCount()); int index = 0; - for (Organization organization : federation.getOrganizations()) + for (Organization organization : federation.getOrganizations().sortByServiceCount()) { data.setAttribute("organizationListLine", index, "organizationListLineNameLink", "href", organization.getTechnicalName() + ".xhtml"); data.setAttribute("organizationListLine", index, "organizationListLineLogo", "src", organization.getTechnicalName() + "-logo.png"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 3f03f76..2c5ed2d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -27,6 +27,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.core.Categories; import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.Factory; import fr.devinsy.statoolinfos.core.Federation; @@ -36,6 +37,7 @@ import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.crawl.CrawlCache; 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; @@ -78,7 +80,7 @@ public class Htmlizer for (File file : htmlizeDirectory.listFiles()) { - if ((file.isFile()) && (StringUtils.endsWithAny(file.getName(), ".properties", ".js", ".html", ".ico", ".css", ".jpg", ".xhtml"))) + if ((file.isFile()) && (StringUtils.endsWithAny(file.getName(), ".properties", ".js", ".html", ".ico", ".css", ".jpg", ".png", ".xhtml"))) { logger.info("Deleting " + file.getName()); file.delete(); @@ -259,12 +261,14 @@ public class Htmlizer page = ServicesPage.build(federation.getAllServices()); FileUtils.write(new File(htmlizeDirectory, "services.xhtml"), page, StandardCharsets.UTF_8); + // { logger.info("Htmlize propertiesFiles page."); PropertiesFileStats stats = StatAgent.statAllPropertiesFiles(federation, cache).sortByName(); page = PropertiesFilesPage.build(stats); FileUtils.write(new File(htmlizeDirectory, "propertiesFiles.xhtml"), page, StandardCharsets.UTF_8); } + // { logger.info("Htmlize propertyStats page."); @@ -275,6 +279,15 @@ public class Htmlizer page = PropertyStatsPage.build(stats, federationStats, organizationsStats, servicesStats); FileUtils.write(new File(htmlizeDirectory, "propertyStats.xhtml"), page, StandardCharsets.UTF_8); } + + // + { + 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); + } } /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java index c544b95..c8475a1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java @@ -62,7 +62,7 @@ public class OrganizationPage data.setContent("serviceCount", organization.getServices().size()); int index = 0; - for (Service service : organization.getServices()) + for (Service service : organization.getServices().sortByName()) { data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); data.setAttribute("serviceListLine", index, "serviceListLineLogo", "src", organization.getTechnicalName() + "-" + service.getTechnicalName() + "-logo.png"); @@ -70,7 +70,7 @@ public class OrganizationPage 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.getSoftware()); + data.setEscapedContent("serviceListLine", index, "serviceListLineSoftware", service.getSoftwareName()); index += 1; } diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java index 7f41ee4..f57fc46 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java @@ -68,7 +68,7 @@ public class PropertiesFilesPage int index = 0; for (PropertiesFileStat stat : stats) { - data.setAttribute("fileListLine", index, "fileListLineNameLink", "href", stat.getLocalName() + ".xhtml"); + data.setAttribute("fileListLine", index, "fileListLineNameLink", "href", stat.getLocalName()); data.setEscapedContent("fileListLine", index, "fileListLineNameLink", stat.getLocalName()); data.setAttribute("fileListLine", index, "fileListLineOwnerLink", "href", stat.getOrganization().getTechnicalName() + ".xhtml"); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java index 478e747..57177b1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java @@ -67,7 +67,7 @@ public class ServicesPage 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.getSoftware()); + data.setEscapedContent("serviceListLine", index, "serviceListLineSoftware", service.getSoftwareName()); index += 1; } diff --git a/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml b/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml new file mode 100644 index 0000000..667778c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/categories.xhtml @@ -0,0 +1,42 @@ + + + + + StatoolInfos + + + + + + + +

Catégories

+ +
Nombre de catégories : n/a
+
+ + + + + + + + + + + + + + + + + + + +
Nom de la catégorieLogicielsServicesOrganizationsUtilisateurs mensuels
+ n/a + n/an/an/an/a
+
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml index bb650cb..5132ee5 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/webCharterView.xhtml @@ -19,8 +19,9 @@ Fichiers Propriétés Services + Catégories Logiciels - Catégories + Candidats diff --git a/src/fr/devinsy/statoolinfos/properties/PathProperties.java b/src/fr/devinsy/statoolinfos/properties/PathProperties.java index 99f979c..fdb7ba7 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathProperties.java +++ b/src/fr/devinsy/statoolinfos/properties/PathProperties.java @@ -82,6 +82,13 @@ public interface PathProperties extends Iterable */ PathProperty getProperty(final String path); + /** + * Gets the sub prefixes. + * + * @return the sub prefixes + */ + StringSet getSubPrefixes(); + /** * Gets the url. * diff --git a/src/fr/devinsy/statoolinfos/properties/PathProperty.java b/src/fr/devinsy/statoolinfos/properties/PathProperty.java index 645f9ac..5a934a0 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathProperty.java +++ b/src/fr/devinsy/statoolinfos/properties/PathProperty.java @@ -64,6 +64,36 @@ public class PathProperty return this.path; } + /** + * Gets the prefix. + * + * @return the prefix + */ + private String getPrefix() + { + String result; + + result = this.path.substring(0, this.path.indexOf(".")); + + // + return result; + } + + /** + * Gets the sub prefix. + * + * @return the sub prefix + */ + public String getSubPrefix() + { + String result; + + result = this.path.substring(0, this.path.indexOf(".", this.path.indexOf(".") + 1)); + + // + return result; + } + public String getValue() { return this.value; diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index 3de37ef..143b4ce 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -31,7 +31,7 @@ import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringSet; /** - * The Class StatoolsInfosProperties. + * The Class PathPropertyList. */ public class PathPropertyList extends ArrayList implements PathProperties { @@ -244,7 +244,7 @@ public class PathPropertyList extends ArrayList implements PathPro for (PathProperty property : this) { - result.add(getPrefix(property.getPath())); + result.add(property.getSubPrefix()); } // @@ -315,6 +315,27 @@ public class PathPropertyList extends ArrayList implements PathPro return result; } + /** + * Gets the sub prefixes. + * + * @return the sub prefixes + */ + @Override + public StringSet getSubPrefixes() + { + StringSet result; + + result = new StringSet(); + + for (PathProperty property : this) + { + result.add(property.getSubPrefix()); + } + + // + return result; + } + /** * Gets the url. * diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java index aa91f27..6679aeb 100644 --- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java +++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java @@ -21,14 +21,19 @@ package fr.devinsy.statoolinfos.stats; import java.io.IOException; import java.net.MalformedURLException; +import fr.devinsy.statoolinfos.core.Categories; +import fr.devinsy.statoolinfos.core.Category; import fr.devinsy.statoolinfos.core.Federation; 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.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.strings.StringSet; /** * The Class StatAgent. @@ -43,6 +48,61 @@ public class StatAgent } + /** + * Stat all categories. + * + * @param federation + * the federation + * @param categories + * the categories + * @return the property stats + */ + public static CategoryStats statAllCategories(final Federation federation, final Categories categories) + { + CategoryStats result; + + result = new CategoryStats(); + + for (Category category : categories) + { + CategoryStat stat = new CategoryStat(category); + StringSet organizations = new StringSet(); + + for (Service service : federation.getAllServices()) + { + String softwareName = service.getSoftwareName(); + if (category.getSoftwares().containsIgnoreCase(softwareName)) + { + stat.incServiceCount(); + stat.incUserCount(service.getUserCount()); + organizations.add(service.getOrganization().getName()); + } + } + stat.setOrganizationCount(organizations.size()); + + 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; + } + /** * Stat all properties. * diff --git a/src/fr/devinsy/statoolinfos/stats/categories/CategoryStat.java b/src/fr/devinsy/statoolinfos/stats/categories/CategoryStat.java new file mode 100644 index 0000000..ca5bf3b --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/categories/CategoryStat.java @@ -0,0 +1,116 @@ +/* + * 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.categories; + +import fr.devinsy.statoolinfos.core.Category; + +/** + * The Class CategoryStat. + */ +public class CategoryStat +{ + private Category category; + private int serviceCount; + private int organizationCount; + private int userCount; + + /** + * Instantiates a new category stat. + * + * @param path + * the path + */ + public CategoryStat(final Category category) + { + this.category = category; + this.serviceCount = 0; + this.organizationCount = 0; + this.userCount = 0; + } + + public Category getCategory() + { + return this.category; + } + + public int getOrganizationCount() + { + return this.organizationCount; + } + + public int getServiceCount() + { + return this.serviceCount; + } + + public int getUserCount() + { + return this.userCount; + } + + /** + * Inc organization count. + */ + public void incOrganizationCount() + { + this.organizationCount += 1; + } + + /** + * 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 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/categories/CategoryStatComparator.java b/src/fr/devinsy/statoolinfos/stats/categories/CategoryStatComparator.java new file mode 100644 index 0000000..bc747b1 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/categories/CategoryStatComparator.java @@ -0,0 +1,198 @@ +/* + * + */ +package fr.devinsy.statoolinfos.stats.categories; + +import java.util.Comparator; + +import fr.devinsy.statoolinfos.util.CompareUtils; + +/** + * The Class CategoryStatComparator. + */ +public class CategoryStatComparator 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 CategoryStatComparator(final Sorting sorting) + { + // + this.sorting = sorting; + } + + /** + * Compare. + * + * @param alpha + * the alpha + * @param bravo + * the bravo + * @return the int + */ + @Override + public int compare(final CategoryStat alpha, final CategoryStat 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 CategoryStat alpha, final CategoryStat 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 CategoryStat 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 CategoryStat 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 CategoryStat 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 CategoryStat source) + { + Long result; + + if (source == null) + { + result = null; + } + else + { + result = (long) source.getUserCount(); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/stats/categories/CategoryStats.java b/src/fr/devinsy/statoolinfos/stats/categories/CategoryStats.java new file mode 100644 index 0000000..d7bd1ae --- /dev/null +++ b/src/fr/devinsy/statoolinfos/stats/categories/CategoryStats.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.categories; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * The Class CategoryStats. + */ +public class CategoryStats extends ArrayList +{ + private static final long serialVersionUID = 4864900171648399075L; + + /** + * Instantiates a new property stat list. + */ + public CategoryStats() + { + super(); + } + + /** + * Reverse. + * + * @return the property stat list + */ + public CategoryStats reverse() + { + CategoryStats result; + + Collections.reverse(this); + + result = this; + + // + return result; + } + + /** + * Sort. + * + * @param sorting + * the sorting + * @return the issues + */ + public CategoryStats sort(final CategoryStatComparator.Sorting sorting) + { + CategoryStats result; + + sort(new CategoryStatComparator(sorting)); + + result = this; + + // + return result; + } + + /** + * Sort by name. + * + * @return the category stats + */ + public CategoryStats sortByName() + { + CategoryStats result; + + result = sort(CategoryStatComparator.Sorting.NAME); + + // + return result; + } + + /** + * Sort by organization count. + * + * @return the category stats + */ + public CategoryStats sortByOrganizationCount() + { + CategoryStats result; + + result = sort(CategoryStatComparator.Sorting.ORGANIZATION_COUNT); + + // + return result; + } + + /** + * Sort by service count. + * + * @return the category stats + */ + public CategoryStats sortByServiceCount() + { + CategoryStats result; + + result = sort(CategoryStatComparator.Sorting.SERVICE_COUNT); + + // + return result; + } + + /** + * Sort by user count. + * + * @return the category stats + */ + public CategoryStats sortByUserCount() + { + CategoryStats result; + + result = sort(CategoryStatComparator.Sorting.USER_COUNT); + + // + return result; + } +}