statoolinfosweb/src/fr/devinsy/statoolinfos/core/Federation.java

696 lines
14 KiB
Java
Raw Normal View History

2020-09-13 01:28:27 +02:00
/*
* Copyright (C) 2020-2022 Christian Pierre MOMON <christian@momon.org>
2020-09-13 01:28:27 +02:00
*
* 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;
2020-09-17 03:59:11 +02:00
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
2020-09-28 03:52:51 +02:00
import java.time.LocalDateTime;
2020-09-17 03:59:11 +02:00
import org.apache.commons.lang3.StringUtils;
import fr.devinsy.statoolinfos.checker.PropertyChecks;
import fr.devinsy.statoolinfos.crawl.CrawlJournal;
2021-06-03 04:25:16 +02:00
import fr.devinsy.statoolinfos.htmlize.charts.MonthValues;
import fr.devinsy.statoolinfos.htmlize.charts.WeekValues;
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
2020-09-17 02:28:37 +02:00
import fr.devinsy.statoolinfos.properties.PathProperties;
2020-09-15 03:16:26 +02:00
import fr.devinsy.statoolinfos.properties.PathPropertyList;
2021-06-10 03:54:39 +02:00
import fr.devinsy.statoolinfos.uptime.URLSet;
2021-06-08 19:01:11 +02:00
import fr.devinsy.statoolinfos.util.URLUtils;
2020-09-13 01:28:27 +02:00
/**
* The Class PathProperty.
*/
2020-09-15 03:16:26 +02:00
public class Federation extends PathPropertyList
2020-09-13 01:28:27 +02:00
{
2020-09-15 03:16:26 +02:00
private static final long serialVersionUID = -8970835291634661580L;
private Organizations organizations;
private URL inputURL;
2020-09-23 21:56:40 +02:00
private File inputFile;
2020-10-23 03:59:44 +02:00
private String logoFileName;
private PropertyChecks inputChecks;
private CrawlJournal crawlJournal;
2020-09-13 01:28:27 +02:00
2020-09-13 02:10:28 +02:00
/**
2020-09-15 03:16:26 +02:00
* Instantiates a new federation.
*/
public Federation()
{
super();
this.inputChecks = new PropertyChecks();
this.organizations = new Organizations();
this.crawlJournal = new CrawlJournal();
2020-09-15 03:16:26 +02:00
}
/**
* Instantiates a new federation.
2020-09-13 02:10:28 +02:00
*
2020-09-15 03:16:26 +02:00
* @param properties
* the properties
2020-09-13 02:10:28 +02:00
*/
2020-09-17 02:28:37 +02:00
public Federation(final PathProperties properties)
2020-09-13 02:10:28 +02:00
{
2020-09-15 03:16:26 +02:00
super(properties);
this.inputChecks = new PropertyChecks();
if ((properties == null) || (StringUtils.isBlank(properties.get("federation.name"))))
{
throw new IllegalArgumentException("Not a federation.");
}
else
{
this.organizations = new Organizations();
this.crawlJournal = new CrawlJournal();
}
2020-09-13 02:10:28 +02:00
}
2020-09-13 01:28:27 +02:00
/**
* Gets the organizations active.
*
* @return the organizations active
*/
public Organizations getActiveOrganizations()
{
Organizations result;
result = this.organizations.filterActiveFor(getTechnicalName());
//
return result;
}
/**
* Gets the active services.
*
* @return the active services
*/
public Services getActiveServices()
{
Services result;
result = new Services();
for (Organization organization : getActiveOrganizations())
{
result.addAll(organization.getActiveServices());
}
//
return result;
}
/**
* Gets the active services.
*
* @return the active services
*/
public long getActiveServiceCount()
{
long result;
result = 0;
for (Organization organization : getActiveOrganizations())
{
result += organization.getActiveServiceCount();
}
//
return result;
}
2020-10-04 05:58:01 +02:00
/**
* Gets the contact email.
*
* @return the contact email
*/
public String getContactEmail()
{
String result;
result = get("federation.contact.email");
//
return result;
}
/**
2021-06-08 19:01:11 +02:00
* Gets the contact URL.
2020-10-04 05:58:01 +02:00
*
2021-06-08 19:01:11 +02:00
* @return the contact URL
2020-10-04 05:58:01 +02:00
*/
2021-06-08 19:01:11 +02:00
public URL getContactURL()
2020-10-04 05:58:01 +02:00
{
2021-06-08 19:01:11 +02:00
URL result;
2020-10-04 05:58:01 +02:00
2021-06-08 19:01:11 +02:00
result = getURL("federation.contact.url");
2020-10-04 05:58:01 +02:00
//
return result;
}
/**
* Gets the crawl date.
*
* @return the crawl date
*/
public LocalDateTime getCrawlDate()
{
LocalDateTime result;
result = LocalDateTime.parse(get("crawl.datetime"));
//
return result;
}
2020-09-28 03:52:51 +02:00
/**
* Gets the crawled date.
*
* @return the crawled date
*/
public LocalDateTime getCrawledDate()
{
LocalDateTime result;
result = LocalDateTime.parse(get("crawl.file.datetime"));
if (result.getYear() == 1970)
{
result = getCrawlDate();
}
2020-09-28 03:52:51 +02:00
//
return result;
}
public CrawlJournal getCrawlJournal()
{
return this.crawlJournal;
}
2020-09-15 03:16:26 +02:00
/**
* Gets the description.
*
* @return the description
*/
public String getDescription()
2020-09-13 02:10:28 +02:00
{
String result;
2020-09-13 01:28:27 +02:00
2020-09-17 03:59:11 +02:00
result = get("federation.description");
//
return result;
}
public PropertyChecks getInputChecks()
{
return this.inputChecks;
}
/**
* Gets the input checks all.
*
* @return the input checks all
*/
public PropertyChecks getInputChecksAll()
{
PropertyChecks result;
result = new PropertyChecks();
result.addAll(this.getInputChecks());
for (Organization organization : this.organizations)
{
result.addAll(organization.getInputChecksAll());
}
//
return result;
}
2020-09-23 21:56:40 +02:00
public File getInputFile()
2020-09-17 03:59:11 +02:00
{
2020-09-23 21:56:40 +02:00
return this.inputFile;
2020-09-17 03:59:11 +02:00
}
public URL getInputURL()
{
return this.inputURL;
}
2020-10-04 05:58:01 +02:00
/**
* Gets the legal website.
*
* @return the legal website
*/
2021-06-08 19:01:11 +02:00
public URL getLegalURL()
2020-10-04 05:58:01 +02:00
{
2021-06-08 19:01:11 +02:00
URL result;
String value = get("federation.legal.url", "federation.legal");
2020-10-04 05:58:01 +02:00
2021-06-08 19:01:11 +02:00
result = URLUtils.of(value);
2020-10-04 05:58:01 +02:00
//
return result;
}
2021-06-03 04:25:16 +02:00
/**
* Gets the local file base name.
*
* @return the local file base name
*/
public String getLocalFileBaseName()
{
String result;
result = getTechnicalName();
//
return result;
}
/**
* Gets the local file name.
*
* @return the local file name
*/
public String getLocalFileName()
{
String result;
result = getTechnicalName() + ".properties";
//
return result;
}
2020-10-23 03:59:44 +02:00
public String getLogoFileName()
{
return this.logoFileName;
}
2020-09-17 03:59:11 +02:00
/**
* Gets the logo URL.
*
* @return the logo URL
*/
2021-06-10 03:54:39 +02:00
public URL getLogoURL()
2020-09-17 03:59:11 +02:00
{
URL result;
2021-06-08 19:01:11 +02:00
try
2020-09-17 03:59:11 +02:00
{
2021-06-08 19:01:11 +02:00
String path = get("federation.logo");
if ((StringUtils.isBlank(path)) || (!StringUtils.startsWith(path, "http")))
{
result = null;
}
else
{
result = new URL(path);
}
2020-09-17 03:59:11 +02:00
}
2021-06-08 19:01:11 +02:00
catch (MalformedURLException exception)
2020-09-17 03:59:11 +02:00
{
2021-06-08 19:01:11 +02:00
result = null;
2020-09-17 03:59:11 +02:00
}
2020-09-13 01:28:27 +02:00
2020-09-13 02:10:28 +02:00
//
return result;
}
2020-09-13 01:28:27 +02:00
2021-06-03 04:25:16 +02:00
/**
* Gets the metric month values all.
*
* @param path
* the path
* @return the metric month values all
*/
public MonthValues getMetricMonthValuesAll(final String path)
{
MonthValues result;
result = getMetricMonthValues(path);
for (Organization organization : getOrganizations())
{
result.addAll(organization.getMetricMonthValuesAll(path));
}
//
return result;
}
/**
* Gets the metric week values all.
*
* @param path
* the path
* @return the metric week values all
*/
public WeekValues getMetricWeekValuesAll(final String path)
{
WeekValues result;
result = getMetricWeekValues(path);
for (Organization organization : getOrganizations())
{
result.addAll(organization.getMetricWeekValuesAll(path));
}
//
return result;
}
/**
* Gets the metric year values all.
*
* @param path
* the path
* @return the metric year values all
*/
public YearValues getMetricYearValuesAll(final String path)
{
YearValues result;
result = getMetricYearValues(path);
for (Organization organization : getOrganizations())
{
result.addAll(organization.getMetricYearValuesAll(path));
}
//
return result;
}
2020-09-15 03:16:26 +02:00
/**
* Gets the name.
*
* @return the name
*/
public String getName()
2020-09-13 02:10:28 +02:00
{
2020-09-15 03:16:26 +02:00
String result;
2020-09-13 01:28:27 +02:00
result = get("federation.name");
2020-09-13 01:28:27 +02:00
2020-09-15 03:16:26 +02:00
//
return result;
2020-09-13 02:10:28 +02:00
}
2020-09-13 01:28:27 +02:00
2020-09-19 02:37:52 +02:00
/**
* Gets the organiation count.
*
* @return the organiation count
*/
public int getOrganiationCount()
{
int result;
result = this.organizations.size();
//
return result;
}
2020-09-15 03:16:26 +02:00
public Organizations getOrganizations()
2020-09-13 02:10:28 +02:00
{
2020-09-15 03:16:26 +02:00
return this.organizations;
2020-09-13 02:10:28 +02:00
}
/**
* Gets the service count.
*
* @return the service count
*/
public int getServiceCount()
{
int result;
result = 0;
for (Organization organization : getActiveOrganizations())
{
result += organization.getServiceCount();
}
//
return result;
}
2020-09-19 02:37:52 +02:00
/**
* Gets the all services.
2020-09-19 02:37:52 +02:00
*
* @return the all services
2020-09-19 02:37:52 +02:00
*/
public Services getServices()
2020-09-19 02:37:52 +02:00
{
Services result;
2020-09-19 02:37:52 +02:00
result = new Services();
for (Organization organization : getActiveOrganizations())
2020-09-19 02:37:52 +02:00
{
result.addAll(organization.getServices());
2020-09-19 02:37:52 +02:00
}
//
return result;
}
2021-06-10 03:54:39 +02:00
/**
* Gets the all services.
*
* @return the all services
*/
public Services getServicesAll()
{
Services result;
result = new Services();
for (Organization organization : this.organizations)
{
result.addAll(organization.getServices());
}
//
return result;
}
2020-09-25 15:46:30 +02:00
/**
* Gets the software catalog.
*
* @return the software catalog
*/
public Softwares getSoftwares()
{
Softwares result;
result = new Softwares();
2021-06-10 03:54:39 +02:00
for (Service service : getServicesAll())
2020-09-25 15:46:30 +02:00
{
if (StringUtils.isNotBlank(service.getSoftwareName()))
{
Software software = result.get(service.getSoftwareName());
if (software == null)
{
2020-10-19 02:17:57 +02:00
software = new Software(service.getSoftwareName(), service.getSoftwareDescription());
2020-09-25 15:46:30 +02:00
result.put(software);
}
}
}
//
return result;
}
2020-10-04 05:58:01 +02:00
/**
* Gets the start date.
*
* @return the start date
*/
public String getStartDate()
{
String result;
result = get("federation.startdate");
2020-10-04 05:58:01 +02:00
//
return result;
}
/**
* Gets the technical doc website.
*
* @return the technical doc website
*/
2021-06-08 19:01:11 +02:00
public URL getTechnicalGuideURL()
2020-10-04 05:58:01 +02:00
{
2021-06-08 19:01:11 +02:00
URL result;
String value = get("federation.guide.technical", "federation.guide.technical.url");
2020-10-04 05:58:01 +02:00
2021-06-08 19:01:11 +02:00
result = URLUtils.of(value);
2020-10-04 05:58:01 +02:00
//
return result;
}
/**
* Gets the technical name.
*
* @return the technical name
*/
public String getTechnicalName()
{
String result;
2020-09-25 04:36:38 +02:00
result = StatoolInfosUtils.toTechnicalName(getName());
//
return result;
}
2020-09-17 03:59:11 +02:00
/**
* Gets the URL active all.
*
* @return the URL active all
*/
public URLSet getURLActiveAll()
{
URLSet result;
result = new URLSet();
//
result.add(getContactURL());
result.add(getLegalURL());
result.add(getLogoURL());
result.add(getTechnicalGuideURL());
result.add(getUserGuideURL());
result.add(getWebsiteURL());
//
for (Organization organization : getOrganizations())
{
result.addAll(organization.getURLActiveAll());
}
//
return result;
}
2021-06-10 03:54:39 +02:00
/**
* Gets the URL all.
*
* @return the URL all
*/
public URLSet getURLAll()
{
URLSet result;
result = new URLSet();
//
result.add(getContactURL());
result.add(getLegalURL());
result.add(getLogoURL());
result.add(getTechnicalGuideURL());
result.add(getUserGuideURL());
result.add(getWebsiteURL());
//
for (Organization organization : getOrganizations())
{
2021-06-11 23:35:50 +02:00
result.addAll(organization.getURLAll());
2021-06-10 03:54:39 +02:00
}
//
return result;
}
2020-10-04 05:58:01 +02:00
/**
* Gets the user doc website.
*
* @return the user doc website
*/
2021-06-08 19:01:11 +02:00
public URL getUserGuideURL()
2020-10-04 05:58:01 +02:00
{
2021-06-08 19:01:11 +02:00
URL result;
2020-10-04 05:58:01 +02:00
2021-06-08 19:01:11 +02:00
String value = get("federation.documentation",
"federation.documentation.url",
"federation.documentation.user",
"federation.documentation.user.url",
"service.documentation.tutorial",
2020-10-04 05:58:01 +02:00
"federation.documentation.tutorial.url",
"federation.guide.user",
"federation.guide.user.url");
2021-06-08 19:01:11 +02:00
result = URLUtils.of(value);
2020-10-04 05:58:01 +02:00
//
return result;
}
/**
* Gets the website.
*
* @return the website
*/
2021-06-08 19:01:11 +02:00
public URL getWebsiteURL()
2020-10-04 05:58:01 +02:00
{
2021-06-08 19:01:11 +02:00
URL result;
2020-10-04 05:58:01 +02:00
2021-06-08 19:01:11 +02:00
result = getURL("federation.website");
2020-10-04 05:58:01 +02:00
//
return result;
}
2020-10-23 03:59:44 +02:00
/**
* Sets the input file.
*
* @param inputFile
* the new input file
*/
2020-09-23 21:56:40 +02:00
public void setInputFile(final File inputFile)
2020-09-17 03:59:11 +02:00
{
2020-09-23 21:56:40 +02:00
this.inputFile = inputFile;
2020-09-17 03:59:11 +02:00
}
2020-10-23 03:59:44 +02:00
public void setInputURL(final URL inputURL)
{
this.inputURL = inputURL;
}
2020-10-23 03:59:44 +02:00
public void setLogoFileName(final String logoFileName)
{
this.logoFileName = logoFileName;
}
2020-09-13 01:28:27 +02:00
}