Search in sources :

Example 11 with SpreadsheetInfo

use of org.teiid.translator.google.api.metadata.SpreadsheetInfo in project teiid by teiid.

the class SpreadsheetUpdateExecution method executeDelete.

private UpdateResult executeDelete() throws TranslatorException {
    SpreadsheetInfo info = connection.getSpreadsheetInfo();
    SpreadsheetDeleteVisitor visitor = new SpreadsheetDeleteVisitor(info);
    visitor.visit((Delete) command);
    checkHeaders(visitor.getWorksheetTitle());
    result = connection.deleteRows(visitor.getWorksheetTitle(), visitor.getCriteriaQuery());
    return result;
}
Also used : SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) SpreadsheetDeleteVisitor(org.teiid.translator.google.visitor.SpreadsheetDeleteVisitor)

Example 12 with SpreadsheetInfo

use of org.teiid.translator.google.api.metadata.SpreadsheetInfo 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);
}
Also used : SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) Column(org.teiid.translator.google.api.metadata.Column) Worksheet(org.teiid.translator.google.api.metadata.Worksheet) BeforeClass(org.junit.BeforeClass)

Example 13 with SpreadsheetInfo

use of org.teiid.translator.google.api.metadata.SpreadsheetInfo in project teiid by teiid.

the class SpreadsheetConnectionImpl4 method deleteRows.

@Override
public UpdateResult deleteRows(String worksheetTitle, String criteria) {
    SpreadsheetInfo info = getV2SpreadsheetInfo();
    org.teiid.translator.google.api.metadata.Worksheet sheet = info.getWorksheetByName(worksheetTitle);
    if (sheet == null) {
        // $NON-NLS-1$
        throw new SpreadsheetOperationException(SpreadsheetManagedConnectionFactory.UTIL.getString("not_visible"));
    }
    return gdata.listFeedDelete(info.getSpreadsheetKey(), sheet.getId(), criteria);
}
Also used : SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) SpreadsheetOperationException(org.teiid.translator.google.api.SpreadsheetOperationException)

Example 14 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 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);
    }
}
Also used : Spreadsheet(com.google.api.services.sheets.v4.model.Spreadsheet) 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) IOException(java.io.IOException) Sheet(com.google.api.services.sheets.v4.model.Sheet)

Example 15 with SpreadsheetInfo

use of org.teiid.translator.google.api.metadata.SpreadsheetInfo in project teiid by teiid.

the class AbstractSpreadsheetExecution method checkHeaders.

void checkHeaders(String worksheetTitle) throws TranslatorException {
    SpreadsheetInfo info = connection.getSpreadsheetInfo();
    Worksheet worksheet = info.getWorksheetByName(worksheetTitle);
    if (worksheet == null) {
        // $NON-NLS-1$
        throw new SpreadsheetOperationException(SpreadsheetExecutionFactory.UTIL.gs("missing_worksheet", worksheetTitle));
    }
    if (!worksheet.isHeaderEnabled()) {
        // $NON-NLS-1$
        throw new TranslatorException(SpreadsheetExecutionFactory.UTIL.gs("headers_required"));
    }
}
Also used : SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) SpreadsheetOperationException(org.teiid.translator.google.api.SpreadsheetOperationException) Worksheet(org.teiid.translator.google.api.metadata.Worksheet) TranslatorException(org.teiid.translator.TranslatorException)

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