statoolinfosweb/src/fr/devinsy/statoolinfos/htmlize/FederationPropertyAlertPage.java

154 lines
6 KiB
Java

/*
* Copyright (C) 2020-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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.checker.PropertyChecks;
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.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class FederationPropertyCheckAlertPage.
*/
public class FederationPropertyAlertPage
{
private static Logger logger = LoggerFactory.getLogger(FederationPropertyAlertPage.class);
public enum PropertyAlertScope
{
ALL,
FEDERATION,
ORGANIZATIONS,
SERVICES,
METRICS
}
/**
* Builds the all.
*
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static void buildAll() throws IOException, StatoolInfosException
{
Federation federation = HtmlizerContext.instance().getFederation();
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
String page = htmlize(PropertyAlertScope.ALL);
FileUtils.write(new File(htmlizeDirectory, federation.getTechnicalName() + "-propertyalerts.xhtml"), page, StandardCharsets.UTF_8);
page = htmlize(PropertyAlertScope.FEDERATION);
FileUtils.write(new File(htmlizeDirectory, federation.getLocalFileBaseName() + "-propertyalerts-federation.xhtml"), page, StandardCharsets.UTF_8);
page = htmlize(PropertyAlertScope.ORGANIZATIONS);
FileUtils.write(new File(htmlizeDirectory, federation.getLocalFileBaseName() + "-propertyalerts-organizations.xhtml"), page, StandardCharsets.UTF_8);
page = htmlize(PropertyAlertScope.SERVICES);
FileUtils.write(new File(htmlizeDirectory, federation.getLocalFileBaseName() + "-propertyalerts-services.xhtml"), page, StandardCharsets.UTF_8);
}
/**
* Htmlize.
*
* @param scope
* the scope
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlize(final PropertyAlertScope scope) throws StatoolInfosException
{
String result;
try
{
Federation federation = HtmlizerContext.instance().getFederation();
TagDataManager data = new TagDataManager();
data.setContent("headerView", FederationHeaderView.htmlize(federation));
// TODO submenu
data.setAttribute("allButton", "href", federation.getLocalFileBaseName() + "-propertyalerts.xhtml");
data.setAttribute("federationButton", "href", federation.getLocalFileBaseName() + "-propertyalerts-federation.xhtml");
data.setAttribute("organizationButton", "href", federation.getLocalFileBaseName() + "-propertyalerts-organizations.xhtml");
data.setAttribute("serviceButton", "href", federation.getLocalFileBaseName() + "-propertyalerts-services.xhtml");
data.setAttribute("metricsButton", "href", federation.getLocalFileBaseName() + "-propertyalerts-metrics.xhtml");
PropertyChecks checks;
if (scope == PropertyAlertScope.ALL)
{
checks = federation.getInputChecksAll().getAlertLines();
}
else if (scope == PropertyAlertScope.FEDERATION)
{
checks = federation.getInputChecks().getAlertLines();
}
else if (scope == PropertyAlertScope.ORGANIZATIONS)
{
checks = new PropertyChecks();
for (Organization organization : federation.getOrganizations())
{
checks.addAll(organization.getInputChecks().getAlertLines());
}
}
else if (scope == PropertyAlertScope.SERVICES)
{
checks = new PropertyChecks();
for (Service service : federation.getServicesAll())
{
checks.addAll(service.getInputChecksAll().getAlertLines());
}
}
else
{
checks = new PropertyChecks();
}
data.setContent("contentView", PropertyAlertView.htmlize(checks));
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationPropertyAlertView.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add("Propriétés en alertes", federation.getLocalFileBaseName() + "-propertyalerts.xhtml");
result = WebCharterView.build(content, trail);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building federation property file check alert page: " + exception.getMessage(), exception);
}
//
return result;
}
}