From 193273216593f95c5080b90254e7556939e89c80 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Fri, 1 Mar 2024 18:18:34 +0100 Subject: [PATCH 01/15] Pass used services to operations --- .../v13/bulk/BulkDownloadOperation.java | 46 +++++++++--- .../bingads/v13/bulk/BulkOperation.java | 74 +++++-------------- .../bingads/v13/bulk/BulkServiceManager.java | 62 +++++++++------- .../bingads/v13/bulk/BulkUploadOperation.java | 46 +++++++++--- .../BulkDownloadOperationTest.java | 10 +-- .../BulkUploadOperationTest.java | 10 +-- 6 files changed, 131 insertions(+), 117 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java index 40143c6392..83517d8c78 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java @@ -4,6 +4,11 @@ import com.microsoft.bingads.ApiEnvironment; import com.microsoft.bingads.AuthorizationData; +import com.microsoft.bingads.internal.utilities.HttpClientHttpFileService; +import com.microsoft.bingads.internal.utilities.HttpFileService; +import com.microsoft.bingads.internal.utilities.SimpleZipExtractor; +import com.microsoft.bingads.internal.utilities.ZipExtractor; +import com.microsoft.bingads.v13.internal.bulk.Config; import com.microsoft.bingads.v13.internal.bulk.DownloadStatusProvider; /** @@ -32,20 +37,37 @@ public class BulkDownloadOperation extends BulkOperation { * @param authorizationData Represents a user who intends to access the * corresponding customer and account. */ - public BulkDownloadOperation(String requestId, AuthorizationData authorizationData) { - super(requestId, authorizationData, new DownloadStatusProvider(requestId, authorizationData)); + public BulkDownloadOperation(String requestId, AuthorizationData authorizationData, int statusPollIntervalInMilliseconds) { + this( + requestId, + authorizationData, + null, + null, + statusPollIntervalInMilliseconds, + new HttpClientHttpFileService(), + Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, + new SimpleZipExtractor()); } - public BulkDownloadOperation(String requestId, AuthorizationData authorizationData, ApiEnvironment apiEnvironment) { - super(requestId, authorizationData, new DownloadStatusProvider(requestId, authorizationData), null, apiEnvironment); - } - - BulkDownloadOperation(String requestId, AuthorizationData authorizationData, String trackingId) { - super(requestId, authorizationData, new DownloadStatusProvider(requestId, authorizationData), trackingId); - } - - BulkDownloadOperation(String requestId, AuthorizationData authorizationData, String trackingId, ApiEnvironment apiEnvironment) { - super(requestId, authorizationData, new DownloadStatusProvider(requestId, authorizationData), trackingId, apiEnvironment); + BulkDownloadOperation( + String requestId, + AuthorizationData authorizationData, + String trackingId, + ApiEnvironment apiEnvironment, + int statusPollIntervalInMilliseconds, + HttpFileService httpFileService, + int downloadHttpTimeoutInMilliseconds, + ZipExtractor zipExtractor) { + super( + requestId, + authorizationData, + new DownloadStatusProvider(requestId, authorizationData), + trackingId, + apiEnvironment, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index 77f1e2af28..6c5c42b37b 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -49,52 +49,43 @@ public abstract class BulkOperation { /** * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. */ - private int statusPollIntervalInMilliseconds; + private final int statusPollIntervalInMilliseconds; /** * The timeout in milliseconds of HttpClient download operation. */ - private int downloadHttpTimeoutInMilliseconds; + private final int downloadHttpTimeoutInMilliseconds; BulkOperationStatusProvider statusProvider; - private HttpFileService httpFileService; - private ZipExtractor zipExtractor; + private final HttpFileService httpFileService; + private final ZipExtractor zipExtractor; - private ServiceClient serviceClient; + private final ServiceClient serviceClient; private BulkOperationStatus finalStatus; - BulkOperation(String requestId, AuthorizationData authorizationData) { - this(requestId, authorizationData, null, null, null); - } - - BulkOperation(String requestId, AuthorizationData authorizationData, ApiEnvironment apiEnvironment) { - this(requestId, authorizationData, null, null, apiEnvironment); - } - - BulkOperation(String requestId, AuthorizationData authorizationData, BulkOperationStatusProvider statusProvider) { - this(requestId, authorizationData, statusProvider, null, null); - } - - BulkOperation(String requestId, AuthorizationData authorizationData, BulkOperationStatusProvider statusProvider, String trackingId) { - this(requestId, authorizationData, statusProvider, trackingId, null); - } - - BulkOperation(String requestId, AuthorizationData authorizationData, BulkOperationStatusProvider statusProvider, String trackingId, ApiEnvironment apiEnvironment) { + BulkOperation( + String requestId, + AuthorizationData authorizationData, + BulkOperationStatusProvider statusProvider, + String trackingId, + ApiEnvironment apiEnvironment, + int statusPollIntervalInMilliseconds, + HttpFileService httpFileService, + int downloadHttpTimeoutInMilliseconds, + ZipExtractor zipExtractor) { this.statusProvider = statusProvider; this.requestId = requestId; this.authorizationData = authorizationData; this.trackingId = trackingId; + this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; + this.httpFileService = httpFileService; + this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; + this.zipExtractor = zipExtractor; - statusPollIntervalInMilliseconds = Config.DEFAULT_STATUS_CHECK_INTERVAL_IN_MS; - - downloadHttpTimeoutInMilliseconds = Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS; - - this.serviceClient = new ServiceClient(authorizationData, apiEnvironment, IBulkService.class); + this.serviceClient = new ServiceClient<>(authorizationData, apiEnvironment, IBulkService.class); zipExtractor = new SimpleZipExtractor(); - - httpFileService = new HttpClientHttpFileService(); } /** @@ -204,18 +195,11 @@ HttpFileService getHttpFileService() { return httpFileService; } - void setHttpFileService(HttpFileService httpFileService) { - this.httpFileService = httpFileService; - } ZipExtractor getZipExtractor() { return zipExtractor; } - void setZipExtractor(ZipExtractor zipExtractor) { - this.zipExtractor = zipExtractor; - } - /** * Gets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 second). */ @@ -223,13 +207,6 @@ public int getStatusPollIntervalInMilliseconds() { return statusPollIntervalInMilliseconds; } - /** - * Sets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 second). - */ - public void setStatusPollIntervalInMilliseconds(int statusPollIntervalInMilliseconds) { - this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; - } - /** * Gets the timeout of HttpClient download operation. The default value is 100000(100s). */ @@ -237,13 +214,6 @@ public int getDownloadHttpTimeoutInMilliseconds() { return downloadHttpTimeoutInMilliseconds; } - /** - * Sets the timeout of HttpClient download operation. The default value is 100000(100s). - */ - public void setDownloadHttpTimeoutInMilliseconds(int downloadHttpTimeoutInMilliseconds) { - this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; - } - /** * Downloads and optionally decompress the result file from the bulk operation * @param localResultDirectoryName the directory to place the result file in @@ -339,10 +309,6 @@ private File downloadFileWithFinalStatus(File localResultDirectoryName, String l } private File downloadResultFileZip(String url, File tempZipFile, boolean overwrite) throws IOException, URISyntaxException { - if (httpFileService == null) { - httpFileService = new HttpClientHttpFileService(); - } - httpFileService.downloadFile(url, tempZipFile, overwrite, downloadHttpTimeoutInMilliseconds); return tempZipFile; diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java index 82d89824fd..a501108870 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java @@ -12,7 +12,6 @@ import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.stream.Collectors; import jakarta.xml.ws.AsyncHandler; import jakarta.xml.ws.Response; @@ -200,9 +199,15 @@ public void handleResponse(Response res) { try { UploadEntityRecordsResponse result = res.get(); if (needToFallBacktoAsync(result)) { - BulkUploadOperation operation = new BulkUploadOperation(result.getRequestId(), authorizationData, service, ServiceUtils.GetTrackingId(res), apiEnvironment); - operation.setStatusPollIntervalInMilliseconds(statusPollIntervalInMilliseconds); - operation.setDownloadHttpTimeoutInMilliseconds(downloadHttpTimeoutInMilliseconds); + BulkUploadOperation operation = new BulkUploadOperation( + result.getRequestId(), + authorizationData, + ServiceUtils.GetTrackingId(res), + apiEnvironment, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); operation.trackAsync(progress, new ParentCallback>(resultFuture) { @Override public void onSuccess(BulkOperationStatus status) throws IOException, URISyntaxException { @@ -504,9 +509,6 @@ public void onSuccess(File localFile) { private Future downloadBulkFileAsync(File resultFileDirectory, String resultFileName, boolean overwriteResultFile, BulkOperation operation, AsyncCallback callback) throws IOException, URISyntaxException { - operation.setHttpFileService(this.httpFileService); - operation.setZipExtractor(this.zipExtractor); - final ResultFuture resultFuture = new ResultFuture(callback); File effectiveResultFileDirectory = resultFileDirectory; @@ -568,12 +570,15 @@ public void handleResponse(Response res) String trackingId = ServiceUtils.GetTrackingId(res); - BulkDownloadOperation operation = new BulkDownloadOperation(response.getDownloadRequestId(), authorizationData, trackingId, - apiEnvironment); - - operation.setStatusPollIntervalInMilliseconds(statusPollIntervalInMilliseconds); - - operation.setDownloadHttpTimeoutInMilliseconds(downloadHttpTimeoutInMilliseconds); + BulkDownloadOperation operation = new BulkDownloadOperation( + response.getDownloadRequestId(), + authorizationData, + trackingId, + apiEnvironment, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); resultFuture.setResult(operation); } catch (InterruptedException e) { @@ -596,12 +601,15 @@ public void handleResponse(Response res) response = res.get(); - BulkDownloadOperation operation = new BulkDownloadOperation(response.getDownloadRequestId(), authorizationData, - ServiceUtils.GetTrackingId(res), apiEnvironment); - - operation.setStatusPollIntervalInMilliseconds(statusPollIntervalInMilliseconds); - - operation.setDownloadHttpTimeoutInMilliseconds(downloadHttpTimeoutInMilliseconds); + BulkDownloadOperation operation = new BulkDownloadOperation( + response.getDownloadRequestId(), + authorizationData, + ServiceUtils.GetTrackingId(res), + apiEnvironment, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); resultFuture.setResult(operation); } catch (InterruptedException e) { @@ -692,13 +700,17 @@ public void addHeader(String name, String value) { if (parameters.getAutoDeleteTempFile()) { parameters.getUploadFilePath().delete(); - } - - BulkUploadOperation operation = new BulkUploadOperation(response.getRequestId(), authorizationData, service, trackingId, apiEnvironment); - operation.setStatusPollIntervalInMilliseconds(statusPollIntervalInMilliseconds); - - operation.setDownloadHttpTimeoutInMilliseconds(downloadHttpTimeoutInMilliseconds); + } + BulkUploadOperation operation = new BulkUploadOperation( + response.getRequestId(), + authorizationData, + trackingId, + apiEnvironment, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); resultFuture.setResult(operation); } catch (InterruptedException e) { diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java index a429829b3c..2d5f862eb5 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java @@ -4,6 +4,11 @@ import com.microsoft.bingads.ApiEnvironment; import com.microsoft.bingads.AuthorizationData; +import com.microsoft.bingads.internal.utilities.HttpClientHttpFileService; +import com.microsoft.bingads.internal.utilities.HttpFileService; +import com.microsoft.bingads.internal.utilities.SimpleZipExtractor; +import com.microsoft.bingads.internal.utilities.ZipExtractor; +import com.microsoft.bingads.v13.internal.bulk.Config; import com.microsoft.bingads.v13.internal.bulk.UploadStatusProvider; /** @@ -27,20 +32,37 @@ public class BulkUploadOperation extends BulkOperation { * @param requestId The identifier of an upload request that has previously been submitted. * @param authorizationData Represents a user who intends to access the corresponding customer and account. */ - public BulkUploadOperation(String requestId, AuthorizationData authorizationData, IBulkService service) { - this(requestId, authorizationData, service, null, null); + public BulkUploadOperation(String requestId, AuthorizationData authorizationData, int statusPollIntervalInMilliseconds) { + this( + requestId, + authorizationData, + null, + null, + statusPollIntervalInMilliseconds, + new HttpClientHttpFileService(), + Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, + new SimpleZipExtractor()); } - public BulkUploadOperation(String requestId, AuthorizationData authorizationData, IBulkService service, ApiEnvironment apiEnvironment) { - this(requestId, authorizationData, service, null, apiEnvironment); - } - - protected BulkUploadOperation(String requestId, AuthorizationData authorizationData, IBulkService service, String trackingId) { - this(requestId, authorizationData, service, trackingId, null); - } - - protected BulkUploadOperation(String requestId, AuthorizationData authorizationData, IBulkService service, String trackingId, ApiEnvironment apiEnvironment) { - super(requestId, authorizationData, new UploadStatusProvider(requestId), trackingId, apiEnvironment); + BulkUploadOperation( + String requestId, + AuthorizationData authorizationData, + String trackingId, + ApiEnvironment apiEnvironment, + int statusPollIntervalInMilliseconds, + HttpFileService httpFileService, + int downloadHttpTimeoutInMilliseconds, + ZipExtractor zipExtractor) { + super( + requestId, + authorizationData, + new UploadStatusProvider(requestId), + trackingId, + apiEnvironment, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); } @Override diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java index e9fc857f27..e5ca6dc51e 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java @@ -7,6 +7,7 @@ import com.microsoft.bingads.v13.bulk.BulkDownloadOperation; import com.microsoft.bingads.v13.bulk.GetBulkDownloadStatusResponse; import com.microsoft.bingads.v13.bulk.IBulkService; +import com.microsoft.bingads.v13.internal.bulk.Config; public class BulkDownloadOperationTest extends FakeApiTest { @@ -23,13 +24,8 @@ private static AuthorizationData createUserData() { } protected BulkDownloadOperation createBulkDownloadOperation(Integer statusCheckIntervalInMs) { - BulkDownloadOperation operation = new BulkDownloadOperation("request123", createUserData()); - - if (statusCheckIntervalInMs != null) { - operation.setStatusPollIntervalInMilliseconds(statusCheckIntervalInMs); - } - - return operation; + return new BulkDownloadOperation("request123", createUserData(), + statusCheckIntervalInMs != null ? statusCheckIntervalInMs : Config.DEFAULT_STATUS_CHECK_INTERVAL_IN_MS); } protected GetBulkDownloadStatusResponse createStatusResponse(Integer percentComplete, String status, String resultFileUrl) { diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java index 159c77867c..a323f03a2e 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java @@ -8,6 +8,7 @@ import com.microsoft.bingads.v13.bulk.BulkUploadOperation; import com.microsoft.bingads.v13.bulk.GetBulkUploadStatusResponse; import com.microsoft.bingads.v13.bulk.IBulkService; +import com.microsoft.bingads.v13.internal.bulk.Config; public class BulkUploadOperationTest extends FakeApiTest { @@ -24,13 +25,8 @@ private static AuthorizationData createUserData() { } protected BulkUploadOperation createBulkUploadOperation(Integer statusCheckIntervalInMs) { - BulkUploadOperation operation = new BulkUploadOperation("request123", createUserData(), service); - - if (statusCheckIntervalInMs != null) { - operation.setStatusPollIntervalInMilliseconds(statusCheckIntervalInMs); - } - - return operation; + return new BulkUploadOperation("request123", createUserData(), + statusCheckIntervalInMs != null ? statusCheckIntervalInMs : Config.DEFAULT_STATUS_CHECK_INTERVAL_IN_MS); } protected GetBulkUploadStatusResponse createStatusResponse(Integer percentComplete, String status, String resultFileUrl) { From 609fc621ebac0416bdba236df07beba4a8b3868b Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Fri, 1 Mar 2024 18:28:11 +0100 Subject: [PATCH 02/15] Pass used service client to operations --- .../v13/bulk/BulkDownloadOperation.java | 20 +++----- .../bingads/v13/bulk/BulkOperation.java | 47 +++++-------------- .../bingads/v13/bulk/BulkServiceManager.java | 12 ++--- .../bingads/v13/bulk/BulkUploadOperation.java | 19 +++----- .../BulkDownloadOperationTest.java | 5 +- .../BulkUploadOperationTest.java | 5 +- 6 files changed, 39 insertions(+), 69 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java index 83517d8c78..0a875b77f1 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java @@ -2,8 +2,7 @@ import java.util.List; -import com.microsoft.bingads.ApiEnvironment; -import com.microsoft.bingads.AuthorizationData; +import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.internal.utilities.HttpClientHttpFileService; import com.microsoft.bingads.internal.utilities.HttpFileService; import com.microsoft.bingads.internal.utilities.SimpleZipExtractor; @@ -34,15 +33,12 @@ public class BulkDownloadOperation extends BulkOperation { * * @param requestId The identifier of a download request that has previously * been submitted. - * @param authorizationData Represents a user who intends to access the - * corresponding customer and account. */ - public BulkDownloadOperation(String requestId, AuthorizationData authorizationData, int statusPollIntervalInMilliseconds) { + public BulkDownloadOperation(String requestId, ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { this( requestId, - authorizationData, - null, null, + serviceClient, statusPollIntervalInMilliseconds, new HttpClientHttpFileService(), Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, @@ -51,23 +47,21 @@ public BulkDownloadOperation(String requestId, AuthorizationData authorizationDa BulkDownloadOperation( String requestId, - AuthorizationData authorizationData, String trackingId, - ApiEnvironment apiEnvironment, + ServiceClient serviceClient, int statusPollIntervalInMilliseconds, HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor) { super( requestId, - authorizationData, - new DownloadStatusProvider(requestId, authorizationData), trackingId, - apiEnvironment, + serviceClient, statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, - zipExtractor); + zipExtractor, + new DownloadStatusProvider(requestId, serviceClient.getAuthorizationData())); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index 6c5c42b37b..e5afe2a123 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -6,20 +6,15 @@ import java.util.List; import java.util.concurrent.Future; -import com.microsoft.bingads.ApiEnvironment; import com.microsoft.bingads.AsyncCallback; -import com.microsoft.bingads.AuthorizationData; import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.internal.MessageHandler; import com.microsoft.bingads.internal.ParentCallback; import com.microsoft.bingads.internal.ResultFuture; -import com.microsoft.bingads.internal.utilities.HttpClientHttpFileService; import com.microsoft.bingads.internal.utilities.HttpFileService; -import com.microsoft.bingads.internal.utilities.SimpleZipExtractor; import com.microsoft.bingads.internal.utilities.ZipExtractor; import com.microsoft.bingads.v13.internal.bulk.BulkOperationStatusProvider; import com.microsoft.bingads.v13.internal.bulk.BulkOperationTracker; -import com.microsoft.bingads.v13.internal.bulk.Config; import com.microsoft.bingads.v13.internal.bulk.PollingBulkOperationTracker; /** @@ -31,11 +26,6 @@ */ public abstract class BulkOperation { - /** - * Represents a user who intends to access the corresponding customer and account. - */ - private AuthorizationData authorizationData; - /** * The request identifier corresponding to the bulk upload or download, depending on the derived type. */ @@ -46,46 +36,43 @@ public abstract class BulkOperation { */ private String trackingId; + private final ServiceClient serviceClient; + /** * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. - */ + */ private final int statusPollIntervalInMilliseconds; - + + private final HttpFileService httpFileService; + /** * The timeout in milliseconds of HttpClient download operation. */ private final int downloadHttpTimeoutInMilliseconds; - - BulkOperationStatusProvider statusProvider; - private final HttpFileService httpFileService; + private final ZipExtractor zipExtractor; - private final ServiceClient serviceClient; + private final BulkOperationStatusProvider statusProvider; private BulkOperationStatus finalStatus; BulkOperation( String requestId, - AuthorizationData authorizationData, - BulkOperationStatusProvider statusProvider, String trackingId, - ApiEnvironment apiEnvironment, + ServiceClient serviceClient, int statusPollIntervalInMilliseconds, HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor) { - this.statusProvider = statusProvider; + ZipExtractor zipExtractor, + BulkOperationStatusProvider statusProvider) { this.requestId = requestId; - this.authorizationData = authorizationData; this.trackingId = trackingId; + this.serviceClient = serviceClient; this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; this.httpFileService = httpFileService; this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; this.zipExtractor = zipExtractor; - - this.serviceClient = new ServiceClient<>(authorizationData, apiEnvironment, IBulkService.class); - - zipExtractor = new SimpleZipExtractor(); + this.statusProvider = statusProvider; } /** @@ -163,10 +150,6 @@ public void onSuccess(BulkOperationStatus currentStatus) { return resultFuture; } - public AuthorizationData getAuthorizationData() { - return authorizationData; - } - public String getRequestId() { return requestId; } @@ -187,10 +170,6 @@ void setTrackingId(String trackingId) { this.trackingId = trackingId; } - void setStatusProvider(BulkOperationStatusProvider statusProvider) { - this.statusProvider = statusProvider; - } - HttpFileService getHttpFileService() { return httpFileService; } diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java index a501108870..7c44763e84 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java @@ -201,9 +201,8 @@ public void handleResponse(Response res) { if (needToFallBacktoAsync(result)) { BulkUploadOperation operation = new BulkUploadOperation( result.getRequestId(), - authorizationData, ServiceUtils.GetTrackingId(res), - apiEnvironment, + serviceClient, statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, @@ -572,9 +571,8 @@ public void handleResponse(Response res) BulkDownloadOperation operation = new BulkDownloadOperation( response.getDownloadRequestId(), - authorizationData, trackingId, - apiEnvironment, + serviceClient, statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, @@ -603,9 +601,8 @@ public void handleResponse(Response res) BulkDownloadOperation operation = new BulkDownloadOperation( response.getDownloadRequestId(), - authorizationData, ServiceUtils.GetTrackingId(res), - apiEnvironment, + serviceClient, statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, @@ -704,9 +701,8 @@ public void addHeader(String name, String value) { } BulkUploadOperation operation = new BulkUploadOperation( response.getRequestId(), - authorizationData, trackingId, - apiEnvironment, + serviceClient, statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java index 2d5f862eb5..ab7d3003bb 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java @@ -2,8 +2,7 @@ import java.util.List; -import com.microsoft.bingads.ApiEnvironment; -import com.microsoft.bingads.AuthorizationData; +import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.internal.utilities.HttpClientHttpFileService; import com.microsoft.bingads.internal.utilities.HttpFileService; import com.microsoft.bingads.internal.utilities.SimpleZipExtractor; @@ -30,14 +29,12 @@ public class BulkUploadOperation extends BulkOperation { * Initializes a new instance of this class with the specified requestId and authorization data. * * @param requestId The identifier of an upload request that has previously been submitted. - * @param authorizationData Represents a user who intends to access the corresponding customer and account. */ - public BulkUploadOperation(String requestId, AuthorizationData authorizationData, int statusPollIntervalInMilliseconds) { + public BulkUploadOperation(String requestId, ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { this( requestId, - authorizationData, - null, null, + serviceClient, statusPollIntervalInMilliseconds, new HttpClientHttpFileService(), Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, @@ -46,23 +43,21 @@ public BulkUploadOperation(String requestId, AuthorizationData authorizationData BulkUploadOperation( String requestId, - AuthorizationData authorizationData, String trackingId, - ApiEnvironment apiEnvironment, + ServiceClient serviceClient, int statusPollIntervalInMilliseconds, HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor) { super( requestId, - authorizationData, - new UploadStatusProvider(requestId), trackingId, - apiEnvironment, + serviceClient, statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, - zipExtractor); + zipExtractor, + new UploadStatusProvider(requestId)); } @Override diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java index e5ca6dc51e..ae0459b315 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_download_operation/BulkDownloadOperationTest.java @@ -2,6 +2,7 @@ import com.microsoft.bingads.AuthorizationData; import com.microsoft.bingads.PasswordAuthentication; +import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.v13.api.test.operations.FakeApiTest; import com.microsoft.bingads.v13.bulk.ArrayOfKeyValuePairOfstringstring; import com.microsoft.bingads.v13.bulk.BulkDownloadOperation; @@ -24,7 +25,9 @@ private static AuthorizationData createUserData() { } protected BulkDownloadOperation createBulkDownloadOperation(Integer statusCheckIntervalInMs) { - return new BulkDownloadOperation("request123", createUserData(), + return new BulkDownloadOperation( + "request123", + new ServiceClient<>(createUserData(), IBulkService.class), statusCheckIntervalInMs != null ? statusCheckIntervalInMs : Config.DEFAULT_STATUS_CHECK_INTERVAL_IN_MS); } diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java index a323f03a2e..cc22bd6298 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/bulk_upload_operation/BulkUploadOperationTest.java @@ -3,6 +3,7 @@ import com.microsoft.bingads.AuthorizationData; import com.microsoft.bingads.PasswordAuthentication; +import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.v13.api.test.operations.FakeApiTest; import com.microsoft.bingads.v13.bulk.ArrayOfKeyValuePairOfstringstring; import com.microsoft.bingads.v13.bulk.BulkUploadOperation; @@ -25,7 +26,9 @@ private static AuthorizationData createUserData() { } protected BulkUploadOperation createBulkUploadOperation(Integer statusCheckIntervalInMs) { - return new BulkUploadOperation("request123", createUserData(), + return new BulkUploadOperation( + "request123", + new ServiceClient<>(createUserData(), IBulkService.class), statusCheckIntervalInMs != null ? statusCheckIntervalInMs : Config.DEFAULT_STATUS_CHECK_INTERVAL_IN_MS); } From 2be2c83b47272a2da8fe3725bcd5872e93e74873 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Fri, 1 Mar 2024 18:29:59 +0100 Subject: [PATCH 03/15] Make fields final --- .../microsoft/bingads/v13/bulk/BulkOperation.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index e5afe2a123..8f91ee5a33 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -29,12 +29,12 @@ public abstract class BulkOperation { /** * The request identifier corresponding to the bulk upload or download, depending on the derived type. */ - private String requestId; + private final String requestId; /** * The identifier of the log entry that contains the details of the upload or download request. */ - private String trackingId; + private final String trackingId; private final ServiceClient serviceClient; @@ -162,14 +162,6 @@ BulkOperationStatusProvider getStatusProvider() { return statusProvider; } - void setRequestId(String requestId) { - this.requestId = requestId; - } - - void setTrackingId(String trackingId) { - this.trackingId = trackingId; - } - HttpFileService getHttpFileService() { return httpFileService; } @@ -226,7 +218,8 @@ public Future downloadResultFileAsync(File localResultDirectoryName, Strin abstract RuntimeException getOperationCouldNotBeCompletedException(List errors, TStatus status); - private Future downloadResultFileAsyncImpl(final File localResultDirectoryName, final String localResultFileName, final boolean decompress, final boolean overwrite, AsyncCallback callback) throws IOException, URISyntaxException { + private Future downloadResultFileAsyncImpl(final File + localResultDirectoryName, final String localResultFileName, final boolean decompress, final boolean overwrite, AsyncCallback callback) throws IOException, URISyntaxException { final ResultFuture resultFuture = new ResultFuture(callback); if (finalStatus == null) { From 2d1a65142c6aef74115d18ce675b71821518a3e4 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Fri, 1 Mar 2024 23:50:24 +0100 Subject: [PATCH 04/15] Pass used service client to operations --- .../utilities/HttpClientHttpFileService.java | 52 ----- .../internal/utilities/HttpFileService.java | 2 - .../v13/bulk/BulkDownloadOperation.java | 18 +- .../bingads/v13/bulk/BulkOperation.java | 22 +-- .../bingads/v13/bulk/BulkServiceManager.java | 24 +-- .../bingads/v13/bulk/BulkUploadOperation.java | 16 +- .../internal/bulk/DownloadStatusProvider.java | 5 +- .../reporting/ReportingDownloadOperation.java | 179 ++++-------------- .../reporting/ReportingServiceManager.java | 16 +- .../reporting/ReportingStatusProvider.java | 5 +- .../test/operations/FakeHttpFileService.java | 13 -- 11 files changed, 88 insertions(+), 264 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java index f08dab54ec..910e5542ab 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java @@ -140,56 +140,4 @@ public void uploadFile(URI uri, File uploadFilePath, Consumer addHe } } } - - @Override - public Future downloadFileAsync(String url, File tempZipFile, AsyncCallback callback, int timeoutInMilliseconds) { - final ResultFuture resultFuture = new ResultFuture(callback); - - CloseableHttpClient client = HttpClients - .custom() - .setDefaultRequestConfig(RequestConfig.custom() - .setConnectionRequestTimeout(timeoutInMilliseconds) - .setConnectTimeout(timeoutInMilliseconds) - .setSocketTimeout(timeoutInMilliseconds) - .build()) - .useSystemProperties() - .build(); - - try { - - HttpGet httpget = new HttpGet(new URI(url)); - HttpResponse response = client.execute(httpget); - InputStream content = response.getEntity().getContent(); - - FileOutputStream tempFileOutput = null; - - try { - tempFileOutput = new FileOutputStream(tempZipFile); - FileUtils.copy(content, tempFileOutput); - - resultFuture.setResult(tempZipFile); - } finally { - if (tempFileOutput != null) { - tempFileOutput.close(); - } - } - } catch (URISyntaxException ex) { - resultFuture.setException(ex); - } catch (IOException ex) { - resultFuture.setException(new CouldNotDownloadResultFileException(ex)); - } catch (IllegalStateException ex) { - resultFuture.setException(new CouldNotDownloadResultFileException(ex)); - } finally { - if (client != null) { - try { - client.close(); - } catch (IOException e) { - // Ignore - e.printStackTrace(); - } - } - } - - return resultFuture; - } } diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java index 2abe7bab94..9b98dd18db 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java @@ -15,6 +15,4 @@ public interface HttpFileService { void uploadFile(URI uri, File uploadFilePath, Consumer addHeaders, int timeoutInMilliseconds); - Future downloadFileAsync(String url, File tempZipFile, AsyncCallback callback, int timeoutInMilliseconds); - } diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java index 0a875b77f1..85412febe9 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java @@ -38,30 +38,30 @@ public BulkDownloadOperation(String requestId, ServiceClient servi this( requestId, null, - serviceClient, - statusPollIntervalInMilliseconds, new HttpClientHttpFileService(), Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, - new SimpleZipExtractor()); + new SimpleZipExtractor(), + serviceClient, + statusPollIntervalInMilliseconds); } BulkDownloadOperation( String requestId, String trackingId, - ServiceClient serviceClient, - int statusPollIntervalInMilliseconds, HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor) { + ZipExtractor zipExtractor, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds) { super( requestId, trackingId, - serviceClient, - statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, - new DownloadStatusProvider(requestId, serviceClient.getAuthorizationData())); + serviceClient, + statusPollIntervalInMilliseconds, + new DownloadStatusProvider(requestId)); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index 8f91ee5a33..5b40e48de4 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -36,13 +36,6 @@ public abstract class BulkOperation { */ private final String trackingId; - private final ServiceClient serviceClient; - - /** - * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. - */ - private final int statusPollIntervalInMilliseconds; - private final HttpFileService httpFileService; /** @@ -52,6 +45,13 @@ public abstract class BulkOperation { private final ZipExtractor zipExtractor; + private final ServiceClient serviceClient; + + /** + * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. + */ + private final int statusPollIntervalInMilliseconds; + private final BulkOperationStatusProvider statusProvider; private BulkOperationStatus finalStatus; @@ -59,19 +59,19 @@ public abstract class BulkOperation { BulkOperation( String requestId, String trackingId, - ServiceClient serviceClient, - int statusPollIntervalInMilliseconds, HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds, BulkOperationStatusProvider statusProvider) { this.requestId = requestId; this.trackingId = trackingId; - this.serviceClient = serviceClient; - this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; this.httpFileService = httpFileService; this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; this.zipExtractor = zipExtractor; + this.serviceClient = serviceClient; + this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; this.statusProvider = statusProvider; } diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java index 7c44763e84..545db204e5 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java @@ -202,11 +202,11 @@ public void handleResponse(Response res) { BulkUploadOperation operation = new BulkUploadOperation( result.getRequestId(), ServiceUtils.GetTrackingId(res), - serviceClient, - statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, - zipExtractor); + zipExtractor, + serviceClient, + statusPollIntervalInMilliseconds); operation.trackAsync(progress, new ParentCallback>(resultFuture) { @Override public void onSuccess(BulkOperationStatus status) throws IOException, URISyntaxException { @@ -572,11 +572,11 @@ public void handleResponse(Response res) BulkDownloadOperation operation = new BulkDownloadOperation( response.getDownloadRequestId(), trackingId, - serviceClient, - statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, - zipExtractor); + zipExtractor, + serviceClient, + statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { @@ -602,11 +602,11 @@ public void handleResponse(Response res) BulkDownloadOperation operation = new BulkDownloadOperation( response.getDownloadRequestId(), ServiceUtils.GetTrackingId(res), - serviceClient, - statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, - zipExtractor); + zipExtractor, + serviceClient, + statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { @@ -702,11 +702,11 @@ public void addHeader(String name, String value) { BulkUploadOperation operation = new BulkUploadOperation( response.getRequestId(), trackingId, - serviceClient, - statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, - zipExtractor); + zipExtractor, + serviceClient, + statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java index ab7d3003bb..327fb2d79e 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java @@ -34,29 +34,29 @@ public BulkUploadOperation(String requestId, ServiceClient service this( requestId, null, - serviceClient, - statusPollIntervalInMilliseconds, new HttpClientHttpFileService(), Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, - new SimpleZipExtractor()); + new SimpleZipExtractor(), + serviceClient, + statusPollIntervalInMilliseconds); } BulkUploadOperation( String requestId, String trackingId, - ServiceClient serviceClient, - int statusPollIntervalInMilliseconds, HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor) { + ZipExtractor zipExtractor, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds) { super( requestId, trackingId, - serviceClient, - statusPollIntervalInMilliseconds, httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, + serviceClient, + statusPollIntervalInMilliseconds, new UploadStatusProvider(requestId)); } diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java index 0a2b2b22e9..683994a0d9 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java @@ -21,11 +21,8 @@ public class DownloadStatusProvider implements BulkOperationStatusProvider serviceClient; - - /** - * The final status of reporting download operation. - */ - private ReportingOperationStatus finalStatus; + private final ZipExtractor zipExtractor; - /**@param requestId - * @param authorizationData - */ - public ReportingDownloadOperation(String requestId, AuthorizationData authorizationData) { - this(requestId, authorizationData, null, null); - } - - public ReportingDownloadOperation(String requestId, AuthorizationData authorizationData, ApiEnvironment apiEnvironment) { - this(requestId, authorizationData, null, apiEnvironment); - } - - /**@param requestId - * @param authorizationData - * @param trackingId + /** + * The client of reporting service. */ - ReportingDownloadOperation(String requestId, AuthorizationData authorizationData, String trackingId) { - this(requestId, authorizationData, new ReportingStatusProvider(requestId, authorizationData), trackingId, null); - } - - ReportingDownloadOperation(String requestId, AuthorizationData authorizationData, String trackingId, ApiEnvironment apiEnvironment) { - this(requestId, authorizationData, new ReportingStatusProvider(requestId, authorizationData), trackingId, apiEnvironment); - } + private final ServiceClient serviceClient; - /**@param requestId - * @param authorizationData - * @param statusProvider - * @param trackingId + /** + * The amount of time in milliseconds that the download operations should wait before polling the Reporting service for status. */ - ReportingDownloadOperation(String requestId, AuthorizationData authorizationData, ReportingStatusProvider statusProvider, String trackingId, ApiEnvironment apiEnvironment) { - this.statusProvider = statusProvider; - this.requestId = requestId; - this.authorizationData = authorizationData; - this.trackingId = trackingId; + private final int statusPollIntervalInMilliseconds; - statusPollIntervalInMilliseconds = ReportingConfig.DEFAULT_STATUS_CHECK_INTERVAL_IN_MS; - - downloadHttpTimeoutInMilliseconds = ReportingConfig.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS; - - this.serviceClient = new ServiceClient(authorizationData, apiEnvironment, IReportingService.class); + /** + * Provide the status of the reporting download operation. + */ + private final ReportingStatusProvider statusProvider; - zipExtractor = new SimpleZipExtractor(); + /** + * The final status of reporting download operation. + */ + private ReportingOperationStatus finalStatus; - httpFileService = new HttpClientHttpFileService(); + ReportingDownloadOperation( + String requestId, + String trackingId, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds, + HttpFileService httpFileService, + int downloadHttpTimeoutInMilliseconds, + ZipExtractor zipExtractor) { + this.requestId = requestId; + this.trackingId = trackingId; + this.serviceClient = serviceClient; + this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; + this.httpFileService = httpFileService; + this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; + this.zipExtractor = zipExtractor; + this.statusProvider = new ReportingStatusProvider(requestId); } /** @@ -283,22 +247,11 @@ private File downloadFileWithFinalStatus(File localResultDirectoryName, String l } private File downloadResultFileZip(String url, File tempZipFile, boolean overwrite) throws IOException, URISyntaxException { - if (httpFileService == null) { - httpFileService = new HttpClientHttpFileService(); - } - httpFileService.downloadFile(url, tempZipFile, overwrite, downloadHttpTimeoutInMilliseconds); return tempZipFile; } - /** - * @return the authorizationData - */ - public AuthorizationData getAuthorizationData() { - return authorizationData; - } - /** * @return the requestId */ @@ -306,13 +259,6 @@ public String getRequestId() { return requestId; } - /** - * @param requestId the requestId to set - */ - public void setRequestId(String requestId) { - this.requestId = requestId; - } - /** * @return the trackingId */ @@ -320,13 +266,6 @@ public String getTrackingId() { return trackingId; } - /** - * @param trackingId the trackingId to set - */ - public void setTrackingId(String trackingId) { - this.trackingId = trackingId; - } - /** * @return the statusProvider */ @@ -334,13 +273,6 @@ public ReportingStatusProvider getStatusProvider() { return statusProvider; } - /** - * @param statusProvider the statusProvider to set - */ - public void setStatusProvider(ReportingStatusProvider statusProvider) { - this.statusProvider = statusProvider; - } - /** * @return the httpFileService */ @@ -348,13 +280,6 @@ public HttpFileService getHttpFileService() { return httpFileService; } - /** - * @param httpFileService the httpFileService to set - */ - public void setHttpFileService(HttpFileService httpFileService) { - this.httpFileService = httpFileService; - } - /** * @return the zipExtractor */ @@ -362,13 +287,6 @@ public ZipExtractor getZipExtractor() { return zipExtractor; } - /** - * @param zipExtractor the zipExtractor to set - */ - public void setZipExtractor(ZipExtractor zipExtractor) { - this.zipExtractor = zipExtractor; - } - /** * @return the serviceClient */ @@ -376,13 +294,6 @@ public ServiceClient getServiceClient() { return serviceClient; } - /** - * @param serviceClient the serviceClient to set - */ - public void setServiceClient(ServiceClient serviceClient) { - this.serviceClient = serviceClient; - } - /** * @return the finalStatus */ @@ -404,24 +315,10 @@ public int getStatusPollIntervalInMilliseconds() { return statusPollIntervalInMilliseconds; } - /** - * Sets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 second). - */ - public void setStatusPollIntervalInMilliseconds(int statusPollIntervalInMilliseconds) { - this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; - } - /** * Gets the timeout of HttpClient download operation. The default value is 100000(100s). */ public int getDownloadHttpTimeoutInMilliseconds() { return downloadHttpTimeoutInMilliseconds; } - - /** - * Sets the timeout of HttpClient download operation. The default value is 100000(100s). - */ - public void setDownloadHttpTimeoutInMilliseconds(int downloadHttpTimeoutInMilliseconds) { - this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; - } } diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java index 94eab680f1..e65a0ddd92 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java @@ -171,9 +171,6 @@ public void onSuccess(File localFile) { } private Future downloadReportingFileAsync(File resultFileDirectory, String resultFileName, boolean overwriteResultFile, ReportingDownloadOperation operation, AsyncCallback callback) throws IOException, URISyntaxException { - operation.setHttpFileService(this.httpFileService); - operation.setZipExtractor(this.zipExtractor); - final ResultFuture resultFuture = new ResultFuture(callback); File effectiveResultFileDirectory = resultFileDirectory; @@ -234,11 +231,14 @@ public void handleResponse(Response res) { String trackingId = ServiceUtils.GetTrackingId(res); - ReportingDownloadOperation operation = new ReportingDownloadOperation(response.getReportRequestId(), authorizationData, trackingId, apiEnvironment); - - operation.setStatusPollIntervalInMilliseconds(statusPollIntervalInMilliseconds); - - operation.setDownloadHttpTimeoutInMilliseconds(downloadHttpTimeoutInMilliseconds); + ReportingDownloadOperation operation = new ReportingDownloadOperation( + response.getReportRequestId(), + trackingId, + serviceClient, + statusPollIntervalInMilliseconds, + httpFileService, + downloadHttpTimeoutInMilliseconds, + zipExtractor); resultFuture.setResult(operation); } catch (InterruptedException e) { diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java index def37bd201..5bf68b1b5e 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java @@ -15,11 +15,8 @@ public class ReportingStatusProvider{ private final String requestId; - private final AuthorizationData authorizationData; - - public ReportingStatusProvider(String requestId, AuthorizationData authorizationData) { + public ReportingStatusProvider(String requestId) { this.requestId = requestId; - this.authorizationData = authorizationData; } public Future getCurrentStatus(ServiceClient serviceClient, AsyncCallback callback) { diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java index bfb0a33522..d97f9cea29 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java @@ -42,17 +42,4 @@ public void downloadFile(String url, File tempZipFile, boolean overwrite, int ti public void uploadFile(URI uri, File uploadFilePath, Consumer addHeaders, int timeoutInMilliseconds) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - - @Override - public Future downloadFileAsync(String url, File tempZipFile, AsyncCallback callback, int timeoutInMilliseconds) { - onDownloadFile.accept(url, tempZipFile); - - Future result = new CompleteResponse(tempZipFile, new ArrayList()); - - callback.onCompleted(result); - - downloadWasCalled = true; - - return result; - } } From dce15dd8d3eebeb2950345ebc6a6ed35757cfdb2 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:02:53 +0100 Subject: [PATCH 05/15] Let status provider know its service client --- .../internal/OperationStatusRetry.java | 36 +++++++++---------- .../v13/bulk/BulkDownloadOperation.java | 3 +- .../bingads/v13/bulk/BulkOperation.java | 9 ++--- .../bingads/v13/bulk/BulkUploadOperation.java | 3 +- .../bulk/BulkOperationStatusProvider.java | 4 +-- .../internal/bulk/DownloadStatusProvider.java | 10 +++--- .../bulk/PollingBulkOperationTracker.java | 18 ++++------ .../internal/bulk/UploadStatusProvider.java | 11 +++--- .../reporting/ReportingOperationTracker.java | 10 +++--- 9 files changed, 47 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/internal/OperationStatusRetry.java b/src/main/java/com/microsoft/bingads/internal/OperationStatusRetry.java index 50300ae06c..559ff332c9 100644 --- a/src/main/java/com/microsoft/bingads/internal/OperationStatusRetry.java +++ b/src/main/java/com/microsoft/bingads/internal/OperationStatusRetry.java @@ -8,9 +8,8 @@ import java.util.function.Function; import com.microsoft.bingads.AsyncCallback; -import com.microsoft.bingads.ServiceClient; +import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; -import com.microsoft.bingads.internal.functionalinterfaces.TriConsumer; public class OperationStatusRetry { private static final int INTERVAL_OF_RETRY = 1000; // TimeUnit Milliseconds @@ -28,20 +27,21 @@ public OperationStatusRetry(Function f) { } public void executeWithRetry( - final TriConsumer, AsyncCallback> action, - final TOperationStatusProvider statusProvider, final ServiceClient serviceClient, - final Consumer statusConsumer, final Consumer exceptionConsumer, + final BiConsumer> action, + final TOperationStatusProvider statusProvider, + final Consumer statusConsumer, + final Consumer exceptionConsumer, final int maxRetryCount) { executor = Executors.newSingleThreadScheduledExecutor(); - doPollOperationStatus(action, statusProvider, serviceClient, statusConsumer, exceptionConsumer, maxRetryCount); + doPollOperationStatus(action, statusProvider, statusConsumer, exceptionConsumer, maxRetryCount); } private void doPollOperationStatus( - final TriConsumer, AsyncCallback> action, - final TOperationStatusProvider statusProvider, final ServiceClient serviceClient, + final BiConsumer> action, + final TOperationStatusProvider statusProvider, final Consumer statusConsumer, final Consumer exceptionConsumer, final int maxRetryCount) { - action.accept(statusProvider, serviceClient, new AsyncCallback() { + action.accept(statusProvider, new AsyncCallback() { @Override public void onCompleted(Future result) { @@ -49,22 +49,21 @@ public void onCompleted(Future result) { statusConsumer.accept(result.get()); executor.shutdown(); } catch (InterruptedException exception) { - retryWhenException(action, statusProvider, serviceClient, statusConsumer, exceptionConsumer, + retryWhenException(action, statusProvider, statusConsumer, exceptionConsumer, maxRetryCount, exception); } catch (ExecutionException exception) { - retryWhenException(action, statusProvider, serviceClient, statusConsumer, exceptionConsumer, + retryWhenException(action, statusProvider, statusConsumer, exceptionConsumer, maxRetryCount, exception); } } private void retryWhenException( - final TriConsumer, AsyncCallback> action, - final TOperationStatusProvider statusProvider, final ServiceClient serviceClient, + final BiConsumer> action, + final TOperationStatusProvider statusProvider, final Consumer statusConsumer, final Consumer exceptionConsumer, final int maxRetryCount, Exception exception) { if (maxRetryCount > 0) { - retry(action, statusProvider, serviceClient, statusConsumer, exceptionConsumer, maxRetryCount - 1, - exception); + retry(action, statusProvider, statusConsumer, exceptionConsumer, maxRetryCount - 1, exception); } else { executor.shutdown(); exceptionConsumer.accept(exception); @@ -74,16 +73,15 @@ private void retryWhenException( } private void retry( - final TriConsumer, AsyncCallback> action, - final TOperationStatusProvider statusProvider, final ServiceClient serviceClient, + final BiConsumer> action, + final TOperationStatusProvider statusProvider, final Consumer statusConsumer, final Consumer exceptionConsumer, final int maxRetryCount, Exception exception) { int interval = getInterval(exception, maxRetryCount); executor.schedule(new Runnable() { @Override public void run() { - doPollOperationStatus(action, statusProvider, serviceClient, statusConsumer, exceptionConsumer, - maxRetryCount); + doPollOperationStatus(action, statusProvider, statusConsumer, exceptionConsumer, maxRetryCount); } }, interval, TimeUnit.MILLISECONDS); diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java index 85412febe9..5d26e47ae2 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java @@ -59,9 +59,8 @@ public BulkDownloadOperation(String requestId, ServiceClient servi httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, - serviceClient, statusPollIntervalInMilliseconds, - new DownloadStatusProvider(requestId)); + new DownloadStatusProvider(requestId, serviceClient)); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index 5b40e48de4..b97177648f 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -7,7 +7,6 @@ import java.util.concurrent.Future; import com.microsoft.bingads.AsyncCallback; -import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.internal.MessageHandler; import com.microsoft.bingads.internal.ParentCallback; import com.microsoft.bingads.internal.ResultFuture; @@ -45,8 +44,6 @@ public abstract class BulkOperation { private final ZipExtractor zipExtractor; - private final ServiceClient serviceClient; - /** * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. */ @@ -62,7 +59,6 @@ public abstract class BulkOperation { HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, - ServiceClient serviceClient, int statusPollIntervalInMilliseconds, BulkOperationStatusProvider statusProvider) { this.requestId = requestId; @@ -70,7 +66,6 @@ public abstract class BulkOperation { this.httpFileService = httpFileService; this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; this.zipExtractor = zipExtractor; - this.serviceClient = serviceClient; this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; this.statusProvider = statusProvider; } @@ -114,7 +109,7 @@ public void onSuccess(BulkOperationStatus status) { private BulkOperationTracker generateTracker(Progress progress) { BulkOperationTracker tracker; - tracker = new PollingBulkOperationTracker(statusProvider, this.serviceClient, progress, this.statusPollIntervalInMilliseconds); + tracker = new PollingBulkOperationTracker(statusProvider, progress, this.statusPollIntervalInMilliseconds); return tracker; } @@ -134,7 +129,7 @@ public Future> getStatusAsync(AsyncCallback>(resultFuture) { + statusProvider.getCurrentStatus(new ParentCallback>(resultFuture) { @Override public void onSuccess(BulkOperationStatus currentStatus) { diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java index 327fb2d79e..8d6aeb4ba4 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java @@ -55,9 +55,8 @@ public BulkUploadOperation(String requestId, ServiceClient service httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, - serviceClient, statusPollIntervalInMilliseconds, - new UploadStatusProvider(requestId)); + new UploadStatusProvider(requestId, serviceClient)); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java index 3b0130b97e..eb0bb0dc20 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java @@ -3,13 +3,11 @@ import java.util.concurrent.Future; import com.microsoft.bingads.AsyncCallback; -import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.v13.bulk.BulkOperationStatus; -import com.microsoft.bingads.v13.bulk.IBulkService; public interface BulkOperationStatusProvider { - Future> getCurrentStatus(ServiceClient serviceClient, AsyncCallback> callback); + Future> getCurrentStatus(AsyncCallback> callback); boolean isFinalStatus(BulkOperationStatus currentStatus); diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java index 683994a0d9..05331e1369 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java @@ -4,7 +4,6 @@ import java.util.concurrent.Future; 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; @@ -20,13 +19,16 @@ public class DownloadStatusProvider implements BulkOperationStatusProvider { private final String requestId; - - public DownloadStatusProvider(String requestId) { + + private final ServiceClient serviceClient; + + public DownloadStatusProvider(String requestId, ServiceClient serviceClient) { this.requestId = requestId; + this.serviceClient = serviceClient; } @Override - public Future> getCurrentStatus(ServiceClient serviceClient, AsyncCallback> callback) { + public Future> getCurrentStatus(AsyncCallback> callback) { GetBulkDownloadStatusRequest request = new GetBulkDownloadStatusRequest(); request.setRequestId(this.requestId); diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java index 18e268ee04..0065982f2d 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java @@ -9,11 +9,10 @@ import java.util.function.Function; import com.microsoft.bingads.AsyncCallback; -import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.internal.OperationStatusRetry; import com.microsoft.bingads.internal.ResultFuture; +import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; -import com.microsoft.bingads.internal.functionalinterfaces.TriConsumer; import com.microsoft.bingads.internal.utilities.ThreadPool; import com.microsoft.bingads.v13.bulk.AdApiFaultDetail_Exception; import com.microsoft.bingads.v13.bulk.BulkOperationProgressInfo; @@ -37,8 +36,6 @@ public class PollingBulkOperationTracker implements BulkOperationTracke private ResultFuture> trackResultFuture; - private ServiceClient serviceClient; - private OperationStatusRetry, BulkOperationStatusProvider, IBulkService> operationStatusRetry; private int numberOfStatusRetry = 4; @@ -50,12 +47,11 @@ public void run() { }; public PollingBulkOperationTracker(BulkOperationStatusProvider statusProvider, - ServiceClient serviceClient, Progress progress, + Progress progress, int statusCheckIntervalInMs) { this.statusCheckIntervalInMs = statusCheckIntervalInMs; this.statusProvider = statusProvider; - this.serviceClient = serviceClient; this.progress = progress; this.operationStatusRetry = new OperationStatusRetry, BulkOperationStatusProvider, IBulkService>( new Function() { @@ -206,14 +202,14 @@ private void refreshStatus(AsyncCallback> callback) callback); operationStatusRetry.executeWithRetry( - new TriConsumer, ServiceClient, AsyncCallback>>() { + new BiConsumer, AsyncCallback>>() { @Override - public void accept(BulkOperationStatusProvider statusProvider, - ServiceClient serviceClient, + public void accept( + BulkOperationStatusProvider statusProvider, AsyncCallback> callback) { - statusProvider.getCurrentStatus(serviceClient, callback); + statusProvider.getCurrentStatus(callback); } - }, statusProvider, serviceClient, new Consumer>() { + }, statusProvider, new Consumer>() { @Override public void accept(BulkOperationStatus status) { currentStatus = status; diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java index 59854ee53d..43e3783163 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java @@ -18,14 +18,17 @@ public class UploadStatusProvider implements BulkOperationStatusProvider { - private final String requestId; + private final String requestId; - public UploadStatusProvider(String requestId) { - this.requestId = requestId; + private final ServiceClient serviceClient; + + public UploadStatusProvider(String requestId, ServiceClient serviceClient) { + this.requestId = requestId; + this.serviceClient = serviceClient; } @Override - public Future> getCurrentStatus(ServiceClient serviceClient, AsyncCallback> callback) { + public Future> getCurrentStatus(AsyncCallback> callback) { GetBulkUploadStatusRequest request = new GetBulkUploadStatusRequest(); request.setRequestId(this.requestId); diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java index edb6dd9a4b..afaea21d6f 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java @@ -12,8 +12,8 @@ import com.microsoft.bingads.ServiceClient; import com.microsoft.bingads.internal.OperationStatusRetry; import com.microsoft.bingads.internal.ResultFuture; +import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; -import com.microsoft.bingads.internal.functionalinterfaces.TriConsumer; /** * Track the status of reporting operation. @@ -160,14 +160,14 @@ private void refreshStatus(AsyncCallback callback) { callback); operationStatusRetry.executeWithRetry( - new TriConsumer, AsyncCallback>() { + new BiConsumer>() { @Override - public void accept(ReportingStatusProvider statusProvider, - ServiceClient serviceClient, + public void accept( + ReportingStatusProvider statusProvider, AsyncCallback callback) { statusProvider.getCurrentStatus(serviceClient, callback); } - }, statusProvider, serviceClient, new Consumer() { + }, statusProvider, new Consumer() { @Override public void accept(ReportingOperationStatus status) { currentStatus = status; From b37bc8feced6bd9f8827dbe1472d78628cf03f71 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:12:16 +0100 Subject: [PATCH 06/15] Configure tracker via status provider --- .../bingads/v13/bulk/BulkDownloadOperation.java | 3 +-- .../bingads/v13/bulk/BulkOperation.java | 16 +--------------- .../bingads/v13/bulk/BulkUploadOperation.java | 3 +-- .../bulk/BulkOperationStatusProvider.java | 2 ++ .../internal/bulk/DownloadStatusProvider.java | 16 +++++++++++++++- .../bulk/PollingBulkOperationTracker.java | 10 ++++------ .../v13/internal/bulk/UploadStatusProvider.java | 16 +++++++++++++++- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java index 5d26e47ae2..5714e02221 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java @@ -59,8 +59,7 @@ public BulkDownloadOperation(String requestId, ServiceClient servi httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, - statusPollIntervalInMilliseconds, - new DownloadStatusProvider(requestId, serviceClient)); + new DownloadStatusProvider(requestId, serviceClient, statusPollIntervalInMilliseconds)); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index b97177648f..14719ba582 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -44,11 +44,6 @@ public abstract class BulkOperation { private final ZipExtractor zipExtractor; - /** - * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. - */ - private final int statusPollIntervalInMilliseconds; - private final BulkOperationStatusProvider statusProvider; private BulkOperationStatus finalStatus; @@ -59,14 +54,12 @@ public abstract class BulkOperation { HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, - int statusPollIntervalInMilliseconds, BulkOperationStatusProvider statusProvider) { this.requestId = requestId; this.trackingId = trackingId; this.httpFileService = httpFileService; this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; this.zipExtractor = zipExtractor; - this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; this.statusProvider = statusProvider; } @@ -109,7 +102,7 @@ public void onSuccess(BulkOperationStatus status) { private BulkOperationTracker generateTracker(Progress progress) { BulkOperationTracker tracker; - tracker = new PollingBulkOperationTracker(statusProvider, progress, this.statusPollIntervalInMilliseconds); + tracker = new PollingBulkOperationTracker(statusProvider, progress); return tracker; } @@ -166,13 +159,6 @@ ZipExtractor getZipExtractor() { return zipExtractor; } - /** - * Gets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 second). - */ - public int getStatusPollIntervalInMilliseconds() { - return statusPollIntervalInMilliseconds; - } - /** * Gets the timeout of HttpClient download operation. The default value is 100000(100s). */ diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java index 8d6aeb4ba4..dd98a3df7a 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java @@ -55,8 +55,7 @@ public BulkUploadOperation(String requestId, ServiceClient service httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, - statusPollIntervalInMilliseconds, - new UploadStatusProvider(requestId, serviceClient)); + new UploadStatusProvider(requestId, serviceClient, statusPollIntervalInMilliseconds)); } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java index eb0bb0dc20..550fcb6e60 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/BulkOperationStatusProvider.java @@ -7,6 +7,8 @@ public interface BulkOperationStatusProvider { + int getStatusPollIntervalInMilliseconds(); + Future> getCurrentStatus(AsyncCallback> callback); boolean isFinalStatus(BulkOperationStatus currentStatus); diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java index 05331e1369..fbb147d55f 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java @@ -22,9 +22,23 @@ public class DownloadStatusProvider implements BulkOperationStatusProvider serviceClient; - public DownloadStatusProvider(String requestId, ServiceClient serviceClient) { + /** + * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. + */ + private final int statusPollIntervalInMilliseconds; + + public DownloadStatusProvider( + String requestId, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds) { this.requestId = requestId; this.serviceClient = serviceClient; + this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; + } + + @Override + public int getStatusPollIntervalInMilliseconds() { + return statusPollIntervalInMilliseconds; } @Override diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java index 0065982f2d..34311bbc73 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/PollingBulkOperationTracker.java @@ -32,7 +32,6 @@ public class PollingBulkOperationTracker implements BulkOperationTracke private boolean stopTracking; protected int lastProgressReported; private BulkOperationStatus currentStatus; - private final int statusCheckIntervalInMs; private ResultFuture> trackResultFuture; @@ -46,11 +45,10 @@ public void run() { } }; - public PollingBulkOperationTracker(BulkOperationStatusProvider statusProvider, - Progress progress, - int statusCheckIntervalInMs) { + public PollingBulkOperationTracker( + BulkOperationStatusProvider statusProvider, + Progress progress) { - this.statusCheckIntervalInMs = statusCheckIntervalInMs; this.statusProvider = statusProvider; this.progress = progress; this.operationStatusRetry = new OperationStatusRetry, BulkOperationStatusProvider, IBulkService>( @@ -116,7 +114,7 @@ public void onCompleted(Future> result) { int interval = INITIAL_STATUS_CHECK_INTERVAL_IN_MS; if (numberOfStatusChecks >= NUMBER_OF_INITIAL_STATUS_CHECKS) { - interval = statusCheckIntervalInMs; + interval = statusProvider.getStatusPollIntervalInMilliseconds(); } executorService.schedule(pollExecutorTask, interval, TimeUnit.MILLISECONDS); diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java index 43e3783163..398348e13c 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java @@ -22,9 +22,23 @@ public class UploadStatusProvider implements BulkOperationStatusProvider serviceClient; - public UploadStatusProvider(String requestId, ServiceClient serviceClient) { + /** + * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. + */ + private final int statusPollIntervalInMilliseconds; + + public UploadStatusProvider( + String requestId, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds) { this.requestId = requestId; this.serviceClient = serviceClient; + this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; + } + + @Override + public int getStatusPollIntervalInMilliseconds() { + return statusPollIntervalInMilliseconds; } @Override From b9af05d9ee5d8785be3f4016cd9721837f89bf04 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:12:54 +0100 Subject: [PATCH 07/15] Remove unused imports --- .../bingads/internal/utilities/HttpClientHttpFileService.java | 3 --- .../microsoft/bingads/internal/utilities/HttpFileService.java | 2 -- .../bingads/v13/api/test/operations/FakeHttpFileService.java | 3 --- 3 files changed, 8 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java index 910e5542ab..e4728577e3 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java @@ -10,7 +10,6 @@ import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; -import java.util.concurrent.Future; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; @@ -24,10 +23,8 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import com.microsoft.bingads.AsyncCallback; import com.microsoft.bingads.CouldNotDownloadResultFileException; import com.microsoft.bingads.CouldNotUploadFileException; -import com.microsoft.bingads.internal.ResultFuture; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; public class HttpClientHttpFileService implements HttpFileService { diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java index 9b98dd18db..56a0a6cdd9 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java @@ -1,12 +1,10 @@ package com.microsoft.bingads.internal.utilities; -import com.microsoft.bingads.AsyncCallback; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.concurrent.Future; import org.apache.http.HttpRequest; public interface HttpFileService { diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java index d97f9cea29..f19a5a9220 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java @@ -4,12 +4,9 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.concurrent.Future; import org.apache.http.HttpRequest; -import com.microsoft.bingads.AsyncCallback; import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; import com.microsoft.bingads.internal.utilities.HttpFileService; From a9bf68167437dee89e0c47293ccc483908c8a052 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:14:13 +0100 Subject: [PATCH 08/15] Reduce code duplication --- .../utilities/HttpClientHttpFileService.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java index e4728577e3..fe8a80ff9e 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java @@ -35,12 +35,7 @@ public void downloadFile(String url, File tempZipFile, boolean overwrite, int ti throw new IOException(String.format("Could not download result file due to file %s already exists", tempZipFile)); } - CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom() - .setConnectionRequestTimeout(timeoutInMilliseconds) - .setConnectTimeout(timeoutInMilliseconds) - .setSocketTimeout(timeoutInMilliseconds).build()) - .useSystemProperties() - .build(); + CloseableHttpClient client = createHttpClient(timeoutInMilliseconds); try { HttpGet httpget = new HttpGet(new URI(url)); @@ -76,15 +71,8 @@ public void uploadFile(URI uri, File uploadFilePath, Consumer addHe try { stream = new FileInputStream(uploadFilePath); - CloseableHttpClient client = HttpClients.custom() - .setDefaultRequestConfig(RequestConfig.custom() - .setConnectionRequestTimeout(timeoutInMilliseconds) - .setConnectTimeout(timeoutInMilliseconds) - .setSocketTimeout(timeoutInMilliseconds) - .build()) - .useSystemProperties() - .build(); - + CloseableHttpClient client = createHttpClient(timeoutInMilliseconds); + try { HttpPost post = new HttpPost(uri); @@ -137,4 +125,14 @@ public void uploadFile(URI uri, File uploadFilePath, Consumer addHe } } } + + private CloseableHttpClient createHttpClient(int timeoutInMilliseconds) { + return HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom() + .setConnectionRequestTimeout(timeoutInMilliseconds) + .setConnectTimeout(timeoutInMilliseconds) + .setSocketTimeout(timeoutInMilliseconds) + .build()) + .useSystemProperties() + .build(); + } } From fd388e6a23da82739f87dfd2d955d93f822df74d Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:26:58 +0100 Subject: [PATCH 09/15] Simplify http file service --- .../utilities/HttpClientHttpFileService.java | 132 ++++++------------ .../internal/utilities/HttpFileService.java | 2 +- .../test/operations/FakeHttpFileService.java | 2 +- 3 files changed, 46 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java index fe8a80ff9e..458629a63d 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java @@ -3,22 +3,22 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.CopyOption; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; @@ -27,107 +27,63 @@ import com.microsoft.bingads.CouldNotUploadFileException; import com.microsoft.bingads.internal.functionalinterfaces.Consumer; -public class HttpClientHttpFileService implements HttpFileService { - - @Override - public void downloadFile(String url, File tempZipFile, boolean overwrite, int timeoutInMilliseconds) throws IOException, URISyntaxException { - if (!overwrite && tempZipFile.exists()) { - throw new IOException(String.format("Could not download result file due to file %s already exists", tempZipFile)); - } +import static java.lang.String.format; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.http.entity.mime.HttpMultipartMode.BROWSER_COMPATIBLE; - CloseableHttpClient client = createHttpClient(timeoutInMilliseconds); - - try { - HttpGet httpget = new HttpGet(new URI(url)); - HttpResponse response = client.execute(httpget); - InputStream content = response.getEntity().getContent(); +public class HttpClientHttpFileService implements HttpFileService { - FileOutputStream tempFileOutput = null; + private static final ContentType APPLICATION_ZIP = ContentType.create("application/zip"); - try { - tempFileOutput = new FileOutputStream(tempZipFile); - - FileUtils.copy(content, tempFileOutput); - } finally { - if (tempFileOutput != null) { - tempFileOutput.close(); - } + @Override + public void downloadFile(String url, File tempZipFile, boolean overwrite, int timeoutInMilliseconds) throws URISyntaxException { + try (CloseableHttpClient client = createHttpClient(timeoutInMilliseconds)) { + HttpGet get = new HttpGet(new URI(url)); + try (CloseableHttpResponse response = client.execute(get)) { + InputStream content = response.getEntity().getContent(); + Files.copy(content, tempZipFile.toPath(), copyOptions(overwrite)); } } catch (IOException ex) { throw new CouldNotDownloadResultFileException(ex); - } catch (IllegalStateException ex) { - throw new CouldNotDownloadResultFileException(ex); - } finally { - if (client != null) { - client.close(); - } } } + @SuppressWarnings("ZeroLengthArrayAllocation") + private CopyOption[] copyOptions(boolean overwrite) { + return overwrite ? + new CopyOption[] { StandardCopyOption.REPLACE_EXISTING } : + new CopyOption[0]; + } + @Override public void uploadFile(URI uri, File uploadFilePath, Consumer addHeaders, int timeoutInMilliseconds) { - FileInputStream stream = null; - - try { - stream = new FileInputStream(uploadFilePath); - - CloseableHttpClient client = createHttpClient(timeoutInMilliseconds); - - - try { - HttpPost post = new HttpPost(uri); - addHeaders.accept(post); - MultipartEntityBuilder builder = MultipartEntityBuilder.create() - .addBinaryBody("upstream", stream, ContentType.create("application/zip"), uploadFilePath.getName()); - builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); - - post.setEntity(builder.build()); - - HttpResponse response = client.execute(post); - - if (response.getStatusLine().getStatusCode() != 200) { - InputStream in = response.getEntity().getContent(); - BufferedReader streamReader = new BufferedReader(new InputStreamReader(in, "UTF-8")); - StringBuilder exceptionMessage = new StringBuilder(); - - String inputStr; - while ((inputStr = streamReader.readLine()) != null) { - exceptionMessage.append(inputStr); - } - - throw new CouldNotUploadFileException("Unsuccessful Status Code: " + response.getStatusLine().getStatusCode() + "; Exception Message: " + exceptionMessage); - } - } catch (ClientProtocolException e) { - throw new CouldNotUploadFileException(e); - } catch (IOException e) { - throw new CouldNotUploadFileException(e); - } catch (IllegalStateException e) { - throw new CouldNotUploadFileException(e); - } finally { - if (client != null) { - try { - client.close(); - } catch (IOException e) { - // Ignore - e.printStackTrace(); - } + try (CloseableHttpClient client = createHttpClient(timeoutInMilliseconds); + FileInputStream stream = new FileInputStream(uploadFilePath)) { + HttpPost post = new HttpPost(uri); + addHeaders.accept(post); + post.setEntity(MultipartEntityBuilder.create() + .addBinaryBody("upstream", stream, APPLICATION_ZIP, uploadFilePath.getName()) + .setMode(BROWSER_COMPATIBLE) + .build()); + try (CloseableHttpResponse response = client.execute(post)) { + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + InputStream content = response.getEntity().getContent(); + BufferedReader reader = new BufferedReader(new InputStreamReader(content, UTF_8)); + StringBuilder exceptionMessage = new StringBuilder(64); + reader.lines().forEach(exceptionMessage::append); + throw new CouldNotUploadFileException(format( + "Unsuccessful Status Code: %d; Exception Message: %s", statusCode, exceptionMessage)); } } - } catch (FileNotFoundException e) { + } catch (IOException | UncheckedIOException e) { throw new CouldNotUploadFileException(e); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - throw new CouldNotUploadFileException(e); - } - } } } private CloseableHttpClient createHttpClient(int timeoutInMilliseconds) { - return HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom() + return HttpClients.custom() + .setDefaultRequestConfig(RequestConfig.custom() .setConnectionRequestTimeout(timeoutInMilliseconds) .setConnectTimeout(timeoutInMilliseconds) .setSocketTimeout(timeoutInMilliseconds) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java index 56a0a6cdd9..74ba133f55 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java @@ -9,7 +9,7 @@ public interface HttpFileService { - void downloadFile(String url, File tempZipFile, boolean overwrite, int timeoutInMilliseconds) throws IOException, URISyntaxException; + void downloadFile(String url, File tempZipFile, boolean overwrite, int timeoutInMilliseconds) throws URISyntaxException; void uploadFile(URI uri, File uploadFilePath, Consumer addHeaders, int timeoutInMilliseconds); diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java index f19a5a9220..d03ad0496c 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java @@ -29,7 +29,7 @@ public Boolean getDownloadWasCalled() { } @Override - public void downloadFile(String url, File tempZipFile, boolean overwrite, int timeoutInMilliseconds) throws IOException, URISyntaxException { + public void downloadFile(String url, File tempZipFile, boolean overwrite, int timeoutInMilliseconds) { onDownloadFile.accept(url, tempZipFile); downloadWasCalled = true; From f4668ce1ba6ac6f52263e0b22b81f8c10bf54a1d Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:27:23 +0100 Subject: [PATCH 10/15] Remove unused imports --- .../microsoft/bingads/internal/utilities/HttpFileService.java | 1 - .../bingads/v13/api/test/operations/FakeHttpFileService.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java index 74ba133f55..1c4c7871ab 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpFileService.java @@ -2,7 +2,6 @@ import com.microsoft.bingads.internal.functionalinterfaces.Consumer; import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.apache.http.HttpRequest; diff --git a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java index d03ad0496c..059a40155f 100644 --- a/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java +++ b/src/test/java/com/microsoft/bingads/v13/api/test/operations/FakeHttpFileService.java @@ -1,9 +1,7 @@ package com.microsoft.bingads.v13.api.test.operations; import java.io.File; -import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; import org.apache.http.HttpRequest; From 3e903664d60466c7070f338ded80892b86953220 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:29:56 +0100 Subject: [PATCH 11/15] Remove annotation --- .../bingads/internal/utilities/HttpClientHttpFileService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java index 458629a63d..346faaf09a 100644 --- a/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java +++ b/src/main/java/com/microsoft/bingads/internal/utilities/HttpClientHttpFileService.java @@ -48,7 +48,6 @@ public void downloadFile(String url, File tempZipFile, boolean overwrite, int ti } } - @SuppressWarnings("ZeroLengthArrayAllocation") private CopyOption[] copyOptions(boolean overwrite) { return overwrite ? new CopyOption[] { StandardCopyOption.REPLACE_EXISTING } : From 92be2e79fd11f239e4ada4c1ff3eb4c724b27b4a Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 00:57:27 +0100 Subject: [PATCH 12/15] Consolidate code --- .../microsoft/bingads/v13/bulk/BulkServiceManager.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java index 545db204e5..334a7adfe3 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java @@ -567,11 +567,9 @@ public void handleResponse(Response res) response = res.get(); - String trackingId = ServiceUtils.GetTrackingId(res); - BulkDownloadOperation operation = new BulkDownloadOperation( response.getDownloadRequestId(), - trackingId, + ServiceUtils.GetTrackingId(res), httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, @@ -650,8 +648,6 @@ public void handleResponse(Response res) { try { GetBulkUploadUrlResponse response = res.get(); - String trackingId = ServiceUtils.GetTrackingId(res); - String uploadUrl = response.getUploadUrl(); File effectiveUploadPath = parameters.getUploadFilePath(); @@ -701,7 +697,7 @@ public void addHeader(String name, String value) { } BulkUploadOperation operation = new BulkUploadOperation( response.getRequestId(), - trackingId, + ServiceUtils.GetTrackingId(res), httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, From 4661a39259537c89dc6c9a9176d961f0f714bb67 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 01:09:28 +0100 Subject: [PATCH 13/15] Consolidate reporting tracking --- .../v13/bulk/BulkDownloadOperation.java | 27 ++++-------- .../bingads/v13/bulk/BulkOperation.java | 7 +--- .../bingads/v13/bulk/BulkUploadOperation.java | 27 ++++-------- .../reporting/ReportingDownloadOperation.java | 42 +++---------------- .../reporting/ReportingOperationTracker.java | 10 ++--- .../reporting/ReportingServiceManager.java | 10 ++--- .../reporting/ReportingStatusProvider.java | 24 +++++++++-- 7 files changed, 51 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java index 5714e02221..b81f00afdf 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkDownloadOperation.java @@ -36,29 +36,18 @@ public class BulkDownloadOperation extends BulkOperation { */ public BulkDownloadOperation(String requestId, ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { this( - requestId, - null, - new HttpClientHttpFileService(), - Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, - new SimpleZipExtractor(), - serviceClient, - statusPollIntervalInMilliseconds); + requestId, null, + new HttpClientHttpFileService(), Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, new SimpleZipExtractor(), + serviceClient, statusPollIntervalInMilliseconds); } BulkDownloadOperation( - String requestId, - String trackingId, - HttpFileService httpFileService, - int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor, - ServiceClient serviceClient, - int statusPollIntervalInMilliseconds) { + String requestId, String trackingId, + HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, + ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { super( - requestId, - trackingId, - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor, + requestId, trackingId, + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, new DownloadStatusProvider(requestId, serviceClient, statusPollIntervalInMilliseconds)); } diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java index 14719ba582..e97ede6e5a 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkOperation.java @@ -49,11 +49,8 @@ public abstract class BulkOperation { private BulkOperationStatus finalStatus; BulkOperation( - String requestId, - String trackingId, - HttpFileService httpFileService, - int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor, + String requestId, String trackingId, + HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, BulkOperationStatusProvider statusProvider) { this.requestId = requestId; this.trackingId = trackingId; diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java index dd98a3df7a..a60cdcf505 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkUploadOperation.java @@ -32,29 +32,18 @@ public class BulkUploadOperation extends BulkOperation { */ public BulkUploadOperation(String requestId, ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { this( - requestId, - null, - new HttpClientHttpFileService(), - Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, - new SimpleZipExtractor(), - serviceClient, - statusPollIntervalInMilliseconds); + requestId, null, + new HttpClientHttpFileService(), Config.DEFAULT_HTTPCLIENT_TIMEOUT_IN_MS, new SimpleZipExtractor(), + serviceClient, statusPollIntervalInMilliseconds); } BulkUploadOperation( - String requestId, - String trackingId, - HttpFileService httpFileService, - int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor, - ServiceClient serviceClient, - int statusPollIntervalInMilliseconds) { + String requestId, String trackingId, + HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, + ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { super( - requestId, - trackingId, - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor, + requestId, trackingId, + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, new UploadStatusProvider(requestId, serviceClient, statusPollIntervalInMilliseconds)); } diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingDownloadOperation.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingDownloadOperation.java index 9ced9c3a26..f91660c6af 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingDownloadOperation.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingDownloadOperation.java @@ -46,16 +46,6 @@ public class ReportingDownloadOperation { */ private final ZipExtractor zipExtractor; - /** - * The client of reporting service. - */ - private final ServiceClient serviceClient; - - /** - * The amount of time in milliseconds that the download operations should wait before polling the Reporting service for status. - */ - private final int statusPollIntervalInMilliseconds; - /** * Provide the status of the reporting download operation. */ @@ -67,21 +57,15 @@ public class ReportingDownloadOperation { private ReportingOperationStatus finalStatus; ReportingDownloadOperation( - String requestId, - String trackingId, - ServiceClient serviceClient, - int statusPollIntervalInMilliseconds, - HttpFileService httpFileService, - int downloadHttpTimeoutInMilliseconds, - ZipExtractor zipExtractor) { + String requestId, String trackingId, + HttpFileService httpFileService, int downloadHttpTimeoutInMilliseconds, ZipExtractor zipExtractor, + ServiceClient serviceClient, int statusPollIntervalInMilliseconds) { this.requestId = requestId; this.trackingId = trackingId; - this.serviceClient = serviceClient; - this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; this.httpFileService = httpFileService; this.downloadHttpTimeoutInMilliseconds = downloadHttpTimeoutInMilliseconds; this.zipExtractor = zipExtractor; - this.statusProvider = new ReportingStatusProvider(requestId); + this.statusProvider = new ReportingStatusProvider(requestId, serviceClient, statusPollIntervalInMilliseconds); } /** @@ -112,7 +96,7 @@ public void onSuccess(ReportingOperationStatus status) { private ReportingOperationTracker generateTracker() { ReportingOperationTracker tracker; - tracker = new ReportingOperationTracker(statusProvider, this.serviceClient, this.statusPollIntervalInMilliseconds); + tracker = new ReportingOperationTracker(statusProvider); return tracker; } @@ -132,7 +116,7 @@ public Future getStatusAsync(AsyncCallback(resultFuture) { + statusProvider.getCurrentStatus(new ParentCallback(resultFuture) { @Override public void onSuccess(ReportingOperationStatus currentStatus) { if (statusProvider.isFinalStatus(currentStatus)) { @@ -287,13 +271,6 @@ public ZipExtractor getZipExtractor() { return zipExtractor; } - /** - * @return the serviceClient - */ - public ServiceClient getServiceClient() { - return serviceClient; - } - /** * @return the finalStatus */ @@ -308,13 +285,6 @@ public void setFinalStatus(ReportingOperationStatus finalStatus) { this.finalStatus = finalStatus; } - /** - * Gets the time interval in milliseconds between two status polling attempts. The default value is 5000 (5 second). - */ - public int getStatusPollIntervalInMilliseconds() { - return statusPollIntervalInMilliseconds; - } - /** * Gets the timeout of HttpClient download operation. The default value is 100000(100s). */ diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java index afaea21d6f..28b602515a 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingOperationTracker.java @@ -29,7 +29,6 @@ public class ReportingOperationTracker { private boolean stopTracking; protected int lastProgressReported; private ReportingOperationStatus currentStatus; - private final int statusCheckIntervalInMs; private ResultFuture trackResultFuture; @@ -45,12 +44,9 @@ public void run() { } }; - public ReportingOperationTracker(ReportingStatusProvider statusProvider, - ServiceClient serviceClient, int statusCheckIntervalInMs) { + public ReportingOperationTracker(ReportingStatusProvider statusProvider) { - this.statusCheckIntervalInMs = statusCheckIntervalInMs; this.statusProvider = statusProvider; - this.serviceClient = serviceClient; this.operationStatusRetry = new OperationStatusRetry( new Function() { @@ -112,7 +108,7 @@ public void onCompleted(Future result) { int interval = INITIAL_STATUS_CHECK_INTERVAL_IN_MS; if (numberOfStatusChecks >= NUMBER_OF_INITIAL_STATUS_CHECKS) { - interval = statusCheckIntervalInMs; + interval = statusProvider.getStatusPollIntervalInMilliseconds(); } executorService.schedule(pollExecutorTask, interval, TimeUnit.MILLISECONDS); @@ -165,7 +161,7 @@ private void refreshStatus(AsyncCallback callback) { public void accept( ReportingStatusProvider statusProvider, AsyncCallback callback) { - statusProvider.getCurrentStatus(serviceClient, callback); + statusProvider.getCurrentStatus(callback); } }, statusProvider, new Consumer() { @Override diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java index e65a0ddd92..65c6e53efb 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java @@ -232,13 +232,9 @@ public void handleResponse(Response res) { String trackingId = ServiceUtils.GetTrackingId(res); ReportingDownloadOperation operation = new ReportingDownloadOperation( - response.getReportRequestId(), - trackingId, - serviceClient, - statusPollIntervalInMilliseconds, - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor); + response.getReportRequestId(), trackingId, + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, + serviceClient, statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java index 5bf68b1b5e..8dac6196c4 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java @@ -8,18 +8,36 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; + +import com.microsoft.bingads.v13.bulk.IBulkService; import jakarta.xml.ws.AsyncHandler; import jakarta.xml.ws.Response; public class ReportingStatusProvider{ private final String requestId; - - public ReportingStatusProvider(String requestId) { + + private final ServiceClient serviceClient; + + /** + * The amount of time in milliseconds that the upload and download operations should wait before polling the Bulk service for status. + */ + private final int statusPollIntervalInMilliseconds; + + public ReportingStatusProvider( + String requestId, + ServiceClient serviceClient, + int statusPollIntervalInMilliseconds) { this.requestId = requestId; + this.serviceClient = serviceClient; + this.statusPollIntervalInMilliseconds = statusPollIntervalInMilliseconds; + } + + public int getStatusPollIntervalInMilliseconds() { + return statusPollIntervalInMilliseconds; } - public Future getCurrentStatus(ServiceClient serviceClient, AsyncCallback callback) { + public Future getCurrentStatus(AsyncCallback callback) { PollGenerateReportRequest request = new PollGenerateReportRequest(); request.setReportRequestId(this.requestId); From 45c4b3c2f8a61c2240ff0b26273de6b2fac3ef28 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 01:11:41 +0100 Subject: [PATCH 14/15] Format code --- .../bingads/v13/bulk/BulkServiceManager.java | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java index 334a7adfe3..527c922c57 100644 --- a/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/bulk/BulkServiceManager.java @@ -200,13 +200,9 @@ public void handleResponse(Response res) { UploadEntityRecordsResponse result = res.get(); if (needToFallBacktoAsync(result)) { BulkUploadOperation operation = new BulkUploadOperation( - result.getRequestId(), - ServiceUtils.GetTrackingId(res), - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor, - serviceClient, - statusPollIntervalInMilliseconds); + result.getRequestId(), ServiceUtils.GetTrackingId(res), + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, + serviceClient, statusPollIntervalInMilliseconds); operation.trackAsync(progress, new ParentCallback>(resultFuture) { @Override public void onSuccess(BulkOperationStatus status) throws IOException, URISyntaxException { @@ -568,13 +564,9 @@ public void handleResponse(Response res) response = res.get(); BulkDownloadOperation operation = new BulkDownloadOperation( - response.getDownloadRequestId(), - ServiceUtils.GetTrackingId(res), - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor, - serviceClient, - statusPollIntervalInMilliseconds); + response.getDownloadRequestId(), ServiceUtils.GetTrackingId(res), + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, + serviceClient, statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { @@ -598,13 +590,9 @@ public void handleResponse(Response res) response = res.get(); BulkDownloadOperation operation = new BulkDownloadOperation( - response.getDownloadRequestId(), - ServiceUtils.GetTrackingId(res), - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor, - serviceClient, - statusPollIntervalInMilliseconds); + response.getDownloadRequestId(), ServiceUtils.GetTrackingId(res), + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, + serviceClient, statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { @@ -696,13 +684,9 @@ public void addHeader(String name, String value) { } BulkUploadOperation operation = new BulkUploadOperation( - response.getRequestId(), - ServiceUtils.GetTrackingId(res), - httpFileService, - downloadHttpTimeoutInMilliseconds, - zipExtractor, - serviceClient, - statusPollIntervalInMilliseconds); + response.getRequestId(), ServiceUtils.GetTrackingId(res), + httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, + serviceClient, statusPollIntervalInMilliseconds); resultFuture.setResult(operation); } catch (InterruptedException e) { From b0ab9943ec6f4cfe37fa623c8e295875eaa03a3b Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Sat, 2 Mar 2024 01:15:01 +0100 Subject: [PATCH 15/15] Consolidate code --- .../bingads/v13/internal/bulk/DownloadStatusProvider.java | 4 +--- .../bingads/v13/internal/bulk/UploadStatusProvider.java | 4 +--- .../bingads/v13/reporting/ReportingServiceManager.java | 4 +--- .../bingads/v13/reporting/ReportingStatusProvider.java | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java index fbb147d55f..149ba3a62e 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/DownloadStatusProvider.java @@ -54,13 +54,11 @@ 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, + ServiceUtils.GetTrackingId(result), statusResponse.getErrors() != null ? statusResponse.getErrors().getOperationErrors() : null ); diff --git a/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java index 398348e13c..e2da8952fe 100644 --- a/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/internal/bulk/UploadStatusProvider.java @@ -56,13 +56,11 @@ 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, + ServiceUtils.GetTrackingId(result), statusResponse.getErrors() != null ? statusResponse.getErrors().getOperationErrors() : null ); diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java index 65c6e53efb..6f20b92438 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingServiceManager.java @@ -229,10 +229,8 @@ public void handleResponse(Response res) { response = res.get(); - String trackingId = ServiceUtils.GetTrackingId(res); - ReportingDownloadOperation operation = new ReportingDownloadOperation( - response.getReportRequestId(), trackingId, + response.getReportRequestId(), ServiceUtils.GetTrackingId(res), httpFileService, downloadHttpTimeoutInMilliseconds, zipExtractor, serviceClient, statusPollIntervalInMilliseconds); diff --git a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java index 8dac6196c4..5d45cc3872 100644 --- a/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java +++ b/src/main/java/com/microsoft/bingads/v13/reporting/ReportingStatusProvider.java @@ -49,12 +49,10 @@ 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 + ServiceUtils.GetTrackingId(result) ); resultFuture.setResult(status); } catch (InterruptedException e) {