Step in dev.
This commit is contained in:
parent
3de7de0ef1
commit
9ee525ffe7
10 changed files with 128 additions and 33 deletions
|
@ -119,12 +119,68 @@ public class CrawlCache
|
|||
else
|
||||
{
|
||||
result = buildFile(url.toString());
|
||||
if (!result.exists())
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore file to.
|
||||
*
|
||||
* @param url
|
||||
* the url
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public void restoreFileTo(final URL url, final File target) throws IOException
|
||||
{
|
||||
if (url != null)
|
||||
{
|
||||
File logoFile = restoreFile(url);
|
||||
if (logoFile != null)
|
||||
{
|
||||
FileUtils.copyFile(logoFile, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore file to.
|
||||
*
|
||||
* @param url
|
||||
* the url
|
||||
* @param targetDirectory
|
||||
* the target directory
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public void restoreLogoTo(final URL url, final File target) throws IOException
|
||||
{
|
||||
if (url == null)
|
||||
{
|
||||
StatoolInfosUtils.generateCatLogo(target.getName(), target);
|
||||
}
|
||||
else
|
||||
{
|
||||
File logoFile = restoreFile(url);
|
||||
if (logoFile == null)
|
||||
{
|
||||
StatoolInfosUtils.generateCatLogo(target.getName(), target);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileUtils.copyFile(logoFile, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore properties.
|
||||
*
|
||||
|
@ -167,7 +223,7 @@ public class CrawlCache
|
|||
if (StringUtils.startsWith(url.getProtocol(), "http"))
|
||||
{
|
||||
final int TIMEOUT = 5000;
|
||||
result = restoreFile(url);
|
||||
result = buildFile(url.toString());
|
||||
FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT);
|
||||
}
|
||||
else
|
||||
|
@ -230,8 +286,9 @@ public class CrawlCache
|
|||
else
|
||||
{
|
||||
final int TIMEOUT = 5000;
|
||||
result = restoreFile(url);
|
||||
result = buildFile(url.toString());
|
||||
FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT);
|
||||
logger.info("Crawled {}", url);
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
|
|
|
@ -66,7 +66,9 @@ public class Factory
|
|||
{
|
||||
if (StringUtils.startsWith(property.getValue(), "http"))
|
||||
{
|
||||
PathProperties subProperties = cache.restoreProperties(new URL(property.getValue()));
|
||||
URL url = new URL(property.getValue());
|
||||
result.setLocalFile(cache.restoreFile(url));
|
||||
PathProperties subProperties = cache.restoreProperties(url);
|
||||
|
||||
Organization organization = loadOrganization(subProperties, cache);
|
||||
result.getOrganizations().add(organization);
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
*/
|
||||
package fr.devinsy.statoolinfos.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
|
@ -30,6 +34,7 @@ public class Federation extends PathPropertyList
|
|||
{
|
||||
private static final long serialVersionUID = -8970835291634661580L;
|
||||
private Organizations organizations;
|
||||
private File localFile;
|
||||
|
||||
/**
|
||||
* Instantiates a new federation.
|
||||
|
@ -69,7 +74,36 @@ public class Federation extends PathPropertyList
|
|||
{
|
||||
String result;
|
||||
|
||||
result = get("service.description");
|
||||
result = get("federation.description");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public File getLocalFile()
|
||||
{
|
||||
return this.localFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the logo URL.
|
||||
*
|
||||
* @return the logo URL
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
public URL getLogoURL() throws MalformedURLException
|
||||
{
|
||||
URL result;
|
||||
|
||||
String path = get("federation.logo");
|
||||
if ((StringUtils.isBlank(path)) || (!StringUtils.startsWith(path, "http")))
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new URL(path);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
|
@ -109,4 +143,9 @@ public class Federation extends PathPropertyList
|
|||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setLocalFile(final File localFile)
|
||||
{
|
||||
this.localFile = localFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class Service extends PathPropertyList
|
|||
{
|
||||
String result;
|
||||
|
||||
result = get("service.website.url");
|
||||
result = get("service.website");
|
||||
|
||||
//
|
||||
return result;
|
||||
|
|
|
@ -172,6 +172,13 @@ public class StatoolInfos
|
|||
logger.info("Cache setting: {}", configuration.get("conf.crawl.cache"));
|
||||
CrawlCache cache = new CrawlCache(new File(crawlCachePath));
|
||||
|
||||
cache.storeQuietly(configuration.getURL("federation.logo"));
|
||||
cache.storeQuietly(configuration.getURL("federation.logo.url"));
|
||||
cache.storeQuietly(configuration.getURL("organization.logo"));
|
||||
cache.storeQuietly(configuration.getURL("organization.logo.url"));
|
||||
cache.storeQuietly(configuration.getURL("service.logo"));
|
||||
cache.storeQuietly(configuration.getURL("service.logo.url"));
|
||||
|
||||
PathProperties subs = configuration.getByPrefix("subs");
|
||||
for (PathProperty property : subs)
|
||||
{
|
||||
|
@ -236,21 +243,20 @@ public class StatoolInfos
|
|||
{
|
||||
PathProperties properties = PathPropertyUtils.load(input);
|
||||
|
||||
String crawlCachePath = properties.get("conf.crawl.cache");
|
||||
logger.info("Cache setting: {}", properties.get("conf.crawl.cache"));
|
||||
CrawlCache cache = new CrawlCache(new File(crawlCachePath));
|
||||
|
||||
String className = properties.get("conf.class");
|
||||
if (StringUtils.equals(className, "federation"))
|
||||
{
|
||||
Federation federation = Factory.loadFederation(properties);
|
||||
Htmlizer.htmlize(federation);
|
||||
Htmlizer.htmlize(federation, cache);
|
||||
}
|
||||
else if (StringUtils.equals(className, "organization"))
|
||||
{
|
||||
Organization organization = Factory.loadOrganization(properties);
|
||||
Htmlizer.htmlize(organization);
|
||||
}
|
||||
else if (StringUtils.equals(className, "service"))
|
||||
{
|
||||
Service service = Factory.loadService(properties);
|
||||
Htmlizer.htmlize(service);
|
||||
Htmlizer.htmlize(organization, cache);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -116,7 +116,7 @@ public class StatoolInfosUtils
|
|||
{
|
||||
URL source = new URL("https://www.peppercarrot.com/extras/html/2016_cat-generator/avatar.php?seed=" + seed);
|
||||
|
||||
FileUtils.copyURLToFile(source, target);
|
||||
FileUtils.copyURLToFile(source, target, 5000, 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,9 +62,11 @@ public class FederationPage
|
|||
data.setContent("versionsup", BuildInformation.instance().version());
|
||||
data.setContent("lastUpdateDate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE)));
|
||||
|
||||
data.setAttribute("federationLogo", "src", federation.getTechnicalName() + "-logo.jpg");
|
||||
data.setEscapedContent("federationName", federation.getName());
|
||||
data.setEscapedContent("federationDescription", federation.getDescription());
|
||||
data.setContent("organizationCount", federation.getOrganizations().size());
|
||||
data.setAttribute("federationRawButton", "href", federation.getTechnicalName() + "-origin.properties");
|
||||
|
||||
int index = 0;
|
||||
for (Organization organization : federation.getOrganizations())
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.commons.io.FileUtils;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.core.CrawlCache;
|
||||
import fr.devinsy.statoolinfos.core.Federation;
|
||||
import fr.devinsy.statoolinfos.core.Organization;
|
||||
import fr.devinsy.statoolinfos.core.Service;
|
||||
|
@ -81,7 +82,7 @@ public class Htmlizer
|
|||
* @throws IOException
|
||||
* @throws StatoolInfosException
|
||||
*/
|
||||
public static void htmlize(final Federation federation) throws IOException, StatoolInfosException
|
||||
public static void htmlize(final Federation federation, final CrawlCache cache) throws IOException, StatoolInfosException
|
||||
{
|
||||
File targetDirectory = new File(federation.get("conf.htmlize.directory"));
|
||||
logger.info("Htmlize target directory: {}", targetDirectory.getAbsoluteFile());
|
||||
|
@ -97,6 +98,7 @@ public class Htmlizer
|
|||
else
|
||||
{
|
||||
copyStuff(targetDirectory);
|
||||
cache.restoreLogoTo(federation.getLogoURL(), new File(targetDirectory, federation.getTechnicalName() + "-logo.jpg"));
|
||||
|
||||
//
|
||||
String page = FederationPage.build(federation);
|
||||
|
@ -136,7 +138,7 @@ public class Htmlizer
|
|||
* @throws IOException
|
||||
* @throws StatoolInfosException
|
||||
*/
|
||||
public static void htmlize(final Organization organization) throws IOException, StatoolInfosException
|
||||
public static void htmlize(final Organization organization, final CrawlCache cache) throws IOException, StatoolInfosException
|
||||
{
|
||||
File targetDirectory = new File(organization.get("conf.htmlize.directory"));
|
||||
logger.info("Htmlize target directory: {}", targetDirectory.getAbsoluteFile());
|
||||
|
@ -174,15 +176,4 @@ public class Htmlizer
|
|||
// Build service page.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Htmlize.
|
||||
*
|
||||
* @param service
|
||||
* the service
|
||||
*/
|
||||
public static void htmlize(final Service service)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
<div style="margin: 5px 10px 10px 10px;">
|
||||
<h1><a href="index.xhtml"><img src="logo.jpg" style="width: 35px;"/> StatoolInfos</a><sup id="versionsup" style="font-size: 9px;">v0.0.14</sup> – <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1>
|
||||
|
||||
<div style="margin: 5px;">
|
||||
<a id="federationRawButton" href="#" class="button">Raw properties</a>
|
||||
</div>
|
||||
<h2><img id="federationLogo" src="#" style="width: 100px; heigth: 100px;"/> <span id="federationName">Federation name</span></h2>
|
||||
|
||||
<h2 id="federationName">Federation name</h2>
|
||||
<p id="federationDescription">Bla bla description</p>
|
||||
<div>Nombre de membres : <span id="organizationCount">n/a</span></div>
|
||||
<div>
|
||||
|
|
|
@ -14,11 +14,12 @@
|
|||
<div style="margin: 5px 10px 10px 10px;">
|
||||
<h1><a href="index.xhtml"><img src="logo.jpg" style="width: 35px;"/> StatoolInfos</a><sup id="versionsup" style="font-size: 9px;">v0.0.14</sup> – <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1>
|
||||
|
||||
<h2 id="organizationName">Organization name</h2>
|
||||
|
||||
<div style="margin: 5px;">
|
||||
<a id="organizationRawButton" href="#" class="button">Raw properties</a>
|
||||
<a id="federationRawButton" href="#" class="button">Raw properties</a>
|
||||
</div>
|
||||
|
||||
<h2 id="organizationName">Organization name</h2>
|
||||
<p id="organizationDescription">Bla bla description</p>
|
||||
<div>Nombre de services : <span id="serviceCount">n/a</span></div>
|
||||
<div>
|
||||
|
|
Loading…
Reference in a new issue