Example usage for com.google.api.client.googleapis.batch.json JsonBatchCallback JsonBatchCallback

List of usage examples for com.google.api.client.googleapis.batch.json JsonBatchCallback JsonBatchCallback

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.batch.json JsonBatchCallback JsonBatchCallback.

Prototype

JsonBatchCallback

Source Link

Usage

From source file:calendariotaller.CalendarSample.java

License:Apache License

private static void addCalendarsUsingBatch() throws IOException {
    View.header("Add Calendars using Batch");
    BatchRequest batch = client.batch();

    // Create the callback.
    JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {

        @Override/*w ww . j a v  a 2 s . c om*/
        public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
            View.display(calendar);
            addedCalendarsUsingBatch.add(calendar);
        }

        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
            System.out.println("Error Message: " + e.getMessage());
        }
    };

    // Create 2 Calendar Entries to insert.
    Calendar entry1 = new Calendar().setSummary("Calendar for Testing 1");
    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();
}

From source file:calendariotaller.CalendarSample.java

License:Apache License

private static 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>() {

            @Override//from  ww w .  ja  v  a 2s. c om
            public void onSuccess(Void content, HttpHeaders responseHeaders) {
                System.out.println("Delete is successful!");
            }

            @Override
            public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                System.out.println("Error Message: " + e.getMessage());
            }
        });
    }

    batch.execute();
}

From source file:calendar_cmdline_sample.CalendarSample.java

License:Apache License

@SuppressWarnings("unused")
private static void addCalendarsUsingBatch() throws IOException {
    View.header("Add Calendars using Batch");
    BatchRequest batch = client.batch();

    // Create the callback.
    JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {

        @Override//from   w ww  . j av  a  2  s  .co  m
        public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
            View.display(calendar);
            addedCalendarsUsingBatch.add(calendar);
        }

        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
            System.out.println("Error Message: " + e.getMessage());
        }
    };

    // Create 2 Calendar Entries to insert.
    Calendar entry1 = new Calendar().setSummary("Calendar for Testing 1");
    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();
}

From source file:calendar_cmdline_sample.CalendarSample.java

License:Apache License

@SuppressWarnings("unused")
private static 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>() {

            @Override/* w ww.j  av  a2 s .c  o  m*/
            public void onSuccess(Void content, HttpHeaders responseHeaders) {
                System.out.println("Delete is successful!");
            }

            @Override
            public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                System.out.println("Error Message: " + e.getMessage());
            }
        });
    }

    batch.execute();
}

From source file:ch.cyberduck.core.googledrive.DriveBatchDeleteFeature.java

License:Open Source License

@Override
public void delete(final List<Path> files, final LoginCallback prompt, final Callback callback)
        throws BackgroundException {
    final BatchRequest batch = session.getClient().batch();
    final List<BackgroundException> failures = new ArrayList<>();
    for (Path file : files) {
        try {//from ww  w  .j a va2s. c om
            session.getClient().files().delete(new DriveFileidProvider(session).getFileid(file)).queue(batch,
                    new JsonBatchCallback<Void>() {
                        @Override
                        public void onFailure(final GoogleJsonError e, final HttpHeaders responseHeaders)
                                throws IOException {
                            log.warn(String.format("Failure deleting %s. %s", file, e.getMessage()));
                            failures.add(new HttpResponseExceptionMappingService()
                                    .map(new HttpResponseException(e.getCode(), e.getMessage())));
                        }

                        @Override
                        public void onSuccess(final Void aVoid, final HttpHeaders responseHeaders)
                                throws IOException {
                            callback.delete(file);
                        }
                    });
        } catch (IOException e) {
            throw new DriveExceptionMappingService().map("Cannot delete {0}", e, file);
        }
    }
    try {
        batch.execute();
    } catch (IOException e) {
        throw new DriveExceptionMappingService().map(e);
    }
    for (BackgroundException e : failures) {
        throw e;
    }
}

From source file:com.bibibig.yeon.navitest.CalendarList.AsyncBatchInsertCalendarList.java

License:Apache License

@Override
protected void doInBackground() throws IOException {
    BatchRequest batch = client.batch();
    for (Calendar calendar : calendars) {
        client.calendars().insert(calendar).setFields(BasicInfo.CALFIELDS).queue(batch,
                new JsonBatchCallback<Calendar>() {

                    public void onSuccess(Calendar calendar, HttpHeaders headers) {
                        model.add(calendar);
                    }/*from  www . j  a v  a  2s. c o  m*/

                    @Override
                    public void onFailure(GoogleJsonError err, HttpHeaders headers) throws IOException {
                        Utils.logAndShowError(activity, MainActivity.TAG, err.getMessage());
                    }
                });
    }
    batch.execute();
}

From source file:com.example.eventgooglecalendar.asynctasks.AsyncBatchInsertCalendars.java

License:Apache License

@Override
protected void doInBackground() throws IOException {
    BatchRequest batch = client.batch();
    for (Calendar calendar : calendars) {
        client.calendars().insert(calendar).setFields(CalendarInfo.FIELDS).queue(batch,
                new JsonBatchCallback<Calendar>() {

                    public void onSuccess(Calendar calendar, HttpHeaders headers) {
                        model.add(calendar);
                    }//from w  w w  .j a  va 2 s .  com

                    @Override
                    public void onFailure(GoogleJsonError err, HttpHeaders headers) throws IOException {
                        Utils.logAndShowError(activity, CalendarSampleActivity.TAG, err.getMessage());
                    }
                });
    }
    batch.execute();
}

From source file:com.google.cloud.dataflow.sdk.util.GcsUtil.java

License:Apache License

private void enqueueCopy(final GcsPath from, final GcsPath to, BatchRequest batch) throws IOException {
    Storage.Objects.Copy copyRequest = storageClient.objects().copy(from.getBucket(), from.getObject(),
            to.getBucket(), to.getObject(), null);
    copyRequest.queue(batch, new JsonBatchCallback<StorageObject>() {
        @Override//from  w  w w . j a va  2s .co  m
        public void onSuccess(StorageObject obj, HttpHeaders responseHeaders) {
            LOG.debug("Successfully copied {} to {}", from, to);
        }

        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
            if (errorExtractor.itemNotFound(e)) {
                // Do nothing on item not found.
                LOG.debug("{} does not exist, assuming this is a retry after deletion.", from);
                return;
            }
            throw new IOException(String.format("Error trying to copy %s to %s: %s", from, to, e));
        }
    });
}

From source file:com.google.cloud.dataflow.sdk.util.GcsUtil.java

License:Apache License

private void enqueueDelete(final GcsPath file, BatchRequest batch) throws IOException {
    Storage.Objects.Delete deleteRequest = storageClient.objects().delete(file.getBucket(), file.getObject());
    deleteRequest.queue(batch, new JsonBatchCallback<Void>() {
        @Override/* ww  w . ja v  a 2s  .  c  om*/
        public void onSuccess(Void obj, HttpHeaders responseHeaders) {
            LOG.debug("Successfully deleted {}", file);
        }

        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
            if (errorExtractor.itemNotFound(e)) {
                // Do nothing on item not found.
                LOG.debug("{} does not exist.", file);
                return;
            }
            throw new IOException(String.format("Error trying to delete %s: %s", file, e));
        }
    });
}

From source file:com.google.cloud.dns.spi.DefaultDnsRpc.java

License:Open Source License

private static <T> JsonBatchCallback<T> toJsonCallback(final RpcBatch.Callback<T> callback) {
    return new JsonBatchCallback<T>() {
        @Override//from  w  ww. ja  va 2 s.  c  om
        public void onSuccess(T response, HttpHeaders httpHeaders) throws IOException {
            callback.onSuccess(response);
        }

        @Override
        public void onFailure(GoogleJsonError googleJsonError, HttpHeaders httpHeaders) throws IOException {
            callback.onFailure(googleJsonError);
        }
    };
}