use of org.teiid.translator.google.api.UpdateSet in project teiid by teiid.
the class GDataClientLoginAPI method listFeedUpdate.
/**
* Updates spreadsheet using the listfeed.
*
* @param spreadsheetKey key that identifies spreadsheet
* @param worksheetID id that identifies worksheet
* @param criteria update criteria
* @param updateSet fields that should be updated
* @param allColumns
* @return number of updated rows
*/
public UpdateResult listFeedUpdate(String spreadsheetKey, String worksheetID, String criteria, List<UpdateSet> updateSet, List<Column> allColumns) {
SpreadsheetQuery query = null;
try {
// $NON-NLS-1$ //$NON-NLS-2$
query = new SpreadsheetQuery(factory.getListFeedUrl(spreadsheetKey, worksheetID, "private", "full"));
if (criteria != null) {
// $NON-NLS-1$
query.setStringCustomParameter("sq", criteria);
}
} catch (MalformedURLException e) {
throw new SpreadsheetOperationException("Error getting spreadsheet URL: " + e);
}
ListFeed listfeed = (ListFeed) getSpreadsheetFeedQuery(query, ListFeed.class);
int counter = 0;
// TEIID-4870 existing string values can get corrupted unless we re-set the entry
List<Column> stringColumns = new ArrayList<Column>();
for (Column c : allColumns) {
if (c.getLabel() != null && c.getDataType() == SpreadsheetColumnType.STRING) {
stringColumns.add(c);
// could skip if in the update set
}
}
for (ListEntry row : listfeed.getEntries()) {
for (int i = 0; i < stringColumns.size(); i++) {
Column c = stringColumns.get(i);
String value = row.getCustomElements().getValue(c.getLabel());
if (value != null && !value.isEmpty()) {
// $NON-NLS-1$
row.getCustomElements().setValueLocal(c.getLabel(), "'" + value);
}
}
for (UpdateSet set : updateSet) {
row.getCustomElements().setValueLocal(set.getColumnID(), set.getValue());
}
try {
row.update();
} catch (IOException e) {
LogManager.logWarning(this.getClass().getName(), e, "Error occured when updating spreadsheet row");
continue;
} catch (ServiceException e2) {
LogManager.logWarning(this.getClass().getName(), e2, "Error occured when updating spreadsheet row");
continue;
}
counter++;
}
return new UpdateResult(listfeed.getEntries().size(), counter);
}
use of org.teiid.translator.google.api.UpdateSet in project teiid by teiid.
the class TestGoogleDataProtocolAPI method testColumnsWithoutLabel.
@Test
public void testColumnsWithoutLabel() {
GDataClientLoginAPI api = new GDataClientLoginAPI() {
protected com.google.gdata.data.BaseFeed<?, ?> getSpreadsheetFeedQuery(com.google.gdata.client.spreadsheet.SpreadsheetQuery squery, java.lang.Class<? extends com.google.gdata.data.BaseFeed<?, ?>> feedClass) {
ListFeed lf = new ListFeed();
lf.setEntries(Arrays.asList(new ListEntry()));
return lf;
}
};
Column c1 = new Column();
c1.setLabel("valid");
c1.setDataType(SpreadsheetColumnType.STRING);
c1.setAlphaName("A");
Column c2 = new Column();
c2.setDataType(SpreadsheetColumnType.STRING);
c2.setAlphaName("B");
// should succeed without an NPE
api.listFeedUpdate("x", "y", "", Arrays.asList(new UpdateSet("valid", "value")), Arrays.asList(c1, c2));
}
use of org.teiid.translator.google.api.UpdateSet in project teiid by teiid.
the class SpreadsheetUpdateVisitor method visit.
public void visit(Update obj) {
worksheetTitle = obj.getTable().getName();
changes = new ArrayList<UpdateSet>();
String columnName;
if (obj.getTable().getMetadataObject().getNameInSource() != null) {
this.worksheetTitle = obj.getTable().getMetadataObject().getNameInSource();
}
for (SetClause s : obj.getChanges()) {
if (s.getSymbol().getMetadataObject().getNameInSource() != null) {
columnName = s.getSymbol().getMetadataObject().getNameInSource();
} else {
columnName = s.getSymbol().getMetadataObject().getName();
}
changes.add(new UpdateSet(columnName, getStringValue(s.getValue())));
}
translateWhere(obj.getWhere());
}
Aggregations