Search in sources :

Example 1 with SpreadsheetInfo

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;
}
Also used : ServiceException(com.google.gdata.util.ServiceException) SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) Column(org.teiid.translator.google.api.metadata.Column) SpreadsheetOperationException(org.teiid.translator.google.api.SpreadsheetOperationException) Worksheet(org.teiid.translator.google.api.metadata.Worksheet) SpreadsheetEntry(com.google.gdata.data.spreadsheet.SpreadsheetEntry) IOException(java.io.IOException) WorksheetEntry(com.google.gdata.data.spreadsheet.WorksheetEntry)

Example 2 with SpreadsheetInfo

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());
}
Also used : SpreadsheetMetadataExtractor(org.teiid.resource.adapter.google.gdata.SpreadsheetMetadataExtractor) SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) Test(org.junit.Test)

Example 3 with SpreadsheetInfo

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;
}
Also used : SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) SpreadsheetInsertVisitor(org.teiid.translator.google.visitor.SpreadsheetInsertVisitor)

Example 4 with SpreadsheetInfo

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());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) Column(org.teiid.translator.google.api.metadata.Column) Worksheet(org.teiid.translator.google.api.metadata.Worksheet) Properties(java.util.Properties) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) Test(org.junit.Test)

Example 5 with SpreadsheetInfo

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;
}
Also used : SpreadsheetMetadataExtractor(org.teiid.resource.adapter.google.gdata.SpreadsheetMetadataExtractor) SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo)

Aggregations

SpreadsheetInfo (org.teiid.translator.google.api.metadata.SpreadsheetInfo)15 SpreadsheetOperationException (org.teiid.translator.google.api.SpreadsheetOperationException)5 Worksheet (org.teiid.translator.google.api.metadata.Worksheet)5 Column (org.teiid.translator.google.api.metadata.Column)4 IOException (java.io.IOException)2 Test (org.junit.Test)2 SpreadsheetMetadataExtractor (org.teiid.resource.adapter.google.gdata.SpreadsheetMetadataExtractor)2 SpreadsheetMetadataExtractor (org.teiid.resource.adapter.google.v4.SpreadsheetMetadataExtractor)2 Sheet (com.google.api.services.sheets.v4.model.Sheet)1 Spreadsheet (com.google.api.services.sheets.v4.model.Spreadsheet)1 SpreadsheetEntry (com.google.gdata.data.spreadsheet.SpreadsheetEntry)1 WorksheetEntry (com.google.gdata.data.spreadsheet.WorksheetEntry)1 ServiceException (com.google.gdata.util.ServiceException)1 Properties (java.util.Properties)1 BeforeClass (org.junit.BeforeClass)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1 Table (org.teiid.metadata.Table)1 TranslatorException (org.teiid.translator.TranslatorException)1 GoogleSpreadsheetConnection (org.teiid.translator.google.api.GoogleSpreadsheetConnection)1 SpreadsheetDeleteVisitor (org.teiid.translator.google.visitor.SpreadsheetDeleteVisitor)1