Commit 72577a25 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added possibility to load XML models also from config folder

parent 3d3a99b0
...@@ -53,12 +53,26 @@ public class SchemaModels { ...@@ -53,12 +53,26 @@ public class SchemaModels {
String[] tapSchemaModelFiles = getXMLModelFileNames(properties, "tap_schema_models"); String[] tapSchemaModelFiles = getXMLModelFileNames(properties, "tap_schema_models");
String[] ivoaModelFiles = getXMLModelFileNames(properties, "ivoa_schema_models"); String[] ivoaModelFiles = getXMLModelFileNames(properties, "ivoa_schema_models");
TAP_SCHEMA_MODELS = new XMLModelsLoader(tapSchemaModelFiles).load(); TAP_SCHEMA_MODELS = new XMLModelsLoader(tapSchemaModelFiles, getTapSchemaModelsFromExternalFolder()).load();
IVOA_SCHEMA_MODELS = new XMLModelsLoader(ivoaModelFiles).load(); IVOA_SCHEMA_MODELS = new XMLModelsLoader(ivoaModelFiles).load();
} catch (IOException e) { } catch (IOException e) {
throw new ExceptionInInitializerError(e); throw new ExceptionInInitializerError(e);
} }
} }
private static File[] getTapSchemaModelsFromExternalFolder() {
String tasmanConfigFolder = System.getenv("TASMAN_CONFIG_FOLDER");
if (tasmanConfigFolder != null) {
File tapSchemaModelsExternalFolder = new File(tasmanConfigFolder).toPath().resolve("schema_definition").toFile();
if (tapSchemaModelsExternalFolder.exists()) {
return tapSchemaModelsExternalFolder.listFiles();
}
}
return new File[]{};
}
private static Properties getCoreProperties() throws IOException { private static Properties getCoreProperties() throws IOException {
Properties props = new Properties(); Properties props = new Properties();
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
*/ */
package it.inaf.ia2.tsm.model; package it.inaf.ia2.tsm.model;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -52,13 +54,19 @@ public class XMLModelsLoader { ...@@ -52,13 +54,19 @@ public class XMLModelsLoader {
private static final Logger LOG = LoggerFactory.getLogger(XMLModelsLoader.class); private static final Logger LOG = LoggerFactory.getLogger(XMLModelsLoader.class);
private final String[] xmlModelFileNames; private final String[] xmlModelFileNames;
private final File[] xmlModelExternalFiles;
// key: doc version // key: doc version
private final Map<String, Document> documents; private final Map<String, Document> documents;
private final Map<String, String> inheritanceGraph; private final Map<String, String> inheritanceGraph;
private final Map<Integer, List<Document>> inheritanceLevels; private final Map<Integer, List<Document>> inheritanceLevels;
public XMLModelsLoader(String[] xmlModelFileNames) { public XMLModelsLoader(String[] xmlModelFileNames) {
this(xmlModelFileNames, new File[]{});
}
public XMLModelsLoader(String[] xmlModelFileNames, File[] xmlModelExternalFiles) {
this.xmlModelFileNames = xmlModelFileNames; this.xmlModelFileNames = xmlModelFileNames;
this.xmlModelExternalFiles = xmlModelExternalFiles;
this.documents = new HashMap<>(); this.documents = new HashMap<>();
inheritanceGraph = new HashMap<>(); inheritanceGraph = new HashMap<>();
inheritanceLevels = new HashMap<>(); inheritanceLevels = new HashMap<>();
...@@ -110,19 +118,29 @@ public class XMLModelsLoader { ...@@ -110,19 +118,29 @@ public class XMLModelsLoader {
for (String xmlModelFileName : xmlModelFileNames) { for (String xmlModelFileName : xmlModelFileNames) {
try (InputStream in = classLoader.getResourceAsStream(xmlModelFileName)) { try (InputStream in = classLoader.getResourceAsStream(xmlModelFileName)) {
Document doc = builder.parse(in); loadFile(builder, in);
Element root = doc.getDocumentElement(); }
String version = root.getAttribute("version"); }
// TODO: XML Model validation
for (File xmlModelExternalFile : xmlModelExternalFiles) {
// Documents loaded in a single XMLModelsLoader instance must try (FileInputStream fis = new FileInputStream(xmlModelExternalFile)) {
// have different versions. loadFile(builder, fis);
assert documents.get(version) == null;
documents.put(version, doc);
} }
} }
} }
private void loadFile(DocumentBuilder builder, InputStream in) throws IOException, SAXException {
Document doc = builder.parse(in);
Element root = doc.getDocumentElement();
String version = root.getAttribute("version");
// TODO: XML Model validation
// Documents loaded in a single XMLModelsLoader instance must
// have different versions.
assert documents.get(version) == null;
documents.put(version, doc);
}
private void buildInheritanceGraph() { private void buildInheritanceGraph() {
for (Document document : documents.values()) { for (Document document : documents.values()) {
Element root = document.getDocumentElement(); Element root = document.getDocumentElement();
......
...@@ -110,8 +110,8 @@ cd - 1> /dev/null ...@@ -110,8 +110,8 @@ cd - 1> /dev/null
# Creating executable # Creating executable
tasman_bin="$install_dir""tasman" tasman_bin="$install_dir""tasman"
echo "#!/bin/bash" > $tasman_bin echo "#!/bin/sh" > $tasman_bin
echo "java -jar $install_dir""tasman-embedded.jar \$1" >> $tasman_bin echo "TASMAN_CONFIG_FOLDER=$tasman_config_dir java -jar $install_dir""tasman-embedded.jar \$1" >> $tasman_bin
chmod +x $tasman_bin chmod +x $tasman_bin
# Creating executable symbolic link # Creating executable symbolic link
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment