use of org.teiid.translator.google.api.metadata.Worksheet in project teiid by teiid.
the class SpreadsheetMetadataExtractor method extractMetadata.
public SpreadsheetInfo extractMetadata(String spreadsheetName, boolean isKey) {
SpreadsheetEntry sentry = gdataAPI.getSpreadsheetEntry(spreadsheetName, isKey);
SpreadsheetInfo metadata = new SpreadsheetInfo(spreadsheetName);
metadata.setSpreadsheetKey(sentry.getKey());
try {
for (WorksheetEntry wentry : sentry.getWorksheets()) {
String title = wentry.getTitle().getPlainText();
Worksheet worksheet = metadata.createWorksheet(title);
worksheet.setId(wentry.getId().substring(wentry.getId().lastIndexOf('/') + 1));
List<Column> cols = visualizationAPI.getMetadata(sentry.getKey(), title);
if (!cols.isEmpty()) {
if (cols.get(0).getLabel() != null) {
worksheet.setHeaderEnabled(true);
}
}
for (Column c : cols) {
worksheet.addColumn(c.getLabel() != null ? c.getLabel() : c.getAlphaName(), c);
}
}
} catch (IOException ex) {
throw new SpreadsheetOperationException(SpreadsheetManagedConnectionFactory.UTIL.gs("metadata_error"), // $NON-NLS-1$
ex);
} catch (ServiceException ex) {
throw new SpreadsheetOperationException(SpreadsheetManagedConnectionFactory.UTIL.gs("metadata_error"), // $NON-NLS-1$
ex);
}
return metadata;
}
use of org.teiid.translator.google.api.metadata.Worksheet in project teiid by teiid.
the class SpreadsheetSQLVisitor method replaceElementName.
/**
* Return only col name e.g. "A"
*/
@Override
protected String replaceElementName(String group, String element) {
Worksheet worksheetSourceName = info.getWorksheetByName(worksheetTitle);
if (worksheetSourceName == null) {
// $NON-NLS-1$
throw new SpreadsheetOperationException(SpreadsheetExecutionFactory.UTIL.gs("missing_worksheet", worksheetTitle));
}
String columnId = worksheetSourceName.getColumnID(element);
if (columnId == null) {
throw new SpreadsheetOperationException("Column " + element + " doesn't exist in the worksheet " + worksheetTitle);
}
return columnId;
}
use of org.teiid.translator.google.api.metadata.Worksheet in project teiid by teiid.
the class TestMetadataProcessor method testRemoveColumns.
@Test
public void testRemoveColumns() throws Exception {
GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
SpreadsheetInfo people = new SpreadsheetInfo("People");
Worksheet worksheet = people.createWorksheet("PeopleList");
worksheet.setHeaderEnabled(true);
for (int i = 1; i <= 3; i++) {
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();
newCol.setAlphaName("empty");
worksheet.addColumn(null, newCol);
Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
processor.process(factory, conn);
Table t = factory.getSchema().getTables().get("PeopleList");
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());
}
use of org.teiid.translator.google.api.metadata.Worksheet in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method createSpreadSheetInfo.
@BeforeClass
public static void createSpreadSheetInfo() {
people = new SpreadsheetInfo("People");
Worksheet worksheet = people.createWorksheet("PeopleList");
worksheet.setHeaderEnabled(true);
for (int i = 1; i <= 4; i++) {
Column newCol = new Column();
newCol.setAlphaName(Util.convertColumnIDtoString(i));
newCol.setLabel(newCol.getAlphaName());
worksheet.addColumn(newCol.getAlphaName(), newCol);
}
worksheet.getColumns().get("C").setDataType(SpreadsheetColumnType.NUMBER);
worksheet.getColumns().get("D").setDataType(SpreadsheetColumnType.BOOLEAN);
}
use of org.teiid.translator.google.api.metadata.Worksheet in project teiid by teiid.
the class SpreadsheetMetadataExtractor method extractMetadata.
public SpreadsheetInfo extractMetadata(String spreadsheetId) {
try {
Spreadsheet spreadsheet = sheetsAPI.getSpreadsheet(spreadsheetId);
SpreadsheetInfo metadata = new SpreadsheetInfo(spreadsheet.getProperties().getTitle());
metadata.setSpreadsheetKey(spreadsheet.getSpreadsheetId());
for (Sheet sheet : spreadsheet.getSheets()) {
String title = sheet.getProperties().getTitle();
Worksheet worksheet = metadata.createWorksheet(title);
worksheet.setId(sheet.getProperties().getSheetId().toString());
List<Column> cols = dataProtocolAPI.getMetadata(spreadsheet.getSpreadsheetId(), title);
if (!cols.isEmpty()) {
if (cols.get(0).getLabel() != null) {
worksheet.setHeaderEnabled(true);
}
}
for (Column c : cols) {
worksheet.addColumn(c.getLabel() != null ? c.getLabel() : c.getAlphaName(), c);
}
}
return metadata;
} catch (IOException ex) {
throw new SpreadsheetOperationException(SpreadsheetManagedConnectionFactory.UTIL.gs("metadata_error"), // $NON-NLS-1$
ex);
}
}
Aggregations