Search in sources :

Example 61 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class TransferFromXtf method allReferencesKnownHelper.

private void allReferencesKnownHelper(IomObject iomObj, AttributeDef attr, FixIomObjectExtRefs extref) {
    String attrName = attr.getName();
    if (attr.isDomainBoolean()) {
    } else if (attr.isDomainIli1Date()) {
    } else if (attr.isDomainIli2Date()) {
    } else if (attr.isDomainIli2Time()) {
    } else if (attr.isDomainIli2DateTime()) {
    } else {
        Type type = attr.getDomainResolvingAliases();
        if (type instanceof CompositionType) {
            // enqueue struct values
            int structc = iomObj.getattrvaluecount(attrName);
            for (int structi = 0; structi < structc; structi++) {
                IomObject struct = iomObj.getattrobj(attrName, structi);
                allReferencesKnownHelper(struct, extref);
            }
        } else if (type instanceof PolylineType) {
        } else if (type instanceof SurfaceOrAreaType) {
        } else if (type instanceof CoordType) {
        } else if (type instanceof NumericType) {
        } else if (type instanceof EnumerationType) {
        } else if (type instanceof ReferenceType) {
            IomObject structvalue = iomObj.getattrobj(attrName, 0);
            String refoid = null;
            if (structvalue != null) {
                refoid = structvalue.getobjectrefoid();
            }
            if (refoid != null) {
                Viewable targetClass = ((ReferenceType) type).getReferred();
                if (!oidPool.containsXtfid(Ili2cUtility.getRootViewable(targetClass).getScopedName(null), refoid)) {
                    extref.addFix(structvalue, targetClass);
                }
            }
        } else {
        }
    }
}
Also used : PolylineType(ch.interlis.ili2c.metamodel.PolylineType) NumericType(ch.interlis.ili2c.metamodel.NumericType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) IomObject(ch.interlis.iom.IomObject) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) Viewable(ch.interlis.ili2c.metamodel.Viewable) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 62 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class TranslationTest method exportItf10.

@Test
public void exportItf10() 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/Translation/CreateTableItf10.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/InsertIntoTableItf10.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);
            data = new File("test/data/Translation/ModelBsimple10a-out.itf");
            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) 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) Test(org.junit.Test)

Example 63 with IomObject

use of ch.interlis.iom.IomObject 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)

Example 64 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class Array23Test method exportSmartCustom.

@Test
public void exportSmartCustom() 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/Array/Array23CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Array/Array23InsertIntoTable.sql"));
        File data = new File("test/data/Array/Array23a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("Array23");
        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));
        // check values of array
        {
            IomObject obj0 = objs.get("13");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Auto", obj0.getobjecttag());
            Assert.assertEquals(2, obj0.getattrvaluecount("Farben"));
            Assert.assertEquals("Rot", obj0.getattrobj("Farben", 0).getattrvalue("Wert"));
            Assert.assertEquals("Blau", obj0.getattrobj("Farben", 1).getattrvalue("Wert"));
        }
        {
            IomObject obj0 = objs.get("14");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Auto", obj0.getobjecttag());
            Assert.assertEquals(0, obj0.getattrvaluecount("Farben"));
        }
        {
            IomObject obj0 = objs.get("100");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Datatypes", obj0.getobjecttag());
            Assert.assertEquals(0, obj0.getattrvaluecount("aUuid"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aBoolean"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aTime"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aDate"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aDateTime"));
            Assert.assertEquals(0, obj0.getattrvaluecount("numericInt"));
            Assert.assertEquals(0, obj0.getattrvaluecount("numericDec"));
        }
        {
            IomObject obj0 = objs.get("101");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Datatypes", obj0.getobjecttag());
            Assert.assertEquals(1, obj0.getattrvaluecount("aUuid"));
            Assert.assertEquals("15b6bcce-8772-4595-bf82-f727a665fbf3", obj0.getattrobj("aUuid", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aBoolean"));
            Assert.assertEquals("true", obj0.getattrobj("aBoolean", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aTime"));
            Assert.assertEquals("09:00:00.000", obj0.getattrobj("aTime", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aDate"));
            Assert.assertEquals("2002-09-24", obj0.getattrobj("aDate", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aDateTime"));
            Assert.assertEquals("1900-01-01T12:30:05.000", obj0.getattrobj("aDateTime", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("numericInt"));
            Assert.assertEquals("5", obj0.getattrobj("numericInt", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("numericDec"));
            Assert.assertEquals("6.0", obj0.getattrobj("numericDec", 0).getattrvalue("Value"));
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } 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) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) 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 65 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class ExtendedModel23Test method exportXtfBase.

@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/ExtendedModel/ExtendedModelCreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/ExtendedModel/ExtendedModelInsertIntoTable.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));
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } 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) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) 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)

Aggregations

IomObject (ch.interlis.iom.IomObject)66 EndBasketEvent (ch.interlis.iox.EndBasketEvent)35 EndTransferEvent (ch.interlis.iox.EndTransferEvent)35 IoxEvent (ch.interlis.iox.IoxEvent)35 StartTransferEvent (ch.interlis.iox.StartTransferEvent)35 File (java.io.File)35 HashMap (java.util.HashMap)35 Config (ch.ehi.ili2db.gui.Config)34 ObjectEvent (ch.interlis.iox.ObjectEvent)34 StartBasketEvent (ch.interlis.iox.StartBasketEvent)34 Connection (java.sql.Connection)34 XtfReader (ch.interlis.iom_j.xtf.XtfReader)30 Test (org.junit.Test)29 IoxException (ch.interlis.iox.IoxException)12 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)11 Iom_jObject (ch.interlis.iom_j.Iom_jObject)9 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)8 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)8 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8