All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.bingads.v13.internal.bulk.DownloadStatusProvider Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 13.0.22.1
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy