Skip to content

Commit

Permalink
Support for parameter metaConfig (#162)
Browse files Browse the repository at this point in the history
* [Ili2pgImportSchema] Add support for metaConfig

* [Ili2pgImportSchema] Remove remote dependencies in integration tests

* start-gretl.sh: use tagged version

---------

Co-authored-by: Stefan Ziegler <[email protected]>
  • Loading branch information
webrian and edigonzales authored May 27, 2024
1 parent d36ba0b commit 0bae5a9
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,58 @@ public void schemaImport_Options1_Ok() throws Exception {
}
}

@Test
public void schemaImport_MetaConfigIliData_Ok() throws Exception {
Connection con = null;
try {
GradleVariable[] gvs = {GradleVariable.newGradleProperty(IntegrationTestUtilSql.VARNAME_PG_CON_URI, postgres.getJdbcUrl())};
IntegrationTestUtil.runJob("src/integrationTest/jobs/Ili2pgImportSchema_MetaConfigIliData", gvs);

// check results
con = IntegrationTestUtilSql.connectPG(postgres);
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT setting FROM simple_table_ilidata.t_ili2db_settings WHERE tag ILIKE 'ch.ehi.ili2db.metaConfigFileName'");

if(!rs.next()) {
fail();
}

assertTrue(rs.getString(1).contains("ilidata:metaconfig_simple_table_ini_20240502"));

if(rs.next()) {
fail();
}

} finally {
IntegrationTestUtilSql.closeCon(con);
}
}

@Test
public void schemaImport_MetaConfigFile_Ok() throws Exception {
Connection con = null;
try {
GradleVariable[] gvs = {GradleVariable.newGradleProperty(IntegrationTestUtilSql.VARNAME_PG_CON_URI, postgres.getJdbcUrl())};
IntegrationTestUtil.runJob("src/integrationTest/jobs/Ili2pgImportSchema_MetaConfigFile", gvs);

// check results
con = IntegrationTestUtilSql.connectPG(postgres);
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT setting FROM simple_table_metaconfigfile.t_ili2db_settings WHERE tag ILIKE 'ch.ehi.ili2db.metaConfigFileName'");

if(!rs.next()) {
fail();
}

assertTrue(rs.getString(1).contains("simple_table_ini_20240502.ini"));

if(rs.next()) {
fail();
}

} finally {
IntegrationTestUtilSql.closeCon(con);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
INTERLIS 2.3;

MODEL SimpleTable (de)
AT "mailto:[email protected]"
VERSION "2024-05-02" =

DOMAIN

LKoord = COORD 2460000.000 .. 2870000.000 [INTERLIS.M], 1045000.000 .. 1310000.000 [INTERLIS.M] ,ROTATION 2 -> 1;

TOPIC SimpleTopic =

CLASS Table =
Anzahl : MANDATORY 1 .. 1000;
Bezeichnung : MANDATORY MTEXT*64;
Geometrie : MANDATORY SimpleTable.LKoord;
END Table;

END SimpleTopic;

END SimpleTable.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ch.so.agi.gretl.tasks.*

apply plugin: 'ch.so.agi.gretl'

def GRETLTEST_DBURI = 'gretltest_dburi_pg'
def db_uri = findProperty(GRETLTEST_DBURI) != null ? findProperty(GRETLTEST_DBURI) : 'jdbc:postgresql://localhost:5432/gretl'

def db_user = "ddluser"
def db_pass = "ddluser"

defaultTasks 'ili2pgschemaimport'

task ili2pgschemaimport(type: Ili2pgImportSchema){
database = [db_uri, db_user, db_pass]
dbschema = "simple_table_metaconfigfile"
modeldir = "%ILI_FROM_DB;" + rootProject.projectDir.toString() + ";https://geo.so.ch/models;http://models.interlis.ch"
metaConfig = "simple_table_ini_20240502.ini"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[ch.ehi.ili2db]
models = SimpleTable
beautifyEnumDispName = True
coalesceArray = True
coalesceCatalogueRef = True
coalesceMultiLine = True
coalesceMultiPoint = True
coalesceMultiSurface = True
createBasketCol = False
createEnumTabs = True
createEnumTabsWithId = False
createNumChecks = False
createUnique = False
createFk = True
createFkIdx = True
createMetaInfo = True
createTidCol = True
createTypeConstraint = False
defaultSrsAuth = EPSG
defaultSrsCode = 2056
expandMultilingual = True
smart2Inheritance = True
sqlEnableNull = True
strokeArcs = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
INTERLIS 2.3;

MODEL SimpleTable (de)
AT "mailto:[email protected]"
VERSION "2024-05-02" =

DOMAIN

LKoord = COORD 2460000.000 .. 2870000.000 [INTERLIS.M], 1045000.000 .. 1310000.000 [INTERLIS.M] ,ROTATION 2 -> 1;

TOPIC SimpleTopic =

CLASS Table =
Anzahl : MANDATORY 1 .. 1000;
Bezeichnung : MANDATORY MTEXT*64;
Geometrie : MANDATORY SimpleTable.LKoord;
END Table;

END SimpleTopic;

END SimpleTable.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ch.so.agi.gretl.tasks.*

apply plugin: 'ch.so.agi.gretl'

def GRETLTEST_DBURI = 'gretltest_dburi_pg'
def db_uri = findProperty(GRETLTEST_DBURI) != null ? findProperty(GRETLTEST_DBURI) : 'jdbc:postgresql://localhost:5432/gretl'

def db_user = "ddluser"
def db_pass = "ddluser"

defaultTasks 'ili2pgschemaimport'

task ili2pgschemaimport(type: Ili2pgImportSchema){
database = [db_uri, db_user, db_pass]
dbschema = "simple_table_ilidata"
modeldir = "%ILI_FROM_DB;" + rootProject.projectDir.toString() + ";https://geo.so.ch/models;http://models.interlis.ch"
metaConfig = "ilidata:metaconfig_simple_table_ini_20240502"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[ch.ehi.ili2db]
models = SimpleTable
beautifyEnumDispName = True
coalesceArray = True
coalesceCatalogueRef = True
coalesceMultiLine = True
coalesceMultiPoint = True
coalesceMultiSurface = True
createBasketCol = False
createEnumTabs = True
createEnumTabsWithId = False
createNumChecks = False
createUnique = False
createFk = True
createFkIdx = True
createMetaInfo = True
createTidCol = True
createTypeConstraint = False
defaultSrsAuth = EPSG
defaultSrsCode = 2056
expandMultilingual = True
smart2Inheritance = True
sqlEnableNull = True
strokeArcs = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?><TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<HEADERSECTION SENDER="SOGIS-INTERLIS-REPOSITORY-CREATOR" VERSION="2.3">
<MODELS>
<MODEL NAME="DatasetIdx16" VERSION="2022-10-10" URI="mailto:[email protected]"></MODEL>
</MODELS>
</HEADERSECTION>
<DATASECTION>
<DatasetIdx16.DataIndex BID="b1">
<DatasetIdx16.DataIndex.DatasetMetadata TID="037f8229-ac14-42de-a299-81038f229790">
<id>metaconfig_simple_table_ini_20240502</id>
<version>2024-02-18</version>
<publishingDate>2024-02-18</publishingDate>
<owner>mailto:bjsvwweb</owner>
<title>
<DatasetIdx16.MultilingualText>
<LocalisedText>
<DatasetIdx16.LocalisedText>
<Text>simple_table_ini_20240502</Text>
</DatasetIdx16.LocalisedText>
</LocalisedText>
</DatasetIdx16.MultilingualText>
</title>
<shortDescription>
<DatasetIdx16.MultilingualMText>
<LocalisedText>
<DatasetIdx16.LocalisedMText>
<Text>Metaconfig file for simple_table_ini_20240502 - ('simple_table_ini_20240502', '.ini')</Text>
</DatasetIdx16.LocalisedMText>
</LocalisedText>
</DatasetIdx16.MultilingualMText>
</shortDescription>
<categories>
<DatasetIdx16.Code_>
<value>http://codes.interlis.ch/type/metaconfig</value>
</DatasetIdx16.Code_>
<DatasetIdx16.Code_>
<value>http://codes.interlis.ch/model/SO_AFU_Schutzbauten_20231212</value>
</DatasetIdx16.Code_>
</categories>
<files>
<DatasetIdx16.DataFile>
<fileFormat>text/plain</fileFormat>
<file>
<DatasetIdx16.File>
<path>files/simple_table_ini_20240502.ini</path>
</DatasetIdx16.File>
</file>
</DatasetIdx16.DataFile>
</files>
</DatasetIdx16.DataIndex.DatasetMetadata>
</DatasetIdx16.DataIndex>
</DATASECTION>
</TRANSFER>
Empty file.
21 changes: 17 additions & 4 deletions gretl/src/main/java/ch/so/agi/gretl/tasks/Ili2pgImportSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public class Ili2pgImportSchema extends Ili2pgAbstractTask {
public boolean expandMultilingual = false;
@Input
@Optional
public boolean coalesceJson = false;
public boolean coalesceJson = false;
@Input
@Optional
public boolean coalesceArray = false;
public boolean coalesceArray = false;
@Input
@Optional
public boolean createTypeConstraint = false;
Expand Down Expand Up @@ -158,6 +158,9 @@ public class Ili2pgImportSchema extends Ili2pgAbstractTask {
@Input
@Optional
public boolean createMetaInfo = false;
@Input
@Optional
public String metaConfig = null;

@TaskAction
public void importSchema() {
Expand All @@ -174,12 +177,12 @@ public void importSchema() {
}
}
settings.setXtffile(iliFilename);

if (iliMetaAttrs != null) {
String iliMetaAttrsFilename = this.getProject().file(iliMetaAttrs).getPath();
settings.setIliMetaAttrsFile(iliMetaAttrsFilename);
}

init(settings);
run(function, settings);
}
Expand Down Expand Up @@ -330,5 +333,15 @@ private void init(Config settings) {
if (createMetaInfo) {
settings.setCreateMetaInfo(true);
}
if (metaConfig != null) {
String metaConfigFile = null;
if (metaConfig.startsWith("ilidata")) {
metaConfigFile = metaConfig;
} else {
java.io.File file = this.getProject().file(metaConfig);
metaConfigFile = file.getAbsolutePath();
}
settings.setMetaConfigFile(metaConfigFile);
}
}
}

0 comments on commit 0bae5a9

Please sign in to comment.