/* * Copyright (C) 2020 Christian Pierre MOMON * * 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 . */ package fr.devinsy.statoolinfos.core; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDateTime; import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathPropertyList; /** * The Class Service. */ public class Service extends PathPropertyList { private static final long serialVersionUID = 3629841771102288863L; public enum Status { OK, WARNING, ALERT, ERROR, OVER, UNKNOWN } private Organization organization; private File inputFile; private URL inputURL; /** * Instantiates a new service. */ public Service() { super(null); } /** * Instantiates a new service. * * @param properties * the properties */ public Service(final PathProperties properties) { super(properties); } /** * Gets the contact email. * * @return the contact email */ public String getContactEmail() { String result; result = get("service.contact.email"); // return result; } /** * Gets the contact website. * * @return the contact website */ public String getContactWebsite() { String result; result = get("service.contact.url"); // return result; } public LocalDateTime getCrawledDate() { LocalDateTime result; result = LocalDateTime.parse(get("crawl.file.datetime")); // return result; } /** * Gets the description. * * @return the description */ public String getDescription() { String result; result = get("service.description"); // return result; } /** * Gets the end date. * * @return the end date */ public String getEndDate() { String result; result = get("service.enddate", "service.deathdate"); // return result; } public File getInputFile() { return this.inputFile; } public URL getInputURL() { return this.inputURL; } /** * Gets the legal website. * * @return the legal website */ public String getLegalWebsite() { String result; result = get("service.legal.url", "service.legal"); // return result; } /** * Gets the license name. * * @return the license name */ public String getLicenseName() { String result; result = get("software.license.name"); // 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 = get("service.logo"); if ((StringUtils.isBlank(path)) || (!StringUtils.startsWith(path, "http"))) { result = null; } else { result = new URL(path); } // return result; } /** * Gets the name. * * @return the name */ public String getName() { String result; result = get("service.name"); // return result; } public Organization getOrganization() { return this.organization; } /** * Gets the software license name. * * @return the software license name */ public String getSoftwareLicenseName() { String result; result = get("software.license.name"); // return result; } /** * Gets the software license webpage. * * @return the software license webpage */ public String getSoftwareLicenseWebpage() { String result; result = get("software.license.url"); // return result; } /** * Gets the software name. * * @return the software name */ public String getSoftwareName() { String result; result = get("software.name"); // return result; } /** * Gets the software source website. * * @return the software source website */ public String getSoftwareSourceWebsite() { String result; result = get("software.source.url"); // return result; } /** * Gets the software version. * * @return the software version */ public String getSoftwareVersion() { String result; result = get("software.version"); // return result; } /** * Gets the software website. * * @return the software website */ public String getSoftwareWebsite() { String result; result = get("software.website"); // return result; } /** * Gets the start date. * * @return the start date */ public String getStartDate() { String result; result = get("service.startdate", "service.birthdate"); // return result; } /** * Gets the status. * * @return the status */ public Status getStatus() { Status result; String value = get("service.status", "service.status.level"); if ((StringUtils.isBlank(value)) || (StringUtils.equals(value, "unknonw"))) { result = Status.UNKNOWN; } else if (StringUtils.equalsAnyIgnoreCase(value, "ON", "OK")) { result = Status.OK; } else if (StringUtils.equalsAnyIgnoreCase(value, "alert")) { result = Status.ALERT; } else if (StringUtils.equalsAnyIgnoreCase(value, "error", "KO", "broken")) { result = Status.ERROR; } else if (StringUtils.equalsAnyIgnoreCase(value, "over", "terminated", "closed")) { result = Status.OVER; } else { result = Status.UNKNOWN; } // return result; } /** * Gets the status description. * * @return the status description */ public String getStatusDescription() { String result; result = get("service.status.description"); // return result; } public String getTechnicalDocWebsite() { String result; result = get("service.documentation.technical", "service.documentation.technical.url"); // return result; } /** * Gets the technical name. * * @return the technical name */ public String getTechnicalName() { String result; result = StatoolInfosUtils.toTechnicalName(getName()); // return result; } /** * User count. * * @return the int */ public int getUserCount() { int result; result = 0; // return result; } /** * Gets the user doc. * * @return the user doc */ public String getUserDocWebsite() { String result; result = get("service.documentation.user", "service.documentation.user.url", "service.documentation.tutorial", "service.documentation.tutorial.url"); // return result; } /** * Gets the website. * * @return the website */ public String getWebsite() { String result; result = get("service.website"); // return result; } /** * Checks if is registration client. * * @return true, if is registration client */ public boolean isRegistrationClient() { boolean result; result = StringUtils.containsIgnoreCase(get("service.registration"), "Client"); // return result; } /** * Checks if is registration free. * * @return true, if is registration free */ public boolean isRegistrationFree() { boolean result; result = StringUtils.containsIgnoreCase(get("service.registration"), "Free"); // return result; } /** * Checks if is registration member. * * @return true, if is registration member */ public boolean isRegistrationMember() { boolean result; result = StringUtils.containsIgnoreCase(get("service.registration"), "Member"); // return result; } /** * Checks if is registration none. * * @return true, if is registration none */ public boolean isRegistrationNone() { boolean result; result = StringUtils.containsIgnoreCase(get("service.registration"), "None"); // return result; } public void setInputFile(final File inputFile) { this.inputFile = inputFile; } public void setInputURL(final URL inputURL) { this.inputURL = inputURL; } public void setOrganization(final Organization organization) { this.organization = organization; } }