diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 26e8d525..45544a0c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -16,6 +16,7 @@ LATEST - import fails with --noSmartMapping (#381) - ili2gpkg: failed to import MultiPoint - ili2pg-4.4.1 failed to build polygons (#376) +- NPE with schema import and --createMetaInfo and a VIEW with implicit typed attributes (#385) - iox-ili-1.21.5-SNAPSHOT ili2db 4.4.5 (2020-12-28) diff --git a/ili2pg/test/java/ch/ehi/ili2db/MetaInfo23Test.java b/ili2pg/test/java/ch/ehi/ili2db/MetaInfo23Test.java index a308da80..eeed5832 100644 --- a/ili2pg/test/java/ch/ehi/ili2db/MetaInfo23Test.java +++ b/ili2pg/test/java/ch/ehi/ili2db/MetaInfo23Test.java @@ -164,6 +164,40 @@ public void importIli() throws Exception } } @Test + public void importIliView() 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_DIR,"View23.ili"); + Config config=initConfig(data.getPath(),DBSCHEMA,data.getPath()+".log"); + config.setFunction(Config.FC_SCHEMAIMPORT); + config.setCreateFk(Config.CREATE_FK_YES); + config.setTidHandling(Config.TID_HANDLING_PROPERTY); + config.setBasketHandling(Config.BASKET_HANDLING_READWRITE); + config.setCreateEnumDefs(Config.CREATE_ENUM_DEFS_MULTI); + config.setCatalogueRefTrafo(null); + config.setMultiSurfaceTrafo(null); + config.setMultilingualTrafo(null); + config.setInheritanceTrafo(Config.INHERITANCE_TRAFO_SMART1); + config.setCreateMetaInfo(true); + Ili2db.readSettingsFromDb(config); + Ili2db.run(config,null); + { + } + } + }finally{ + if(jdbcConnection!=null){ + jdbcConnection.close(); + } + } + } + @Test public void importIliAssoc() throws Exception { //EhiLogger.getInstance().setTraceFilter(false); diff --git a/src/ch/ehi/ili2db/metaattr/MetaAttrUtility.java b/src/ch/ehi/ili2db/metaattr/MetaAttrUtility.java index a55bc76f..bfd5b5a6 100644 --- a/src/ch/ehi/ili2db/metaattr/MetaAttrUtility.java +++ b/src/ch/ehi/ili2db/metaattr/MetaAttrUtility.java @@ -10,8 +10,12 @@ import ch.interlis.ili2c.metamodel.Element; +import ch.interlis.ili2c.metamodel.Evaluable; +import ch.interlis.ili2c.metamodel.LocalAttribute; +import ch.interlis.ili2c.metamodel.ObjectPath; import ch.interlis.ili2c.metamodel.RoleDef; import ch.interlis.ili2c.metamodel.TransferDescription; +import ch.interlis.ili2c.metamodel.Type; import ch.interlis.iox_j.inifile.IniFileReader; import ch.interlis.iox_j.validator.ValidationConfig; import ch.interlis.ili2c.metamodel.AttributeDef; @@ -168,25 +172,30 @@ private static void visitElement(HashMap> entries, throws Ili2dbException { Settings metaValues = el.getMetaValues(); - if(metaValues.getValues().size() > 0){ - for(String attr:metaValues.getValues()){ + try { + if(metaValues.getValues().size() > 0){ + for(String attr:metaValues.getValues()){ + HashMap exstValues=getMetaValues(entries,el); + exstValues.put(attr, metaValues.getValue(attr)); + } + } + if(el instanceof RoleDef){ + RoleDef role=(RoleDef)el; HashMap exstValues=getMetaValues(entries,el); - exstValues.put(attr, metaValues.getValue(attr)); - } + exstValues.put(ILI2DB_ILI_ASSOC_KIND, mapRoleKind(role.getKind())); + exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MIN, mapCardinality(role.getCardinality().getMinimum())); + exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MAX, mapCardinality(role.getCardinality().getMaximum())); + } + if(el instanceof AttributeDef){ + AttributeDef attr=(AttributeDef)el; + HashMap exstValues=getMetaValues(entries,el); + exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MIN, mapCardinality(getDomain(attr).getCardinality().getMinimum())); + exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MAX, mapCardinality(getDomain(attr).getCardinality().getMaximum())); + } + }catch(RuntimeException e) { + EhiLogger.traceUnusualState(el.getScopedName()+": "+e.getMessage()); + throw e; } - if(el instanceof RoleDef){ - RoleDef role=(RoleDef)el; - HashMap exstValues=getMetaValues(entries,el); - exstValues.put(ILI2DB_ILI_ASSOC_KIND, mapRoleKind(role.getKind())); - exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MIN, mapCardinality(role.getCardinality().getMinimum())); - exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MAX, mapCardinality(role.getCardinality().getMaximum())); - } - if(el instanceof AttributeDef){ - AttributeDef attr=(AttributeDef)el; - HashMap exstValues=getMetaValues(entries,el); - exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MIN, mapCardinality(attr.getDomain().getCardinality().getMinimum())); - exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MAX, mapCardinality(attr.getDomain().getCardinality().getMaximum())); - } if(el instanceof Container){ Container e = (Container) el; Iterator it = e.iterator(); @@ -196,7 +205,14 @@ private static void visitElement(HashMap> entries, } } - + private static Type getDomain(AttributeDef attr) { + Type type = attr.getDomain(); + if ((type == null) && ((attr instanceof LocalAttribute))) { + Evaluable[] ev = ((LocalAttribute) attr).getBasePaths(); + type = ((ObjectPath) ev[0]).getType(); + } + return type; + } private static String mapCardinality(long val) { if (val == Cardinality.UNBOUND) { return "*"; diff --git a/test/data/MetaInfo/View23.ili b/test/data/MetaInfo/View23.ili new file mode 100644 index 00000000..e33f435a --- /dev/null +++ b/test/data/MetaInfo/View23.ili @@ -0,0 +1,21 @@ +INTERLIS 2.3; + +MODEL View23 + AT "mailto:ce@eisenhutinformatik.ch" VERSION "2015-09-23" = + + TOPIC Topic = + + CLASS ClassA = + attrA1 : MANDATORY TEXT*10; + attrA2 : TEXT*10; + END ClassA; + + VIEW ViewA + PROJECTION OF base~ClassA; + = + ATTRIBUTE + a :=base-> attrA1; + END ViewA; + + END Topic; +END View23. \ No newline at end of file