76 lines
2.4 KiB
Java
76 lines
2.4 KiB
Java
package org.gcube.common.software.analyser;
|
|
|
|
import java.net.URL;
|
|
import java.util.List;
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import org.gcube.common.software.model.SoftwareVersion;
|
|
import org.gcube.common.software.model.SoftwareVersionFile;
|
|
import org.gcube.common.software.model.Variables;
|
|
import org.gcube.common.software.process.export.SoftwareVersionExporter;
|
|
import org.gcube.common.software.process.publish.SoftwareVersionPublisher;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class SoftwareVersionAnalyser {
|
|
|
|
protected JsonNode originalJson;
|
|
protected SoftwareVersion softwareVersion;
|
|
protected boolean first;
|
|
|
|
public SoftwareVersionAnalyser(SoftwareVersion softwareVersion) {
|
|
this.softwareVersion = softwareVersion;
|
|
}
|
|
|
|
public boolean isFirst() {
|
|
return first;
|
|
}
|
|
|
|
public void setFirst(boolean first) {
|
|
this.first = first;
|
|
}
|
|
|
|
public void setOriginalJson(JsonNode jsonNode) {
|
|
this.originalJson = jsonNode;
|
|
}
|
|
|
|
public void analyse() throws Exception {
|
|
Variables variables = softwareVersion.getVariables();
|
|
List<SoftwareVersionFile> svfs = softwareVersion.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);
|
|
}
|
|
|
|
ObjectNode publishers = (ObjectNode) originalJson.get(SoftwareConceptAnalyser.PUBLISHERS_PROPERTY_NAME).deepCopy();
|
|
List<SoftwareVersionPublisher> svps = SoftwareVersionPublisher.getPublishers();
|
|
for(SoftwareVersionPublisher svp: svps) {
|
|
JsonNode conf = publishers.get(svp.getClass().getSimpleName());
|
|
svp.setSpecificConfiguration(conf);
|
|
svp.setSoftwareVersion(softwareVersion);
|
|
svp.setFirst(first);
|
|
svp.publish();
|
|
}
|
|
|
|
ObjectNode exporters = (ObjectNode) originalJson.get(SoftwareConceptAnalyser.EXPORTERS_PROPERTY_NAME).deepCopy();
|
|
List<SoftwareVersionExporter> sves = SoftwareVersionExporter.getExporters();
|
|
for(SoftwareVersionExporter sve: sves) {
|
|
JsonNode conf = publishers.get(exporters.getClass().getSimpleName());
|
|
sve.setSpecificConfiguration(conf);
|
|
sve.setSoftwareVersion(softwareVersion);
|
|
sve.setFirst(first);
|
|
sve.export();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|