AppInfos.java
package fr.metabocloud.core.model;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
import org.springframework.stereotype.Component;
import fr.metabocloud.about.openapi.model.AboutVersion.StatusEnum;
import lombok.Getter;
import lombok.Setter;
/**
* Object used to map JSON information about the REST API.
*
* @author Faustine Souc
* @author Nils Paulhe
* @since 1.0.0
* @version 1.0.0
*/
@Getter
@Setter
@Component
public class AppInfos {
///////////////////////////////////////////////////////////////////////////
// Attributes
private String name;
private String artifactId;
private String shortDescription;
private List<String> keywords;
private String longDescription;
private String docSwagger;
private String docReadthedocs;
private StatusEnum status;
private String version;
private String shortCommitSha1;
private String commitSha1;
private String buildTimestamp;
private String license;
private String authorsMicroserviceCode;
private String authorsAlgorithmCode;
private String isPublic;
private String urlRepoGit;
private List<String> publicationsRef;
private static ResourceBundle bundleInfos = ResourceBundle.getBundle("infos");
///////////////////////////////////////////////////////////////////////////
// Constructor
/**
* Default constructor, load properties values.
*/
public AppInfos() {
this.name = getBundleInfosElement("info.app.name");
this.artifactId = getBundleInfosElement("info.app.artifactId");
this.shortDescription = getBundleInfosElement("info.app.shortdescription");
this.keywords = getListStringElement("info.app.keywords");
this.longDescription = getBundleInfosElement("info.app.longdescription");
this.docSwagger = getBundleInfosElement("info.app.doc.swagger");
this.docReadthedocs = getBundleInfosElement("info.app.doc.readthedocs");
this.status = getStatusEnumElement();
this.version = getBundleInfosElement("info.app.version");
this.commitSha1 = getBundleInfosElement("info.app.sha1");
this.shortCommitSha1 = computeShortSha1();
this.buildTimestamp = getBundleInfosElement("info.app.timestamp");
this.license = getBundleInfosElement("info.app.license");
this.authorsMicroserviceCode = getBundleInfosElement("info.app.authors.microservice");
this.authorsAlgorithmCode = getBundleInfosElement("info.app.authors.algorithm");
this.isPublic = getBundleInfosElement("info.app.opening");
this.urlRepoGit = getBundleInfosElement("info.app.repogit");
this.publicationsRef = getListStringElement("info.app.refpubli");
}
///////////////////////////////////////////////////////////////////////////
// Public methods
/**
* Compute the Short SHA1 using the long one as reference.
*
* @return the 8 first character of the SHA1 or NULL if impossible
*/
public String computeShortSha1() {
return (this.commitSha1 != null && this.commitSha1.length() > 7) ? //
this.commitSha1.substring(0, 8) : //
null;
}
/** {@inheritDoc} */
@Override
public String toString() {
String output = getClass().getName() + "\n";
output += "main:\t" + "\n";
output += "name:\t" + this.getName() + "\n";
output += "artifactId:\t" + this.getArtifactId() + "\n";
output += "short_description:\t" + this.getShortDescription() + "\n";
output += "keywords:\t" + this.getKeywords() + "\n";
output += "long_description:\t" + this.getLongDescription() + "\n";
output += "doc_swagger:\t" + this.getDocSwagger() + "\n";
output += "doc_readthedocs:\t" + this.getDocReadthedocs() + "\n";
output += "status:\t" + this.getStatus().getValue() + "\n";
output += "version:\t" + this.getVersion() + "\n";
output += "shortSha1:\t" + this.getShortCommitSha1() + "\n";
output += "sha1:\t" + this.getCommitSha1() + "\n";
output += "timestamp:\t" + this.getBuildTimestamp() + "\n";
output += "license:\t" + this.getLicense() + "\n";
output += "authors_microservice_code:\t" + this.getAuthorsMicroserviceCode() + "\n";
output += "authors_algorithm_code:\t" + this.getAuthorsAlgorithmCode() + "\n";
output += "is_public:\t" + this.getIsPublic() + "\n";
output += "url_repo_git:\t" + this.getUrlRepoGit() + "\n";
output += "publications_ref:\t" + this.getPublicationsRef() + "\n";
// Return
return output;
}
///////////////////////////////////////////////////////////////////////////
// Static methods
/**
* Get the "info." value matching the given key from the "infos.properties"
* file. Specific to String value.
*
* @param key the "info." property key
* @return the "info." property value
*/
static String getBundleInfosElement(final String key) {
return bundleInfos.getString(key);
}
/**
* Get the "info." value matching the given key from the "infos.properties"
* file. Specific to List< String> value.
*
* @param key the "info." property key
* @return the "info." property value
*/
static List<String> getListStringElement(final String key) {
final var str = bundleInfos.getString(key);
return Arrays.asList(str.split(","));
}
/**
* Get the "info." value matching the given key from the "infos.properties"
* file. Specific to {@link StatusEnum} value.
*
* @return the "info." property value
*/
static StatusEnum getStatusEnumElement() {
final var str = bundleInfos.getString("info.app.status");
return StatusEnum.fromValue(str);
}
}