737 lines
14 KiB
Java
737 lines
14 KiB
Java
/*
|
|
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
|
*
|
|
* This file is part of StatoolInfos, simple service statistics tool.
|
|
*
|
|
* StatoolInfos is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* StatoolInfos is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package fr.devinsy.statoolinfos.core;
|
|
|
|
import java.io.File;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import fr.devinsy.statoolinfos.checker.PropertyChecks;
|
|
import fr.devinsy.statoolinfos.crawl.CrawlJournal;
|
|
import fr.devinsy.statoolinfos.properties.PathProperties;
|
|
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
|
|
|
/**
|
|
* The Class PathProperty.
|
|
*/
|
|
public class Organization extends PathPropertyList
|
|
{
|
|
private static final long serialVersionUID = -2709210934548224213L;
|
|
private Federation federation;
|
|
private Services services;
|
|
private File inputFile;
|
|
private URL inputURL;
|
|
private String logoFileName;
|
|
private PropertyChecks inputChecks;
|
|
private CrawlJournal crawlJournal;
|
|
|
|
/**
|
|
* Instantiates a new organization.
|
|
*/
|
|
public Organization()
|
|
{
|
|
super();
|
|
this.inputChecks = new PropertyChecks();
|
|
this.services = new Services();
|
|
this.crawlJournal = new CrawlJournal();
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new organization.
|
|
*
|
|
* @param properties
|
|
* the properties
|
|
*/
|
|
public Organization(final PathProperties properties)
|
|
{
|
|
super(properties);
|
|
this.inputChecks = new PropertyChecks();
|
|
this.services = new Services();
|
|
this.crawlJournal = new CrawlJournal();
|
|
}
|
|
|
|
/**
|
|
* Gets the age.
|
|
*
|
|
* @return the age
|
|
*/
|
|
public String getAge()
|
|
{
|
|
String result;
|
|
|
|
LocalDate startDate = StatoolInfosUtils.parseDate(getStartDate());
|
|
LocalDate endDate = StatoolInfosUtils.parseDate(getEndDate());
|
|
|
|
result = StatoolInfosUtils.toHumanDuration(startDate, endDate);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the contact email.
|
|
*
|
|
* @return the contact email
|
|
*/
|
|
public String getContactEmail()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.contact.email");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the contact website.
|
|
*
|
|
* @return the contact website
|
|
*/
|
|
public String getContactWebsite()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.contact.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the country code.
|
|
*
|
|
* @return the country code
|
|
*/
|
|
public String getCountryCode()
|
|
{
|
|
String result;
|
|
|
|
result = StringUtils.toRootUpperCase(get("organization.country.code"));
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the crawl date.
|
|
*
|
|
* @return the crawl date
|
|
*/
|
|
public LocalDateTime getCrawlDate()
|
|
{
|
|
LocalDateTime result;
|
|
|
|
result = LocalDateTime.parse(get("crawl.datetime"));
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the crawled date.
|
|
*
|
|
* @return the crawled date
|
|
*/
|
|
public LocalDateTime getCrawledDate()
|
|
{
|
|
LocalDateTime result;
|
|
|
|
result = LocalDateTime.parse(get("crawl.file.datetime"));
|
|
|
|
if (result.getYear() == 1970)
|
|
{
|
|
result = getCrawlDate();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public CrawlJournal getCrawlJournal()
|
|
{
|
|
return this.crawlJournal;
|
|
}
|
|
|
|
public String getDescription()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.description");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the diaspora page.
|
|
*
|
|
* @return the diaspora page
|
|
*/
|
|
public String getDiasporaWebpage()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.socialnetworks.diaspora", "organization.socialnetworks.diaspora.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the end date.
|
|
*
|
|
* @return the end date
|
|
*/
|
|
public String getEndDate()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.enddate");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public Federation getFederation()
|
|
{
|
|
return this.federation;
|
|
}
|
|
|
|
/**
|
|
* Gets the funkwhale webpage.
|
|
*
|
|
* @return the funkwhale webpage
|
|
*/
|
|
public String getFunkwhaleWebpage()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.socialnetworks.funkwhale", "organization.socialnetworks.funkwhale.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public PropertyChecks getInputChecks()
|
|
{
|
|
return this.inputChecks;
|
|
}
|
|
|
|
/**
|
|
* Gets the input checks all.
|
|
*
|
|
* @return the input checks all
|
|
*/
|
|
public PropertyChecks getInputChecksAll()
|
|
{
|
|
PropertyChecks result;
|
|
|
|
result = new PropertyChecks();
|
|
|
|
result.addAll(this.inputChecks);
|
|
for (Service service : this.services)
|
|
{
|
|
result.addAll(service.getInputChecks());
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public File getInputFile()
|
|
{
|
|
return this.inputFile;
|
|
}
|
|
|
|
/**
|
|
* Gets the crawled input URL.
|
|
*
|
|
* @return the crawled input URL
|
|
*/
|
|
public URL getInputURL()
|
|
{
|
|
URL result;
|
|
|
|
result = this.inputURL;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the legal website.
|
|
*
|
|
* @return the legal website
|
|
*/
|
|
public String getLegalWebsite()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.legal.url", "organization.legal");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the local file name.
|
|
*
|
|
* @return the local file name
|
|
*/
|
|
public String getLocalFileName()
|
|
{
|
|
String result;
|
|
|
|
result = getTechnicalName() + ".properties";
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the logo file name.
|
|
*
|
|
* @return the logo file name
|
|
*/
|
|
public String getLogoFileName()
|
|
{
|
|
String result;
|
|
|
|
result = this.logoFileName;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the logo URL.
|
|
*
|
|
* @return the logo URL
|
|
* @throws MalformedURLException
|
|
* the malformed URL exception
|
|
*/
|
|
public URL getLogoURL() throws MalformedURLException
|
|
{
|
|
URL result;
|
|
|
|
String path = getLogoURLValue();
|
|
if ((StringUtils.isBlank(path)) || (!StringUtils.startsWith(path, "http")))
|
|
{
|
|
result = null;
|
|
}
|
|
else
|
|
{
|
|
result = new URL(path);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the logo URL value.
|
|
*
|
|
* @return the logo URL value
|
|
*/
|
|
public String getLogoURLValue()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.logo");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the mastodon page.
|
|
*
|
|
* @return the mastodon page
|
|
*/
|
|
public String getMastodonWebpage()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.socialnetworks.mastodon", "organization.socialnetworks.mastodon.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the member age.
|
|
*
|
|
* @return the member age
|
|
*/
|
|
public String getMemberAge()
|
|
{
|
|
String result;
|
|
|
|
LocalDate startDate = StatoolInfosUtils.parseDate(getMemberStartDate());
|
|
LocalDate endDate = StatoolInfosUtils.parseDate(getMemberEndDate());
|
|
|
|
result = StatoolInfosUtils.toHumanDuration(startDate, endDate);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the member end date.
|
|
*
|
|
* @return the member end date
|
|
*/
|
|
public String getMemberEndDate()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.memberof." + this.federation.getName() + ".enddate");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the member start date.
|
|
*
|
|
* @return the member start date
|
|
*/
|
|
public String getMemberStartDate()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.memberof." + this.federation.getName() + ".startdate");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the mobilizon webpage.
|
|
*
|
|
* @return the mobilizon webpage
|
|
*/
|
|
public String getMobilizonWebpage()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.socialnetworks.mobilizon", "organization.socialnetworks.mobilizon.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the name.
|
|
*
|
|
* @return the name
|
|
*/
|
|
public String getName()
|
|
{
|
|
String result;
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* Gets the peertube webpage.
|
|
*
|
|
* @return the peertube webpage
|
|
*/
|
|
public String getPeertubeWebpage()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.socialnetworks.peertube", "organization.socialnetworks.peertube.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the pixelfed webpage.
|
|
*
|
|
* @return the pixelfed webpage
|
|
*/
|
|
public String getPixelfedWebpage()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.socialnetworks.pixelfed", "organization.socialnetworks.pixelfed.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the service count.
|
|
*
|
|
* @return the service count
|
|
*/
|
|
public int getServiceCount()
|
|
{
|
|
int result;
|
|
|
|
result = this.services.size();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public Services getServices()
|
|
{
|
|
return this.services;
|
|
}
|
|
|
|
/**
|
|
* Gets the start date.
|
|
*
|
|
* @return the start date
|
|
*/
|
|
public String getStartDate()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.startdate");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the technical guide website.
|
|
*
|
|
* @return the technical guide website
|
|
*/
|
|
public String getTechnicalGuideWebsite()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.guide.technical", "organization.guide.technical.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the technical name.
|
|
*
|
|
* @return the technical name
|
|
*/
|
|
public String getTechnicalName()
|
|
{
|
|
String result;
|
|
|
|
result = StatoolInfosUtils.toTechnicalName(getName());
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the user count.
|
|
*
|
|
* @return the user count
|
|
*/
|
|
public int getUserCount()
|
|
{
|
|
int result;
|
|
|
|
result = 0;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the user guide website.
|
|
*
|
|
* @return the user guide website
|
|
*/
|
|
public String getUserGuideWebsite()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.guide.user", "organization.guide.user.url");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the website.
|
|
*
|
|
* @return the website
|
|
*/
|
|
public String getWebsite()
|
|
{
|
|
String result;
|
|
|
|
result = get("organization.website");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Checks for social network.
|
|
*
|
|
* @return true, if successful
|
|
*/
|
|
public boolean hasSocialNetwork()
|
|
{
|
|
boolean result;
|
|
|
|
if (StringUtils.isAllBlank(getDiasporaWebpage(), getMastodonWebpage()))
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
result = true;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Checks for social network.
|
|
*
|
|
* @param value
|
|
* the value
|
|
* @return true, if successful
|
|
*/
|
|
public boolean hasSocialNetwork(final SocialNetworks value)
|
|
{
|
|
boolean result;
|
|
|
|
String link;
|
|
switch (value)
|
|
{
|
|
case DIASPORA:
|
|
link = getDiasporaWebpage();
|
|
break;
|
|
case MASTODON:
|
|
link = getMastodonWebpage();
|
|
break;
|
|
default:
|
|
link = null;
|
|
}
|
|
|
|
if (StringUtils.isBlank(link))
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
result = true;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Checks if is default.
|
|
*
|
|
* @return true, if is default
|
|
*/
|
|
public boolean isDefault()
|
|
{
|
|
boolean result;
|
|
|
|
if ((getServiceCount() == 0) && (getLogoURLValue() == null) && (getStartDate() == null))
|
|
{
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
public void setInputFile(final File inputFile)
|
|
{
|
|
this.inputFile = inputFile;
|
|
}
|
|
|
|
public void setInputURL(final URL inputURL)
|
|
{
|
|
this.inputURL = inputURL;
|
|
}
|
|
|
|
public void setLogoFileName(final String logoFileName)
|
|
{
|
|
this.logoFileName = logoFileName;
|
|
}
|
|
}
|