Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
edigonzales committed Jun 30, 2023
1 parent 9d22461 commit 000c40a
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 49 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ch/so/agi/csv2parquet/IoxWkfConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
1 change: 0 additions & 1 deletion src/main/java/ch/so/agi/csv2parquet/Meta2Xtf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
58 changes: 51 additions & 7 deletions src/main/java/ch/so/agi/csv2parquet/SettingsMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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
// ...
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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<String> modelNames = new ArrayList<String>();
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;
}


}
80 changes: 40 additions & 40 deletions src/main/resources/ili/SO_OGD_Metadata_20230629.ili
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -69,34 +69,34 @@ 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;

TOPIC FileFormats =
OID AS SO_OGD_Metadata_20230629.SOOID;

CLASS FileFormat EXTENDS SO_OGD_Metadata_20230629.FileFormat =
UNIQUE name;
UNIQUE Name;
END FileFormat;
END FileFormats;


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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 000c40a

Please sign in to comment.