Improved bad organization file management.

This commit is contained in:
Christian P. MOMON 2021-01-08 04:19:21 +01:00
parent d525cfcb8d
commit 5afdd07c2b
2 changed files with 61 additions and 24 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
*
* 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);
}
}
//

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
*
* 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;