Runs the example.

@param adManagerServices the services factory.
@param session the session.
@throws ApiException if the API request failed with one or more service errors.
@throws RemoteException if the API request failed due to other errors.
768922
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the AdjustmentService.
    AdjustmentServiceInterface adjustmentService =
        adManagerServices.get(session, AdjustmentServiceInterface.class);

    // Create a statement to get all forecast adjustments.
    StatementBuilder statementBuilder =
        new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get forecast adjustments by statement.
      TrafficForecastAdjustmentPage page =
          adjustmentService.getTrafficAdjustmentsByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (TrafficForecastAdjustment adjustment : page.getResults()) {
          System.out.printf(
              "%d) Forecast adjustment with ID %d containing %d adjustment segments was found.%n",
              i++,
              adjustment.getId(),
              adjustment.getForecastAdjustmentSegments() != null
                  ? adjustment.getForecastAdjustmentSegments().length
                  : 0);
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
1038961
public static void runExample(
      AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService =
        adWordsServices.get(session, CampaignCriterionServiceInterface.class);

    int offset = 0;

    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder
        .fields(
            CampaignCriterionField.CampaignId,
            CampaignCriterionField.Id,
            CampaignCriterionField.CriteriaType,
            CampaignCriterionField.PlatformName,
            CampaignCriterionField.LanguageName,
            CampaignCriterionField.LocationName,
            CampaignCriterionField.KeywordText)
        .in(CampaignCriterionField.CriteriaType, "KEYWORD", "LANGUAGE", "LOCATION", "PLATFORM")
        .offset(0)
        .limit(PAGE_SIZE)
        .build();

    CampaignCriterionPage page = null;
    do {
      page = campaignCriterionService.get(selector);

      if (page.getEntries() != null) {
        // Display campaigns.
        for (CampaignCriterion campaignCriterion : page.getEntries()) {
          System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, "
              + "and type '%s' was found.%n", campaignCriterion.getCampaignId(), campaignCriterion
              .getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
        }
      } else {
        System.out.println("No campaign criteria were found.");
      }
      offset += PAGE_SIZE;
      selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
  }
210557
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    CreativeServiceInterface creativeService =
        adManagerServices.get(session, CreativeServiceInterface.class);

    // Create a statement to select creatives.
    StatementBuilder statementBuilder =
        new StatementBuilder()
            .where("creativeType = :creativeType")
            .orderBy("id ASC")
            .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
            .withBindVariableValue("creativeType", "ImageCreative");

    // Retrieve a small amount of creatives at a time, paging through
    // until all creatives have been retrieved.
    int totalResultSetSize = 0;
    do {
      CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        // Print out some information for each creative.
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Creative creative : page.getResults()) {
          System.out.printf(
              "%d) Creative with ID %d and name '%s' was found.%n",
              i++, creative.getId(), creative.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
1031982
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the TeamService.
    TeamServiceInterface teamService = adManagerServices.get(session, TeamServiceInterface.class);

    // Create a read/write team.
    Team readWriteTeam = new Team();
    readWriteTeam.setName("Read/write team #" + new Random().nextInt(Integer.MAX_VALUE));
    readWriteTeam.setTeamAccessType(TeamAccessType.READ_WRITE);
    readWriteTeam.setHasAllCompanies(false);
    readWriteTeam.setHasAllInventory(false);

    // Create a read-only team.
    Team readOnlyTeam = new Team();
    readOnlyTeam.setName("Read-only team #" + new Random().nextInt(Integer.MAX_VALUE));
    readOnlyTeam.setTeamAccessType(TeamAccessType.READ_ONLY);
    readOnlyTeam.setHasAllCompanies(false);
    readOnlyTeam.setHasAllInventory(false);

    // Create the teams on the server.
    Team[] teams = teamService.createTeams(new Team[] {readWriteTeam, readOnlyTeam});

    for (Team createdTeam : teams) {
      System.out.printf(
          "A team with ID %d and name '%s' was created.%n",
          createdTeam.getId(), createdTeam.getName());
    }
  }
435020
@Override
    public void doSessionCreated(ManagementContext managementContext,
                                 ServiceManagementBean serviceBean,
                                 IoSessionEx session,
                                 ManagementSessionType managementSessionType) throws Exception {
        SessionManagementBean sessionBean = managementContext.addSessionManagementBean(serviceBean, session);
        serviceBean.storeSessionManagementBean(sessionBean);

        managementContext.getManagementSessionStrategy().doSessionCreated(sessionBean);

        super.doSessionCreated(managementContext, serviceBean, session, managementSessionType);
    }
1062528
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    LabelServiceInterface labelService =
        adManagerServices.get(session, LabelServiceInterface.class);

    // Create a statement to select labels.
    StatementBuilder statementBuilder =
        new StatementBuilder()
            .where("isActive = :isActive")
            .orderBy("id ASC")
            .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
            .withBindVariableValue("isActive", true);

    // Retrieve a small amount of labels at a time, paging through
    // until all labels have been retrieved.
    int totalResultSetSize = 0;
    do {
      LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        // Print out some information for each label.
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Label label : page.getResults()) {
          System.out.printf(
              "%d) Label with ID %d and name '%s' was found.%n",
              i++, label.getId(), label.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
32034
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session)
      throws RemoteException {
    // Get all of the feeds for the session's account.
    List<Feed> feeds = getFeeds(adWordsServices, session);

    for (Feed feed : feeds) {
      // Retrieve all the sitelinks from the current feed.
      Map<Long, SiteLinkFromFeed> feedItems = getSiteLinksFromFeed(adWordsServices, session, feed);

      // Get all the instances where a sitelink from this feed has been added to a campaign.
      List<CampaignFeed> campaignFeeds =
          getCampaignFeeds(adWordsServices, session, feed, PLACEHOLDER_SITELINKS);

      Set<Long> allFeedItemsToDelete = Sets.newHashSet();
      for (CampaignFeed campaignFeed : campaignFeeds) {
        // Retrieve the sitelinks that have been associated with this campaign.
        Set<Long> feedItemIds = getFeedItemIdsForCampaign(campaignFeed);

        ExtensionSettingPlatform platformRestrictions =
            getPlatformRestictionsForCampaign(campaignFeed);

        if (feedItemIds.isEmpty()) {
          System.out.printf("Migration skipped for campaign feed with campaign ID %d "
              + "and feed ID %d because no mapped feed item IDs were found in the "
              + "campaign feed's matching function.%n", campaignFeed.getCampaignId(),
              campaignFeed.getFeedId());
        } else {
          // Delete the campaign feed that associates the sitelinks from the feed to the campaign.
          deleteCampaignFeed(adWordsServices, session, campaignFeed);

          // Create extension settings instead of sitelinks.
          createExtensionSetting(adWordsServices,
              session,
              feedItems,
              campaignFeed,
              feedItemIds,
              platformRestrictions);

          // Mark the sitelinks from the feed for deletion.
          allFeedItemsToDelete.addAll(feedItemIds);
        }
      }

      // Delete all the sitelinks from the feed.
      deleteOldFeedItems(adWordsServices, session, allFeedItemsToDelete, feed);
    }
  }
649518
@SuppressWarnings("unchecked") /* See constructor comments. */
  public void setAuthorization(Object soapClient, AdsSession adsSession)
      throws AuthenticationException {
    final String authorizationHeader =
        authorizationHeaderProvider.getAuthorizationHeader(adsSession,
            soapClientHandler.getEndpointAddress(soapClient));
    soapClientHandler.putAllHttpHeaders(soapClient, new HashMap<String, String>() {
      {
        put("Authorization", authorizationHeader);
      }
    });
  }
592624
@Override
    public void addMBeanServers(Set<MBeanServerConnection> servers) {
        try {
            /*
			 * this.mbeanServer = AdminServiceFactory.getMBeanFactory().getMBeanServer();
			 */
            Class adminServiceClass = ClassUtil.classForName("com.ibm.websphere.management.AdminServiceFactory",getClass().getClassLoader());
            if (adminServiceClass != null) {
                Method getMBeanFactoryMethod = adminServiceClass.getMethod("getMBeanFactory", new Class[0]);
                Object mbeanFactory = getMBeanFactoryMethod.invoke(null);
                if (mbeanFactory != null) {
                    Method getMBeanServerMethod = mbeanFactory.getClass().getMethod("getMBeanServer", new Class[0]);
                    servers.add((MBeanServer) getMBeanServerMethod.invoke(mbeanFactory));
                }
            }
        }
        catch (InvocationTargetException ex) {
            // CNFE should be earlier
            throw new IllegalArgumentException(INTERNAL_ERROR_MSG,ex);
        } catch (IllegalAccessException ex) {
            throw new IllegalArgumentException(INTERNAL_ERROR_MSG,ex);
        } catch (NoSuchMethodException ex) {
            throw new IllegalArgumentException(INTERNAL_ERROR_MSG,ex);
        }
    }
6297
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the NativeStyleService.
    NativeStyleServiceInterface nativeStyleService =
        adManagerServices.get(session, NativeStyleServiceInterface.class);

    String htmlSnippet =
            "<div id=\"adunit\" style=\"overflow: hidden;\">\n"
            + "  <img src='[%Thirdpartyimpressiontracker%]' style='display:none'>\n"
            + "  <div class='attribution'>Ad</div>\n"
            + "  <div class='image'>\n"
            + "    <a class='image-link' "
            + "href='%%CLICK_URL_UNESC%%[%Thirdpartyclicktracker%]%%DEST_URL%%' target='_top'>"
            + "<img src=\"[%Image%]\"></a>\n"
            + "  </div>\n"
            + "  <div class='app-icon'><img src=\"[%Appicon%]\"/></div>\n"
            + "  <div class='title'>\n"
            + "    <a class='title-link' "
            + "href='%%CLICK_URL_UNESC%%[%Thirdpartyclicktracker%]%%DEST_URL%%' "
            + "target='_top'>[%Headline%]</a>\n"
            + "  </div>\n"
            + "  <div class='reviews'></div>\n"
            + "  <div class='body'>\n"
            + "    <a class='body-link' "
            + "href='%%CLICK_URL_UNESC%%[%Thirdpartyclicktracker%]%%DEST_URL%%' "
            + "target='_top'>[%Body%]</a>\n"
            + "  </div>\n"
            + "  <div class='price'>[%Price%]</div>\n"
            + "  <div class='button'>\n"
            + "    <a class='button-link' "
            + "href='%%CLICK_URL_UNESC%%[%Thirdpartyclicktracker%]%%DEST_URL%%' "
            + "target='_top'>[%Calltoaction%]</a>\n"
            + "  </div>\n"
            + "</div>\n";

    String cssSnippet =
        "body {"
            + "    background-color: rgba(255, 255, 255, 1);"
            + "    font-family: \"Roboto-Regular\", sans-serif;"
            + "    font-weight: normal;"
            + "    font-size: 12px;"
            + "    line-height: 14px;"
            + "}"
            + ".attribution {"
            + "    background-color: rgba(236, 182, 0, 1);"
            + "    color: rgba(255, 255, 255, 1);"
            + "    font-size: 13px;"
            + "    display: table;"
            + "    margin: 4px 8px;"
            + "    padding: 0 3px;"
            + "    border-radius: 2px;"
            + "}"
            + ".image {"
            + "    text-align: center;"
            + "    margin: 8px;"
            + "}"
            + ".image img,"
            + ".image-link {"
            + "    width: 100%;"
            + "}"
            + ".app-icon {"
            + "    float: left;"
            + "    margin: 0 8px 4px 8px;"
            + "    height: 40px;"
            + "    width: 40px;"
            + "    background-color: transparent;"
            + "}"
            + ".app-icon img {"
            + "    height: 100%;"
            + "    width: 100%;"
            + "    border-radius: 20%;"
            + "}"
            + ".title {"
            + "    font-weight: bold;"
            + "    font-size: 14px;"
            + "    line-height: 20px;"
            + "    margin: 8px 8px 4px 8px;"
            + "}"
            + ".title a {"
            + "    color: rgba(112, 112, 112, 1);"
            + "    text-decoration: none;"
            + "}"
            + ".reviews {"
            + "    float: left;"
            + "}"
            + ".reviews svg {"
            + "    fill: rgba(0, 0, 0, 0.7);"
            + "}"
            + ".body {"
            + "    clear: left;"
            + "    margin: 8px;"
            + "}"
            + ".body a {"
            + "    color: rgba(110, 110, 110, 1);"
            + "    text-decoration: none;"
            + "}"
            + ".price {"
            + "    display: none;"
            + "}"
            + ".button {"
            + "    font-size: 14px;"
            + "    font-weight: bold;"
            + "    float: right;"
            + "    margin: 0px 16px 16px 0px;"
            + "    white-space: nowrap;"
            + "}"
            + ".button a {"
            + "    color: #2196F3;"
            + "    text-decoration: none;"
            + "}"
            + ".button svg {"
            + "    display: none;"
            + "}";

    // This is the creative template ID for the system-defined native app
    // install ad format, which we will create the native style from. Use
    // CreativeTemplateService.getCreativeTemplatesByStatement() and
    // CreativeTemplate.isNativeEligible to get other native ad formats
    // available in your network.
    long nativeAppInstallTemplateId = 10004400L;

    // Set the size for the native style.
    Size size = new Size();
    size.setWidth(300);
    size.setHeight(250);
    size.setIsAspectRatio(false);

    // Create a style for native app install ads.
    NativeStyle nativeStyle = new NativeStyle();
    nativeStyle.setName("Native style #" + new Random().nextInt(Integer.MAX_VALUE));
    nativeStyle.setCreativeTemplateId(nativeAppInstallTemplateId);
    nativeStyle.setSize(size);
    nativeStyle.setHtmlSnippet(htmlSnippet);
    nativeStyle.setCssSnippet(cssSnippet);

    // Create the native style on the server.
    NativeStyle[] nativeStyles =
        nativeStyleService.createNativeStyles(new NativeStyle[] {nativeStyle});

    for (NativeStyle createdNativeStyle : nativeStyles) {
      System.out.printf(
          "A native style with ID %d and name '%s' was created.%n",
          createdNativeStyle.getId(), createdNativeStyle.getName());
    }
  }
219891
private static Map<Long, ManagedCustomer> getAllManagedCustomers(
      AdWordsServicesInterface adWordsServices, ImmutableAdWordsSession session)
      throws RemoteException {
    // Get the ManagedCustomerService.
    ManagedCustomerServiceInterface managedCustomerService =
        adWordsServices.get(session, ManagedCustomerServiceInterface.class);

    SelectorBuilder selectorBuilder =
        new SelectorBuilder()
            .fields(ManagedCustomerField.CustomerId)
            .equals(ManagedCustomerField.CanManageClients, "false")
            .limit(PAGE_SIZE)
            .offset(0);

    ManagedCustomerPage managedCustomerPage;
    int offset = 0;
    Map<Long, ManagedCustomer> managedCustomers = Maps.newHashMap();
    do {
      selectorBuilder.offset(offset);
      managedCustomerPage = managedCustomerService.get(selectorBuilder.build());
      if (managedCustomerPage.getEntries() != null) {
        for (ManagedCustomer managedCustomer : managedCustomerPage.getEntries()) {
          managedCustomers.put(managedCustomer.getCustomerId(), managedCustomer);
        }
      }
      offset += PAGE_SIZE;
    } while (offset < managedCustomerPage.getTotalNumEntries());

    return managedCustomers;
  }
1169620
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the RateCardService.
    RateCardServiceInterface rateCardService =
        adManagerServices.get(session, RateCardServiceInterface.class);

    // Create a statement to get all rate cards using USD as currency.
    StatementBuilder statementBuilder =
        new StatementBuilder()
            .where("currencyCode = 'USD'")
            .orderBy("id ASC")
            .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get rate cards by statement.
      RateCardPage page = rateCardService.getRateCardsByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (RateCard rateCard : page.getResults()) {
          System.out.printf(
              "%d) Rate card with ID %d, name '%s', and currency '%s' was found.%n",
              i++, rateCard.getId(), rateCard.getName(), rateCard.getCurrencyCode());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
844622
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    NativeStyleServiceInterface nativeStyleService =
        adManagerServices.get(session, NativeStyleServiceInterface.class);

    // Create a statement to select native styles.
    StatementBuilder statementBuilder =
        new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Retrieve a small amount of native styles at a time, paging through
    // until all native styles have been retrieved.
    int totalResultSetSize = 0;
    do {
      NativeStylePage page =
          nativeStyleService.getNativeStylesByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        // Print out some information for each native style.
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (NativeStyle nativeStyle : page.getResults()) {
          System.out.printf(
              "%d) Native style with ID %d and name '%s' was found.%n",
              i++, nativeStyle.getId(), nativeStyle.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
356993
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the LabelService.
    LabelServiceInterface labelService =
        adManagerServices.get(session, LabelServiceInterface.class);

    // Create a competitive exclusion label.
    Label competitiveExclusionLabel = new Label();
    competitiveExclusionLabel.setName(
        "Car company label #" + new Random().nextInt(Integer.MAX_VALUE));
    competitiveExclusionLabel.setTypes(new LabelType[] {LabelType.COMPETITIVE_EXCLUSION});

    // Create an ad unit frequency cap label.
    Label adUnitFrequencyCapLabel = new Label();
    adUnitFrequencyCapLabel.setName(
        "Don't run too often label #" + new Random().nextInt(Integer.MAX_VALUE));
    adUnitFrequencyCapLabel.setTypes(new LabelType[] {LabelType.AD_UNIT_FREQUENCY_CAP});

    // Create the labels on the server.
    Label[] labels =
        labelService.createLabels(new Label[] {competitiveExclusionLabel, adUnitFrequencyCapLabel});

    for (Label createdLabel : labels) {
      System.out.printf("A label with ID %d and name '%s' was created.%n",
          createdLabel.getId(), createdLabel.getName());
    }
  }
272350
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ProductTemplateService.
    ProductTemplateServiceInterface productTemplateService =
        adManagerServices.get(session, ProductTemplateServiceInterface.class);

    // Create a statement to select all product templates.
    StatementBuilder statementBuilder = new StatementBuilder()
        .orderBy("id ASC")
        .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Default for total result set size.
    int totalResultSetSize = 0;

    do {
      // Get product templates by statement.
      ProductTemplatePage page =
          productTemplateService.getProductTemplatesByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (ProductTemplate productTemplate : page.getResults()) {
          System.out.printf(
              "%d) Product template with ID %d and name '%s' was found.%n", i++,
              productTemplate.getId(), productTemplate.getName());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
730094
protected void remoteInit() throws JMSException
    {
        CreateBrowserQuery query = new CreateBrowserQuery();
        query.setBrowserId(id);
        query.setSessionId(session.getId());
        query.setQueue(queue);
        query.setMessageSelector(messageSelector);
        transportEndpoint.blockingRequest(query);
    }
1125779
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    // Get the ReportService.
    ReportServiceInterface reportService =
        adManagerServices.get(session, ReportServiceInterface.class);

    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] {Dimension.DATE, Dimension.ORDER_ID});
    reportQuery.setColumns(new Column[] {Column.AD_SERVER_IMPRESSIONS});

    // Set the dynamic date range type or a custom start and end date.
    reportQuery.setDateRangeType(DateRangeType.LAST_WEEK);

    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);

    // Run report job.
    reportJob = reportService.runReportJob(reportJob);

    // Create report downloader.
    final ReportDownloader reportDownloader =
        new ReportDownloader(reportService, reportJob.getId());

    reportDownloader.whenReportReady(
        new ReportCallback() {
          @Override
          public void onSuccess() {
            try {
              // Change to your file location.
              File file = File.createTempFile("async-report-", ".csv.gz");

              System.out.printf("Downloading report to %s ...", file.toString());

              // Download the report.
              ReportDownloadOptions options = new ReportDownloadOptions();
              options.setExportFormat(ExportFormat.CSV_DUMP);
              options.setUseGzipCompression(true);
              URL url = reportDownloader.getDownloadUrl(options);
              Resources.asByteSource(url).copyTo(Files.asByteSink(file));

              System.out.println("done.");
            } catch (IOException e) {
              System.err.println("Failed to write report.");
            }
          }

          @Override
          public void onInterruption() {
            System.err.println("Report download interupted.");
          }

          @Override
          public void onFailure() {
            System.err.println("Report download failed.");
          }

          @Override
          public void onException(Exception e) {
            System.err.println("Report download failed.");
            e.printStackTrace();
          }
        });
  }