Skip to content

Commit

Permalink
NPE with schema import and --createMetaInfo and a VIEW with implicit …
Browse files Browse the repository at this point in the history
…typed attributes (#385)
  • Loading branch information
claeis committed Feb 4, 2021
1 parent f3d8f5e commit 31c5c0e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions ili2pg/test/java/ch/ehi/ili2db/MetaInfo23Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 34 additions & 18 deletions src/ch/ehi/ili2db/metaattr/MetaAttrUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,25 +172,30 @@ private static void visitElement(HashMap<String,HashMap<String,String>> 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<String,String> exstValues=getMetaValues(entries,el);
exstValues.put(attr, metaValues.getValue(attr));
}
}
if(el instanceof RoleDef){
RoleDef role=(RoleDef)el;
HashMap<String,String> 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<String,String> 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<String,String> 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<String,String> 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();
Expand All @@ -196,7 +205,14 @@ private static void visitElement(HashMap<String,HashMap<String,String>> 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 "*";
Expand Down
21 changes: 21 additions & 0 deletions test/data/MetaInfo/View23.ili
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 31c5c0e

Please sign in to comment.