2021-06-03 03:05:12 +02:00
|
|
|
/*
|
|
|
|
* 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.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, IOException
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
|
2021-06-08 19:01:11 +02:00
|
|
|
if (federation.getWebsiteURL() != null)
|
|
|
|
{
|
|
|
|
data.setEscapedContent("federationURL", federation.getWebsiteURL().toString());
|
|
|
|
data.setEscapedAttribute("federationURL", "href", federation.getWebsiteURL().toString());
|
|
|
|
}
|
2021-06-03 03:05:12 +02:00
|
|
|
data.setContent("federationStartDate", StringUtils.defaultIfBlank(federation.getStartDate(), "n/a"));
|
|
|
|
|
|
|
|
data.setAttribute("subsLink", "href", "index.xhtml");
|
|
|
|
data.setAttribute("rawLink", "href", federation.getTechnicalName() + ".properties");
|
|
|
|
data.setAttribute("rawCheckLink", "href", federation.getTechnicalName() + "-check.xhtml");
|
|
|
|
data.setAttribute("statsLink", "href", federation.getTechnicalName() + "-stats.xhtml");
|
2021-06-07 18:48:18 +02:00
|
|
|
data.setAttribute("metricsLink", "href", federation.getTechnicalName() + "-metrics-summary-months-last.xhtml");
|
2021-06-03 03:05:12 +02:00
|
|
|
|
|
|
|
data.setAttribute("crawlLink", "href", federation.getTechnicalName() + "-crawl.xhtml");
|
2021-06-10 03:54:39 +02:00
|
|
|
data.setAttribute("uptimeLink", "href", federation.getLocalFileBaseName() + "-uptimes.xhtml");
|
|
|
|
|
2021-06-03 03:05:12 +02:00
|
|
|
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() + "-checkalerts.xhtml");
|
|
|
|
}
|
|
|
|
|
2021-06-08 19:01:11 +02:00
|
|
|
if (federation.getLegalURL() != null)
|
2021-06-03 03:05:12 +02:00
|
|
|
{
|
2021-06-08 19:01:11 +02:00
|
|
|
data.setEscapedAttribute("legalLink", "href", federation.getLegalURL().toString());
|
2021-06-03 03:05:12 +02:00
|
|
|
data.setAttribute("legalLinkImg", "class", "");
|
|
|
|
data.getIdData("legalLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
|
|
|
|
}
|
2021-06-08 19:01:11 +02:00
|
|
|
if (federation.getContactURL() != null)
|
2021-06-03 03:05:12 +02:00
|
|
|
{
|
2021-06-08 19:01:11 +02:00
|
|
|
data.setEscapedAttribute("contactLink", "href", federation.getContactURL().toString());
|
2021-06-03 03:05:12 +02:00
|
|
|
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);
|
|
|
|
}
|
2021-06-08 19:01:11 +02:00
|
|
|
if (federation.getUserGuideURL() != null)
|
2021-06-03 03:05:12 +02:00
|
|
|
{
|
2021-06-08 19:01:11 +02:00
|
|
|
data.setEscapedAttribute("userDocLink", "href", federation.getUserGuideURL().toString());
|
2021-06-03 03:05:12 +02:00
|
|
|
data.setAttribute("userDocLinkImg", "class", "");
|
|
|
|
data.getIdData("userDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
|
|
|
|
}
|
2021-06-08 19:01:11 +02:00
|
|
|
if (federation.getTechnicalGuideURL() != null)
|
2021-06-03 03:05:12 +02:00
|
|
|
{
|
2021-06-08 19:01:11 +02:00
|
|
|
data.setEscapedAttribute("technicalDocLink", "href", federation.getTechnicalGuideURL().toString());
|
2021-06-03 03:05:12 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|