diff --git a/src/main/java/ch/so/agi/csv2parquet/IoxWkfConfig.java b/src/main/java/ch/so/agi/csv2parquet/IoxWkfConfig.java index eef9874..1c7e9ef 100644 --- a/src/main/java/ch/so/agi/csv2parquet/IoxWkfConfig.java +++ b/src/main/java/ch/so/agi/csv2parquet/IoxWkfConfig.java @@ -35,5 +35,8 @@ private IoxWkfConfig() {} public final static String INI_VALUESEPARATOR = "valueSeparator"; public final static String INI_ENCODING = "encoding"; public final static String INI_MODELS = "models"; + public final static String SETTING_TRANSFERDESCRIPTION = "transferDescription"; + public final static String INI_META_TITLE = "title"; + public final static String INI_META_DESCRIPTION = "description"; } \ No newline at end of file diff --git a/src/main/java/ch/so/agi/csv2parquet/Meta2Xtf.java b/src/main/java/ch/so/agi/csv2parquet/Meta2Xtf.java index 55177ef..8651235 100644 --- a/src/main/java/ch/so/agi/csv2parquet/Meta2Xtf.java +++ b/src/main/java/ch/so/agi/csv2parquet/Meta2Xtf.java @@ -14,7 +14,6 @@ public class Meta2Xtf { // TODO: // - - // Wenn wir eine Config-Datei haben, wird sie bereits geparsed. Man muss einfach // noch mehr auslesen und in die Settings schreiben. Und ein paar Konstanten mehr. // Meta2Xtf bedingt zwingend ein Modell (nicht bloss eine Config-Datei) -> if(). diff --git a/src/main/java/ch/so/agi/csv2parquet/SettingsMapper.java b/src/main/java/ch/so/agi/csv2parquet/SettingsMapper.java index 3c12bae..b4a708f 100644 --- a/src/main/java/ch/so/agi/csv2parquet/SettingsMapper.java +++ b/src/main/java/ch/so/agi/csv2parquet/SettingsMapper.java @@ -2,6 +2,8 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; import java.util.Set; import org.interlis2.validator.Validator; @@ -10,11 +12,16 @@ import org.tomlj.TomlTable; import ch.ehi.basics.settings.Settings; +import ch.interlis.ili2c.Ili2c; +import ch.interlis.ili2c.Ili2cException; +import ch.interlis.ili2c.config.Configuration; +import ch.interlis.ili2c.metamodel.TransferDescription; +import ch.interlis.ilirepository.IliManager; import ch.interlis.iom_j.csv.CsvReader; public class SettingsMapper { - public static Settings run(File configFile, String identifier) throws IOException { + public static Settings run(File configFile, String identifier) throws IOException, Ili2cException { Settings settings = new Settings(); TomlParseResult tomlContent = Toml.parse(configFile.toPath()); @@ -25,10 +32,18 @@ public static Settings run(File configFile, String identifier) throws IOExceptio setSettingsFromTomlTable(tomlContent, settings); } else { String parentIdentifier = identifier.substring(0, identifier.lastIndexOf(".")); - TomlTable parentTable = tomlContent.getTable(parentIdentifier); + + TomlTable resourceTable = tomlContent.getTable(identifier); + if (resourceTable != null) { + setSettingsFromTomlTable(resourceTable, settings); + } // TODO wird erst interessant, wenn wir neben tool-config-Daten auch Metadatenauslesen. + + // In der Methode wird also immer der identifier (oder falls null irgendeins) verwendet. + // Falls ein parentTable vorhanden ist, muss man diesen noch behandeln. Gewisse Teile + // werden überschrieben? / verschoben? if (parentTable != null) { // Theme title von parent // ... @@ -37,11 +52,13 @@ public static Settings run(File configFile, String identifier) throws IOExceptio // ... } - TomlTable resourceTable = tomlContent.getTable(identifier); - if (resourceTable != null) { - setSettingsFromTomlTable(resourceTable, settings); - } } + + if (settings.getValue(Validator.SETTING_MODELNAMES) != null) { + TransferDescription td = getTransferDescriptionFromModelName(settings.getValue(Validator.SETTING_MODELNAMES), configFile.getParentFile().toPath()); + settings.setTransientObject(IoxWkfConfig.SETTING_TRANSFERDESCRIPTION, td); + } + return settings; } @@ -73,7 +90,7 @@ private static void setSettingsFromTomlTable(TomlTable tomlTable, Settings setti if (key.endsWith(IoxWkfConfig.INI_MODELS)) { String models = tomlTable.getString(key); if (models != null) { - settings.setValue(Validator.SETTING_MODELNAMES, models); + settings.setValue(Validator.SETTING_MODELNAMES, models); } } @@ -83,7 +100,34 @@ private static void setSettingsFromTomlTable(TomlTable tomlTable, Settings setti settings.setValue(CsvReader.ENCODING, encoding); } } + + if (key.endsWith(IoxWkfConfig.INI_META_TITLE)) { + String title = tomlTable.getString(key); + if (title != null) { + settings.setValue(IoxWkfConfig.INI_META_TITLE, title); + } + } + + //... } } + private static TransferDescription getTransferDescriptionFromModelName(String iliModelName, Path additionalRepository) throws Ili2cException { + IliManager manager = new IliManager(); + String ilidirs = IoxWkfConfig.SETTING_ILIDIRS_DEFAULT + additionalRepository; + String repositories[] = ilidirs.split(";"); + manager.setRepositories(repositories); + ArrayList modelNames = new ArrayList(); + modelNames.add(iliModelName); + Configuration config = manager.getConfig(modelNames, 2.3); + TransferDescription td = Ili2c.runCompiler(config); + + if (td == null) { + throw new IllegalArgumentException("INTERLIS compiler failed"); // TODO: can this be tested? + } + + return td; + } + + } diff --git a/src/main/resources/ili/SO_OGD_Metadata_20230629.ili b/src/main/resources/ili/SO_OGD_Metadata_20230629.ili index 822add1..5b9ec49 100644 --- a/src/main/resources/ili/SO_OGD_Metadata_20230629.ili +++ b/src/main/resources/ili/SO_OGD_Metadata_20230629.ili @@ -17,50 +17,50 @@ VERSION "2023-06-09" = SOOID = OID TEXT*255; STRUCTURE ModelLink = - name : MANDATORY TEXT; !! Name or Namespace - locationHint : URI; !! repo - versionHint : TEXT; + Name : MANDATORY TEXT; !! Name or Namespace + LocationHint : URI; !! repo + VersionHint : TEXT; END ModelLink; STRUCTURE Office_ = - agencyName : TEXT; - abbreviation : TEXT; - division : TEXT; - officeAtWeb : URI; - email : URI; - phone : TEXT; + AgencyName : TEXT; + Abbreviation : TEXT; + Division : TEXT; + OfficeAtWeb : URI; + Email : URI; + Phone : TEXT; END Office_; STRUCTURE FileFormat = - name: MANDATORY TEXT; - abbreviation: MANDATORY TEXT; - mimeType: MANDATORY TEXT; - extension: MANDATORY TEXT; + Name: MANDATORY TEXT; + Abbreviation: MANDATORY TEXT; + MimeType: MANDATORY TEXT; + Extension: MANDATORY TEXT; END FileFormat; STRUCTURE AttributeDescription = - name : TEXT; !! so wie er im Modell steht - description : MTEXT; - dataType : TEXT; + Name : TEXT; !! so wie er im Modell steht + Description : MTEXT; + DataType : TEXT; isMandatory : BOOLEAN; END AttributeDescription; STRUCTURE ClassDescription = - name : TEXT; !! entspricht originalem Klassennamen. - title : TEXT; !! mittels ilidoc - description : MTEXT; - attributeDescription : BAG {0..*} OF SO_OGD_Metadata_20230629.AttributeDescription; + Name : TEXT; !! entspricht originalem Klassennamen. + Title : TEXT; !! mittels ilidoc + Description : MTEXT; + AttributeDescription : BAG {0..*} OF SO_OGD_Metadata_20230629.AttributeDescription; END ClassDescription; STRUCTURE Resource = - identifier : MANDATORY TEXT; - title : MANDATORY TEXT; - description : TEXT; - model : SO_OGD_Metadata_20230629.ModelLink; - configId : TEXT; !! in ilidata.xml + Identifier : MANDATORY TEXT; + Title : MANDATORY TEXT; + Description : TEXT; + Model : SO_OGD_Metadata_20230629.ModelLink; + ConfigId : TEXT; !! in ilidata.xml lastPublishingDate : MANDATORY FORMAT INTERLIS.XMLDate "1990-1-1" .. "2100-12-31"; - classDescription : BAG {0..*} OF SO_OGD_Metadata_20230629.ClassDescription; !! Kommt darauf an, ob auch "komplexe" Strukturen möglich/erlaubt sind. - fileFormats : BAG {1..*} OF SO_OGD_Metadata_20230629.FileFormat; + ClassDescription : BAG {0..*} OF SO_OGD_Metadata_20230629.ClassDescription; !! Kommt darauf an, ob auch "komplexe" Strukturen möglich/erlaubt sind. + FileFormats : BAG {1..*} OF SO_OGD_Metadata_20230629.FileFormat; !!rights : MANDATORY TEXT; END Resource; @@ -69,7 +69,7 @@ VERSION "2023-06-09" = OID AS SO_OGD_Metadata_20230629.SOOID; CLASS Office EXTENDS SO_OGD_Metadata_20230629.Office_ = - UNIQUE abbreviation, division; + UNIQUE Abbreviation, Division; END Office; END Offices; @@ -77,7 +77,7 @@ VERSION "2023-06-09" = OID AS SO_OGD_Metadata_20230629.SOOID; CLASS FileFormat EXTENDS SO_OGD_Metadata_20230629.FileFormat = - UNIQUE name; + UNIQUE Name; END FileFormat; END FileFormats; @@ -85,18 +85,18 @@ VERSION "2023-06-09" = TOPIC Datasets = CLASS Dataset = - identifier : MANDATORY TEXT; - title : MANDATORY TEXT; - description : MTEXT; + Identifier : MANDATORY TEXT; + Title : MANDATORY TEXT; + Description : MTEXT; furtherInformation : URI; - publisher : MANDATORY SO_OGD_Metadata_20230629.Office_; - theme : TEXT; - keywords : TEXT; - startDate : MANDATORY FORMAT INTERLIS.XMLDate "1990-1-1" .. "2100-12-31"; - endDate : FORMAT INTERLIS.XMLDate "1990-1-1" .. "2100-12-31"; - resources : BAG {1..*} OF SO_OGD_Metadata_20230629.Resource; - - UNIQUE identifier; + Publisher : MANDATORY SO_OGD_Metadata_20230629.Office_; + Theme : TEXT; + Keywords : TEXT; + StartDate : MANDATORY FORMAT INTERLIS.XMLDate "1990-1-1" .. "2100-12-31"; + EndDate : FORMAT INTERLIS.XMLDate "1990-1-1" .. "2100-12-31"; + Resources : BAG {1..*} OF SO_OGD_Metadata_20230629.Resource; + + UNIQUE Identifier; !! TODO: resource identifier muss auch unique sein. END Dataset; diff --git a/src/test/data/amtliche_vermessung_statistik/ch.so.agi.amtliche_vermessung_statistik.toml b/src/test/data/amtliche_vermessung_statistik/ch.so.agi.amtliche_vermessung_statistik.toml index c857cb7..e6f9ced 100644 --- a/src/test/data/amtliche_vermessung_statistik/ch.so.agi.amtliche_vermessung_statistik.toml +++ b/src/test/data/amtliche_vermessung_statistik/ch.so.agi.amtliche_vermessung_statistik.toml @@ -1,5 +1,5 @@ [ch.so.agi.amtliche_vermessung_statistik] -title="Ich bin ein Titel" +title="Ich bin ein Thema-Titel" description="Ich bin eine Beschreibung" [ch.so.agi.amtliche_vermessung_statistik.umsatz]