Added multi categories for software.
This commit is contained in:
parent
7ac3a80631
commit
be6c6e1643
10 changed files with 158 additions and 46 deletions
|
@ -44,29 +44,17 @@ public class Categories extends ArrayList<Category>
|
|||
* 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<Category> iterator = this.iterator();
|
||||
result = null;
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
Category category = iterator.next();
|
||||
result = new Categories();
|
||||
|
||||
if (category.getSoftwares().contains(softwareName))
|
||||
for (Category category : this)
|
||||
{
|
||||
ended = true;
|
||||
result = category;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (category.getSoftwares().containsAnyIgnoreCase(softwareName))
|
||||
{
|
||||
ended = true;
|
||||
result = null;
|
||||
result.add(category);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
103
src/fr/devinsy/statoolinfos/htmlize/CategoriesView.java
Normal file
103
src/fr/devinsy/statoolinfos/htmlize/CategoriesView.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
19
src/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml
Normal file
19
src/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>StatoolInfos</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="keywords" content="statoolinfos,devinsy,federation" />
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
|
||||
</head>
|
||||
<body>
|
||||
<span id="category">
|
||||
<a id="categoryLink" href="#" title="Catégorie">
|
||||
<img id="categoryLogo" src="categories/default.png" style="width: 26px; height: 26px; padding-top:0; padding-bottom: 0; vertical-align: middle;"/>
|
||||
<span id="categoryName">n/a</span>
|
||||
</a>
|
||||
</span>
|
||||
</body>
|
||||
</html>
|
|
@ -21,7 +21,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th class="">Nom</th>
|
||||
<th class="">Catégorie</th>
|
||||
<th class="">Catégories</th>
|
||||
<th class="" style="width: 100px;">Services</th>
|
||||
<th class="" style="width: 100px;">Organisations</th>
|
||||
<th class="" style="width: 100px;">Utilisateurs mensuels</th>
|
||||
|
@ -32,12 +32,7 @@
|
|||
<td id="softwareListLineName" style="padding-top: 0; padding-bottom: 0;">
|
||||
<a href="#" id="softwareListLineNameLink" title="">n/a</a>
|
||||
</td>
|
||||
<td id="softwareListLineCategory" style="padding-top: 0; padding-bottom: 0;">
|
||||
<a href="#" id="softwareListLineCategoryLink" title="">
|
||||
<img id="softwareListLineCategoryLogo" src="categories/default.png" style="width: 26px; height: 26px; padding-top:0; padding-bottom: 0; vertical-align: middle;"/>
|
||||
 <span id="softwareListLineCategoryName">n/a</span>
|
||||
</a>
|
||||
</td>
|
||||
<td id="softwareListLineCategory" style="padding-top: 0; padding-bottom: 0;">n/a</td>
|
||||
<td id="softwareListLineServiceCount" class="td_number">n/a</td>
|
||||
<td id="softwareListLineOrganizationCount" class="td_number">n/a</td>
|
||||
<td id="softwareListLineUserCount" class="td_number">n/a</td>
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue