Added categories management.
This commit is contained in:
parent
ff0e9cfb1e
commit
00320d7df4
28 changed files with 1442 additions and 36 deletions
75
src/fr/devinsy/statoolinfos/core/Categories.java
Normal file
75
src/fr/devinsy/statoolinfos/core/Categories.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The Class Categories.
|
||||
*/
|
||||
public class Categories extends ArrayList<Category>
|
||||
{
|
||||
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<Category> 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;
|
||||
}
|
||||
}
|
114
src/fr/devinsy/statoolinfos/core/Category.java
Normal file
114
src/fr/devinsy/statoolinfos/core/Category.java
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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.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;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -192,7 +192,7 @@ public class Federation extends PathPropertyList
|
|||
{
|
||||
String result;
|
||||
|
||||
result = StatoolInfosUtils.buildTechnicalName(getName());
|
||||
result = StatoolInfosUtils.toTechnicalName(getName());
|
||||
|
||||
//
|
||||
return result;
|
||||
|
|
|
@ -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;
|
||||
|
|
169
src/fr/devinsy/statoolinfos/core/OrganizationComparator.java
Normal file
169
src/fr/devinsy/statoolinfos/core/OrganizationComparator.java
Normal file
|
@ -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<Organization>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Organization>
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
139
src/fr/devinsy/statoolinfos/core/ServiceComparator.java
Normal file
139
src/fr/devinsy/statoolinfos/core/ServiceComparator.java
Normal file
|
@ -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<Service>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<Service>
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]+", "");
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
package fr.devinsy.statoolinfos.htmlize;
|
||||
|
||||
/**
|
||||
* The Class Breadcrumb.
|
||||
*/
|
||||
public class Breadcrumb
|
||||
{
|
||||
private String label;
|
||||
|
|
87
src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java
Normal file
87
src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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.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;
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
42
src/fr/devinsy/statoolinfos/htmlize/categories.xhtml
Normal file
42
src/fr/devinsy/statoolinfos/htmlize/categories.xhtml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?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" />
|
||||
<script src="sorttable.js" />
|
||||
<script src="Chart.bundle.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Catégories</h2>
|
||||
|
||||
<div>Nombre de catégories : <span id="categoryCount">n/a</span></div>
|
||||
<div>
|
||||
<table class="table_classic sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="">Nom de la catégorie</th>
|
||||
<th class="">Logiciels</th>
|
||||
<th class="" style="width: 100px;">Services</th>
|
||||
<th class="" style="width: 100px;">Organizations</th>
|
||||
<th class="" style="width: 100px;">Utilisateurs mensuels</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="categoryListLine">
|
||||
<td id="categoryListLineName" style="padding-top: 0; padding-bottom: 0;">
|
||||
<a href="#" id="categoryListLineNameLink" title="categoryListLineNameDescription">n/a</a>
|
||||
</td>
|
||||
<td id="categoryListLineSoftwares">n/a</td>
|
||||
<td id="categoryListLineServiceCount" class="td_number">n/a</td>
|
||||
<td id="categoryListLineOrganizationCount" class="td_number">n/a</td>
|
||||
<td id="categoryListLineUserCount" class="td_number">n/a</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -19,8 +19,9 @@
|
|||
<a id="propertiesRawButton" href="propertiesFiles.xhtml" class="button">Fichiers</a>
|
||||
<a id="propertiesRawButton" href="propertyStats.xhtml" class="button">Propriétés</a>
|
||||
<a id="" href="services.xhtml" class="button">Services</a>
|
||||
<a id="" href="categories.xhtml" class="button">Catégories</a>
|
||||
<a id="" href="#" class="button">Logiciels</a>
|
||||
<a id="" href="#" class="button">Catégories</a>
|
||||
<a id="" href="#" class="button">Candidats</a>
|
||||
</div>
|
||||
|
||||
<div id="breadcrumbTrail" style="margin: 5px;">n/a > n/a</div>
|
||||
|
|
|
@ -82,6 +82,13 @@ public interface PathProperties extends Iterable<PathProperty>
|
|||
*/
|
||||
PathProperty getProperty(final String path);
|
||||
|
||||
/**
|
||||
* Gets the sub prefixes.
|
||||
*
|
||||
* @return the sub prefixes
|
||||
*/
|
||||
StringSet getSubPrefixes();
|
||||
|
||||
/**
|
||||
* Gets the url.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<PathProperty> implements PathProperties
|
||||
{
|
||||
|
@ -244,7 +244,7 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
|
|||
|
||||
for (PathProperty property : this)
|
||||
{
|
||||
result.add(getPrefix(property.getPath()));
|
||||
result.add(property.getSubPrefix());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -315,6 +315,27 @@ public class PathPropertyList extends ArrayList<PathProperty> 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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
116
src/fr/devinsy/statoolinfos/stats/categories/CategoryStat.java
Normal file
116
src/fr/devinsy/statoolinfos/stats/categories/CategoryStat.java
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* 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.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;
|
||||
}
|
||||
}
|
|
@ -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<CategoryStat>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
134
src/fr/devinsy/statoolinfos/stats/categories/CategoryStats.java
Normal file
134
src/fr/devinsy/statoolinfos/stats/categories/CategoryStats.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* 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.stats.categories;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* The Class CategoryStats.
|
||||
*/
|
||||
public class CategoryStats extends ArrayList<CategoryStat>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue