Skip to content

Commit

Permalink
TEIID-4854 adding a property to disable making non-string/boolean values
Browse files Browse the repository at this point in the history
updatable
  • Loading branch information
shawkins committed Oct 13, 2017
1 parent 270875f commit f3f2562
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -25,13 +25,17 @@
import org.teiid.metadata.Table;
import org.teiid.translator.MetadataProcessor;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.TranslatorProperty.PropertyType;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.google.api.GoogleSpreadsheetConnection;
import org.teiid.translator.google.api.metadata.Column;
import org.teiid.translator.google.api.metadata.SpreadsheetInfo;
import org.teiid.translator.google.api.metadata.Worksheet;

public class GoogleMetadataProcessor implements MetadataProcessor<GoogleSpreadsheetConnection>{

private boolean allTypesUpdatable = true;

/**
* Creates metadata from all spreadsheets in the user account. Table name
Expand Down Expand Up @@ -72,22 +76,27 @@ private void addTable(MetadataFactory mf, Worksheet worksheet) {
* @throws TranslatorException
*/
private void addColumnsToTable(MetadataFactory mf, Table table, Worksheet worksheet) {
boolean updatable = true;
for(Column column : worksheet.getColumnsAsList()){
String type = null;
switch(column.getDataType()){
case DATE:
updatable = false;
type = TypeFacility.RUNTIME_NAMES.DATE;
break;
case BOOLEAN:
type = TypeFacility.RUNTIME_NAMES.BOOLEAN;
break;
case DATETIME:
updatable = false;
type = TypeFacility.RUNTIME_NAMES.TIMESTAMP;
break;
case NUMBER:
updatable = false;
type = TypeFacility.RUNTIME_NAMES.DOUBLE;
break;
case TIMEOFDAY:
updatable = false;
type = TypeFacility.RUNTIME_NAMES.TIME;
break;
default:
Expand All @@ -103,11 +112,20 @@ private void addColumnsToTable(MetadataFactory mf, Table table, Worksheet worksh
}
org.teiid.metadata.Column c = mf.addColumn(name, type, table);
if (table.supportsUpdate()) {
c.setUpdatable(true);
c.setUpdatable(updatable || allTypesUpdatable);
}
c.setNameInSource(worksheet.isHeaderEnabled()?column.getLabel():column.getAlphaName());
c.setNativeType(column.getDataType().name());
}
}

@TranslatorProperty (display="All Types Updatable", category=PropertyType.IMPORT, description="Allow all types to be updatable even those that may have formatting or locale inconsistencies.")
public boolean isAllTypesUpdatable() {
return allTypesUpdatable;
}

public void setAllTypesUpdatable(boolean allTypesUpdatable) {
this.allTypesUpdatable = allTypesUpdatable;
}

}
Expand Up @@ -29,6 +29,7 @@
import org.teiid.query.metadata.SystemMetadata;
import org.teiid.translator.google.api.GoogleSpreadsheetConnection;
import org.teiid.translator.google.api.metadata.Column;
import org.teiid.translator.google.api.metadata.SpreadsheetColumnType;
import org.teiid.translator.google.api.metadata.SpreadsheetInfo;
import org.teiid.translator.google.api.metadata.Util;
import org.teiid.translator.google.api.metadata.Worksheet;
Expand All @@ -46,6 +47,9 @@ public class TestMetadataProcessor {
Column newCol = new Column();
newCol.setAlphaName(Util.convertColumnIDtoString(i));
newCol.setLabel("c" + i);
if (i == 1) {
newCol.setDataType(SpreadsheetColumnType.DATETIME);
}
worksheet.addColumn(newCol.getAlphaName(), newCol);
}
Column newCol = new Column();
Expand All @@ -61,6 +65,12 @@ public class TestMetadataProcessor {
assertTrue(t.supportsUpdate());
assertEquals(3, t.getColumns().size());
assertTrue(t.getColumns().get(0).isUpdatable());

processor.setAllTypesUpdatable(false);
factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
processor.process(factory, conn);
t = factory.getSchema().getTables().get("PeopleList");
assertFalse(t.getColumns().get(0).isUpdatable());
}

}

0 comments on commit f3f2562

Please sign in to comment.