Permalink
Browse files

new option --exportModels to export according to a base model (#46)

  • Loading branch information...
claeis committed Oct 24, 2017
1 parent b8f7e3b commit d5585aea95c99e9cc76e5888fbaf60c4a21bbbdb
@@ -17,6 +17,7 @@ LATEST

ili2fgdb 3.10.9 (2017-10-xx)
-----------------------------
- ili2db: new option --exportModels to export according to a base model
- ili2fgdb: fixed schema import of 3D shapes (z-values)
- ili2fgdb: hardcoded XYFalseOrigin values for LV03/LV95

@@ -85,7 +85,8 @@ Das Programm setzt Java 1.6 voraus.
1.5 vorhanden sein. Falls das Interlis Datenmodell INTERLIS.UUIDOID als
OID verwendet, wird die Funktion uuid_generate_v4() verwendet.
Dazu muss die PostgreSQL-Erweiterung uuid-ossp konfiguriert sein
(``CREATE EXTENSION "uuid-ossp";``).
(``CREATE EXTENSION "uuid-ossp";``). Mit der Option ``--setupPgExt``
erstellt ili2pg die fehlenden notwendigen Erweiterungen.

**FileGDB:** Es muss `Visual Studio 2015 C and C++ Runtimes <https://www.microsoft.com/en-us/download/details.aspx?id=48145>`_
installiert sein. Je nach Java Version (Die Java Version ist massgebend, nicht die Windows Version) muss
@@ -549,6 +550,8 @@ Optionen:
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --translation modelT=modelU | Definiert bei übersetzten INTERLIS 1 Modellen (modelT), das Modell der Ursprungssprache (ModelU) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --exportModels modelname | Beim Export werden die Daten gem. dem gegebenen Basis-Modell exportiert. Ohne die Option ``--exportModels`` werden die Daten so wie sie erfasst sind, exportiert. Mehrere Modellnamen können durch Semikolon ‚;‘ getrennt werden. |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --ILIGML20 | Verwendet beim Export eCH-0118-2.0 als Transferformat. |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --log filename | Schreibt die log-Meldungen in eine Datei. |
@@ -0,0 +1,191 @@
package ch.ehi.ili2pg;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import ch.ehi.basics.logging.EhiLogger;
import ch.ehi.ili2db.base.DbNames;
import ch.ehi.ili2db.base.DbUrlConverter;
import ch.ehi.ili2db.base.Ili2db;
import ch.ehi.ili2db.base.Ili2dbException;
import ch.ehi.ili2db.gui.Config;
import ch.ehi.ili2db.mapping.NameMapping;
import ch.ehi.sqlgen.DbUtility;
import ch.ehi.sqlgen.repository.DbTableName;
import ch.interlis.iom.IomObject;
import ch.interlis.iom_j.xtf.XtfReader;
import ch.interlis.iox.EndBasketEvent;
import ch.interlis.iox.EndTransferEvent;
import ch.interlis.iox.IoxEvent;
import ch.interlis.iox.ObjectEvent;
import ch.interlis.iox.StartBasketEvent;
import ch.interlis.iox.StartTransferEvent;

//-Ddburl=jdbc:postgresql:dbname -Ddbusr=usrname -Ddbpwd=1234
public class ExtendedModel23Test {
private static final String DBSCHEMA = "ExtendedModel23x";
String dburl=System.getProperty("dburl");
String dbuser=System.getProperty("dbusr");
String dbpwd=System.getProperty("dbpwd");
Connection jdbcConnection=null;
Statement stmt=null;

public Config initConfig(String xtfFilename,String dbschema,String logfile) {
Config config=new Config();
new ch.ehi.ili2pg.PgMain().initConfig(config);
config.setDburl(dburl);
config.setDbusr(dbuser);
config.setDbpwd(dbpwd);
if(dbschema!=null){
config.setDbschema(dbschema);
}
if(logfile!=null){
config.setLogfile(logfile);
}
config.setXtffile(xtfFilename);
if(xtfFilename!=null && Ili2db.isItfFilename(xtfFilename)){
config.setItfTransferfile(true);
}
return config;
}


@Test
public void importXtf() throws Exception
{
EhiLogger.getInstance().setTraceFilter(false);
Connection jdbcConnection=null;
try{
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
stmt=jdbcConnection.createStatement();
stmt.execute("DROP SCHEMA IF EXISTS "+DBSCHEMA+" CASCADE");
{
{
File data=new File("test/data/ExtendedModel/ExtendedModel1.xtf");
Config config=initConfig(data.getPath(),DBSCHEMA,data.getPath()+".log");
config.setFunction(Config.FC_IMPORT);
config.setModels("BaseModel;ExtendedModel");
config.setCreateFk(config.CREATE_FK_YES);
config.setTidHandling(Config.TID_HANDLING_PROPERTY);
config.setBasketHandling(config.BASKET_HANDLING_READWRITE);
config.setCatalogueRefTrafo(null);
config.setMultiSurfaceTrafo(null);
config.setMultilingualTrafo(null);
config.setInheritanceTrafo(Config.INHERITANCE_TRAFO_SMART1);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config,null);
}
}
}finally{
if(jdbcConnection!=null){
jdbcConnection.close();
}
}
}
@Test
public void exportXtfOriginal() throws Exception
{
Connection jdbcConnection=null;
try{
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
//DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset1NoSmart/CreateTable.sql"));
//DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset1NoSmart/InsertIntoTable.sql"));
File data=new File("test/data/ExtendedModel/ExtendedModel1-out.xtf");
Config config=initConfig(data.getPath(),DBSCHEMA,data.getPath()+".log");
config.setModels("BaseModel;ExtendedModel");
config.setFunction(Config.FC_EXPORT);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config,null);

HashMap<String,IomObject> objs=new HashMap<String,IomObject>();
XtfReader reader=new XtfReader(data);
IoxEvent event=null;
do{
event=reader.read();
if(event instanceof StartTransferEvent){
}else if(event instanceof StartBasketEvent){
}else if(event instanceof ObjectEvent){
IomObject iomObj=((ObjectEvent)event).getIomObject();
if(iomObj.getobjectoid()!=null){
objs.put(iomObj.getobjectoid(), iomObj);
}
}else if(event instanceof EndBasketEvent){
}else if(event instanceof EndTransferEvent){
}
}while(!(event instanceof EndTransferEvent));
{
IomObject obj0 = objs.get("32");
Assert.assertNotNull(obj0);
Assert.assertEquals("ExtendedModel.TestAp.ClassA2", obj0.getobjecttag());
Assert.assertEquals("rot.dunkel", obj0.getattrvalue("farbe"));
Assert.assertEquals("33", obj0.getattrobj("a3",0).getobjectrefoid());
Assert.assertEquals("1.1", obj0.getattrvalue("wert"));
Assert.assertEquals("34", obj0.getattrobj("ap1",0).getobjectrefoid());
}
}finally{
if(jdbcConnection!=null){
jdbcConnection.close();
}
}
}
@Test
public void exportXtfBase() throws Exception
{
Connection jdbcConnection=null;
try{
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
//DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset1NoSmart/CreateTable.sql"));
//DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset1NoSmart/InsertIntoTable.sql"));
File data=new File("test/data/ExtendedModel/ExtendedModel1-out.xtf");
Config config=initConfig(data.getPath(),DBSCHEMA,data.getPath()+".log");
config.setModels("BaseModel;ExtendedModel");
config.setExportModels("BaseModel");
config.setFunction(Config.FC_EXPORT);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config,null);

HashMap<String,IomObject> objs=new HashMap<String,IomObject>();
XtfReader reader=new XtfReader(data);
IoxEvent event=null;
do{
event=reader.read();
if(event instanceof StartTransferEvent){
}else if(event instanceof StartBasketEvent){
}else if(event instanceof ObjectEvent){
IomObject iomObj=((ObjectEvent)event).getIomObject();
if(iomObj.getobjectoid()!=null){
objs.put(iomObj.getobjectoid(), iomObj);
}
}else if(event instanceof EndBasketEvent){
}else if(event instanceof EndTransferEvent){
}
}while(!(event instanceof EndTransferEvent));
{
IomObject obj0 = objs.get("32");
Assert.assertNotNull(obj0);
Assert.assertEquals("BaseModel.TestA.ClassA2", obj0.getobjecttag());
Assert.assertEquals("rot", obj0.getattrvalue("farbe"));
Assert.assertEquals("33", obj0.getattrobj("a3",0).getobjectrefoid());
Assert.assertEquals(null, obj0.getattrvalue("wert"));
Assert.assertEquals(null, obj0.getattrobj("ap1",0));
}
}finally{
if(jdbcConnection!=null){
jdbcConnection.close();
}
}
}

}
@@ -98,6 +98,10 @@ public void domain(String args[]){
argi++;
config.setModels(args[argi]);
argi++;
}else if(arg.equals("--exportModels")){
argi++;
config.setExportModels(args[argi]);
argi++;
}else if(arg.equals("--dataset")){
argi++;
config.setDatasetName(args[argi]);
@@ -387,6 +391,7 @@ public void domain(String args[]){
System.err.println("--createUnique create UNIQUE db constraints.");
System.err.println("--createNumChecks create CHECK db constraints for numeric data types.");
System.err.println("--ILIGML20 use eCH-0118-2.0 as transferformat");
System.err.println("--exportModels modelname export data according to the given base ili-models");
System.err.println("--ver4-translation supports TRANSLATION OF in ili2db 4.x mode (incompatible with ili2db 3.x versions).");
System.err.println("--translation translatedModel=originModel assigns a translated model to its orginal language equivalent.");
System.err.println("--createMetaInfo Create aditional ili-model information.");
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import ch.ehi.basics.logging.EhiLogger;
@@ -61,6 +62,7 @@
import ch.interlis.ili2c.config.Configuration;
import ch.interlis.ili2c.metamodel.Element;
import ch.interlis.ili2c.metamodel.Ili2cMetaAttrs;
import ch.interlis.ili2c.metamodel.Model;
import ch.interlis.ili2c.metamodel.TransferDescription;
import ch.interlis.ilirepository.IliFiles;
import ch.interlis.iom_j.iligml.Iligml10Writer;
@@ -274,7 +276,7 @@ public static void runUpdate(Config config,String appHome,int function)
throw new Ili2dbException("no models given");
}
EhiLogger.traceState("models <"+models+">");
String modelnames[]=models.split(ch.interlis.ili2c.Main.MODELS_SEPARATOR);
String modelnames[]=getModelNames(models);
for(int modeli=0;modeli<modelnames.length;modeli++){
String m=modelnames[modeli];
if(m.equals(XTF)){
@@ -1347,10 +1349,10 @@ public static void runExport(Config config,String appHome)
basketSqlIds=getBasketSqlIdsFromTopic(topicv,modelv,conn,config);
}else{
if(createBasketCol){
String modelnames[]=models.split(ch.interlis.ili2c.Main.MODELS_SEPARATOR);
String[] modelnames = getModelNames(models);
basketSqlIds=getBasketSqlIdsFromModel(modelnames,modelv,conn,config);
}else{
exportModelnames=models.split(ch.interlis.ili2c.Main.MODELS_SEPARATOR);
exportModelnames=getModelNames(models);
for(int modeli=0;modeli<exportModelnames.length;modeli++){
String m=exportModelnames[modeli];
if(m.equals(XTF)){
@@ -1989,6 +1991,10 @@ static private HashSet getModelNames(ArrayList modelv){
}
return ret;
}
public static String[] getModelNames(String models) {
String modelnames[]=models.split(ch.interlis.ili2c.Main.MODELS_SEPARATOR);
return modelnames;
}
static private void writeScript(String filename,Iterator linei)
throws java.io.IOException
{
@@ -2067,5 +2073,20 @@ public static void setNoSmartMapping(Config config) {
config.setMultilingualTrafo(null);
config.setInheritanceTrafo(null);
}
public static List<Model> getModels(String modelNames, TransferDescription td) {
List<Model> models=new ArrayList<Model>();
if(modelNames==null) {
return models;
}
String modelNamev[]=getModelNames(modelNames);
for(String modelName:modelNamev) {
Model model=(Model)td.getElement(Model.class, modelName);
if(model==null) {
throw new IllegalArgumentException("unknown model <"+modelName+">");
}
models.add(model);
}
return models;
}

}
@@ -85,6 +85,7 @@
private String dbschema=null;
private String modeldir;
private String models=null;
private String exportModels=null;
private String datasetName=null;
private String baskets=null;
private String topics=null;
@@ -177,6 +178,12 @@ public String getModels() {
public void setModels(String models) {
this.models = models;
}
public String getExportModels() {
return exportModels;
}
public void setExportModels(String models) {
this.exportModels = models;
}
public String getDatasetName() {
return datasetName;
}
Oops, something went wrong.

0 comments on commit d5585ae

Please sign in to comment.