com.microsoft.bingads.v13.internal.bulk.UploadStatusProvider 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 jakarta.xml.ws.AsyncHandler;
import jakarta.xml.ws.Response;
import com.microsoft.bingads.AsyncCallback;
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.GetBulkUploadStatusRequest;
import com.microsoft.bingads.v13.bulk.GetBulkUploadStatusResponse;
import com.microsoft.bingads.v13.bulk.IBulkService;
import com.microsoft.bingads.v13.bulk.UploadStatus;
public class UploadStatusProvider implements BulkOperationStatusProvider {
private final String requestId;
public UploadStatusProvider(String requestId) {
this.requestId = requestId;
}
@Override
public Future> getCurrentStatus(ServiceClient serviceClient, AsyncCallback> callback) {
GetBulkUploadStatusRequest request = new GetBulkUploadStatusRequest();
request.setRequestId(this.requestId);
final ResultFuture> resultFuture = new ResultFuture>(callback);
serviceClient.getService().getBulkUploadStatusAsync(request, new AsyncHandler() {
@Override
public void handleResponse(Response result) {
try {
GetBulkUploadStatusResponse statusResponse = result.get();
String trackingId = ServiceUtils.GetTrackingId(result);
BulkOperationStatus status = new BulkOperationStatus(
UploadStatus.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 currentStatus) {
return currentStatus.getStatus() == UploadStatus.COMPLETED ||
currentStatus.getStatus() == UploadStatus.COMPLETED_WITH_ERRORS ||
currentStatus.getStatus() == UploadStatus.FAILED ||
currentStatus.getStatus() == UploadStatus.EXPIRED ||
currentStatus.getStatus() == UploadStatus.ABORTED;
}
@Override
public boolean isSuccessStatus(UploadStatus status) {
return status == UploadStatus.COMPLETED || status == UploadStatus.COMPLETED_WITH_ERRORS;
}
}