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

155 lines
6.9 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.IOException;
import org.apache.commons.lang3.StringUtils;
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.StatoolInfosException;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.DisplayMode;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class FederationHeaderView.
*/
public class FederationHeaderView
{
private static Logger logger = LoggerFactory.getLogger(FederationHeaderView.class);
/**
* Builds the.
*
* @param federation
* the organization
* @return the string
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
*/
public static String htmlize(final Federation federation) throws StatoolInfosException
{
String result;
try
{
TagDataManager data = new TagDataManager();
data.setAttribute("federationRawButton", "href", federation.getTechnicalName() + ".properties");
data.setAttribute("federationLogo", "src", federation.getLogoFileName());
data.setEscapedContent("federationName", federation.getName());
data.setEscapedContent("federationDescription", federation.getDescription());
if (federation.getWebsiteURL() != null)
{
data.setEscapedContent("federationURL", federation.getWebsiteURL().toString());
data.setEscapedAttribute("federationURL", "href", federation.getWebsiteURL().toString());
}
data.setContent("federationStartDate", StringUtils.defaultIfBlank(federation.getStartDate(), "n/a"));
data.setAttribute("organizationsLink", "href", federation.getTechnicalName() + "-organizations.xhtml");
data.setAttribute("servicesLink", "href", federation.getTechnicalName() + "-services.xhtml");
data.setAttribute("rawLink", "href", federation.getTechnicalName() + ".properties");
data.setAttribute("propertyCheckLink", "href", federation.getTechnicalName() + "-propertycheck.xhtml");
data.setAttribute("statsLink", "href", federation.getTechnicalName() + "-stats.xhtml");
data.setAttribute("metricsLink", "href", federation.getTechnicalName() + "-metrics-summary-months-last.xhtml");
data.setAttribute("crawlLink", "href", federation.getTechnicalName() + "-crawl.xhtml");
data.setAttribute("uptimeLink", "href", federation.getLocalFileBaseName() + "-uptimes.xhtml");
if (HtmlizerContext.instance().getUptimeJournal().hasRecentError(federation.getServicesAll()))
{
data.setAttribute("uptimeLinkImg", "src", "circle-icons/countdown-ko-mono.svg");
}
else
{
data.setAttribute("uptimeLinkImg", "src", "circle-icons/countdown-ok-mono.svg");
}
if (federation.getCrawlJournal().getErrors().isEmpty())
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg");
}
else
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download.svg");
}
{
PropertyChecks checks = federation.getInputChecksAll();
data.setContent("errorCount", checks.getErrorCount());
data.setContent("warningCount", checks.getWarningCount());
data.setContent("voidCount", checks.getVoidCount());
data.setAttribute("alertLink", "href", federation.getTechnicalName() + "-propertyalerts.xhtml");
}
if (federation.getLegalURL() != null)
{
data.setEscapedAttribute("legalLink", "href", federation.getLegalURL().toString());
data.setAttribute("legalLinkImg", "class", "");
data.getIdData("legalLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (federation.getContactURL() != null)
{
data.setEscapedAttribute("contactLink", "href", federation.getContactURL().toString());
data.setAttribute("contactLinkImg", "class", "");
data.getIdData("contactLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (StringUtils.isNotBlank(federation.getContactEmail()))
{
data.setEscapedAttribute("emailLink", "href", "mailto:" + federation.getContactEmail());
data.setAttribute("emailLinkImg", "class", "");
data.getIdData("emailLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (federation.getUserGuideURL() != null)
{
data.setEscapedAttribute("userDocLink", "href", federation.getUserGuideURL().toString());
data.setAttribute("userDocLinkImg", "class", "");
data.getIdData("userDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (federation.getTechnicalGuideURL() != null)
{
data.setEscapedAttribute("technicalDocLink", "href", federation.getTechnicalGuideURL().toString());
data.setAttribute("technicalDocLinkImg", "class", "");
data.getIdData("technicalDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml", data).toString();
result = XidynUtils.extractBodyContent(content);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building federation header view: " + exception.getMessage(), exception);
}
//
return result;
}
}