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

com.microsoft.bingads.v13.reporting.ReportingStatusProvider 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.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 jakarta.xml.ws.AsyncHandler;
import jakarta.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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy