Improved bad organization file management.
This commit is contained in:
parent
d525cfcb8d
commit
5afdd07c2b
2 changed files with 61 additions and 24 deletions
|
@ -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.
|
* This file is part of StatoolInfos, simple service statistics tool.
|
||||||
*
|
*
|
||||||
|
@ -245,25 +245,33 @@ public class Factory
|
||||||
{
|
{
|
||||||
PathProperties properties = PathPropertyUtils.load(inputFile);
|
PathProperties properties = PathPropertyUtils.load(inputFile);
|
||||||
result = new Organization(properties);
|
result = new Organization(properties);
|
||||||
result.setInputFile(inputFile);
|
if (result.isValid())
|
||||||
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 (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());
|
if (StringUtils.startsWith(property.getValue(), "http"))
|
||||||
Service service = loadService(serviceInputURL, cache);
|
|
||||||
if (service != null)
|
|
||||||
{
|
{
|
||||||
service.setOrganization(result);
|
URL serviceInputURL = new URL(property.getValue());
|
||||||
service.setLogoFileName(result.getTechnicalName() + "-" + service.getLogoFileName());
|
Service service = loadService(serviceInputURL, cache);
|
||||||
result.getServices().add(service);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -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.
|
* This file is part of StatoolInfos, simple service statistics tool.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,7 @@ import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||||
|
@ -58,15 +59,7 @@ public class Organization extends PathPropertyList
|
||||||
public Organization(final PathProperties properties)
|
public Organization(final PathProperties properties)
|
||||||
{
|
{
|
||||||
super(properties);
|
super(properties);
|
||||||
|
this.services = new Services();
|
||||||
if ((properties == null) || (StringUtils.isBlank(properties.get("organization.name"))))
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Not an organization.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.services = new Services();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -290,6 +283,19 @@ public class Organization extends PathPropertyList
|
||||||
|
|
||||||
result = get("organization.name");
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -493,6 +499,29 @@ public class Organization extends PathPropertyList
|
||||||
return result;
|
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)
|
public void setFederation(final Federation federation)
|
||||||
{
|
{
|
||||||
this.federation = federation;
|
this.federation = federation;
|
||||||
|
|
Loading…
Reference in a new issue