diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index 8d1100d..fb1b8c9 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2023 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -32,7 +32,9 @@ import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.crawl.CrawlJournal; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; +import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyUtils; +import fr.devinsy.statoolinfos.properties.PropertyClassType; import fr.devinsy.statoolinfos.util.Chrono; import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringSet; @@ -372,43 +374,51 @@ public class Factory } else { - PathProperties properties = PathPropertyUtils.load(inputFile); - result = new Service(properties); - result.setOrganization(organization); - result.setInputFile(inputFile); - result.setInputURL(inputURL); - result.setLogoFileName(organization.getTechnicalName() + "-" + result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png")); - - // - PathProperties subs = result.getByPrefix("subs"); - for (PathProperty property : subs) + PathPropertyList properties = PathPropertyUtils.load(inputFile); + if (properties.getClassType() != PropertyClassType.SERVICE) { - if (StringUtils.startsWith(property.getValue(), "http")) + logger.warn("WARNING: not file class service [{}]", inputURL); + result = null; + } + else + { + result = new Service(properties); + result.setOrganization(organization); + result.setInputFile(inputFile); + result.setInputURL(inputURL); + result.setLogoFileName(organization.getTechnicalName() + "-" + result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png")); + + // + PathProperties subs = result.getByPrefix("subs"); + for (PathProperty property : subs) { - URL metricsInputURL = new URL(property.getValue()); - Metrics metrics = loadMetrics(metricsInputURL, cache, organization.getTechnicalName() + "-" + result.getTechnicalName()); - if (metrics != null) + if (StringUtils.startsWith(property.getValue(), "http")) { - result.getMetrics().add(metrics); + URL metricsInputURL = new URL(property.getValue()); + Metrics metrics = loadMetrics(metricsInputURL, cache, organization.getTechnicalName() + "-" + result.getTechnicalName()); + if (metrics != null) + { + result.getMetrics().add(metrics); + } } } - } - // - PropertyChecker checker = new PropertyChecker(); - PropertyChecks checks = checker.checkService(result.getInputFile()); - checks.setFileName(result.getLocalFileName()); - result.getInputChecks().addAll(checks); + // + PropertyChecker checker = new PropertyChecker(); + PropertyChecks checks = checker.checkService(result.getInputFile()); + checks.setFileName(result.getLocalFileName()); + result.getInputChecks().addAll(checks); - // - CrawlJournal journal = cache.restoreCrawlJournal(); - result.getCrawlJournal().add(journal.getByUrl(inputURL)); - result.getCrawlJournal().addAll(journal.searchByParent(result.getInputURL())); + // + CrawlJournal journal = cache.restoreCrawlJournal(); + result.getCrawlJournal().add(journal.getByUrl(inputURL)); + result.getCrawlJournal().addAll(journal.searchByParent(result.getInputURL())); - // - for (Metrics metrics : result.getMetrics()) - { - result.addAll(metrics.getByPrefix("metrics.")); + // + for (Metrics metrics : result.getMetrics()) + { + result.addAll(metrics.getByPrefix("metrics.")); + } } } diff --git a/src/fr/devinsy/statoolinfos/crawl/Crawler.java b/src/fr/devinsy/statoolinfos/crawl/Crawler.java index 9b2d5c5..21885ca 100644 --- a/src/fr/devinsy/statoolinfos/crawl/Crawler.java +++ b/src/fr/devinsy/statoolinfos/crawl/Crawler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2023 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -32,13 +32,13 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fr.devinsy.statoolinfos.core.PropertyClassType; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyUtils; +import fr.devinsy.statoolinfos.properties.PropertyClassType; /** * The Class Crawler. @@ -151,8 +151,8 @@ public class Crawler } else { - PathProperties downloadProperties = PathPropertyUtils.load(downloadFile); - PropertyClassType downloadClass = PropertyClassType.of(downloadProperties.get("file.class")); + PathPropertyList downloadProperties = PathPropertyUtils.load(downloadFile); + PropertyClassType downloadClass = downloadProperties.getClassType(); if ((downloadClass == null) || (!downloadClass.isChildOf(parent))) { diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index 12cda43..af9bce2 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Christian Pierre MOMON + * Copyright (C) 2020-2023 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -319,6 +319,21 @@ public class PathPropertyList extends ArrayList implements PathPro return result; } + /** + * Gets the file class. + * + * @return the file class + */ + public PropertyClassType getClassType() + { + PropertyClassType result; + + result = PropertyClassType.of(get("file.class")); + + // + return result; + } + /** * Gets the index property. * diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java index d6b0ca2..6c42e82 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2023 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -78,9 +78,9 @@ public class PathPropertyUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static PathProperties load(final File file) throws IOException + public static PathPropertyList load(final File file) throws IOException { - PathProperties result; + PathPropertyList result; result = load(file, StandardCharsets.UTF_8); @@ -99,9 +99,9 @@ public class PathPropertyUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static PathProperties load(final File file, final Charset charset) throws IOException + public static PathPropertyList load(final File file, final Charset charset) throws IOException { - PathProperties result; + PathPropertyList result; if (file == null) { @@ -136,9 +136,9 @@ public class PathPropertyUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static PathProperties load(final URL url) throws IOException + public static PathPropertyList load(final URL url) throws IOException { - PathProperties result; + PathPropertyList result; StringList lines = StringsUtils.load(url); @@ -157,9 +157,9 @@ public class PathPropertyUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static PathProperties read(final BufferedReader in) throws IOException + public static PathPropertyList read(final BufferedReader in) throws IOException { - PathProperties result; + PathPropertyList result; result = new PathPropertyList(); @@ -191,9 +191,9 @@ public class PathPropertyUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static PathProperties read(final StringList source) throws IOException + public static PathPropertyList read(final StringList source) throws IOException { - PathProperties result; + PathPropertyList result; result = new PathPropertyList(); diff --git a/src/fr/devinsy/statoolinfos/core/PropertyClassType.java b/src/fr/devinsy/statoolinfos/properties/PropertyClassType.java similarity index 86% rename from src/fr/devinsy/statoolinfos/core/PropertyClassType.java rename to src/fr/devinsy/statoolinfos/properties/PropertyClassType.java index 0fa48b4..99ffe12 100644 --- a/src/fr/devinsy/statoolinfos/core/PropertyClassType.java +++ b/src/fr/devinsy/statoolinfos/properties/PropertyClassType.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Christian Pierre MOMON + * Copyright (C) 2021-2023 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ -package fr.devinsy.statoolinfos.core; +package fr.devinsy.statoolinfos.properties; import org.apache.commons.lang3.StringUtils; @@ -25,6 +25,7 @@ public enum PropertyClassType FEDERATION, ORGANIZATION, SERVICE, + HOSTING, METRICS; /** @@ -70,6 +71,16 @@ public enum PropertyClassType result = false; } break; + case HOSTING: + if (parent == ORGANIZATION) + { + result = true; + } + else + { + result = false; + } + break; case METRICS: if (parent == METRICS) { @@ -117,6 +128,10 @@ public enum PropertyClassType { result = SERVICE; } + else if (StringUtils.equals(target, "hosting")) + { + result = HOSTING; + } else if (StringUtils.equals(target, "metrics")) { result = METRICS;