com.microsoft.bingads.v13.reporting.ReportingStatusProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of microsoft.bingads Show documentation
Show all versions of microsoft.bingads Show documentation
The Bing Ads Java SDK is a library improving developer experience when working with the Bing Ads services by providing high-level access to features such as Bulk API, OAuth Authorization and SOAP API.
package com.microsoft.bingads.v13.reporting;
import com.microsoft.bingads.AsyncCallback;
import com.microsoft.bingads.AuthorizationData;
import com.microsoft.bingads.ServiceClient;
import com.microsoft.bingads.internal.ResultFuture;
import com.microsoft.bingads.internal.ServiceUtils;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
public class ReportingStatusProvider{
private final String requestId;
private final AuthorizationData authorizationData;
public ReportingStatusProvider(String requestId, AuthorizationData authorizationData) {
this.requestId = requestId;
this.authorizationData = authorizationData;
}
public Future getCurrentStatus(ServiceClient serviceClient, AsyncCallback callback) {
PollGenerateReportRequest request = new PollGenerateReportRequest();
request.setReportRequestId(this.requestId);
final ResultFuture resultFuture = new ResultFuture(callback);
serviceClient.getService().pollGenerateReportAsync(request, new AsyncHandler() {
@Override
public void handleResponse(Response result) {
try {
PollGenerateReportResponse statusResponse = result.get();
String trackingId = ServiceUtils.GetTrackingId(result);
ReportingOperationStatus status = new ReportingOperationStatus(
ReportRequestStatusType.fromValue(statusResponse.getReportRequestStatus().getStatus().value()),
statusResponse.getReportRequestStatus().getReportDownloadUrl(),
trackingId
);
resultFuture.setResult(status);
} catch (InterruptedException e) {
resultFuture.setException(e);
} catch (ExecutionException e) {
resultFuture.setException(e);
}
}
});
return resultFuture;
}
public boolean isFinalStatus(ReportingOperationStatus status) {
if (status == null) {
return false;
}
return status.getStatus() == ReportRequestStatusType.SUCCESS || status.getStatus() == ReportRequestStatusType.ERROR;
}
public boolean isSuccessStatus(ReportingOperationStatus status) {
return status.getStatus() == ReportRequestStatusType.SUCCESS;
}
public boolean isResultFileUrl(ReportingOperationStatus status) {
return status.getResultFileUrl() != null;
}
}