Search in sources :

Example 16 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class Dataset23Smart1Test method exportSmart1.

@Test
public void exportSmart1() 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/Dataset23Smart1/CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset23Smart1/InsertIntoTable.sql"));
        File data = new File("test/data/Dataset23Smart1/Dataset1-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setDatasetName(DATASETNAME_A);
        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("4");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Dataset1.TestA.ClassA1", obj0.getobjecttag());
            Assert.assertEquals("a1", obj0.getattrvalue("attr1"));
        }
        {
            IomObject obj0 = objs.get("6");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Dataset1.TestA.ClassA1b", obj0.getobjecttag());
            Assert.assertEquals("a1", obj0.getattrvalue("attr1"));
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) Test(org.junit.Test)

Example 17 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class Dataset23NoSmartTest method exportDataset.

@Test
public void exportDataset() 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/Dataset23NoSmart/CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset23NoSmart/InsertIntoTable.sql"));
        File data = new File("test/data/Dataset23NoSmart/Dataset1-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setDatasetName(DATASETNAME_A);
        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("6");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Dataset1.TestA.ClassA1b", obj0.getobjecttag());
            Assert.assertEquals("a1", obj0.getattrvalue("attr1"));
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) Test(org.junit.Test)

Example 18 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class Datatypes23Test method exportXtfSurface.

@Test
public void exportXtfSurface() 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(CREATETABLES_SURFACES));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(INSERTINTOTABLES_SURFACES));
        File data = new File(TEST_OUT + "Datatypes23Surface-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        config.setModels(DBSCHEMA);
        config.setBasketHandling(null);
        // config.setValidation(false);
        Ili2db.readSettingsFromDb(config);
        try {
            Ili2db.run(config, null);
        } catch (Exception ex) {
            EhiLogger.logError(ex);
            Assert.fail();
        }
        // tests
        // read objects of db and write objectValue to HashMap
        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 obj1 = objs.get("Surface2.1");
            Assert.assertNotNull(obj1);
            Assert.assertEquals("Datatypes23.Topic.Surface2", obj1.getobjecttag());
            IomObject surface = obj1.getattrobj("surfacearcs2d", 0);
            Assert.assertEquals("MULTISURFACE {surface SURFACE {boundary [BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460001.0, C2 1045001.0}, COORD {C1 2460020.0, C2 1045015.0}, ARC {A1 2460010.0, A2 1045018.0, C1 2460001.0, C2 1045015.0}, COORD {C1 2460001.0, C2 1045001.0}]}}}, BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460005.0, C2 1045005.0}, COORD {C1 2460010.0, C2 1045010.0}, ARC {A1 2460007.0, A2 1045009.0, C1 2460005.0, C2 1045010.0}, COORD {C1 2460005.0, C2 1045005.0}]}}}]}}", surface.toString());
        }
    } catch (SQLException e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) IoxException(ch.interlis.iox.IoxException) Test(org.junit.Test)

Example 19 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class TranslationTest method exportXtf23.

@Test
public void exportXtf23() throws Exception {
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        Statement stmt = jdbcConnection.createStatement();
        stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/CreateTableXtf23.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/InsertIntoTableXtf23.sql"));
        EhiLogger.getInstance().setTraceFilter(false);
        File data = new File("test/data/Translation/EnumOka-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        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(null);
        config.setDatasetName("EnumOka");
        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("o1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("EnumOkA.TopicA.ClassA", obj0.getobjecttag());
        }
        {
            IomObject obj0 = objs.get("o2");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("EnumOkA.TopicA.ClassA", obj0.getobjecttag());
            Assert.assertEquals("a2.a21", obj0.getattrvalue("attrA"));
        }
        {
            IomObject obj0 = objs.get("x1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("EnumOkB.TopicB.ClassB", obj0.getobjecttag());
        }
        {
            IomObject obj0 = objs.get("x2");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("EnumOkB.TopicB.ClassB", obj0.getobjecttag());
            Assert.assertEquals("b2.b21", obj0.getattrvalue("attrB"));
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) Test(org.junit.Test)

Example 20 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class InheritanceNoSmartTest method exportNoSmart.

@Test
public void exportNoSmart() throws Exception {
    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");
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceNoSmart/CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceNoSmart/InsertIntoTable.sql"));
        File data = new File("test/data/InheritanceNoSmart/Inheritance1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("Inheritance1");
        config.setFunction(Config.FC_EXPORT);
        Ili2db.readSettingsFromDb(config);
        Ili2db.run(config, null);
        // read objects of db and write objectValue to HashMap
        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 obj1 = objs.get("17");
            Assert.assertNotNull(obj1);
            Assert.assertEquals("Inheritance1.TestB.ClassB1", obj1.getobjecttag());
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("x2", obj1.getattrobj("s3b", 0).getattrvalue("attrB3b"));
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("b2", obj1.getattrobj("s2", 0).getattrvalue("attrB2b"));
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("b3a", obj1.getattrobj("s3a", 0).getattrvalue("attrB3"));
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("b1", obj1.getattrobj("s1", 0).getattrvalue("attrB1"));
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) Test(org.junit.Test)

Aggregations

XtfReader (ch.interlis.iom_j.xtf.XtfReader)31 Connection (java.sql.Connection)31 HashMap (java.util.HashMap)31 Config (ch.ehi.ili2db.gui.Config)30 IomObject (ch.interlis.iom.IomObject)30 EndBasketEvent (ch.interlis.iox.EndBasketEvent)30 EndTransferEvent (ch.interlis.iox.EndTransferEvent)30 IoxEvent (ch.interlis.iox.IoxEvent)30 ObjectEvent (ch.interlis.iox.ObjectEvent)30 StartBasketEvent (ch.interlis.iox.StartBasketEvent)30 StartTransferEvent (ch.interlis.iox.StartTransferEvent)30 File (java.io.File)30 Test (org.junit.Test)25 IoxException (ch.interlis.iox.IoxException)8 SQLException (java.sql.SQLException)5 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)4 StdLogEvent (ch.ehi.basics.logging.StdLogEvent)1 ConverterException (ch.ehi.ili2db.converter.ConverterException)1 SqlColumnConverter (ch.ehi.ili2db.converter.SqlColumnConverter)1 CustomMapping (ch.ehi.ili2db.fromili.CustomMapping)1