From 5afdd07c2b55d00c2f808ba15196f98582506aea Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 8 Jan 2021 04:19:21 +0100 Subject: [PATCH] Improved bad organization file management. --- src/fr/devinsy/statoolinfos/core/Factory.java | 36 ++++++++------ .../statoolinfos/core/Organization.java | 49 +++++++++++++++---- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index e81ccf7..6f82d9a 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -245,25 +245,33 @@ public class Factory { PathProperties properties = PathPropertyUtils.load(inputFile); result = new Organization(properties); - result.setInputFile(inputFile); - result.setInputURL(inputURL); - result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png")); - - PathProperties subs = result.getByPrefix("subs"); - for (PathProperty property : subs) + if (result.isValid()) { - if (StringUtils.startsWith(property.getValue(), "http")) + result.setInputFile(inputFile); + result.setInputURL(inputURL); + result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png")); + + PathProperties subs = result.getByPrefix("subs"); + for (PathProperty property : subs) { - URL serviceInputURL = new URL(property.getValue()); - Service service = loadService(serviceInputURL, cache); - if (service != null) + if (StringUtils.startsWith(property.getValue(), "http")) { - service.setOrganization(result); - service.setLogoFileName(result.getTechnicalName() + "-" + service.getLogoFileName()); - result.getServices().add(service); + URL serviceInputURL = new URL(property.getValue()); + Service service = loadService(serviceInputURL, cache); + if (service != null) + { + service.setOrganization(result); + service.setLogoFileName(result.getTechnicalName() + "-" + service.getLogoFileName()); + result.getServices().add(service); + } } } } + else + { + result = null; + logger.warn("WARNING: organization has invalid file [{}]", inputURL); + } } // diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index abb30b9..7795043 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -23,6 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDateTime; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.properties.PathProperties; @@ -58,15 +59,7 @@ public class Organization extends PathPropertyList public Organization(final PathProperties properties) { super(properties); - - if ((properties == null) || (StringUtils.isBlank(properties.get("organization.name")))) - { - throw new IllegalArgumentException("Not an organization."); - } - else - { - this.services = new Services(); - } + this.services = new Services(); } /** @@ -290,6 +283,19 @@ public class Organization extends PathPropertyList result = get("organization.name"); + if (StringUtils.isBlank(result)) + { + URL url = getInputURL(); + if (url == null) + { + result = "anonymous"; + } + else + { + result = DigestUtils.md5Hex(url.toString()).substring(0, 8); + } + } + // return result; } @@ -493,6 +499,29 @@ public class Organization extends PathPropertyList return result; } + /** + * Checks if is valid. + * + * @return true, if is valid + */ + public boolean isValid() + { + boolean result; + + // if (StringUtils.equalsIgnoreCase(get("file.class"), "organization")) + if (isEmpty()) + { + result = false; + } + else + { + result = true; + } + + // + return result; + } + public void setFederation(final Federation federation) { this.federation = federation;