From 6285cb84e97d59863dedfc2eebc3c12c65202934 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 17 Oct 2020 17:57:10 +0200 Subject: [PATCH] Added property file check management. --- .../statoolinfos/checker/PropertyCheck.java | 103 ++++++ .../statoolinfos/checker/PropertyChecker.java | 314 ++++++++++++++++++ .../statoolinfos/checker/PropertyChecks.java | 37 +++ .../statoolinfos/checker/PropertyRule.java | 149 +++++++++ .../statoolinfos/checker/PropertyRules.java | 72 ++++ .../statoolinfos/checker/organization.rules | 27 ++ src/fr/devinsy/statoolinfos/core/Service.java | 10 + .../statoolinfos/htmlize/FederationPage.java | 1 + .../statoolinfos/htmlize/Htmlizer.java | 23 ++ .../htmlize/OrganizationPage.java | 1 + .../htmlize/PropertyFileCheckPage.java | 125 +++++++ .../statoolinfos/htmlize/ServicePage.java | 1 + .../statoolinfos/htmlize/federation.xhtml | 2 +- .../statoolinfos/htmlize/organization.xhtml | 2 +- .../htmlize/propertyFileCheck.xhtml | 32 ++ .../statoolinfos/htmlize/service.xhtml | 2 +- .../htmlize/stuff/statoolinfos.css | 30 ++ 17 files changed, 928 insertions(+), 3 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/checker/PropertyCheck.java create mode 100644 src/fr/devinsy/statoolinfos/checker/PropertyChecker.java create mode 100644 src/fr/devinsy/statoolinfos/checker/PropertyChecks.java create mode 100644 src/fr/devinsy/statoolinfos/checker/PropertyRule.java create mode 100644 src/fr/devinsy/statoolinfos/checker/PropertyRules.java create mode 100644 src/fr/devinsy/statoolinfos/checker/organization.rules create mode 100644 src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java create mode 100644 src/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml diff --git a/src/fr/devinsy/statoolinfos/checker/PropertyCheck.java b/src/fr/devinsy/statoolinfos/checker/PropertyCheck.java new file mode 100644 index 0000000..f8a852c --- /dev/null +++ b/src/fr/devinsy/statoolinfos/checker/PropertyCheck.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos.checker; + +import fr.devinsy.statoolinfos.core.Service.Status; + +/** + * The Class PropertyCheck. + */ +public class PropertyCheck +{ + private long index; + private String line; + private Status status; + private String comment; + + /** + * Instantiates a new property check. + * + * @param index + * the index + * @param line + * the line + */ + public PropertyCheck(final long index, final String line) + { + this(index, line, Status.VOID); + } + + /** + * Instantiates a new property check. + * + * @param index + * the index + * @param line + * the line + * @param status + * the status + */ + public PropertyCheck(final long index, final String line, final Status status) + { + this.index = index; + this.line = line; + this.status = status; + this.comment = ""; + } + + public String getComment() + { + return this.comment; + } + + public long getIndex() + { + return this.index; + } + + public String getLine() + { + return this.line; + } + + public Status getStatus() + { + return this.status; + } + + public void setComment(final String comment) + { + this.comment = comment; + } + + public void setIndex(final long index) + { + this.index = index; + } + + public void setLine(final String line) + { + this.line = line; + } + + public void setStatus(final Status status) + { + this.status = status; + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/checker/PropertyChecker.java b/src/fr/devinsy/statoolinfos/checker/PropertyChecker.java new file mode 100644 index 0000000..54100dd --- /dev/null +++ b/src/fr/devinsy/statoolinfos/checker/PropertyChecker.java @@ -0,0 +1,314 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos.checker; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; + +import fr.devinsy.statoolinfos.checker.PropertyRule.PropertyMode; +import fr.devinsy.statoolinfos.core.Service.Status; +import fr.devinsy.statoolinfos.properties.PathProperty; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + +/** + * The Class PropertyChecker. + */ +public class PropertyChecker +{ + private PropertyRules federationRules; + private PropertyRules organizationRules; + private PropertyRules serviceRules; + + /** + * Instantiates a new property checker. + */ + public PropertyChecker() + { + final String STRING = "^.+$"; + final String DATETIME = "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?"; + final String DATE = "^(\\d{4}-\\d{2}-\\d{2}|\\d{2}/\\d{2}/\\d{4}|\\d{2}/\\d{4})"; + final String URL = "^(http(s)?://)?\\w+(\\.\\w+)+(/.*)?$"; + final String EMAIL = "^.*@.*$"; + + // + this.federationRules = new PropertyRules(); + + this.federationRules.add("file.class", "^[Ff]ederation$", PropertyMode.MANDATORY); + this.federationRules.add("file.generator", STRING, PropertyMode.WISHED); + this.federationRules.add("file.datetime", DATETIME, PropertyMode.WISHED); + this.federationRules.add("file.protocol", STRING, PropertyMode.WISHED); + + this.federationRules.add("federation.name", STRING, PropertyMode.MANDATORY); + this.federationRules.add("federation.description", STRING, PropertyMode.WISHED); + this.federationRules.add("federation.website", URL, PropertyMode.WISHED); + this.federationRules.add("federation.logo", URL, PropertyMode.WISHED); + this.federationRules.add("federation.favicon", URL, PropertyMode.WISHED); + this.federationRules.add("federation.contact.url", URL, PropertyMode.WISHED); + this.federationRules.add("federation.contact.email", EMAIL, PropertyMode.WISHED); + this.federationRules.add("federation.legal.url", URL, PropertyMode.WISHED); + this.federationRules.add("federation.legal", URL, PropertyMode.WISHED); + this.federationRules.add("federation.guide.user", URL, PropertyMode.WISHED); + this.federationRules.add("federation.guide.technical", URL, PropertyMode.WISHED); + this.federationRules.add("federation.startdate", DATE, PropertyMode.WISHED); + this.federationRules.add("federation.enddate", DATE, PropertyMode.OPTIONAL); + + // + this.organizationRules = new PropertyRules(); + + this.organizationRules.add("file.class", "^[Oo]rganization$", PropertyMode.MANDATORY); + this.organizationRules.add("file.generator", STRING, PropertyMode.WISHED); + this.organizationRules.add("file.datetime", DATETIME, PropertyMode.WISHED); + this.organizationRules.add("file.protocol", STRING, PropertyMode.WISHED); + + this.organizationRules.add("organization.name", STRING, PropertyMode.MANDATORY); + this.organizationRules.add("organization.description", STRING, PropertyMode.WISHED); + this.organizationRules.add("organization.website", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.logo", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.owner.name", STRING, PropertyMode.OPTIONAL); + this.organizationRules.add("organization.owner.website", URL, PropertyMode.OPTIONAL); + this.organizationRules.add("organization.owner.logo", URL, PropertyMode.OPTIONAL); + this.organizationRules.add("organization.contact.url", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.contact.email", EMAIL, PropertyMode.WISHED); + this.organizationRules.add("organization.legal", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.legal.url", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.technical", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.technical.url", URL, PropertyMode.WISHED); + this.organizationRules.add("organization.startdate", DATE, PropertyMode.WISHED); + this.organizationRules.add("organization.enddate", DATE, PropertyMode.OPTIONAL); + + // + this.serviceRules = new PropertyRules(); + + this.serviceRules.add("file.class", "^[Ss]ervice$", PropertyMode.MANDATORY); + this.serviceRules.add("file.generator", STRING, PropertyMode.WISHED); + this.serviceRules.add("file.datetime", DATETIME, PropertyMode.WISHED); + this.serviceRules.add("file.protocol", STRING, PropertyMode.WISHED); + + this.serviceRules.add("service.name", STRING, PropertyMode.MANDATORY); + this.serviceRules.add("service.description", STRING, PropertyMode.WISHED); + this.serviceRules.add("service.website", URL, PropertyMode.WISHED); + this.serviceRules.add("service.logo", URL, PropertyMode.WISHED); + this.serviceRules.add("service.contact.url", URL, PropertyMode.WISHED); + this.serviceRules.add("service.contact.email", EMAIL, PropertyMode.WISHED); + this.serviceRules.add("service.legal.url", URL, PropertyMode.WISHED); + this.serviceRules.add("service.guide.user", URL, PropertyMode.WISHED); + this.serviceRules.add("service.guide.technical", URL, PropertyMode.WISHED); + this.serviceRules.add("service.startdate", DATE, PropertyMode.WISHED); + this.serviceRules.add("service.enddate", DATE, PropertyMode.OPTIONAL); + this.serviceRules.add("service.status.level", "^(OK|WARNING|ALERT|ERROR|OVER|VOID)$", PropertyMode.MANDATORY); + this.serviceRules.add("service.status.description", DATE, PropertyMode.OPTIONAL); + this.serviceRules.add("service.registration", "^(None|Free|Member|Client)([,;+](None|Free|Member|Client))?$", PropertyMode.MANDATORY); + + this.serviceRules.add("software.name", STRING, PropertyMode.MANDATORY); + this.serviceRules.add("software.website", URL, PropertyMode.WISHED); + this.serviceRules.add("software.license.url", URL, PropertyMode.MANDATORY); + this.serviceRules.add("software.license.name", STRING, PropertyMode.MANDATORY); + this.serviceRules.add("software.version", STRING, PropertyMode.WISHED); + this.serviceRules.add("software.source.url", URL, PropertyMode.WISHED); + } + + /** + * Check. + * + * @param lines + * the lines + * @return the property checks + */ + public PropertyChecks check(final StringList lines, final PropertyRules rules) + { + PropertyChecks result; + + result = new PropertyChecks(); + + int lineIndex = 1; + for (String line : lines) + { + PropertyCheck check; + if (line == null) + { + check = new PropertyCheck(lineIndex, "", Status.OK); + check.setComment("OK"); + } + else if ((StringUtils.isEmpty(line)) || (line.matches("^#.*$"))) + { + check = new PropertyCheck(lineIndex, line, Status.OK); + check.setComment("OK"); + } + else if (!line.matches("^[^#].*[^\\s].*=.*$")) + { + check = new PropertyCheck(lineIndex, line, Status.ERROR); + check.setComment("Ligne malformée"); + } + else + { + String[] tokens = line.split("=", 2); + PathProperty property = new PathProperty(tokens[0].trim(), tokens[1].trim()); + PropertyRule rule = rules.get(property.getPath()); + + check = new PropertyCheck(lineIndex, line, Status.VOID); + + if (rule == null) + { + if (StringUtils.startsWithAny(property.getPath(), "metrics.")) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else if (StringUtils.startsWithAny(property.getPath(), "subs.")) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else if (StringUtils.startsWithAny(property.getPath(), "crawl.")) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else + { + check.setStatus(Status.ALERT); + check.setComment("Propriété inconnue"); + } + } + else if (rule.isOptional()) + { + if (StringUtils.isBlank(property.getValue())) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else if (property.getValue().matches(rule.getPattern())) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else + { + check.setStatus(Status.ERROR); + check.setComment("Valeur incorrecte"); + } + } + else if (rule.isWished()) + { + if (StringUtils.isBlank(property.getValue())) + { + check.setStatus(Status.WARNING); + check.setComment("Valeur recommandée"); + } + else if (property.getValue().matches(rule.getPattern())) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else + { + check.setStatus(Status.ERROR); + check.setComment("Valeur incorrecte"); + } + } + else if (rule.isMandatory()) + { + if (StringUtils.isBlank(property.getValue())) + { + check.setStatus(Status.ERROR); + check.setComment("Value obligatoire"); + } + else if (property.getValue().matches(rule.getPattern())) + { + check.setStatus(Status.OK); + check.setComment("OK"); + } + else + { + check.setStatus(Status.ERROR); + check.setComment("Valeur incorrecte"); + } + } + } + + result.add(check); + lineIndex += 1; + } + + // + return result; + } + + /** + * Check federation. + * + * @param file + * the file + * @return the property checks + * @throws IOException + */ + public PropertyChecks checkFederation(final File file) throws IOException + { + PropertyChecks result; + + StringList lines = StringsUtils.load(file); + result = check(lines, this.federationRules); + + // + return result; + } + + /** + * Check organization. + * + * @param file + * the file + * @return the property checks + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public PropertyChecks checkOrganization(final File file) throws IOException + { + PropertyChecks result; + + StringList lines = StringsUtils.load(file); + result = check(lines, this.organizationRules); + + // + return result; + } + + /** + * Check service. + * + * @param file + * the file + * @return the property checks + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public PropertyChecks checkService(final File file) throws IOException + { + PropertyChecks result; + + StringList lines = StringsUtils.load(file); + result = check(lines, this.serviceRules); + + // + return result; + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/checker/PropertyChecks.java b/src/fr/devinsy/statoolinfos/checker/PropertyChecks.java new file mode 100644 index 0000000..b44f770 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/checker/PropertyChecks.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos.checker; + +import java.util.ArrayList; + +/** + * The Class PropertyChecks. + */ +public class PropertyChecks extends ArrayList +{ + private static final long serialVersionUID = 64500205250126257L; + + /** + * Instantiates a new property checks. + */ + public PropertyChecks() + { + super(); + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/checker/PropertyRule.java b/src/fr/devinsy/statoolinfos/checker/PropertyRule.java new file mode 100644 index 0000000..fb1c5b6 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/checker/PropertyRule.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos.checker; + +/** + * The Class PropertyRule. + */ +public class PropertyRule +{ + public enum PropertyMode + { + MANDATORY, + WISHED, + OPTIONAL + } + + private String path; + private String pattern; + private PropertyMode mode; + + /** + * Instantiates a new property rule. + * + * @param path + * the path + * @param pattern + * the pattern + * @param mode + * the mode + */ + public PropertyRule(final String path, final String pattern, final PropertyMode mode) + { + this.path = path; + this.pattern = pattern; + this.mode = mode; + } + + public PropertyMode getMode() + { + return this.mode; + } + + public String getPath() + { + return this.path; + } + + public String getPattern() + { + return this.pattern; + } + + /** + * Checks if is mandatory. + * + * @return true, if is mandatory + */ + public boolean isMandatory() + { + boolean result; + + if (this.mode == PropertyMode.MANDATORY) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /** + * Checks if is optional. + * + * @return true, if is optional + */ + public boolean isOptional() + { + boolean result; + + if (this.mode == PropertyMode.OPTIONAL) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + /** + * Checks if is wished. + * + * @return true, if is wished + */ + public boolean isWished() + { + boolean result; + + if (this.mode == PropertyMode.WISHED) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + + public void setMode(final PropertyMode mode) + { + this.mode = mode; + } + + public void setPath(final String path) + { + this.path = path; + } + + public void setPattern(final String pattern) + { + this.pattern = pattern; + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/checker/PropertyRules.java b/src/fr/devinsy/statoolinfos/checker/PropertyRules.java new file mode 100644 index 0000000..3fe00b6 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/checker/PropertyRules.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos.checker; + +import java.util.HashMap; + +import org.apache.commons.lang3.StringUtils; + +import fr.devinsy.statoolinfos.checker.PropertyRule.PropertyMode; + +/** + * The Class PropertyRules. + */ +public class PropertyRules extends HashMap +{ + private static final long serialVersionUID = -3830415346239101054L; + + /** + * Instantiates a new property rules. + */ + public PropertyRules() + { + super(); + } + + /** + * Adds the. + * + * @param path + * the path + * @param pattern + * the pattern + * @param mode + * the mode + */ + public void add(final String path, final String pattern, final PropertyMode mode) + { + PropertyRule rule = new PropertyRule(path, pattern, mode); + + this.put(StringUtils.toRootLowerCase(path), rule); + } + + /** + * @param path + * @return + */ + public PropertyRule get(final String path) + { + PropertyRule result; + + result = super.get(StringUtils.toRootLowerCase(path)); + + // + return result; + } +} \ No newline at end of file diff --git a/src/fr/devinsy/statoolinfos/checker/organization.rules b/src/fr/devinsy/statoolinfos/checker/organization.rules new file mode 100644 index 0000000..2893b1d --- /dev/null +++ b/src/fr/devinsy/statoolinfos/checker/organization.rules @@ -0,0 +1,27 @@ +STRING= +DATETIME=2020-07-06T14:23:20 +DATE= +URL= + +# [File] +file.class=^(Federation|Organization|Service)$,MANDATORY +file.generator=STRING,WISHED +file.datetime=DATETIME,WISHED +file.protocol=STRING,WISHED + +# [Organisation] +organization.name = STRING,MANDATORY +organization.description = STRING,WISHED +organization.website = URL,WISHED +organization.logo = URL,WISHED +organization.favicon = URL, WISHED +organization.owner.name = STRING,OPTIONAL +organization.owner.website = URL,OPTIONAL +organization.owner.logo = URL,OPTIONAL +organization.owner.favicon = URL,OPTIONAL +organization.contact.url = URL,WISHED +organization.contact.email = EMAIL,WISHED +organization.legal.url = URL,WISHED +organization.guide.technical = URL,WISHED +organization.startdate = DATE,WISHED +organization.enddate =DATE,OPTIONAL diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index 8e6028c..5a41be5 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -304,6 +304,16 @@ public class Service extends PathPropertyList return this.organization; } + public String getPropertyFileName() + { + String result; + + result = getOrganization().getTechnicalName() + "-" + getTechnicalName() + ".properties"; + + // + return result; + } + /** * Gets the software license name. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java index 088338f..fe9c53c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -66,6 +66,7 @@ public class FederationPage data.setContent("federationStartDate", StringUtils.defaultIfBlank(federation.getStartDate(), "n/a")); data.setAttribute("rawLink", "href", federation.getTechnicalName() + ".properties"); + data.setAttribute("rawCheckLink", "href", federation.getTechnicalName() + "-check.xhtml"); if (StringUtils.isNotBlank(federation.getLegalWebsite())) { diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 84f8d29..5f996ce 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -27,6 +27,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.core.Categories; import fr.devinsy.statoolinfos.core.Category; import fr.devinsy.statoolinfos.core.Configuration; @@ -346,6 +348,27 @@ public class Htmlizer page = ServicesPage.build(federation.getAllServices()); FileUtils.write(new File(htmlizeDirectory, "services.xhtml"), page, StandardCharsets.UTF_8); + // + PropertyChecker checker = new PropertyChecker(); + + PropertyChecks checks = checker.checkFederation(federation.getInputFile()); + page = PropertyFileCheckPage.build("fede", checks); + FileUtils.write(new File(htmlizeDirectory, federation.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); + + for (Organization organization : federation.getOrganizations()) + { + checks = checker.checkOrganization(organization.getInputFile()); + page = PropertyFileCheckPage.build("orga", checks); + FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); + + for (Service service : organization.getServices()) + { + checks = checker.checkService(service.getInputFile()); + page = PropertyFileCheckPage.build("serv", checks); + FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); + } + } + // { logger.info("Htmlize propertiesFiles page."); diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java index 9d20bba..412ffa0 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java @@ -69,6 +69,7 @@ public class OrganizationPage data.setContent("serviceCount", organization.getServices().size()); data.setAttribute("rawLink", "href", organization.getTechnicalName() + ".properties"); + data.setAttribute("rawCheckLink", "href", organization.getTechnicalName() + "-check.xhtml"); if (StringUtils.isNotBlank(organization.getLegalWebsite())) { diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java new file mode 100644 index 0000000..3287ef9 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos.htmlize; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.checker.PropertyCheck; +import fr.devinsy.statoolinfos.checker.PropertyChecks; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.strings.StringList; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; + +/** + * The Class OrganizationPage. + */ +public class PropertyFileCheckPage +{ + private static Logger logger = LoggerFactory.getLogger(PropertyFileCheckPage.class); + + /** + * Builds the. + * + * @param stats + * the stats + * @param federationStats + * the federation stats + * @param organizationsStats + * the organizations stats + * @param servicesStats + * the services stats + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final String title, final PropertyChecks checks) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building propertyStats page…"); + + TagDataManager data = new TagDataManager(); + + // + data.setContent("statsTitle", title); + + StringList lines = new StringList(); + + int index = 0; + for (PropertyCheck check : checks) + { + // + data.setContent("line", index, "lineIndex", check.getIndex()); + data.setEscapedContent("line", index, "lineComment", check.getComment()); + data.setEscapedContent("line", index, "lineContent", check.getLine()); + + // + String statusClass; + switch (check.getStatus()) + { + case OK: + statusClass = "bg_ok"; + break; + + case WARNING: + statusClass = "bg_warning"; + break; + + case ALERT: + statusClass = "bg_alert"; + break; + + case ERROR: + statusClass = "bg_error"; + break; + + case OVER: + statusClass = "bg_over"; + break; + + case VOID: + default: + statusClass = "bg_void"; + } + data.setAttribute("line", index, "lineContent", "class", statusClass); + + index += 1; + } + + // + String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml", data).toString(); + + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add("Propriétés", "propertyStats.xhtml"); + result = WebCharterView.build(content, trail); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index 32ed83d..b4fd091 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -75,6 +75,7 @@ public class ServicePage data.setAttribute("serviceStatusImg", "title", StringUtils.defaultIfBlank(service.getStatusDescription(), service.getStatus().toString())); data.setAttribute("rawLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + ".properties"); + data.setAttribute("rawCheckLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"); if (StringUtils.isNotBlank(service.getLegalWebsite())) { diff --git a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml index 7dabaf7..a3f425c 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml @@ -30,7 +30,7 @@ - +
diff --git a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml index fc9a14a..f9328cf 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml @@ -31,7 +31,7 @@ - +
Nombre de services : n/a
diff --git a/src/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml b/src/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml new file mode 100644 index 0000000..9eee313 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml @@ -0,0 +1,32 @@ + + + + + StatoolInfos + + + + + + + +
+
+

n/a

+
+
+
+ + + + + + + + +
000n/an/a
+
+
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/service.xhtml b/src/fr/devinsy/statoolinfos/htmlize/service.xhtml index f747734..632cebe 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/service.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/service.xhtml @@ -39,7 +39,7 @@ - +