use of org.teiid.translator.google.api.SpreadsheetOperationException in project teiid by teiid.
the class GDataClientLoginAPI method listFeedDelete.
/**
* Deletes spreadsheet rows using the listfeed.
*
* @param spreadsheetKey key that identifies spreadsheet
* @param worksheetID id that identifies worksheet
* @param criteria delete criteria
* @return number of deleted rows
*/
public UpdateResult listFeedDelete(String spreadsheetKey, String worksheetID, String criteria) {
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;
for (int i = listfeed.getEntries().size() - 1; i > -1; i--) {
ListEntry row = listfeed.getEntries().get(i);
try {
row.delete();
} catch (IOException e) {
LogManager.logWarning(this.getClass().getName(), e, "Error occured when deleting spreadsheet row");
continue;
} catch (ServiceException e2) {
LogManager.logWarning(this.getClass().getName(), e2, "Error occured when deleting spreadsheet row");
continue;
}
counter++;
}
return new UpdateResult(listfeed.getEntries().size(), counter);
}
use of org.teiid.translator.google.api.SpreadsheetOperationException in project teiid by teiid.
the class GDataClientLoginAPI method listFeedInsert.
/**
* Insert row into spreadsheet using listfeed
* @param spreadsheetKey key that identifies spreadsheet
* @param worksheetID key that identifies worksheet
* @param pair name - value pair that should be inserted into spreadsheet
* @return 1 if the row is successfully inserted
*/
public UpdateResult listFeedInsert(String spreadsheetKey, String worksheetID, Map<String, Object> pair) {
SpreadsheetQuery query = null;
try {
// $NON-NLS-1$ //$NON-NLS-2$
query = new SpreadsheetQuery(factory.getListFeedUrl(spreadsheetKey, worksheetID, "private", "full"));
} catch (MalformedURLException e) {
throw new SpreadsheetOperationException("Error getting spreadsheet URL: " + e);
}
ListEntry row = new ListEntry();
for (Entry<String, Object> entry : pair.entrySet()) {
Object value = entry.getValue();
Class<?> type = value.getClass();
String valString = null;
if (type.equals(DataTypeManager.DefaultDataClasses.STRING)) {
// $NON-NLS-1$
valString = "'" + value;
} else {
valString = value.toString();
}
row.getCustomElements().setValueLocal(entry.getKey(), valString);
}
try {
service.insert(query.getFeedUrl(), row);
} catch (Exception e) {
throw new SpreadsheetOperationException("Error inserting spreadsheet row: " + e);
}
return new UpdateResult(1, 1);
}
use of org.teiid.translator.google.api.SpreadsheetOperationException in project teiid by teiid.
the class SpreadsheetInsertVisitor method visit.
public void visit(Insert obj) {
worksheetTitle = obj.getTable().getName();
if (obj.getTable().getMetadataObject().getNameInSource() != null) {
worksheetTitle = obj.getTable().getMetadataObject().getNameInSource();
}
worksheetKey = info.getWorksheetByName(worksheetTitle).getId();
ExpressionValueSource evs = (ExpressionValueSource) obj.getValueSource();
for (int i = 0; i < evs.getValues().size(); i++) {
Expression e = evs.getValues().get(i);
if (!(e instanceof Literal)) {
throw new SpreadsheetOperationException("Only literals are allowed in the values section");
}
Literal l = (Literal) e;
if (l.getValue() == null) {
continue;
}
ColumnReference columnReference = obj.getColumns().get(i);
columnNameValuePair.put(columnReference.getMetadataObject().getSourceName(), l.getValue());
}
}
use of org.teiid.translator.google.api.SpreadsheetOperationException 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);
}
use of org.teiid.translator.google.api.SpreadsheetOperationException in project teiid by teiid.
the class GoogleJSONParser method parseLiteral.
private Object parseLiteral(PushbackReader r, char c) throws IOException {
sb.setLength(0);
do {
sb.append(c);
int i = r.read();
if (i == -1) {
break;
}
c = (char) i;
} while (!Character.isWhitespace(c) && c != ',' && c != ']' && c != '}');
// date handling
if (areEquals(sb, "new")) {
// $NON-NLS-1$
sb.setLength(0);
int length = 0;
Arrays.fill(parts, 0);
for (int i = 0; ; i++) {
if (i > 5) {
// remove " Date("
if (c == ',' || c == ')') {
if (length > 6) {
throw new SpreadsheetOperationException("Too many date fields");
}
parts[length++] = Integer.valueOf(sb.toString());
if (c == ')') {
break;
}
sb.setLength(0);
} else {
sb.append(c);
}
}
int chr = r.read();
if (chr == -1) {
throw new SpreadsheetOperationException("Encountered end of stream in date value");
}
c = (char) chr;
}
if (length > 3) {
Calendar calendar = getCalendar();
calendar.set(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5]);
Timestamp ts = new Timestamp(calendar.getTimeInMillis());
// convert from millis to nanos
ts.setNanos(parts[6] * 1000000);
return ts;
}
Calendar calendar = getCalendar();
calendar.set(parts[0], parts[1], parts[2]);
return new java.sql.Date(cal.getTimeInMillis());
}
if (!Character.isWhitespace(c)) {
// the terminating character is still needed by the caller
r.unread(c);
// TODO could hold this state so that a pushback reader is not needed
}
if (areEquals(sb, "false")) {
// $NON-NLS-1$
return Boolean.FALSE;
} else if (areEquals(sb, "true")) {
// $NON-NLS-1$
return Boolean.TRUE;
} else if (areEquals(sb, "null")) {
// $NON-NLS-1$
return null;
}
return Double.valueOf(sb.toString());
}
Aggregations