Search in sources :

Example 6 with ItfReader

use of ch.interlis.iom_j.itf.ItfReader in project ili2db by claeis.

the class TranslationTest method exportItf10lineTable.

// @Test
public void exportItf10lineTable() throws Exception {
    Connection jdbcConnection = null;
    try {
        EhiLogger.getInstance().setTraceFilter(false);
        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/CreateTableItf10LineTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/InsertIntoTableItf10LineTable.sql"));
        {
            File data = new File("test/data/Translation/ModelAsimple10a-out.itf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_EXPORT);
            config.setDatasetName("ModelAsimple10");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
        }
        {
            File data = new File("test/data/Translation/ModelBsimple10a-out.itf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_EXPORT);
            config.setDatasetName("ModelBsimple10");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            HashMap<String, IomObject> objs = new HashMap<String, IomObject>();
            ItfReader reader = new ItfReader(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("21");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("20");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("22");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB2", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("25");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB3", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("26");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB2_geomB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("27");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB3_geomB", obj0.getobjecttag());
            }
        }
    } 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) ItfReader(ch.interlis.iom_j.itf.ItfReader) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File)

Aggregations

ItfReader (ch.interlis.iom_j.itf.ItfReader)6 IomObject (ch.interlis.iom.IomObject)5 EndBasketEvent (ch.interlis.iox.EndBasketEvent)5 EndTransferEvent (ch.interlis.iox.EndTransferEvent)5 IoxEvent (ch.interlis.iox.IoxEvent)5 StartTransferEvent (ch.interlis.iox.StartTransferEvent)5 File (java.io.File)5 Connection (java.sql.Connection)5 HashMap (java.util.HashMap)5 Config (ch.ehi.ili2db.gui.Config)4 ObjectEvent (ch.interlis.iox.ObjectEvent)4 StartBasketEvent (ch.interlis.iox.StartBasketEvent)4 Test (org.junit.Test)3 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 ItfReader2 (ch.interlis.iom_j.itf.ItfReader2)2 IoxException (ch.interlis.iox.IoxException)2 FileNotFoundException (java.io.FileNotFoundException)2 StdLogEvent (ch.ehi.basics.logging.StdLogEvent)1 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)1 SqlColumnConverter (ch.ehi.ili2db.converter.SqlColumnConverter)1