Added property file check management.
This commit is contained in:
parent
2a8f053901
commit
6285cb84e9
17 changed files with 928 additions and 3 deletions
103
src/fr/devinsy/statoolinfos/checker/PropertyCheck.java
Normal file
103
src/fr/devinsy/statoolinfos/checker/PropertyCheck.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.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;
|
||||
}
|
||||
}
|
314
src/fr/devinsy/statoolinfos/checker/PropertyChecker.java
Normal file
314
src/fr/devinsy/statoolinfos/checker/PropertyChecker.java
Normal file
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.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;
|
||||
}
|
||||
}
|
37
src/fr/devinsy/statoolinfos/checker/PropertyChecks.java
Normal file
37
src/fr/devinsy/statoolinfos/checker/PropertyChecks.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.checker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The Class PropertyChecks.
|
||||
*/
|
||||
public class PropertyChecks extends ArrayList<PropertyCheck>
|
||||
{
|
||||
private static final long serialVersionUID = 64500205250126257L;
|
||||
|
||||
/**
|
||||
* Instantiates a new property checks.
|
||||
*/
|
||||
public PropertyChecks()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
149
src/fr/devinsy/statoolinfos/checker/PropertyRule.java
Normal file
149
src/fr/devinsy/statoolinfos/checker/PropertyRule.java
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.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;
|
||||
}
|
||||
}
|
72
src/fr/devinsy/statoolinfos/checker/PropertyRules.java
Normal file
72
src/fr/devinsy/statoolinfos/checker/PropertyRules.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.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<String, PropertyRule>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
27
src/fr/devinsy/statoolinfos/checker/organization.rules
Normal file
27
src/fr/devinsy/statoolinfos/checker/organization.rules
Normal file
|
@ -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
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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()))
|
||||
{
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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()))
|
||||
{
|
||||
|
|
125
src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java
Normal file
125
src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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 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;
|
||||
}
|
||||
}
|
|
@ -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()))
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<a id="userDocLink" href="#"><img id="userDocLinkImg" src="circle-icons/color/bookshelf.png" class="disabled" title="Documentation"/></a>
|
||||
<a id="technicalDocLink" href="#"><img id="technicalDocLinkImg" src="circle-icons/color/tools.png" class="disabled" title="Documentation technique"/></a>
|
||||
<a id="rawLink" href="#"><img id="rawLinkImg" src="circle-icons/mono/document.png" title="Fichier propriétés"/></a>
|
||||
<a id="rawCheckedLink" href="#"><img id="rawCheckedLinkImg" src="circle-icons/mono/clipboard.png" class="disabled" title="Fichier propriétés analysé"/></a>
|
||||
<a id="rawCheckLink" href="#"><img id="rawCheckLinkImg" src="circle-icons/mono/clipboard.png" title="Fichier propriétés analysé"/></a>
|
||||
</div>
|
||||
<br/>
|
||||
</div>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<a id="userDocLink" href="#"><img id="userDocLinkImg" src="circle-icons/color/bookshelf.png" class="disabled" title="Documentation"/></a>
|
||||
<a id="technicalDocLink" href="#"><img id="technicalDocLinkImg" src="circle-icons/color/tools.png" class="disabled" title="Documentation technique"/></a>
|
||||
<a id="rawLink" href="#"><img id="rawLinkImg" src="circle-icons/mono/document.png" title="Fichier propriétés"/></a>
|
||||
<a id="rawCheckedLink" href="#"><img id="rawCheckedLinkImg" src="circle-icons/mono/clipboard.png" class="disabled" title="Fichier propriétés analysé"/></a>
|
||||
<a id="rawCheckLink" href="#"><img id="rawCheckLinkImg" src="circle-icons/mono/clipboard.png" title="Fichier propriétés analysé"/></a>
|
||||
</div>
|
||||
<br/>
|
||||
<div>Nombre de services : <span id="serviceCount">n/a</span></div>
|
||||
|
|
32
src/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml
Normal file
32
src/fr/devinsy/statoolinfos/htmlize/propertyFileCheck.xhtml
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>StatoolInfos</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="keywords" content="statoolinfos,devinsy,federation" />
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
|
||||
<script src="sorttable.js" />
|
||||
<script src="Chart.bundle.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row center_table" style="width: 1100px;">
|
||||
<div class="center">
|
||||
<h2 id="statsTitle">n/a</h2>
|
||||
</div>
|
||||
<br/>
|
||||
<div style="width: 100%;">
|
||||
<table class="table_simple">
|
||||
<tbody>
|
||||
<tr id="line">
|
||||
<td id="lineIndex" style="width: 30px; text-align: right;">000</td>
|
||||
<td id="lineContent" style="padding-left: 10px;">n/a</td>
|
||||
<td id="lineComment" style="width: 200px; padding-left: 10px;">n/a</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -39,7 +39,7 @@
|
|||
<a id="userDocLink" href="#"><img id="userDocLinkImg" src="circle-icons/color/bookshelf.png" class="disabled" title="Documentation"/></a>
|
||||
<a id="technicalDocLink" href="#"><img id="technicalDocLinkImg" src="circle-icons/color/tools.png" class="disabled" title="Documentation technique"/></a>
|
||||
<a id="rawLink" href="#"><img id="rawLinkImg" src="circle-icons/mono/document.png" title="Fichier propriétés"/></a>
|
||||
<a id="rawCheckedLink" href="#"><img id="rawCheckedLinkImg" src="circle-icons/mono/clipboard.png" class="disabled" title="Fichier propriétés analysé"/></a>
|
||||
<a id="rawCheckLink" href="#"><img id="rawCheckLinkImg" src="circle-icons/mono/clipboard.png" title="Fichier propriétés analysé"/></a>
|
||||
</div>
|
||||
<div class="content_infos" style="margin: 5px;">
|
||||
Logiciel :
|
||||
|
|
|
@ -788,3 +788,33 @@ table > tfoot > tr > th.danger
|
|||
font-size: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.bg_ok
|
||||
{
|
||||
background-color : none;
|
||||
}
|
||||
|
||||
.bg_warning
|
||||
{
|
||||
background-color : yellow;
|
||||
}
|
||||
|
||||
.bg_alert
|
||||
{
|
||||
background-color : orange;
|
||||
}
|
||||
|
||||
.bg_error
|
||||
{
|
||||
background-color : red;
|
||||
}
|
||||
|
||||
.bg_over
|
||||
{
|
||||
background-color : grey;
|
||||
}
|
||||
|
||||
.bg_void
|
||||
{
|
||||
background-color : rgb(54, 162, 235, 0.2);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue