From a9cf9057882f51857ec5ca8f6d0816791854fb94 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 14 May 2021 02:40:15 +0200 Subject: [PATCH] Refactored check and check alerts. Add check alerts for federation. --- src/fr/devinsy/statoolinfos/core/Factory.java | 18 +++++ .../devinsy/statoolinfos/core/Federation.java | 46 +++++++++++++ .../statoolinfos/core/Organization.java | 30 +++++++++ src/fr/devinsy/statoolinfos/core/Service.java | 10 ++- .../statoolinfos/htmlize/FederationPage.java | 15 +++++ .../htmlize/OrganizationPage.java | 67 ++++--------------- .../htmlize/PropertyFileCheckPage.java | 9 +-- .../statoolinfos/htmlize/ServicePage.java | 21 ++---- .../statoolinfos/htmlize/federation.xhtml | 7 ++ .../statoolinfos/htmlize/organization.xhtml | 6 +- .../statoolinfos/htmlize/service.xhtml | 6 +- 11 files changed, 153 insertions(+), 82 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index 8e918b7..306ff00 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -26,6 +26,8 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.checker.PropertyChecker; +import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; @@ -166,6 +168,11 @@ public class Factory result.setInputFile(federationFile); result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png")); + PropertyChecker checker = new PropertyChecker(); + PropertyChecks checks = checker.checkFederation(result.getInputFile()); + result.getInputChecks().addAll(checks); + result.getInputChecks().setFileName(result.getLocalFileName()); + PathProperties subs = result.getByPrefix("subs"); for (PathProperty property : subs) { @@ -252,6 +259,12 @@ public class Factory result.setInputURL(inputURL); result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png")); + // + PropertyChecker checker = new PropertyChecker(); + PropertyChecks checks = checker.checkOrganization(result.getInputFile()); + result.getInputChecks().addAll(checks); + result.getInputChecks().setFileName(result.getLocalFileName()); + PathProperties subs = result.getByPrefix("subs"); for (PathProperty property : subs) { @@ -263,6 +276,11 @@ public class Factory { service.setOrganization(result); service.setLogoFileName(result.getTechnicalName() + "-" + service.getLogoFileName()); + + PropertyChecks subChecks = checker.checkService(service.getInputFile()); + service.getInputChecks().addAll(subChecks); + service.getInputChecks().setFileName(service.getLocalFileName()); + result.getServices().add(service); } } diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index adb026a..2dd31a7 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -25,6 +25,7 @@ import java.time.LocalDateTime; import org.apache.commons.lang3.StringUtils; +import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; @@ -37,6 +38,7 @@ public class Federation extends PathPropertyList private Organizations organizations; private File inputFile; private String logoFileName; + private PropertyChecks inputChecks; /** * Instantiates a new federation. @@ -44,6 +46,7 @@ public class Federation extends PathPropertyList public Federation() { super(); + this.inputChecks = new PropertyChecks(); this.organizations = new Organizations(); } @@ -56,6 +59,7 @@ public class Federation extends PathPropertyList public Federation(final PathProperties properties) { super(properties); + this.inputChecks = new PropertyChecks(); if ((properties == null) || (StringUtils.isBlank(properties.get("federation.name")))) { @@ -148,6 +152,33 @@ public class Federation extends PathPropertyList 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; + } + public File getInputFile() { return this.inputFile; @@ -168,6 +199,21 @@ public class Federation extends PathPropertyList return result; } + /** + * Gets the local file name. + * + * @return the local file name + */ + public String getLocalFileName() + { + String result; + + result = getTechnicalName() + ".properties"; + + // + return result; + } + public String getLogoFileName() { return this.logoFileName; diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index 7f5f4e0..9d3180c 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -27,6 +27,7 @@ import java.time.LocalDateTime; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; +import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; @@ -41,6 +42,7 @@ public class Organization extends PathPropertyList private File inputFile; private URL inputURL; private String logoFileName; + private PropertyChecks inputChecks; /** * Instantiates a new organization. @@ -48,6 +50,7 @@ public class Organization extends PathPropertyList public Organization() { super(); + this.inputChecks = new PropertyChecks(); this.services = new Services(); } @@ -60,6 +63,7 @@ public class Organization extends PathPropertyList public Organization(final PathProperties properties) { super(properties); + this.inputChecks = new PropertyChecks(); this.services = new Services(); } @@ -201,6 +205,32 @@ public class Organization extends PathPropertyList 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.inputChecks); + for (Service service : this.services) + { + result.addAll(service.getInputChecks()); + } + + // + return result; + } + public File getInputFile() { return this.inputFile; diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index 9d92ca6..13176f5 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.metrics.Metric; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperty; @@ -102,13 +103,14 @@ public class Service extends PathPropertyList private File inputFile; private URL inputURL; private String logoFileName; + private PropertyChecks inputChecks; /** * Instantiates a new service. */ public Service() { - super(null); + this(null); } /** @@ -120,6 +122,7 @@ public class Service extends PathPropertyList public Service(final PathProperties properties) { super(properties); + this.inputChecks = new PropertyChecks(); } /** @@ -293,6 +296,11 @@ public class Service extends PathPropertyList return result; } + public PropertyChecks getInputChecks() + { + return this.inputChecks; + } + public File getInputFile() { return this.inputFile; diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java index 5769eee..26dd2ec 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import fr.devinsy.catgenerator.core.CatGenerator; 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.StatoolInfosException; @@ -69,6 +70,10 @@ public class FederationPage logger.info("PAGE FEDERATION federation page: {}.", federation.getName()); String page = htmlize(federation); FileUtils.write(new File(htmlizeDirectory, "index.xhtml"), page, StandardCharsets.UTF_8); + + // + page = PropertyFilesCheckPage.htmlize(federation.getName(), federation.getInputChecksAll().getAlertLines()); + FileUtils.write(new File(htmlizeDirectory, federation.getTechnicalName() + "-checkalerts.xhtml"), page, StandardCharsets.UTF_8); } /** @@ -104,6 +109,16 @@ public class FederationPage data.setAttribute("statsLink", "href", federation.getTechnicalName() + "-stats.xhtml"); + { + 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"); + } + if (StringUtils.isNotBlank(federation.getLegalWebsite())) { data.setEscapedAttribute("legalLink", "href", federation.getLegalWebsite()); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java index e674c53..4ba9db4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java @@ -29,11 +29,8 @@ import org.slf4j.LoggerFactory; import fr.devinsy.catgenerator.core.CatGenerator; import fr.devinsy.statoolinfos.HtmlizerContext; -import fr.devinsy.statoolinfos.checker.PropertyCheck; -import fr.devinsy.statoolinfos.checker.PropertyChecker; import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.core.Organization; -import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.xidyn.XidynException; @@ -74,34 +71,9 @@ public class OrganizationPage String page = OrganizationPage.htmlize(organization); FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - { - try - { - PropertyChecker checker = new PropertyChecker(); - PropertyChecks checks = checker.checkOrganization(organization.getInputFile()); - for (PropertyCheck check : checks) - { - check.setFileName(organization.getLocalFileName()); - } - - for (Service service : organization.getServices()) - { - PropertyChecks subChecks = checker.checkService(service.getInputFile()); - for (PropertyCheck check : subChecks) - { - check.setFileName(service.getLocalFileName()); - } - checks.addAll(subChecks); - } - - page = PropertyFilesCheckPage.htmlize(organization.getName(), checks.getAlertLines()); - FileUtils.write(new File(htmlizeDirectory, "alertChecks-" + organization.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - } - catch (IOException exception) - { - exception.printStackTrace(); - } - } + // + page = PropertyFilesCheckPage.htmlize(organization.getName(), organization.getInputChecksAll().getAlertLines()); + FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-checkalerts.xhtml"), page, StandardCharsets.UTF_8); } /** @@ -173,29 +145,6 @@ public class OrganizationPage data.setContent("organizationStartDateWord", ""); } - { - try - { - PropertyChecker checker = new PropertyChecker(); - PropertyChecks checks = checker.checkOrganization(organization.getInputFile()); - for (Service service : organization.getServices()) - { - PropertyChecks subChecks = checker.checkService(service.getInputFile()); - checks.addAll(subChecks); - } - - data.setContent("errorCount", checks.getErrorCount()); - data.setContent("warningCount", checks.getWarningCount()); - data.setContent("voidCount", checks.getVoidCount()); - - data.setAttribute("alertLink", "href", "alertChecks-" + organization.getTechnicalName() + ".xhtml"); - } - catch (IOException exception) - { - exception.printStackTrace(); - } - } - data.setContent("serviceCount", organization.getServices().size()); data.setAttribute("rawLink", "href", organization.getTechnicalName() + ".properties"); @@ -203,6 +152,16 @@ public class OrganizationPage data.setAttribute("statsLink", "href", organization.getTechnicalName() + "-stats.xhtml"); + { + PropertyChecks checks = organization.getInputChecksAll(); + + data.setContent("errorCount", checks.getErrorCount()); + data.setContent("warningCount", checks.getWarningCount()); + data.setContent("voidCount", checks.getVoidCount()); + + data.setAttribute("alertLink", "href", organization.getTechnicalName() + "-checkalerts.xhtml"); + } + if (StringUtils.isNotBlank(organization.getLegalWebsite())) { data.setEscapedAttribute("legalLink", "href", organization.getLegalWebsite()); diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java index f2f616a..1623a53 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java @@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.checker.PropertyCheck; -import fr.devinsy.statoolinfos.checker.PropertyChecker; import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; @@ -57,15 +56,13 @@ public class PropertyFileCheckPage Federation federation = HtmlizerContext.instance().getFederation(); File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); - PropertyChecker checker = new PropertyChecker(); - PropertyChecks allAlertChecks = new PropertyChecks(); PropertyChecks federationAlertChecks = new PropertyChecks(); PropertyChecks organizationAlertChecks = new PropertyChecks(); PropertyChecks serviceAlertChecks = new PropertyChecks(); // - PropertyChecks checks = checker.checkFederation(federation.getInputFile()); + PropertyChecks checks = federation.getInputChecks(); String page = htmlize("Fédération", checks); FileUtils.write(new File(htmlizeDirectory, federation.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); @@ -76,7 +73,7 @@ public class PropertyFileCheckPage // for (Organization organization : federation.getOrganizations()) { - checks = checker.checkOrganization(organization.getInputFile()); + checks = organization.getInputChecks(); page = htmlize("Organisation", checks); FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); @@ -89,7 +86,7 @@ public class PropertyFileCheckPage for (Service service : organization.getServices()) { - checks = checker.checkService(service.getInputFile()); + checks = service.getInputChecks(); page = htmlize("Service", checks); FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index 10a9d5a..929019a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory; import fr.devinsy.catgenerator.core.BirdGenerator; import fr.devinsy.statoolinfos.HtmlizerContext; -import fr.devinsy.statoolinfos.checker.PropertyChecker; import fr.devinsy.statoolinfos.checker.PropertyChecks; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; @@ -107,7 +106,7 @@ public class ServicePage try { - logger.debug("Building organization page {}…", service.get("organization.name")); + logger.debug("Building service page {}…", service.get("service.name")); TagDataManager data = new TagDataManager(); @@ -223,20 +222,12 @@ public class ServicePage } { - try - { - PropertyChecker checker = new PropertyChecker(); - PropertyChecks checks = checker.checkService(service.getInputFile()); - data.setContent("errorCount", checks.getErrorCount()); - data.setContent("warningCount", checks.getWarningCount()); - data.setContent("voidCount", checks.getVoidCount()); + PropertyChecks checks = service.getInputChecks(); + data.setContent("errorCount", checks.getErrorCount()); + data.setContent("warningCount", checks.getWarningCount()); + data.setContent("voidCount", checks.getVoidCount()); - data.setAttribute("alertLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml#alerts"); - } - catch (IOException exception) - { - exception.printStackTrace(); - } + data.setAttribute("alertLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml#alerts"); } // diff --git a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml index 1971705..e388340 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml @@ -32,6 +32,13 @@ +
+ +
n/a
+
n/a
+
n/a
+
+

diff --git a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml index 85cfc34..3b47763 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml @@ -36,9 +36,9 @@
-
n/a
-
n/a
-
n/a
+
n/a
+
n/a
+
n/a
diff --git a/src/fr/devinsy/statoolinfos/htmlize/service.xhtml b/src/fr/devinsy/statoolinfos/htmlize/service.xhtml index 636206b..5cd97d8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/service.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/service.xhtml @@ -44,9 +44,9 @@
-
n/a
-
n/a
-
n/a
+
n/a
+
n/a
+
n/a