try {
// Prepare Control Table.
Key controlId = datastore.allocateIds("restore", 1).getStart();
List<Entity> list = new ArrayList<Entity>();
Queue queue = QueueFactory.getDefaultQueue();
List<TaskOptions> taskList = Lists.newArrayList();
for (int i = 0; i < wsTitles.length; i++) {
Key childKey = KeyFactory.createKey(controlId, GbControl.NAME, wsTitles[i]);
Entity control = new Entity(childKey);
control.setProperty(GbControl.KIND_NAME, wsTitles[i]);
control.setProperty(GbControl.COUNT, 2); // ignore header!
if (currentUser != null) {
control.setProperty(GbControl.REPORT_TO, new Email(currentUser.getEmail()));
}
control.setProperty(GbControl.AUTH_SUB_TOKEN, token);
control.setProperty(GbControl.SPREADSHEET_KEY, ssKey);
control.setProperty(GbControl.UPDATE_DATE, new Date());
list.add(control);
// Start task queue chain for each kind.
taskList.add(TaskOptions.Builder.url("/tasks/restore.gobo").param(
"controlKey",
KeyFactory.keyToString(childKey)).countdownMillis(10000).method(Method.GET));
}
putKeys = datastore.put(list);
queue.add(taskList);
} catch (Exception e) {
if (putKeys != null) {
try {
datastore.delete(putKeys);