/** * Instantiates the report definition, setting all the correct formats. * * @param reportDefinitionReportType the report definition type. * @param dateRangeType the date range type. * @param selector the selector containing the report properties. * @return the {@code ReportDefinition} */ protected ReportDefinition instantiateReportDefinition( ReportDefinitionReportType reportDefinitionReportType, ReportDefinitionDateRangeType dateRangeType, Selector selector) { // Create the Report Definition ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setReportName( REPORT_PREFIX + reportDefinitionReportType.value() + " " + System.currentTimeMillis()); reportDefinition.setDateRangeType(dateRangeType); reportDefinition.setReportType(reportDefinitionReportType); reportDefinition.setDownloadFormat(DownloadFormat.GZIPPED_CSV); reportDefinition.setSelector(selector); return reportDefinition; }
@Override public DownloadFormat getDownloadFormat() { return reportDefinition.getDownloadFormat(); }
return reportDownloader.downloadReport(AWQL_REQUEST, downloadFormat); } else { ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setSelector(new Selector()); reportDefinition .getSelector() .getFields() .addAll(Arrays.asList("CampaignId", "CampaignName", "Impressions")); reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.LAST_7_DAYS); reportDefinition.setReportName("Custom report"); reportDefinition.setReportType(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT); return reportDownloader.downloadReport(reportDefinition);
@Test public void testGetRequestType() { ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setDownloadFormat(DownloadFormat.GZIPPED_CSV); XmlReportDefinitionRequest request = new XmlReportDefinitionRequest(reportDefinition); assertEquals("Incorrect request type", RequestType.XML, request.getRequestType()); assertEquals( "Incorrect download format", DownloadFormat.GZIPPED_CSV, request.getDownloadFormat()); } }
/** * Create an instance of {@link ReportDefinition } * */ public ReportDefinition createReportDefinition() { return new ReportDefinition(); }
String filenamePrefix = reportDefinition.getReportType() + "-" + clientCustomerId + "-"; File reportFile = File.createTempFile(filenamePrefix, ".csv"); } catch (IOException e) { String errorMessage = "Failed to load report data from stream for " + reportDefinition.getReportType() + " with account " + session.getClientCustomerId() + "."; logger.error(errorMessage, e);
/** * Create an instance of {@link ReportDefinition } * */ public ReportDefinition createReportDefinition() { return new ReportDefinition(); }
ExecutorService executorService = Executors.newFixedThreadPool(numThreads); Stopwatch stopwatch = Stopwatch.createStarted(); logger.info("Downloading {" + reportDefinition.getReportType() + "} reports...");
/** * Gets the report download response from the API and retries on failure. */ @VisibleForTesting ReportDownloadResponse getReportDownloadResponse() throws ReportProcessingException { ReportDownloaderInterface reportDownloader = AdWordsServicesUtil.getUtility(session, ReportDownloaderInterface.class); ReportDownloadResponse result = null; try { result = reportDownloader.downloadReport(reportDefinition); } catch (ReportException | ReportDownloadResponseException e) { String msg = "Failed to download report file for " + reportDefinition.getReportType() + " with account " + session.getClientCustomerId() + "."; logger.error(msg, e); throw new ReportProcessingException(msg, e); } return result; }
@Override public DownloadFormat getDownloadFormat() { return reportDefinition.getDownloadFormat(); }
/** * Downloads the file from the API into an InputStream. * * @return the InputStream from the online report, null if httpStatus is not {@code HTTP_OK}. */ private InputStream getReportInputStream() { ReportDownloaderInterface reportDownloader = AdWordsServicesUtil.getUtility(session, ReportDownloaderInterface.class); InputStream result = null; try { ReportDownloadResponse reportDownloadResponse = reportDownloader.downloadReport(reportDefinition); result = reportDownloadResponse.getInputStream(); } catch (ReportException | ReportDownloadResponseException e) { logger.error( "Failed to download report stream for {} with account {}.", reportDefinition.getReportType(), session.getClientCustomerId(), e); } return result; }