Skip to content

Commit

Permalink
new option --beautifyEnumDispName to replace underscore with space fr…
Browse files Browse the repository at this point in the history
…om dispName (fixes claeis#24)
  • Loading branch information
claeis committed Dec 21, 2016
1 parent f4d52af commit afd6059
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ ideas/open issues/questions
- einfache Liste mit den neu erzeugten Vertexpunkte (aufgrund der Overlap-Bereinigung)
- Schalter f�r das "disablen" der Overlaps-Bereinigung. Bei vorhandenen gueltigen Overlaps erfolgen: a) Import mit NULL als Polygon, ohne Fehlermeldung, b) Import mit NULL als Polygon, mit Warning, c) kein Import, Fehlermeldung

ili2pg/ili2gpkg 3.6.0 (2016-12-xx)
-----------------------------
- new option --beautifyEnumDispName to replace underscore with space from dispName

ili2pg/ili2gpkg 3.5.1 (2016-12-21)
-----------------------------
- import: failed to resolve EXTENDED EXTERNAL ReferenceAttr
Expand Down
2 changes: 2 additions & 0 deletions docs/ili2db.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ Optionen:
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --createSingleEnumTab | Erstellt eine einzige Tablle mit allen Aufzählwerten aller Aufzählungsdefinitionen. (siehe Kapitel Abbildungsregeln/Aufzählungen) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --beautifyEnumDispName | Verschönert den Anzeigetext für das Aufzählelement. Beim Import wird die Spalte mit dem XTF-Code ohne Untersstriche befüllt ("Strasse befestigt" statt "Strasse_befestigt") (siehe Kapitel Abbildungsregeln/Aufzählungen) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --createStdCols | Erstellt in jeder Tabelle zusätzliche Metadatenspalten T\_User, T\_CreateDate, T\_LastChange. (siehe Kapitel Abbildungsregeln/Tabellen) |
+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| --t\_id\_Name name | Definiert den Namen für die interne technische Schlüsselspalte in jeder Tabelle (nicht zu verwechseln mit dem externen Transferidentifikator). Default ist T\_Id. (siehe Kapitel Abbildungsregeln/Tabellen) |
Expand Down
4 changes: 2 additions & 2 deletions ili2gpkg/src/ch/ehi/ili2gpkg/Version.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed, 21 Dec 2016 10:32:43 +0100
#Fri Apr 11 13:48:33 CEST 2008
versionMicro=1
versionMinor=5
versionMicro=0
versionMinor=6
versionDate=20161221
versionMajor=3
4 changes: 2 additions & 2 deletions ili2pg/src/ch/ehi/ili2pg/Version.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri, 25 Nov 2016 14:52:18 +0100
#Fri Apr 11 13:48:33 CEST 2008
versionMicro=1
versionMinor=5
versionMicro=0
versionMinor=6
versionDate=20161125
versionMajor=3
4 changes: 4 additions & 0 deletions src/ch/ehi/ili2db/AbstractMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public void domain(String args[]){
}else if(arg.equals("--createEnumColAsItfCode")){
argi++;
config.setCreateEnumColAsItfCode(config.CREATE_ENUMCOL_AS_ITFCODE_YES);
}else if(arg.equals("--beautifyEnumDispName")){
argi++;
config.setBeautifyEnumDispName(config.BEAUTIFY_ENUM_DISPNAME_UNDERSCORE);
}else if(arg.equals("--noSmartMapping")){
argi++;
config.setCatalogueRefTrafo(null);
Expand Down Expand Up @@ -312,6 +315,7 @@ public void domain(String args[]){
System.err.println("--createEnumTxtCol create an additional column with the text of the enumeration value.");
System.err.println("--createEnumTabs generate tables with enum definitions.");
System.err.println("--createSingleEnumTab generate all enum definitions in a single table.");
System.err.println("--beautifyEnumDispName replace underscore with space in dispName of enum table entries");
System.err.println("--createStdCols generate "+DbNames.T_USER_COL+", "+DbNames.T_CREATE_DATE_COL+", "+DbNames.T_LAST_CHANGE_COL+" columns.");
System.err.println("--t_id_Name name change name of t_id column ("+DbNames.T_ID_COL+")");
System.err.println("--idSeqMin minValue sets the minimum value of the id sequence generator.");
Expand Down
8 changes: 8 additions & 0 deletions src/ch/ehi/ili2db/converter/AbstractRecordConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class AbstractRecordConverter {
private String createEnumTable=null;
protected boolean createStdCols=false;
protected boolean createEnumTxtCol=false;
protected boolean removeUnderscoreFromEnumDispName=false;
protected boolean createEnumColAsItfCode=false;
protected boolean createIliTidCol=false;
protected boolean createTypeDiscriminator=false;
Expand Down Expand Up @@ -104,6 +105,7 @@ public AbstractRecordConverter(TransferDescription td1,ch.ehi.ili2db.mapping.Nam
createEnumColAsItfCode=config.CREATE_ENUMCOL_AS_ITFCODE_YES.equals(config.getCreateEnumColAsItfCode());
createStdCols=config.CREATE_STD_COLS_ALL.equals(config.getCreateStdCols());
createEnumTxtCol=config.CREATE_ENUM_TXT_COL.equals(config.getCreateEnumCols());
removeUnderscoreFromEnumDispName=config.BEAUTIFY_ENUM_DISPNAME_UNDERSCORE.equals(config.getBeautifyEnumDispName());
createFk=config.CREATE_FK_YES.equals(config.getCreateFk());
createFkIdx=config.CREATE_FKIDX_YES.equals(config.getCreateFkIdx());
colT_ID=config.getColT_ID();
Expand All @@ -129,6 +131,12 @@ public AbstractRecordConverter(TransferDescription td1,ch.ehi.ili2db.mapping.Nam
createItfAreaRef=isIli1Model && config.AREA_REF_KEEP.equals(config.getAreaRef());

}
public String beautifyEnumDispName(String value) {
if(removeUnderscoreFromEnumDispName){
return value.replace('_', ' ');
}
return value;
}
public DbColGeometry generatePolylineType(LineType type, String attrName) {
DbColGeometry ret=new DbColGeometry();
boolean compoundCurve=false;
Expand Down
2 changes: 1 addition & 1 deletion src/ch/ehi/ili2db/fromili/TransferFromIli.java
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ private void updateEnumEntries(HashSet exstEntires,java.sql.PreparedStatement ps
}
ps.setString(2, ele);
ps.setInt(3, itfCode);
ps.setString(4, ele); // dispName
ps.setString(4, recConv.beautifyEnumDispName(ele)); // dispName
// single table for all enums?
if(thisClass!=null){
ps.setString(5, thisClass);
Expand Down
2 changes: 1 addition & 1 deletion src/ch/ehi/ili2db/fromxtf/FromXtfRecordConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ public int addAttrValue(IomObject iomObj, String sqlType, long sqlId,
valuei++;
if(createEnumTxtCol){
if(value!=null){
ps.setString(valuei, value);
ps.setString(valuei, beautifyEnumDispName(value));
}else{
ps.setNull(valuei,Types.VARCHAR);
}
Expand Down
8 changes: 8 additions & 0 deletions src/ch/ehi/ili2db/gui/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class Config extends Settings {
private static final String UUID_DEFAULT_VALUE=PREFIX+".uuidDefaultValue";
private static final String CREATE_ENUMCOL_AS_ITFCODE=PREFIX+".createEnumColAsItfCode";
public static final String CREATE_ENUMCOL_AS_ITFCODE_YES="yes";
private static final String BEAUTIFY_ENUM_DISPNAME=PREFIX+".beautifyEnumDispName";
public static final String BEAUTIFY_ENUM_DISPNAME_UNDERSCORE="underscore";
private static final String CREATE_ENUM_DEFS=PREFIX+".createEnumDefs";
public static final String CREATE_ENUM_DEFS_NO="no";
public static final String CREATE_ENUM_DEFS_SINGLE="singleTable";
Expand Down Expand Up @@ -249,6 +251,12 @@ public String getCreateEnumDefs() {
public void setCreateEnumDefs(String value) {
setValue(CREATE_ENUM_DEFS,value);
}
public String getBeautifyEnumDispName() {
return getValue(BEAUTIFY_ENUM_DISPNAME);
}
public void setBeautifyEnumDispName(String value) {
setValue(BEAUTIFY_ENUM_DISPNAME,value);
}
public String getCreateEnumColAsItfCode() {
return getValue(CREATE_ENUMCOL_AS_ITFCODE);
}
Expand Down
19 changes: 19 additions & 0 deletions test/data/Enum23/Enum23.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
INTERLIS 2.3;

MODEL Enum23
AT "mailto:ce@eisenhutinformatik.ch" VERSION "2016-12-21" =

DOMAIN
Enum1 = (Test1, Test2_ele, Test3 (ele1, ele_2));

TOPIC TestA =

CLASS ClassA1 =
attr1 : TEXT*60;
attr2 : Enum1;
END ClassA1;

END TestA;


END Enum23.
140 changes: 140 additions & 0 deletions test/java/ch/ehi/ili2db/Enum23Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package ch.ehi.ili2db;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import ch.ehi.basics.logging.EhiLogger;
import ch.ehi.ili2db.base.DbUrlConverter;
import ch.ehi.ili2db.base.Ili2db;
import ch.ehi.ili2db.base.Ili2dbException;
import ch.ehi.ili2db.gui.Config;
import ch.ehi.ili2db.mapping.NameMapping;

//-Ddburl=jdbc:postgresql:dbname -Ddbusr=usrname -Ddbpwd=1234
public class Enum23Test {
private static final String DBSCHEMA = "Enum23";
String dburl=System.getProperty("dburl");
String dbuser=System.getProperty("dbusr");
String dbpwd=System.getProperty("dbpwd");
Connection jdbcConnection=null;
Statement stmt=null;
@Before
public void initDb() throws Exception
{
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(
dburl, dbuser, dbpwd);
stmt=jdbcConnection.createStatement();
}
@After
public void endDb() throws Exception
{
if(jdbcConnection!=null){
jdbcConnection.close();
}
}
public Config initConfig(String xtfFilename,String dbschema,String logfile) {
Config config=new Config();
new ch.ehi.ili2pg.PgMain().initConfig(config);


config.setDburl(dburl);
config.setDbusr(dbuser);
config.setDbpwd(dbpwd);
if(dbschema!=null){
config.setDbschema(dbschema);
}
if(logfile!=null){
config.setLogfile(logfile);
}


config.setXtffile(xtfFilename);
if(xtfFilename!=null && Ili2db.isItfFilename(xtfFilename)){
config.setItfTransferfile(true);
}
return config;

}

@Test
public void importWithoutBeautify() throws Exception
{
stmt.execute("DROP SCHEMA IF EXISTS "+DBSCHEMA+" CASCADE");

File data=new File("test/data/Enum23/Enum23.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(null);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config,null);

{
String stmtTxt="SELECT dispName FROM "+DBSCHEMA+".enum1 WHERE ilicode ='Test2_ele'";
Assert.assertTrue(stmt.execute(stmtTxt));
ResultSet rs=stmt.getResultSet();
Assert.assertTrue(rs.next());
Assert.assertEquals("Test2_ele",rs.getString(1));
}
{
String stmtTxt="SELECT dispName FROM "+DBSCHEMA+".enum1 WHERE ilicode ='Test3.ele_2'";
Assert.assertTrue(stmt.execute(stmtTxt));
ResultSet rs=stmt.getResultSet();
Assert.assertTrue(rs.next());
Assert.assertEquals("Test3.ele_2",rs.getString(1));
}

}
@Test
public void importWithBeautify() throws Exception
{
stmt.execute("DROP SCHEMA IF EXISTS "+DBSCHEMA+" CASCADE");

File data=new File("test/data/Enum23/Enum23.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.setBeautifyEnumDispName(Config.BEAUTIFY_ENUM_DISPNAME_UNDERSCORE);
config.setCatalogueRefTrafo(null);
config.setMultiSurfaceTrafo(null);
config.setMultilingualTrafo(null);
config.setInheritanceTrafo(null);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config,null);

{
String stmtTxt="SELECT dispName FROM "+DBSCHEMA+".enum1 WHERE ilicode ='Test2_ele'";
Assert.assertTrue(stmt.execute(stmtTxt));
ResultSet rs=stmt.getResultSet();
Assert.assertTrue(rs.next());
Assert.assertEquals("Test2 ele",rs.getString(1));
}
{
String stmtTxt="SELECT dispName FROM "+DBSCHEMA+".enum1 WHERE ilicode ='Test3.ele_2'";
Assert.assertTrue(stmt.execute(stmtTxt));
ResultSet rs=stmt.getResultSet();
Assert.assertTrue(rs.next());
Assert.assertEquals("Test3.ele 2",rs.getString(1));
}

}

}

0 comments on commit afd6059

Please sign in to comment.