public Calendar addCalendarsUsingBatch(String nameCalendar) throws IOException { View.header("Add Calendars using Batch"); BatchRequest batch = client.batch(); // Create the callback. JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() { public void onSuccess(Calendar calendar, GoogleHeaders responseHeaders) { View.display(calendar); addedCalendarsUsingBatch.add(calendar); } @Override public void onFailure(GoogleJsonError e, GoogleHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }; // Create 2 Calendar Entries to insert. Calendar entry1 = new Calendar().setSummary(nameCalendar); client.calendars().insert(entry1).queue(batch, callback); // Calendar entry2 = new Calendar().setSummary("Calendar for Testing 2"); // client.calendars().insert(entry2).queue(batch, callback); batch.execute(); return entry1; }
public void deleteCalendarsUsingBatch() throws IOException { View.header("Delete Calendars Using Batch"); BatchRequest batch = client.batch(); for (Calendar calendar : addedCalendarsUsingBatch) { client .calendars() .delete(calendar.getId()) .queue( batch, new JsonBatchCallback<Void>() { public void onSuccess(Void content, GoogleHeaders responseHeaders) { System.out.println("Delete is successful!"); } @Override public void onFailure(GoogleJsonError e, GoogleHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }); } batch.execute(); }