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,6 +245,8 @@ public class Factory
{
PathProperties properties = PathPropertyUtils.load(inputFile);
result = new Organization(properties);
if (result.isValid())
{
result.setInputFile(inputFile);
result.setInputURL(inputURL);
result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png"));
@ -265,6 +267,12 @@ public class Factory
}
}
}
else
{
result = null;
logger.warn("WARNING: organization has invalid file [{}]", inputURL);
}
}
//
return result;

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,16 +59,8 @@ 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();
}
}
/**
* Gets the contact email.
@ -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;