Added JSON export management.
This commit is contained in:
parent
802e0c568f
commit
ce6cf6620f
7 changed files with 353 additions and 3 deletions
242
src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java
Normal file
242
src/fr/devinsy/statoolinfos/htmlize/ExportsPage.java
Normal file
|
@ -0,0 +1,242 @@
|
|||
/*
|
||||
* Copyright (C) 2021 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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.HtmlizerContext;
|
||||
import fr.devinsy.statoolinfos.core.Federation;
|
||||
import fr.devinsy.statoolinfos.core.Organization;
|
||||
import fr.devinsy.statoolinfos.core.Service;
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
import fr.devinsy.xidyn.XidynException;
|
||||
import fr.devinsy.xidyn.presenters.PresenterUtils;
|
||||
|
||||
/**
|
||||
* The Class ExportsPage.
|
||||
*/
|
||||
public class ExportsPage
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(ExportsPage.class);
|
||||
|
||||
/**
|
||||
* Builds the.
|
||||
*
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void build() throws StatoolInfosException, IOException
|
||||
{
|
||||
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
|
||||
|
||||
//
|
||||
logger.info("EXPORTS JSON.");
|
||||
ExportsPage.buildFederationExport();
|
||||
ExportsPage.buildOrganizationsExport();
|
||||
ExportsPage.buildServicesExport();
|
||||
|
||||
//
|
||||
String page = htmlize();
|
||||
FileUtils.write(new File(htmlizeDirectory, "exports.xhtml"), page, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the federation export.
|
||||
*
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildFederationExport() throws StatoolInfosException, IOException
|
||||
{
|
||||
Federation federation = HtmlizerContext.instance().getFederation();
|
||||
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
|
||||
|
||||
StringList lines = new StringList();
|
||||
|
||||
lines.appendln("{ \"federation\" : ");
|
||||
|
||||
lines.addAll(PathPropertyUtils.toJSON(federation));
|
||||
|
||||
lines.removeLast();
|
||||
lines.appendln(",");
|
||||
lines.appendln("\"organizations\" : [");
|
||||
|
||||
for (Organization organization : federation.getOrganizations())
|
||||
{
|
||||
lines.addAll(PathPropertyUtils.toJSON(organization));
|
||||
lines.removeLast();
|
||||
|
||||
lines.appendln(",");
|
||||
lines.append("\"services\" : [");
|
||||
|
||||
for (Service service : organization.getServices())
|
||||
{
|
||||
lines.addAll(PathPropertyUtils.toJSON(service));
|
||||
lines.appendln(",");
|
||||
}
|
||||
if (!organization.getServices().isEmpty())
|
||||
{
|
||||
lines.removeLast(2);
|
||||
}
|
||||
lines.appendln();
|
||||
lines.appendln("]");
|
||||
lines.append("}");
|
||||
lines.appendln(",");
|
||||
}
|
||||
if (!federation.getOrganizations().isEmpty())
|
||||
{
|
||||
lines.removeLast(2);
|
||||
lines.appendln();
|
||||
}
|
||||
|
||||
lines.appendln("]");
|
||||
|
||||
lines.appendln("}");
|
||||
lines.appendln("}");
|
||||
|
||||
logger.info("Htmlize federation JSON Export pages.");
|
||||
StringsUtils.writeToFile(new File(htmlizeDirectory, "federation.json"), lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the organizations export.
|
||||
*
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildOrganizationsExport() throws StatoolInfosException, IOException
|
||||
{
|
||||
Federation federation = HtmlizerContext.instance().getFederation();
|
||||
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
|
||||
|
||||
StringList lines = new StringList();
|
||||
|
||||
lines.appendln("{ \"organizations\" : [");
|
||||
|
||||
for (Organization organization : federation.getOrganizations())
|
||||
{
|
||||
lines.addAll(PathPropertyUtils.toJSON(organization));
|
||||
lines.append(",");
|
||||
}
|
||||
if (!federation.getOrganizations().isEmpty())
|
||||
{
|
||||
lines.removeLast();
|
||||
}
|
||||
|
||||
lines.appendln("] }");
|
||||
|
||||
logger.info("Htmlize organizations JSON Export pages.");
|
||||
StringsUtils.writeToFile(new File(htmlizeDirectory, "organizations.json"), lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the services export.
|
||||
*
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildServicesExport() throws StatoolInfosException, IOException
|
||||
{
|
||||
Federation federation = HtmlizerContext.instance().getFederation();
|
||||
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
|
||||
|
||||
StringList lines = new StringList();
|
||||
|
||||
lines.appendln("{ \"services\" : [");
|
||||
|
||||
for (Service service : federation.getAllServices())
|
||||
{
|
||||
lines.addAll(PathPropertyUtils.toJSON(service));
|
||||
lines.append(",");
|
||||
}
|
||||
if (!federation.getAllServices().isEmpty())
|
||||
{
|
||||
lines.removeLast();
|
||||
}
|
||||
|
||||
lines.appendln("] }");
|
||||
|
||||
logger.info("Htmlize services JSON Export pages.");
|
||||
StringsUtils.writeToFile(new File(htmlizeDirectory, "services.json"), lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the string
|
||||
*/
|
||||
public static String escapeJSON(final String source)
|
||||
{
|
||||
String result;
|
||||
|
||||
result = StringEscapeUtils.escapeJson(source);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Htmlize.
|
||||
*
|
||||
* @return the string
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
*/
|
||||
public static String htmlize() throws StatoolInfosException
|
||||
{
|
||||
String result;
|
||||
|
||||
try
|
||||
{
|
||||
logger.info("PAGE EXPORTS.");
|
||||
|
||||
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/exports.xhtml", null).toString();
|
||||
|
||||
BreadcrumbTrail trail = new BreadcrumbTrail();
|
||||
result = WebCharterView.build(content, trail);
|
||||
}
|
||||
catch (XidynException exception)
|
||||
{
|
||||
throw new StatoolInfosException("Error building federation page: " + exception.getMessage(), exception);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -86,7 +86,7 @@ public class FederationPage
|
|||
|
||||
try
|
||||
{
|
||||
logger.debug("Building propoertiesFile page {}…", federation.getName());
|
||||
logger.debug("Building federation page {}…", federation.getName());
|
||||
|
||||
TagDataManager data = new TagDataManager();
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ public class Htmlizer
|
|||
SoftwaresPage.build();
|
||||
SoftwarePage.buildAll();
|
||||
SocialNetworksPage.buildAll();
|
||||
ExportsPage.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -271,7 +272,7 @@ public class Htmlizer
|
|||
|
||||
chart = new BarChart("Nombre de membres");
|
||||
|
||||
PathPropertyList values = federation.getByYearPrefix("metrics.federation.members.count").sortByPath();
|
||||
PathPropertyList values = federation.getByYearPrefix("metrics.members.count").sortByPath();
|
||||
|
||||
for (PathProperty property : values)
|
||||
{
|
||||
|
|
40
src/fr/devinsy/statoolinfos/htmlize/exports.xhtml
Normal file
40
src/fr/devinsy/statoolinfos/htmlize/exports.xhtml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?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>
|
||||
<div class="row center" style="border: 0px solid yellow;">
|
||||
<h1 style="margin-bottom: 40px;">Exports</h1>
|
||||
</div>
|
||||
<div class="center_table" style="width: 500px;">
|
||||
<div class="row exportsView">
|
||||
<div class="column">La fédération :</div>
|
||||
<div class="column"><img src="csv-logo.svg" title="CSV" style="opacity: 0.2"/></div>
|
||||
<div class="column"><a href="federation.json"><img src="json-logo.svg" title="JSON"/></a></div>
|
||||
<div class="column"><img src="ods-logo.svg" title="ODS" style="opacity: 0.2"/></div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row exportsView">
|
||||
<div class="column">Les organisations :</div>
|
||||
<div class="column"><a href="#"><img src="csv-logo.svg" title="CSV" style="opacity: 0.2"/></a></div>
|
||||
<div class="column"><a href="organizations.json"><img src="json-logo.svg" title="JSON"/></a></div>
|
||||
<div class="column"><a href="#"><img src="ods-logo.svg" title="ODS" style="opacity: 0.2"/></a></div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row exportsView">
|
||||
<div class="column">Les services :</div>
|
||||
<div class="column"><a href="#"><img src="csv-logo.svg" title="CSV" style="opacity: 0.2"/></a></div>
|
||||
<div class="column"><a href="services.json"><img src="json-logo.svg" title="JSON"/></a></div>
|
||||
<div class="column"><a href="#"><img src="ods-logo.svg" title="ODS" style="opacity: 0.2"/></a></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -823,3 +823,26 @@ table > tfoot > tr > th.danger
|
|||
{
|
||||
border: 1px solid #e7e7e7;
|
||||
}
|
||||
|
||||
/************************************************/
|
||||
.exportsView div:first-child
|
||||
{
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.exportsView div
|
||||
{
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.exportsView div:nth-child(3),
|
||||
.exportsView div:nth-child(4)
|
||||
{
|
||||
margin-left: 50px;
|
||||
}
|
||||
|
||||
.exportsView div img,
|
||||
.exportsView div a img
|
||||
{
|
||||
width: 50px;
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
<a id="propertiesRawButton" href="propertiesFiles.xhtml" class="button">Fichiers</a>
|
||||
<a id="propertiesStatsButton" href="propertyStats.xhtml" class="button">Propriétés</a>
|
||||
<a id="federationStatsButton" href="federationStats.xhtml" class="button">Statistiques</a>
|
||||
<a id="exportsButton" href="exports.xhtml" class="button">Exports</a>
|
||||
</div>
|
||||
|
||||
<div id="breadcrumbTrail" style="margin: 5px;">n/a > n/a</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
@ -30,6 +30,7 @@ import java.net.URL;
|
|||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -299,6 +300,48 @@ public class PathPropertyUtils
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To JSON.
|
||||
*
|
||||
* @param properties
|
||||
* the properties
|
||||
* @return the string list
|
||||
*/
|
||||
public static StringList toJSON(final PathPropertyList properties)
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = new StringList();
|
||||
|
||||
result.append("{");
|
||||
|
||||
if (properties != null)
|
||||
{
|
||||
boolean firstDone = false;
|
||||
for (PathProperty property : properties)
|
||||
{
|
||||
if (StringUtils.isNotBlank(property.getValue()))
|
||||
{
|
||||
firstDone = true;
|
||||
result.append("\"");
|
||||
result.append(StringEscapeUtils.escapeJson(property.getPath()));
|
||||
result.append("\" : \"");
|
||||
result.append(StringEscapeUtils.escapeJson(property.getValue()));
|
||||
result.append("\"");
|
||||
result.append(",");
|
||||
}
|
||||
}
|
||||
if (firstDone)
|
||||
{
|
||||
result.removeLast();
|
||||
}
|
||||
}
|
||||
result.append("}");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue