use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project halyard by spinnaker.
the class GoogleKms method ensureKeyRingExists.
private static KeyRing ensureKeyRingExists(CloudKMS cloudKms, String locationId, String keyRingId) {
KeyRing keyRing;
try {
keyRing = cloudKms.projects().locations().keyRings().get(keyRingId).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == 404) {
keyRing = null;
} else {
throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving key ring: " + e.getMessage(), e);
}
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving key ring: " + e.getMessage(), e);
}
if (keyRing == null) {
String keyRingName = keyRingId.substring(keyRingId.lastIndexOf('/') + 1);
log.info("Creating a new key ring " + keyRingName);
keyRing = createKeyRing(cloudKms, locationId, keyRingName);
}
return keyRing;
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project beam by apache.
the class PubsubHelper method createTopic.
/**
* Create a topic from short name. Delete it if it already exists. Ensure the topic will be
* deleted on cleanup. Return full topic name.
*/
public TopicPath createTopic(String shortTopic) throws IOException {
TopicPath topic = PubsubClient.topicPathFromName(project, shortTopic);
while (true) {
try {
NexmarkUtils.console("create topic %s", topic);
pubsubClient.createTopic(topic);
createdTopics.add(topic);
return topic;
} catch (GoogleJsonResponseException ex) {
NexmarkUtils.console("attempting to cleanup topic %s", topic);
pubsubClient.deleteTopic(topic);
try {
if (!BackOffUtils.next(sleeper, backOff)) {
NexmarkUtils.console("too many retries for creating topic %s", topic);
throw ex;
}
} catch (InterruptedException in) {
throw new IOException(in);
}
}
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project beam by apache.
the class PubsubHelper method createSubscription.
/**
* Create subscription from short name. Ensure the subscription will be deleted on cleanup. Return
* full subscription name.
*/
public SubscriptionPath createSubscription(String shortTopic, String shortSubscription) throws IOException {
TopicPath topic = PubsubClient.topicPathFromName(project, shortTopic);
SubscriptionPath subscription = PubsubClient.subscriptionPathFromName(project, shortSubscription);
while (true) {
try {
NexmarkUtils.console("create subscription %s", subscription);
pubsubClient.createSubscription(topic, subscription, 60);
createdSubscriptions.add(subscription);
return subscription;
} catch (GoogleJsonResponseException ex) {
NexmarkUtils.console("attempting to cleanup subscription %s", subscription);
pubsubClient.deleteSubscription(subscription);
try {
if (!BackOffUtils.next(sleeper, backOff)) {
NexmarkUtils.console("too many retries for creating subscription %s", subscription);
throw ex;
}
} catch (InterruptedException in) {
throw new IOException(in);
}
}
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project pentaho-kettle by pentaho.
the class GaInputStepDialog method getFields.
// Visible for testing
void getFields() {
Analytics.Data.Ga.Get query = getPreviewQuery();
if (query == null) {
return;
}
query.setMaxResults(1);
try {
GaData dataFeed = query.execute();
if (dataFeed == null || dataFeed.getRows() == null || dataFeed.getRows().size() < 1) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText("Query yields empty feed");
mb.setMessage("The feed did not give any results. Please specify a query that returns data.");
mb.open();
return;
}
int i = 0;
List<GaData.ColumnHeaders> colHeaders = dataFeed.getColumnHeaders();
getTableView().table.setItemCount(colHeaders.size() + dataFeed.getProfileInfo().size());
for (GaData.ColumnHeaders colHeader : colHeaders) {
String name = colHeader.getName();
String dataType = colHeader.getDataType();
String columnType = colHeader.getColumnType();
TableItem item = getTableView().table.getItem(i);
if (columnType.equals("DIMENSION")) {
item.setText(1, GaInputStepMeta.FIELD_TYPE_DIMENSION);
item.setText(2, name);
item.setText(3, name);
// recognize date dimension
if (name.equalsIgnoreCase("ga:date")) {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_DATE));
item.setText(5, "yyyyMMdd");
} else if (name.equalsIgnoreCase("ga:daysSinceLastVisit") || name.equalsIgnoreCase("ga:visitLength") || name.equalsIgnoreCase("ga:visitCount")) {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_INTEGER));
item.setText(5, "#;-#");
} else if (name.equalsIgnoreCase("ga:latitude") || name.equalsIgnoreCase("ga:longitude")) {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_NUMBER));
item.setText(5, "#.#;-#.#");
} else {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
}
i++;
} else if (columnType.equals("METRIC")) {
item.setText(1, GaInputStepMeta.FIELD_TYPE_METRIC);
item.setText(2, name);
item.setText(3, name);
// depending on type
if (dataType.compareToIgnoreCase("currency") == 0 || dataType.compareToIgnoreCase("float") == 0 || dataType.compareToIgnoreCase("percent") == 0 || dataType.compareToIgnoreCase("us_currency") == 0) {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_NUMBER));
item.setText(5, "#.#;-#.#");
} else if (dataType.compareToIgnoreCase("time") == 0 || dataType.compareToIgnoreCase("integer") == 0) {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_INTEGER));
item.setText(5, "#;-#");
} else {
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
}
i++;
}
}
// Fill ds property and ds fields
TableItem item = getTableView().table.getItem(i);
item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY);
item.setText(2, GaInputStepMeta.PROPERTY_DATA_SOURCE_PROFILE_ID);
item.setText(3, GaInputStepMeta.PROPERTY_DATA_SOURCE_PROFILE_ID);
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
i++;
item = getTableView().table.getItem(i);
item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY);
item.setText(2, GaInputStepMeta.PROPERTY_DATA_SOURCE_WEBPROP_ID);
item.setText(3, GaInputStepMeta.PROPERTY_DATA_SOURCE_WEBPROP_ID);
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
i++;
item = getTableView().table.getItem(i);
item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY);
item.setText(2, GaInputStepMeta.PROPERTY_DATA_SOURCE_ACCOUNT_NAME);
item.setText(3, GaInputStepMeta.PROPERTY_DATA_SOURCE_ACCOUNT_NAME);
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
i++;
item = getTableView().table.getItem(i);
item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_FIELD);
item.setText(2, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_ID);
item.setText(3, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_ID);
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
i++;
item = getTableView().table.getItem(i);
item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_FIELD);
item.setText(2, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_NAME);
item.setText(3, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_NAME);
item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
item.setText(5, "");
getTableView().removeEmptyRows();
getTableView().setRowNums();
getTableView().optWidth(true);
getInput().setChanged();
} catch (IOException ioe) {
Exception exceptionToDisplay = ioe;
// Try to display something more user friendly than plain JSON
if (ioe instanceof GoogleJsonResponseException) {
GoogleJsonResponseException gjre = (GoogleJsonResponseException) ioe;
if (gjre.getDetails() != null && gjre.getDetails().getMessage() != null) {
exceptionToDisplay = new IOException(gjre.getDetails().getMessage(), gjre);
}
}
new ErrorDialog(shell, BaseMessages.getString(PKG, "GoogleAnalyticsDialog.RequestError.DialogTitle"), BaseMessages.getString(PKG, "GoogleAnalyticsDialog.RequestError.DialogMessage"), exceptionToDisplay);
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project drbookings by DrBookings.
the class GoogleCalendarSync method clearEvent.
private static void clearEvent(final String calendarId, final BookingBean b) throws IOException {
for (final Iterator<String> it = b.getCalendarIds().iterator(); it.hasNext(); ) {
final String id = it.next();
final Delete d = client.events().delete(calendarId, id);
if (logger.isDebugEnabled()) {
logger.debug("Deleting " + d.getEventId());
}
try {
d.execute();
} catch (final GoogleJsonResponseException e) {
if (logger.isErrorEnabled()) {
logger.error(e.toString());
}
}
it.remove();
}
}
Aggregations