Search in sources :

Example 1 with Analytics

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();
    }
}
Also used : ArrayList(java.util.ArrayList) Segments(com.google.api.services.analytics.model.Segments) Analytics(com.google.api.services.analytics.Analytics) Segment(com.google.api.services.analytics.model.Segment) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with Analytics

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;
}
Also used : Analytics(com.google.api.services.analytics.Analytics) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with Analytics

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();
    }
}
Also used : Profiles(com.google.api.services.analytics.model.Profiles) ArrayList(java.util.ArrayList) Analytics(com.google.api.services.analytics.Analytics) Profile(com.google.api.services.analytics.model.Profile) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)3 Analytics (com.google.api.services.analytics.Analytics)3 IOException (java.io.IOException)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 ArrayList (java.util.ArrayList)2 Profile (com.google.api.services.analytics.model.Profile)1 Profiles (com.google.api.services.analytics.model.Profiles)1 Segment (com.google.api.services.analytics.model.Segment)1 Segments (com.google.api.services.analytics.model.Segments)1