com.google.api.ads.dfp.axis.utils.v201203
Class ReportDownloader

java.lang.Object
  extended by com.google.api.ads.dfp.axis.utils.v201203.ReportDownloader

public class ReportDownloader
extends Object

Retrieves reports using a ReportServiceInterface.

There are two main functions of this class:

ReportUtils also provides the method whenReportReady(ReportCallback) to wait for a scheduled report to finish processing before taking an action on the report through the supplied ReportCallback.

Author:
Adam Rogal

Field Summary
static int SLEEP_TIMER
          The time to sleep before each request to the service.
 
Constructor Summary
ReportDownloader(ReportServiceInterface reportService, long reportJobId)
          Constructs a ReportDownloader object for a ReportServiceInterface and a report job id that the the class works on.
 
Method Summary
 void downloadReport(ExportFormat exportFormat, OutputStream outputStream)
          Downloads a Gzip or plain-text format report XML to output stream indicated by outputStream.
 void downloadReport(ExportFormat exportFormat, String fileName)
          Downloads a Gzip report to file located at fileName.
 String getReport(ExportFormat exportFormat)
          Gets the plain-text format report as a String.
 boolean waitForReportReady()
          Blocks and waits for a report to be ready.
 Thread whenReportReady(ReportCallback callback)
          Waits for the report to be ready and then calls: ReportCallback.onSuccess() for a successful scheduling ReportCallback.onFailure() for a failed scheduling due to a ReportJobStatus.FAILED ReportCallback.onInterruption() if the wait thread is interrupted ReportCallback.onException(Exception) if there was an exception while waiting for the report to finish
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLEEP_TIMER

public static final int SLEEP_TIMER
The time to sleep before each request to the service.

See Also:
Constant Field Values
Constructor Detail

ReportDownloader

public ReportDownloader(ReportServiceInterface reportService,
                        long reportJobId)
Constructs a ReportDownloader object for a ReportServiceInterface and a report job id that the the class works on.

Parameters:
reportService - the ReportService stub to make calls to
reportJobId - the report job ID
Method Detail

whenReportReady

public Thread whenReportReady(ReportCallback callback)
Waits for the report to be ready and then calls:

Parameters:
callback - the ReportCallback to call when the job has finished, successfully or otherwise
Returns:
the thread created that handles waiting for the report. Thread.interrupt() can be called on the returned thread to interrupt it.
Throws:
IllegalArgumentException - if callback == null

waitForReportReady

public boolean waitForReportReady()
                           throws RemoteException,
                                  InterruptedException
Blocks and waits for a report to be ready. When a ReportJobStatus is received that is not ReportJobStatus#Pending or ReportJobStatus#InProgress, the report is considered finished, and the method is returned with a true if the report was successful, or an false if not.

Returns:
true if the report was successful, false otherwise
Throws:
RemoteException - if there was an error performing one of the SOAP calls
InterruptedException - if the thread was interrupted

downloadReport

public void downloadReport(ExportFormat exportFormat,
                           String fileName)
                    throws IOException
Downloads a Gzip report to file located at fileName.

Parameters:
exportFormat - the export format of the report
fileName - the file location to download the report to
Throws:
IOException - if there was an error performing any I/O action, including any SOAP calls
IllegalStateException - if the report is not ready to be downloaded

downloadReport

public void downloadReport(ExportFormat exportFormat,
                           OutputStream outputStream)
                    throws IOException
Downloads a Gzip or plain-text format report XML to output stream indicated by outputStream.

Parameters:
exportFormat - the export format of the report
outputStream - the output stream to download the report to
Throws:
IOException - if there was an error performing any I/O action, including any SOAP calls
IllegalStateException - if the report is not ready to be downloaded

getReport

public String getReport(ExportFormat exportFormat)
                 throws IOException
Gets the plain-text format report as a String.

Parameters:
exportFormat - the export format of the report
Returns:
the plain-text format report XML as a String
Throws:
IOException - if there was an error performing any I/O action, including any SOAP calls
IllegalStateException - if the report is not ready to be downloaded


Copyright © 2012. All Rights Reserved.