use of org.teiid.translator.google.api.metadata.SpreadsheetInfo 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.SpreadsheetInfo in project teiid by teiid.
the class MetadataLoadingTest method testMetadata.
@Test
public void testMetadata() {
SpreadsheetMetadataExtractor extractor = new SpreadsheetMetadataExtractor();
extractor.setGdataAPI(gdata);
extractor.setVisualizationAPI(visualizationAPI);
SpreadsheetInfo metadata = extractor.extractMetadata("integration_tests", false);
Assert.assertEquals(0, metadata.getWorksheetByName("Sheet1").getColumnCount());
Assert.assertEquals(2, metadata.getWorksheetByName("Sheet2").getColumnCount());
metadata = extractor.extractMetadata("people", false);
Assert.assertEquals(5, metadata.getWorksheetByName("list").getColumnCount());
Assert.assertEquals(4, metadata.getWorksheetByName("phones").getColumnCount());
}
use of org.teiid.translator.google.api.metadata.SpreadsheetInfo in project teiid by teiid.
the class SpreadsheetUpdateExecution method executeInsert.
private UpdateResult executeInsert() throws TranslatorException {
SpreadsheetInfo info = connection.getSpreadsheetInfo();
SpreadsheetInsertVisitor visitor = new SpreadsheetInsertVisitor(info);
visitor.visit((Insert) command);
checkHeaders(visitor.getWorksheetTitle());
result = connection.executeRowInsert(visitor.getWorksheetTitle(), visitor.getColumnNameValuePair());
return result;
}
use of org.teiid.translator.google.api.metadata.SpreadsheetInfo 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.SpreadsheetInfo in project teiid by teiid.
the class SpreadsheetConnectionImpl method getSpreadsheetInfo.
@Override
public SpreadsheetInfo getSpreadsheetInfo() {
SpreadsheetInfo info = spreadsheetInfo.get();
if (info == null) {
synchronized (spreadsheetInfo) {
info = spreadsheetInfo.get();
if (info == null) {
SpreadsheetMetadataExtractor metadataExtractor = new SpreadsheetMetadataExtractor();
metadataExtractor.setGdataAPI(gdata);
metadataExtractor.setVisualizationAPI(dataProtocol);
if (config.getSpreadsheetId() == null) {
info = metadataExtractor.extractMetadata(config.getSpreadsheetName(), false);
} else {
info = metadataExtractor.extractMetadata(config.getSpreadsheetId(), true);
}
spreadsheetInfo.set(info);
}
}
}
return info;
}
Aggregations