com.microsoft.bingads.v13.internal.bulk.DownloadStatusProvider 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.internal.bulk;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
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 com.microsoft.bingads.v13.bulk.BulkOperationStatus;
import com.microsoft.bingads.v13.bulk.DownloadStatus;
import com.microsoft.bingads.v13.bulk.GetBulkDownloadStatusRequest;
import com.microsoft.bingads.v13.bulk.GetBulkDownloadStatusResponse;
import com.microsoft.bingads.v13.bulk.IBulkService;
public class DownloadStatusProvider implements BulkOperationStatusProvider {
private final String requestId;
private final AuthorizationData authorizationData;
public DownloadStatusProvider(String requestId, AuthorizationData authorizationData) {
this.requestId = requestId;
this.authorizationData = authorizationData;
}
@Override
public Future> getCurrentStatus(ServiceClient serviceClient, AsyncCallback> callback) {
GetBulkDownloadStatusRequest request = new GetBulkDownloadStatusRequest();
request.setRequestId(this.requestId);
final ResultFuture> resultFuture = new ResultFuture>(callback);
serviceClient.getService().getBulkDownloadStatusAsync(request, new AsyncHandler() {
@Override
public void handleResponse(Response result) {
try {
GetBulkDownloadStatusResponse statusResponse = result.get();
String trackingId = ServiceUtils.GetTrackingId(result);
BulkOperationStatus status = new BulkOperationStatus(
DownloadStatus.fromValue(statusResponse.getRequestStatus()),
statusResponse.getPercentComplete(),
statusResponse.getResultFileUrl(),
trackingId,
statusResponse.getErrors() != null ? statusResponse.getErrors().getOperationErrors() : null
);
resultFuture.setResult(status);
} catch (InterruptedException e) {
resultFuture.setException(e);
} catch (ExecutionException e) {
resultFuture.setException(e);
}
}
});
return resultFuture;
}
@Override
public boolean isFinalStatus(BulkOperationStatus status) {
if (status == null) {
return false;
}
return status.getStatus() == DownloadStatus.COMPLETED || status.getStatus() == DownloadStatus.FAILED || status.getStatus() == DownloadStatus.FAILED_FULL_SYNC_REQUIRED;
}
@Override
public boolean isSuccessStatus(DownloadStatus status) {
return status == DownloadStatus.COMPLETED;
}
}