use of com.google.api.services.analytics.Analytics in project pentaho-kettle by pentaho.
the class GaInputStepDialog method readGaSegments.
// Collect segment list from the GA service for the given authentication information
public void readGaSegments() {
try {
Analytics analytics = getAnalytics();
if (analytics == null) {
return;
}
Segments segments = analytics.management().segments().list().execute();
ArrayList<String> segmentNames = new ArrayList<String>(20);
segmentIds.clear();
for (Segment segmentEntry : segments.getItems()) {
segmentNames.add(segmentEntry.getName());
segmentIds.put(segmentEntry.getName(), "gaid::" + segmentEntry.getId());
}
// put the segments to the combo box and select first one
wQuSegment.setItems(segmentNames.toArray(new String[segmentNames.size()]));
if (segmentNames.size() > 0) {
wQuSegment.select(0);
}
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "GoogleAnalyticsDialog.AuthenticationFailure.DialogTitle"));
mb.setMessage(BaseMessages.getString(PKG, "GoogleAnalyticsDialog.AuthenticationFailure.DialogMessage"));
mb.open();
}
}
use of com.google.api.services.analytics.Analytics in project pentaho-kettle by pentaho.
the class GaInputStepDialog method getPreviewQuery.
protected Analytics.Data.Ga.Get getPreviewQuery() {
try {
String ids = wCustomProfileEnabled.getSelection() ? transMeta.environmentSubstitute(wGaCustomProfile.getText()) : profileTableIds.get(wGaProfile.getText());
String metrics = transMeta.environmentSubstitute(wQuMetrics.getText());
if (Utils.isEmpty(metrics)) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "GoogleAnalytics.Error.NoMetricsSpecified.Title"));
mb.setMessage(BaseMessages.getString(PKG, "GoogleAnalytics.Error.NoMetricsSpecified.Message"));
mb.open();
return null;
}
Analytics analytics = getAnalytics();
if (analytics == null) {
return null;
}
Analytics.Data.Ga.Get query = analytics.data().ga().get(ids, transMeta.environmentSubstitute(wQuStartDate.getText()), transMeta.environmentSubstitute(wQuEndDate.getText()), metrics);
String dimensions = transMeta.environmentSubstitute(wQuDimensions.getText());
if (!Utils.isEmpty(dimensions)) {
query.setDimensions(dimensions);
}
if (wUseSegmentEnabled.getSelection()) {
if (wCustomSegmentEnabled.getSelection()) {
query.setSegment(transMeta.environmentSubstitute(wQuCustomSegment.getText()));
} else {
query.setSegment(segmentIds.get(wQuSegment.getText()));
}
}
if (!Utils.isEmpty(wQuSamplingLevel.getText())) {
query.setSamplingLevel(transMeta.environmentSubstitute(wQuSamplingLevel.getText()));
}
if (!Utils.isEmpty(wQuFilters.getText())) {
query.setFilters(transMeta.environmentSubstitute(wQuFilters.getText()));
}
if (!Utils.isEmpty(wQuSort.getText())) {
query.setSort(transMeta.environmentSubstitute(wQuSort.getText()));
}
return query;
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "GoogleAnalyticsDialog.AuthenticationFailure.DialogTitle"));
mb.setMessage(BaseMessages.getString(PKG, "GoogleAnalyticsDialog.AuthenticationFailure.DialogMessage"));
mb.open();
}
return null;
}
use of com.google.api.services.analytics.Analytics in project pentaho-kettle by pentaho.
the class GaInputStepDialog method readGaProfiles.
// Collect profile list from the GA service for the given authentication
// information
public void readGaProfiles() {
try {
Analytics analytics = getAnalytics();
if (analytics == null) {
return;
}
Analytics.Management.Profiles.List profiles = analytics.management().profiles().list("~all", "~all");
Profiles profileList = profiles.execute();
profileTableIds.clear();
List<String> profileNames = new ArrayList<String>();
for (Profile profile : profileList.getItems()) {
String tableId = "ga:" + profile.getId();
String profileName = tableId + " - profile: " + profile.getName();
profileNames.add(profileName);
profileTableIds.put(profileName, tableId);
}
// put the profiles to the combo box and select first one
wGaProfile.setItems(profileNames.toArray(new String[profileNames.size()]));
if (profileNames.size() > 0) {
wGaProfile.select(0);
}
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "GoogleAnalyticsDialog.AuthenticationFailure.DialogTitle"));
mb.setMessage(BaseMessages.getString(PKG, "GoogleAnalyticsDialog.AuthenticationFailure.DialogMessage"));
mb.open();
}
}
Aggregations