Refactored code to be properly integrated in a service
This commit is contained in:
parent
c06cd2b81c
commit
074d783c7c
|
@ -1,5 +1,11 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -7,7 +13,11 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.software.export.SoftwareVersionExporter;
|
||||
import org.gcube.common.software.model.ExporterConfig;
|
||||
import org.gcube.common.software.model.GlobalConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionFile;
|
||||
import org.gcube.common.software.model.Variables;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -20,18 +30,20 @@ public class Analyser {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Analyser.class);
|
||||
|
||||
public static final String EXPORT_FILENAME_EXTENSION = ".json";
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
protected File outputDirectory;
|
||||
protected ObjectNode globalConfiguration;
|
||||
protected ArrayNode versionConfigurations;
|
||||
protected ArrayNode elaboratedVersions;
|
||||
|
||||
public Analyser() throws Exception {
|
||||
this.objectMapper = Utils.getObjectMapper();
|
||||
}
|
||||
|
||||
public void setOutputDirectory(File outputDirectory) {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
public ObjectNode getGlobalConfiguration() {
|
||||
return globalConfiguration;
|
||||
}
|
||||
|
@ -47,10 +59,6 @@ public class Analyser {
|
|||
public void setVersionConfigurations(ArrayNode originalVersions) {
|
||||
this.versionConfigurations = originalVersions.deepCopy();
|
||||
}
|
||||
|
||||
public ArrayNode getElaboratedVersions() {
|
||||
return elaboratedVersions;
|
||||
}
|
||||
|
||||
protected SoftwareVersionConfig actualizeSoftwareVersionConfig(JsonNode version) throws Exception {
|
||||
Variables variables = objectMapper.treeToValue(version, Variables.class);
|
||||
|
@ -61,18 +69,61 @@ public class Analyser {
|
|||
missingVariables.toArray(new String[size]).toString());
|
||||
}
|
||||
JsonNode swVersion = objectMapper.convertValue(variables.getProperties(), JsonNode.class);
|
||||
SoftwareVersionConfig softwareVersion = objectMapper.treeToValue(swVersion, SoftwareVersionConfig.class);
|
||||
return softwareVersion;
|
||||
SoftwareVersionConfig softwareVersionConfig = objectMapper.treeToValue(swVersion, SoftwareVersionConfig.class);
|
||||
|
||||
List<SoftwareVersionFile> svfs = softwareVersionConfig.getFiles();
|
||||
for(SoftwareVersionFile svf : svfs) {
|
||||
URL url = svf.getURL();
|
||||
String urlString = variables.replaceAllVariables(url.toString());
|
||||
svf.setURL(new URL(urlString));
|
||||
String desiredName = svf.getDesiredName();
|
||||
desiredName = variables.replaceAllVariables(desiredName);
|
||||
svf.setDesiredName(desiredName);
|
||||
}
|
||||
|
||||
return softwareVersionConfig;
|
||||
}
|
||||
|
||||
public void analyse() throws Exception {
|
||||
protected GlobalConfig actualizeGlobalConfig(JsonNode node) throws Exception {
|
||||
Variables variables = objectMapper.treeToValue(node, Variables.class);
|
||||
variables.parse();
|
||||
JsonNode sc = objectMapper.convertValue(variables.getProperties(), JsonNode.class);
|
||||
return objectMapper.treeToValue(sc, GlobalConfig.class);
|
||||
}
|
||||
|
||||
|
||||
protected void checkExporters(Set<String> availableExporterNames, Set<String> requestedExporterNames) throws Exception {
|
||||
if(!availableExporterNames.containsAll(requestedExporterNames)) {
|
||||
requestedExporterNames.removeAll(availableExporterNames);
|
||||
throw new Exception("The following requested exporters does not exists " + requestedExporterNames);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<File> analyse() throws Exception {
|
||||
|
||||
GlobalConfig globalConfig = actualizeGlobalConfig(globalConfiguration);
|
||||
globalConfig.setOriginalJson(globalConfiguration);
|
||||
|
||||
Map<String, Class<? extends SoftwareVersionExporter>> availableExporters = SoftwareVersionExporter.getAvailableExporters();
|
||||
Map<String,ExporterConfig> requestedExporters = globalConfig.getExporters();
|
||||
checkExporters(availableExporters.keySet(), requestedExporters.keySet());
|
||||
|
||||
if(outputDirectory==null) {
|
||||
outputDirectory = new File(globalConfig.getFileName());
|
||||
}
|
||||
|
||||
if(!outputDirectory.exists()) {
|
||||
Files.createDirectories(outputDirectory.toPath());
|
||||
}
|
||||
|
||||
SoftwareVersionConfig previous = null;
|
||||
int i = 0;
|
||||
|
||||
elaboratedVersions = objectMapper.createArrayNode();
|
||||
|
||||
List<File> outputFiles = new ArrayList<>();
|
||||
|
||||
for(i=0; i<versionConfigurations.size(); i++) {
|
||||
ObjectNode versionConfig = (ObjectNode) versionConfigurations.get(i).deepCopy();
|
||||
elaboratedVersions.set(i, versionConfig);
|
||||
JsonNode actualizedVersionConfig = Utils.merge(globalConfiguration, versionConfig);
|
||||
|
||||
SoftwareVersionConfig softwareVersionConfig = actualizeSoftwareVersionConfig(actualizedVersionConfig);
|
||||
|
@ -80,17 +131,37 @@ public class Analyser {
|
|||
softwareVersionConfig.setPrevious(previous);
|
||||
|
||||
logger.trace("Going to process {}", softwareVersionConfig.getTitle());
|
||||
|
||||
|
||||
SoftwareVersionConfigAnalyser softwareVersionAnalyser = new SoftwareVersionConfigAnalyser(softwareVersionConfig);
|
||||
softwareVersionAnalyser.setFirst(i==0);
|
||||
softwareVersionAnalyser.analyse();
|
||||
elaboratedVersions.set(i, softwareVersionAnalyser.getSoftwareVersionConfig().getOriginalJson());
|
||||
for(String className : requestedExporters.keySet()) {
|
||||
logger.debug("Going to export with {}", className);
|
||||
Class<? extends SoftwareVersionExporter> exporterClass = availableExporters.get(className);
|
||||
|
||||
ExporterConfig exporterConfig = requestedExporters.get(className);
|
||||
|
||||
SoftwareVersionExporter sve = exporterClass.newInstance();
|
||||
sve.setOutputDirectory(outputDirectory);
|
||||
sve.setGlobalConfig(globalConfig);
|
||||
sve.setSoftwareVersionConfig(softwareVersionConfig);
|
||||
sve.setExporterConfig(exporterConfig);
|
||||
sve.setFirst(i==0);
|
||||
|
||||
boolean last = i==(versionConfigurations.size()-1);
|
||||
sve.setLast(last);
|
||||
sve.export();
|
||||
|
||||
if(last) {
|
||||
outputFiles.add(sve.getOutputFile());
|
||||
}
|
||||
}
|
||||
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
|
||||
|
||||
previous = softwareVersionAnalyser.getSoftwareVersionConfig();
|
||||
previous = softwareVersionConfig;
|
||||
}
|
||||
|
||||
}
|
||||
return outputFiles;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
|
||||
|
@ -16,7 +13,6 @@ import org.gcube.common.software.utils.Utils;
|
|||
*/
|
||||
public class AnalyserFactory {
|
||||
|
||||
public static final String EXPORT_FILENAME_PROPERTY_NAME = "export_filename";
|
||||
public static final String EXPORT_FILENAME_EXTENSION = ".json";
|
||||
|
||||
public static final String GLOBAL_PROPERTY_NAME = "global";
|
||||
|
@ -43,39 +39,4 @@ public class AnalyserFactory {
|
|||
return analyser;
|
||||
}
|
||||
|
||||
|
||||
public static ObjectNode getAnalysResultAsObjectNode(Analyser analyser) throws Exception {
|
||||
ObjectMapper objectMapper = Utils.getObjectMapper();
|
||||
ObjectNode toBeExported = objectMapper.createObjectNode();
|
||||
toBeExported.replace(GLOBAL_PROPERTY_NAME, analyser.getGlobalConfiguration());
|
||||
toBeExported.replace(VERSIONS_PROPERTY_NAME, analyser.getElaboratedVersions());
|
||||
return toBeExported;
|
||||
}
|
||||
|
||||
public static String getExportFileName(String fileName) {
|
||||
if(fileName==null || fileName.length()==0) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
return simpleDateFormat.format(Calendar.getInstance().getTime()) + EXPORT_FILENAME_EXTENSION;
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public static void writeAnalysResultToFile(Analyser analyser) throws Exception {
|
||||
JsonNode jsonNode = analyser.getGlobalConfiguration().get(AnalyserFactory.EXPORT_FILENAME_PROPERTY_NAME);
|
||||
String fileName = jsonNode.getNodeType() == JsonNodeType.NULL ? null : jsonNode.asText();
|
||||
fileName = AnalyserFactory.getExportFileName(fileName);
|
||||
File file = new File(fileName);
|
||||
writeAnalysResultToFile(analyser, file);
|
||||
}
|
||||
|
||||
public static void writeAnalysResultToFile(Analyser analyser, File file) throws Exception {
|
||||
ObjectNode toBeExported = getAnalysResultAsObjectNode(analyser);
|
||||
writeObjectNodeToFile(toBeExported, file);
|
||||
}
|
||||
|
||||
|
||||
public static void writeObjectNodeToFile(ObjectNode toBeExported, File file) throws Exception {
|
||||
ObjectMapper objectMapper = Utils.getObjectMapper();
|
||||
objectMapper.writeValue(file, toBeExported);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.software.export.SoftwareVersionExporter;
|
||||
import org.gcube.common.software.model.ExporterConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionFile;
|
||||
import org.gcube.common.software.model.Variables;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareVersionConfigAnalyser {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SoftwareVersionConfigAnalyser.class);
|
||||
|
||||
protected SoftwareVersionConfig softwareVersionConfig;
|
||||
protected boolean first;
|
||||
|
||||
public SoftwareVersionConfigAnalyser(SoftwareVersionConfig softwareVersionConfig) {
|
||||
this.softwareVersionConfig = softwareVersionConfig;
|
||||
}
|
||||
|
||||
public SoftwareVersionConfig getSoftwareVersionConfig() {
|
||||
return softwareVersionConfig;
|
||||
}
|
||||
|
||||
public void setSoftwareVersionConfig(SoftwareVersionConfig softwareVersionConfig) {
|
||||
this.softwareVersionConfig = softwareVersionConfig;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public void analyse() throws Exception {
|
||||
|
||||
Variables variables = softwareVersionConfig.getVariables();
|
||||
List<SoftwareVersionFile> svfs = softwareVersionConfig.getFiles();
|
||||
for(SoftwareVersionFile svf : svfs) {
|
||||
URL url = svf.getURL();
|
||||
String urlString = variables.replaceAllVariables(url.toString());
|
||||
svf.setURL(new URL(urlString));
|
||||
String desiredName = svf.getDesiredName();
|
||||
desiredName = variables.replaceAllVariables(desiredName);
|
||||
svf.setDesiredName(desiredName);
|
||||
}
|
||||
|
||||
Map<String, Class<? extends SoftwareVersionExporter>> availableExporters = SoftwareVersionExporter.getAvailableExporters();
|
||||
Map<String,ExporterConfig> requestedExporters = softwareVersionConfig.getExporters();
|
||||
|
||||
Set<String> availableExporterNames = new HashSet<>(availableExporters.keySet());
|
||||
Set<String> requestedExporterNames = new HashSet<>(availableExporters.keySet());
|
||||
|
||||
if(!availableExporterNames.containsAll(requestedExporterNames)) {
|
||||
requestedExporterNames.removeAll(availableExporterNames);
|
||||
throw new Exception("The following requested availableExporters does not exists " + requestedExporterNames);
|
||||
}
|
||||
|
||||
for(String className : requestedExporters.keySet()) {
|
||||
logger.debug("Going to export with {}", className);
|
||||
Class<? extends SoftwareVersionExporter> exporterClass = availableExporters.get(className);
|
||||
SoftwareVersionExporter sve = exporterClass.newInstance();
|
||||
ExporterConfig exporterConfig = requestedExporters.get(className);
|
||||
sve.setSoftwareVersion(softwareVersionConfig);
|
||||
sve.setExporterConfig(exporterConfig);
|
||||
sve.setFirst(first);
|
||||
sve.export();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
package org.gcube.common.software.export;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.software.export.biblatex.BibLaTeXSoftwareVersionExporter;
|
||||
import org.gcube.common.software.export.zenodo.ZenodoSoftwareVersionExporter;
|
||||
import org.gcube.common.software.model.ExporterConfig;
|
||||
import org.gcube.common.software.model.GlobalConfig;
|
||||
import org.gcube.common.software.model.SoftwareVersionConfig;
|
||||
|
||||
/**
|
||||
|
@ -29,18 +31,37 @@ public abstract class SoftwareVersionExporter {
|
|||
return availableExporters;
|
||||
}
|
||||
|
||||
protected File outputDirectory;
|
||||
protected GlobalConfig globalConfig;
|
||||
protected SoftwareVersionConfig softwareVersionConfig;
|
||||
protected ExporterConfig processorConfig;
|
||||
|
||||
protected boolean first;
|
||||
protected boolean last;
|
||||
|
||||
protected String fileExtension;
|
||||
protected String output;
|
||||
protected final String exportFileNameExtension;
|
||||
|
||||
protected SoftwareVersionExporter(String exportFileNameExtension) {
|
||||
this.exportFileNameExtension = exportFileNameExtension;
|
||||
}
|
||||
|
||||
public void setOutputDirectory(File outputDirectory) {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
public GlobalConfig getGlobalConfig() {
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
public void setGlobalConfig(GlobalConfig globalConfig) {
|
||||
this.globalConfig = globalConfig;
|
||||
}
|
||||
|
||||
public SoftwareVersionConfig getSoftwareVersionConfig() {
|
||||
return softwareVersionConfig;
|
||||
}
|
||||
|
||||
public void setSoftwareVersion(SoftwareVersionConfig softwareVersionConfig) {
|
||||
public void setSoftwareVersionConfig(SoftwareVersionConfig softwareVersionConfig) {
|
||||
this.softwareVersionConfig = softwareVersionConfig;
|
||||
}
|
||||
|
||||
|
@ -52,13 +73,20 @@ public abstract class SoftwareVersionExporter {
|
|||
this.processorConfig = processorConfig;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public void setLast(boolean last) {
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public abstract void export() throws Exception;
|
||||
|
||||
public File getOutputFile() throws Exception {
|
||||
String fileName = globalConfig.getFileName()+exportFileNameExtension;
|
||||
File file = new File(outputDirectory, fileName);
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import org.gcube.common.software.analyser.AnalyserFactory;
|
||||
import org.gcube.common.software.export.SoftwareVersionExporter;
|
||||
import org.gcube.common.software.model.ElaborationType;
|
||||
import org.gcube.common.software.model.Variables;
|
||||
|
@ -29,6 +27,10 @@ public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter {
|
|||
public static final String EXPORT_FILENAME_EXTENSION = ".bib";
|
||||
public static final String TEMPLATE_FILENAME = "biblatex.template";
|
||||
|
||||
public BibLaTeXSoftwareVersionExporter() {
|
||||
super(BibLaTeXSoftwareVersionExporter.EXPORT_FILENAME_EXTENSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export() throws Exception {
|
||||
String title = softwareVersionConfig.getTitle();
|
||||
|
@ -166,18 +168,19 @@ public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter {
|
|||
logger.info("Going to export {} in BibLaTex format.", title);
|
||||
|
||||
String template = getTemplate();
|
||||
output = parseTemplate(template);
|
||||
String output = parseTemplate(template);
|
||||
|
||||
writeToFile();
|
||||
writeToFile(output);
|
||||
}
|
||||
|
||||
protected void writeToFile() throws Exception {
|
||||
File exportFile = getExportFile();
|
||||
if (first && exportFile.exists()) {
|
||||
exportFile.delete();
|
||||
}
|
||||
protected void writeToFile(String output) throws Exception {
|
||||
File exportFile = getOutputFile();
|
||||
|
||||
if (!exportFile.exists()) {
|
||||
if(first) {
|
||||
if (exportFile.exists()) {
|
||||
exportFile.delete();
|
||||
}
|
||||
|
||||
exportFile.createNewFile();
|
||||
}
|
||||
|
||||
|
@ -188,12 +191,4 @@ public class BibLaTeXSoftwareVersionExporter extends SoftwareVersionExporter {
|
|||
bw.close();
|
||||
}
|
||||
|
||||
protected File getExportFile() {
|
||||
JsonNode jsonNode = softwareVersionConfig.getAdditionalProperty(AnalyserFactory.EXPORT_FILENAME_PROPERTY_NAME);
|
||||
String fileName = jsonNode.getNodeType() == JsonNodeType.NULL ? null : jsonNode.asText();
|
||||
fileName = AnalyserFactory.getExportFileName(fileName);
|
||||
File file = new File(fileName + EXPORT_FILENAME_EXTENSION);
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
|||
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.common.software.analyser.AnalyserFactory;
|
||||
import org.gcube.common.software.config.Config;
|
||||
import org.gcube.common.software.export.SoftwareVersionExporter;
|
||||
import org.gcube.common.software.model.ElaborationType;
|
||||
|
@ -48,6 +49,8 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZenodoSoftwareVersionExporter.class);
|
||||
|
||||
public static final String EXPORT_FILENAME_EXTENSION = ".json";
|
||||
|
||||
public static final String GUCBE_ZENODO_SOFTWARE_DEPOSIT = "gCubeSoftwareDeposit";
|
||||
|
||||
public static final String HTML_DESCRIPTION_CONFIG_FIELD_NAME = "html_description";
|
||||
|
@ -90,8 +93,10 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
|
|||
return map;
|
||||
}
|
||||
|
||||
public ZenodoSoftwareVersionExporter() {}
|
||||
|
||||
public ZenodoSoftwareVersionExporter() {
|
||||
super(ZenodoSoftwareVersionExporter.EXPORT_FILENAME_EXTENSION);
|
||||
}
|
||||
|
||||
protected void addFilesToDeposition(List<File> files ) throws Exception {
|
||||
String depositID = getZenodoIDFromDOIURL(softwareVersionConfig.getVersionDOIURL());
|
||||
String newFilePath = DEPOSTION_FILES_PATH.replace(":id", depositID);
|
||||
|
@ -522,7 +527,47 @@ public class ZenodoSoftwareVersionExporter extends SoftwareVersionExporter {
|
|||
}
|
||||
}
|
||||
|
||||
output = Utils.getObjectMapper().writeValueAsString(softwareVersionConfig.getOriginalJson());
|
||||
}
|
||||
|
||||
protected ObjectNode getObjectNode() throws Exception {
|
||||
ObjectMapper objectMapper = Utils.getObjectMapper();
|
||||
ObjectNode toBeExported = objectMapper.createObjectNode();
|
||||
toBeExported.replace(AnalyserFactory.GLOBAL_PROPERTY_NAME, globalConfig.getOriginalJson());
|
||||
ArrayNode array = objectMapper.createArrayNode();
|
||||
SoftwareVersionConfig previous = softwareVersionConfig;
|
||||
while(previous!=null){
|
||||
array.insert(0, softwareVersionConfig.getOriginalJson());
|
||||
previous = softwareVersionConfig.getPrevious();
|
||||
}
|
||||
toBeExported.replace(AnalyserFactory.VERSIONS_PROPERTY_NAME, array);
|
||||
return toBeExported;
|
||||
}
|
||||
|
||||
|
||||
protected void writeObjectNodeToFile(ObjectNode toBeExported, File file) throws Exception {
|
||||
ObjectMapper objectMapper = Utils.getObjectMapper();
|
||||
objectMapper.writeValue(file, toBeExported);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getOutputFile() throws Exception {
|
||||
File exportFile = super.getOutputFile();
|
||||
|
||||
if(last) {
|
||||
|
||||
if(exportFile.exists()) {
|
||||
exportFile.delete();
|
||||
}
|
||||
|
||||
if(!exportFile.exists()) {
|
||||
exportFile.createNewFile();
|
||||
}
|
||||
|
||||
ObjectNode toBeExported = getObjectNode();
|
||||
writeObjectNodeToFile(toBeExported, exportFile);
|
||||
}
|
||||
|
||||
return exportFile;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,30 @@
|
|||
package org.gcube.common.software.model;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class GlobalConfig {
|
||||
|
||||
public static final String EXPORT_FILENAME_PROPERTY_NAME = "export_filename";
|
||||
|
||||
public static final String EXPORTERS_PROPERTY_NAME = "availableExporters";
|
||||
|
||||
@JsonProperty(EXPORTERS_PROPERTY_NAME)
|
||||
protected Map<String,ExporterConfig> exporters;
|
||||
|
||||
protected Map<String, JsonNode> properties;
|
||||
|
||||
@JsonIgnore
|
||||
|
@ -23,6 +34,10 @@ public class GlobalConfig {
|
|||
this.properties = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public Map<String,ExporterConfig> getExporters() {
|
||||
return exporters;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public ObjectNode getOriginalJson() {
|
||||
return originalJson;
|
||||
|
@ -47,5 +62,19 @@ public class GlobalConfig {
|
|||
public JsonNode getProperty(String key) {
|
||||
return this.properties.get(key);
|
||||
}
|
||||
|
||||
protected String getExportFileName(String fileName) {
|
||||
if(fileName==null || fileName.length()==0) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
return simpleDateFormat.format(Calendar.getInstance().getTime());
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
JsonNode jsonNode = getProperty(EXPORT_FILENAME_PROPERTY_NAME);
|
||||
String fileName = jsonNode.getNodeType() == JsonNodeType.NULL ? null : jsonNode.asText();
|
||||
return fileName = getExportFileName(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ public class SoftwareVersionConfig {
|
|||
public static final String CONCEPT_DOI_URL_PROPERTY_NAME = "concept_doi_url";
|
||||
public static final String VERSION_DOI_URL_PROPERTY_NAME = "version_doi_url";
|
||||
public static final String GRANTS_PROPERTY_NAME = "grants";
|
||||
public static final String EXPORTERS_PROPERTY_NAME = "availableExporters";
|
||||
|
||||
@JsonIgnore
|
||||
protected SoftwareVersionConfig previous;
|
||||
|
@ -81,8 +80,7 @@ public class SoftwareVersionConfig {
|
|||
@JsonProperty(GRANTS_PROPERTY_NAME)
|
||||
protected JsonNode grants;
|
||||
|
||||
@JsonProperty(EXPORTERS_PROPERTY_NAME)
|
||||
protected Map<String,ExporterConfig> exporters;
|
||||
|
||||
|
||||
protected Map<String, JsonNode> additionalProperties;
|
||||
|
||||
|
@ -187,10 +185,6 @@ public class SoftwareVersionConfig {
|
|||
return grants;
|
||||
}
|
||||
|
||||
public Map<String,ExporterConfig> getExporters() {
|
||||
return exporters;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, JsonNode> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
package org.gcube.common.software.analyser;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.software.utils.FileUtils;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SoftwareConceptAnalyserTest {
|
||||
public class AnalyserTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Analyser.class);
|
||||
|
||||
public static final String FILENAME = "gcat-test-sandbox.json";
|
||||
// public static final String FILENAME = "gcat-from-scratch.json";
|
||||
// public static final String FILENAME = "exported-gcat-from-scratch.json";
|
||||
|
@ -18,9 +23,9 @@ public class SoftwareConceptAnalyserTest {
|
|||
public void testUsingTestFile() throws Exception {
|
||||
File file = FileUtils.getFileFromFilename(FILENAME);
|
||||
Analyser analyser = AnalyserFactory.getAnalyser(file);
|
||||
analyser.analyse();
|
||||
File exportFile = new File("exported-"+file.getName());
|
||||
AnalyserFactory.writeAnalysResultToFile(analyser, exportFile);
|
||||
// analyser.setOutputDirectory(file.getParentFile());
|
||||
List<File> files =analyser.analyse();
|
||||
logger.info("Generated the following files {}", files);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.software.analyser.SoftwareConceptAnalyserTest;
|
||||
import org.gcube.common.software.analyser.AnalyserTest;
|
||||
import org.gcube.common.software.utils.FileUtils;
|
||||
import org.gcube.common.software.utils.Utils;
|
||||
import org.junit.Test;
|
||||
|
@ -28,7 +28,7 @@ public class VariablesTest {
|
|||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
File file = FileUtils.getFileFromFilename(SoftwareConceptAnalyserTest.FILENAME);
|
||||
File file = FileUtils.getFileFromFilename(AnalyserTest.FILENAME);
|
||||
ObjectMapper objectMapper = Utils.getObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(file);
|
||||
JsonNode concept = jsonNode.get("concept");
|
||||
|
|
|
@ -128,6 +128,7 @@
|
|||
"url": "https://cordis.europa.eu/project/id/871042"
|
||||
}
|
||||
],
|
||||
"export_filename" = "{{name}}",
|
||||
"exporters": {
|
||||
"ZenodoSoftwareVersionExporter": {
|
||||
"elaboration": "NONE",
|
||||
|
|
|
@ -129,6 +129,7 @@
|
|||
"url": "https://cordis.europa.eu/project/id/871042"
|
||||
}
|
||||
],
|
||||
"export_filename" = "{{name}}",
|
||||
"exporters": {
|
||||
"ZenodoSoftwareVersionExporter": {
|
||||
"elaboration": "NONE",
|
||||
|
|
Loading…
Reference in New Issue