From e83537d81b2e0a09a625ae6f7b9efe29d03d1c40 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:39:10 +0000 Subject: [PATCH 1/3] [fern-generated] Update SDK Generated by Fern CLI Version: unknown Generators: - fernapi/fern-java-sdk: 4.32.4 --- .fern/metadata.json | 8 +- .github/workflows/ci.yml | 2 +- README.md | 27 +- build.gradle | 4 +- .../catchall/core/BodyProperties.java | 89 ++++ .../catchall/core/ClientOptions.java | 4 +- .../newscatcher/catchall/core/LogLevel.java | 4 +- .../catchall/core/LoggingInterceptor.java | 5 +- .../catchall/core/PathSegments.java | 21 + .../catchall/core/RequestOptions.java | 35 +- .../catchall/core/RetryInterceptor.java | 239 +++++++++- .../catchall/core/SseEventParser.java | 36 ++ .../com/newscatcher/catchall/core/Stream.java | 52 +- .../datasets/AsyncDatasetsClient.java | 450 +++++++++++++++--- .../datasets/AsyncRawDatasetsClient.java | 259 ++++++++-- .../resources/datasets/DatasetsClient.java | 24 +- .../resources/datasets/RawDatasetsClient.java | 108 ++++- .../requests/AddEntitiesToDatasetRequest.java | 9 +- .../requests/CreateDatasetFromCsvRequest.java | 9 +- .../requests/CreateDatasetRequest.java | 11 +- .../requests/DeleteDatasetRequest.java | 6 +- .../datasets/requests/GetDatasetRequest.java | 6 +- .../GetDatasetStatusHistoryRequest.java | 6 +- .../requests/ListDatasetEntitiesRequest.java | 15 +- .../requests/ListDatasetsRequest.java | 16 +- .../RemoveEntitiesFromDatasetRequest.java | 9 +- .../requests/UpdateDatasetRequest.java | 9 +- .../requests/UploadCsvToDatasetRequest.java | 6 +- .../entities/AsyncEntitiesClient.java | 195 +++++++- .../entities/AsyncRawEntitiesClient.java | 73 ++- .../resources/entities/RawEntitiesClient.java | 25 +- .../requests/CreateEntitiesBatchRequest.java | 9 +- .../requests/DeleteEntityRequest.java | 6 +- .../entities/requests/GetEntityRequest.java | 6 +- .../requests/ListEntitiesRequest.java | 16 +- .../requests/UpdateEntityRequest.java | 12 +- .../AsyncEventMonitorsClient.java | 387 +++++++++++++-- .../AsyncRawEventMonitorsClient.java | 121 ++++- .../eventmonitors/RawEventMonitorsClient.java | 41 +- .../requests/CreateMonitorRequestDto.java | 15 +- .../requests/DeleteMonitorRequest.java | 6 +- .../requests/DisableMonitorRequest.java | 6 +- .../requests/EnableMonitorRequestDto.java | 9 +- .../GetMonitorStatusHistoryRequest.java | 6 +- .../requests/ListMonitorJobsRequest.java | 9 +- .../requests/ListMonitorsRequest.java | 13 +- .../PullMonitorResultsCsvRequest.java | 6 +- .../requests/PullMonitorResultsRequest.java | 6 +- .../requests/UpdateMonitorRequestDto.java | 12 +- .../types/DisableMonitorResponse.java | 11 +- .../types/EnableMonitorResponse.java | 11 +- .../types/ListMonitorJobsResponse.java | 12 +- .../resources/jobs/AsyncJobsClient.java | 313 ++++++++++-- .../resources/jobs/AsyncRawJobsClient.java | 111 ++++- .../resources/jobs/RawJobsClient.java | 31 +- .../jobs/requests/ContinueRequestDto.java | 9 +- .../jobs/requests/DeleteJobRequest.java | 6 +- .../requests/GetJobResultsCsvRequest.java | 6 +- .../jobs/requests/GetJobResultsRequest.java | 9 +- .../jobs/requests/GetJobStatusRequest.java | 6 +- .../jobs/requests/GetUserJobsRequest.java | 14 +- .../jobs/requests/InitializeRequestDto.java | 12 +- .../requests/ListSourceGroupsRequest.java | 9 +- .../jobs/requests/SubmitRequestDto.java | 23 +- .../requests/ValidateQueryRequestDto.java | 9 +- .../resources/meta/AsyncMetaClient.java | 58 ++- .../resources/meta/AsyncRawMetaClient.java | 31 +- .../resources/meta/RawMetaClient.java | 7 +- .../meta/types/GetVersionResponse.java | 9 +- .../meta/types/HealthCheckResponse.java | 9 +- .../projects/AsyncProjectsClient.java | 331 +++++++++++-- .../projects/AsyncRawProjectsClient.java | 114 ++++- .../resources/projects/RawProjectsClient.java | 42 +- .../requests/AddResourceRequestDto.java | 9 +- .../requests/CreateProjectRequestDto.java | 9 +- .../requests/DeleteProjectRequest.java | 9 +- .../requests/GetProjectOverviewRequest.java | 6 +- .../projects/requests/GetProjectRequest.java | 6 +- .../requests/ListProjectResourcesRequest.java | 11 +- .../requests/ListProjectsRequest.java | 12 +- .../RemoveResourceFromProjectRequest.java | 6 +- .../requests/UpdateProjectRequestDto.java | 9 +- .../webhooks/AsyncRawWebhooksClient.java | 156 ++++-- .../webhooks/AsyncWebhooksClient.java | 418 +++++++++++++--- .../resources/webhooks/RawWebhooksClient.java | 60 ++- .../AssignWebhookResourceRequestDto.java | 9 +- .../requests/CreateWebhookRequestDto.java | 18 +- .../requests/DeleteWebhookRequest.java | 6 +- .../GetWebhookDeliveryHistoryRequest.java | 12 +- .../webhooks/requests/GetWebhookRequest.java | 6 +- .../requests/ListWebhookResourcesRequest.java | 11 +- .../ListWebhooksForResourceRequest.java | 11 +- .../requests/ListWebhooksRequest.java | 12 +- .../RemoveWebhookResourceRequest.java | 6 +- .../requests/TestWebhookRequestDto.java | 9 +- .../requests/TriggerWebhookRequest.java | 9 +- .../requests/UpdateWebhookRequestDto.java | 18 +- .../types/AddResourceResponseDto.java | 9 +- .../catchall/types/AdditionalAttributes.java | 9 +- .../catchall/types/ApiKeyAuthDto.java | 9 +- .../catchall/types/ApiKeyAuthResponseDto.java | 9 +- .../AssignWebhookResourceResponseDto.java | 12 +- .../catchall/types/BaseRecord.java | 11 +- .../catchall/types/BaseRecordEnrichment.java | 9 +- .../catchall/types/BasicAuthDto.java | 9 +- .../catchall/types/BasicAuthResponseDto.java | 9 +- .../catchall/types/BearerAuthDto.java | 9 +- .../catchall/types/BearerAuthResponseDto.java | 9 +- .../newscatcher/catchall/types/Citation.java | 11 +- .../catchall/types/CompanyAttributes.java | 11 +- .../types/CompanyEnrichmentOutput.java | 11 +- .../CompanyEnrichmentOutputMetadata.java | 11 +- .../catchall/types/ConnectedDataset.java | 9 +- .../catchall/types/ConnectedEntity.java | 16 +- .../catchall/types/ContinueResponseDto.java | 12 +- .../types/CreateDatasetCsvResponse.java | 12 +- .../types/CreateEntitiesBatchResponse.java | 9 +- .../catchall/types/CreateEntityRequest.java | 13 +- .../catchall/types/CreateEntityResponse.java | 9 +- .../types/CreateMonitorResponseDto.java | 9 +- .../types/CreateProjectResponseDto.java | 12 +- .../types/CreateWebhookResponseDto.java | 9 +- .../types/DatasetEntityIdsRequest.java | 9 +- .../types/DatasetEntityListResponse.java | 12 +- .../catchall/types/DatasetListResponse.java | 12 +- .../catchall/types/DatasetResponse.java | 20 +- .../catchall/types/DatasetStatusEntry.java | 11 +- .../types/DatasetStatusHistoryResponse.java | 9 +- .../catchall/types/DeleteJobResponseDto.java | 9 +- .../types/DeleteMonitorResponseDto.java | 11 +- .../types/DeliveryHistoryItemDto.java | 19 +- .../types/DeliveryHistoryResponseDto.java | 15 +- .../catchall/types/EnrichmentSchema.java | 9 +- .../catchall/types/EntityListResponse.java | 12 +- .../catchall/types/EntityResponse.java | 19 +- .../catchall/types/EntitySummary.java | 15 +- .../types/EntityValidationErrorBody.java | 11 +- .../com/newscatcher/catchall/types/Error.java | 9 +- .../newscatcher/catchall/types/EventTags.java | 9 +- .../catchall/types/FormatterConfigDto.java | 9 +- .../types/GetPlanLimitsResponseDto.java | 9 +- .../catchall/types/GetWebhookResponseDto.java | 9 +- .../catchall/types/InitializeResponseDto.java | 15 +- .../newscatcher/catchall/types/JobStep.java | 9 +- .../types/ListMonitorsResponseDto.java | 13 +- .../types/ListSourceGroupsResponseDto.java | 12 +- .../types/ListUserJobsResponseDto.java | 13 +- .../ListWebhookResourcesResponseDto.java | 13 +- .../types/ListWebhooksResponseDto.java | 13 +- .../types/ManageEntitiesResponse.java | 9 +- .../catchall/types/MonitorCitation.java | 14 +- .../catchall/types/MonitorJobItem.java | 11 +- .../catchall/types/MonitorListItemDto.java | 19 +- .../catchall/types/MonitorRecord.java | 14 +- .../catchall/types/MonitorStatusEntry.java | 11 +- .../MonitorStatusHistoryResponseDto.java | 13 +- .../catchall/types/PlanFeature.java | 13 +- .../types/ProjectListResponseDto.java | 13 +- .../types/ProjectOverviewResponseDto.java | 9 +- .../ProjectOverviewResponseDtoOverview.java | 13 +- .../catchall/types/ProjectResourceDto.java | 13 +- .../types/ProjectResourceListResponseDto.java | 13 +- .../catchall/types/ProjectResponseDto.java | 16 +- .../catchall/types/ProjectSummaryDto.java | 14 +- .../catchall/types/PullJobResponseDto.java | 30 +- .../types/PullJobResponseDtoDateRange.java | 9 +- .../types/PullMonitorResponseDto.java | 19 +- .../types/PullMonitorResponseDtoRunInfo.java | 9 +- .../newscatcher/catchall/types/Record.java | 14 +- .../catchall/types/ReferenceJob.java | 11 +- .../types/RemoveResourceResponseDto.java | 9 +- .../catchall/types/ResourceItemDto.java | 9 +- .../catchall/types/ResourceResultDto.java | 13 +- .../catchall/types/SharingInfo.java | 11 +- .../catchall/types/SkippedRow.java | 9 +- .../catchall/types/SourceGroupRef.java | 9 +- .../catchall/types/StatusResponseDto.java | 9 +- .../catchall/types/SubmitResponseDto.java | 9 +- .../catchall/types/Suggestion.java | 9 +- .../types/TestWebhookResponseDto.java | 12 +- .../types/UpdateMonitorResponseDto.java | 9 +- .../types/UpdateProjectResponseDto.java | 11 +- .../types/UpdateWebhookResponseDto.java | 9 +- .../types/UploadCsvToDatasetResponse.java | 11 +- .../newscatcher/catchall/types/UserJob.java | 15 +- .../types/ValidateQueryResponseDto.java | 14 +- .../catchall/types/ValidationErrorDetail.java | 9 +- .../types/ValidationErrorResponse.java | 9 +- .../catchall/types/ValidationReport.java | 12 +- .../catchall/types/ValidatorSchema.java | 9 +- .../catchall/types/WebhookDto.java | 13 +- .../catchall/types/WebhookPayload.java | 17 +- .../WebhookResourceMappingResponseDto.java | 13 +- .../catchall/types/WebhookResponseDto.java | 23 +- .../catchall/core/PathSegmentsTest.java | 36 ++ 195 files changed, 4945 insertions(+), 714 deletions(-) create mode 100644 src/main/java/com/newscatcher/catchall/core/BodyProperties.java create mode 100644 src/main/java/com/newscatcher/catchall/core/PathSegments.java create mode 100644 src/test/java/com/newscatcher/catchall/core/PathSegmentsTest.java diff --git a/.fern/metadata.json b/.fern/metadata.json index 104acf4..e1eaff9 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -1,16 +1,16 @@ { - "cliVersion": "5.143.0", + "cliVersion": "5.170.5", "generatorName": "fernapi/fern-java-sdk", - "generatorVersion": "4.23.1", + "generatorVersion": "4.32.4", "generatorConfig": { "publish-to": "central", "client-class-name": "CatchAllApi", "package-prefix": "com.newscatcher.catchall" }, - "originGitCommit": "6ef7448ab601e5b372caec45717b0390a4150d2c", + "originGitCommit": "b7764dca3eb740a480b120edb87932f928b9210e", "originGitCommitIsDirty": true, "invokedBy": "ci", "requestedVersion": "AUTO", "ciProvider": "unknown", - "sdkVersion": "3.0.5" + "sdkVersion": "0.0.0-fern-placeholder" } \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f32646..7b513f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: env: MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - MAVEN_PUBLISH_REGISTRY_URL: "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + MAVEN_PUBLISH_REGISTRY_URL: "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/" MAVEN_SIGNATURE_KID: ${{ secrets.MAVEN_SIGNATURE_KID }} MAVEN_SIGNATURE_SECRET_KEY: ${{ secrets.MAVEN_SIGNATURE_SECRET_KEY }} MAVEN_SIGNATURE_PASSWORD: ${{ secrets.MAVEN_SIGNATURE_PASSWORD }} diff --git a/README.md b/README.md index a90bbfd..1baa2be 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The Newscatcher Java library provides convenient access to the Newscatcher APIs - [Retries](#retries) - [Timeouts](#timeouts) - [Custom Headers](#custom-headers) + - [Additional Body Properties](#additional-body-properties) - [Access Raw Response Data](#access-raw-response-data) - [Contributing](#contributing) - [Support](#support) @@ -35,7 +36,7 @@ Add the dependency in your `build.gradle` file: ```groovy dependencies { - implementation 'com.newscatcherapi:newscatcher-catchall-sdk:3.0.5' + implementation 'com.newscatcherapi:newscatcher-catchall-sdk:0.0.0-fern-placeholder' } ``` @@ -47,7 +48,7 @@ Add the dependency in your `pom.xml` file: com.newscatcherapi newscatcher-catchall-sdk - 3.0.5 + 0.0.0-fern-placeholder ``` @@ -99,7 +100,7 @@ import com.newscatcher.catchall.core.Environment; CatchAllApi client = CatchAllApi .builder() - .environment(Environment.Default) + .environment(Environment.DEFAULT) .build(); ``` @@ -231,6 +232,25 @@ client.jobs().createJob( ); ``` +### Additional Body Properties + +If you need to send a request body property that is not yet part of the SDK (for example, a beta field), +use the `addBodyProperty` request option. Properties are sent with the key exactly as given and override +any property with the same key; for endpoints without a request body, they are sent as a JSON body. +This is supported for JSON and form-urlencoded request bodies, but not for multipart (file upload) requests. + +```java +import com.newscatcher.catchall.core.RequestOptions; + +client.jobs().createJob( + ..., + RequestOptions + .builder() + .addBodyProperty("extra_field", "extra-value") + .build() +); +``` + ### Access Raw Response Data The SDK provides access to raw response data, including headers, through the `withRawResponse()` method. @@ -268,3 +288,4 @@ On the other hand, contributions to the README are always very welcome! + diff --git a/build.gradle b/build.gradle index 20f4a1b..50f8a68 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ java { group = 'com.newscatcherapi' -version = '3.0.5' +version = '0.0.0-fern-placeholder' jar { dependsOn(":generatePomFileForMavenPublication") @@ -88,7 +88,7 @@ publishing { maven(MavenPublication) { groupId = 'com.newscatcherapi' artifactId = 'newscatcher-catchall-sdk' - version = '3.0.5' + version = '0.0.0-fern-placeholder' from components.java pom { name = 'newscatcher' diff --git a/src/main/java/com/newscatcher/catchall/core/BodyProperties.java b/src/main/java/com/newscatcher/catchall/core/BodyProperties.java new file mode 100644 index 0000000..50ee2eb --- /dev/null +++ b/src/main/java/com/newscatcher/catchall/core/BodyProperties.java @@ -0,0 +1,89 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.newscatcher.catchall.core; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.util.LinkedHashMap; +import java.util.Map; +import okhttp3.RequestBody; + +/** + * Merges the additional body properties set through {@code RequestOptions.Builder#addBodyProperty} into request + * bodies. Properties are sent with the keys exactly as given (no casing transform) and override any generated body + * property with the same key. + * + *

Supported for JSON and {@code application/x-www-form-urlencoded} bodies. Multipart (file upload) and raw bytes + * bodies are sent unchanged. + */ +public final class BodyProperties { + + private BodyProperties() {} + + public static boolean isPresent(Map bodyProperties) { + return bodyProperties != null && !bodyProperties.isEmpty(); + } + + /** + * Returns the value to serialize as the JSON request body. Without body properties the body is returned unchanged. + * Otherwise the body is converted to a JSON object (an empty one when the body is null or absent) and the body + * properties are set on it, overriding existing keys. Bodies that are not JSON objects (arrays, primitives) are + * returned unchanged. + */ + public static Object merge(Object body, Map bodyProperties) throws JsonProcessingException { + if (!isPresent(bodyProperties)) { + return body; + } + JsonNode node; + try { + node = ObjectMappers.JSON_MAPPER.valueToTree(body); + } catch (IllegalArgumentException e) { + throw JsonMappingException.from((com.fasterxml.jackson.core.JsonParser) null, e.getMessage(), e); + } + ObjectNode merged; + if (node == null || node.isNull() || node.isMissingNode()) { + merged = ObjectMappers.JSON_MAPPER.createObjectNode(); + } else if (node.isObject()) { + merged = (ObjectNode) node; + } else { + return body; + } + for (Map.Entry entry : bodyProperties.entrySet()) { + merged.putPOJO(entry.getKey(), entry.getValue()); + } + return merged; + } + + /** + * Returns a JSON request body made of the body properties for an endpoint without a request body, or the fallback + * when there are no body properties. + */ + public static RequestBody toRequestBody(Map bodyProperties, RequestBody fallback) { + if (!isPresent(bodyProperties)) { + return fallback; + } + try { + return RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(merge(null, bodyProperties)), + MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new IllegalArgumentException("Failed to serialize body properties", e); + } + } + + /** Returns the form parameters with the body properties added, overriding existing keys. */ + public static Map mergeFormParams( + Map formParams, Map bodyProperties) { + Map merged = new LinkedHashMap<>(); + if (formParams != null) { + merged.putAll(formParams); + } + if (isPresent(bodyProperties)) { + merged.putAll(bodyProperties); + } + return merged; + } +} diff --git a/src/main/java/com/newscatcher/catchall/core/ClientOptions.java b/src/main/java/com/newscatcher/catchall/core/ClientOptions.java index a831b43..3aa651e 100644 --- a/src/main/java/com/newscatcher/catchall/core/ClientOptions.java +++ b/src/main/java/com/newscatcher/catchall/core/ClientOptions.java @@ -60,10 +60,10 @@ private ClientOptions( this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.newscatcherapi.newscatcher-catchall-sdk/3.0.5"); + put("User-Agent", "com.newscatcherapi.newscatcher-catchall-sdk/0.0.0-fern-placeholder"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.newscatcherapi:newscatcher-catchall-sdk"); - put("X-Fern-SDK-Version", "3.0.5"); + put("X-Fern-SDK-Version", "0.0.0-fern-placeholder"); } }); this.headerSuppliers = headerSuppliers; diff --git a/src/main/java/com/newscatcher/catchall/core/LogLevel.java b/src/main/java/com/newscatcher/catchall/core/LogLevel.java index 488b552..1cdc38a 100644 --- a/src/main/java/com/newscatcher/catchall/core/LogLevel.java +++ b/src/main/java/com/newscatcher/catchall/core/LogLevel.java @@ -3,6 +3,8 @@ */ package com.newscatcher.catchall.core; +import java.util.Locale; + /** * Log levels for SDK logging configuration. * Silent by default — no log output unless explicitly configured. @@ -31,6 +33,6 @@ public int getValue() { * @throws IllegalArgumentException if the string does not match any level */ public static LogLevel fromString(String level) { - return LogLevel.valueOf(level.toUpperCase()); + return LogLevel.valueOf(level.toUpperCase(Locale.ROOT)); } } diff --git a/src/main/java/com/newscatcher/catchall/core/LoggingInterceptor.java b/src/main/java/com/newscatcher/catchall/core/LoggingInterceptor.java index 4cf746e..eef921a 100644 --- a/src/main/java/com/newscatcher/catchall/core/LoggingInterceptor.java +++ b/src/main/java/com/newscatcher/catchall/core/LoggingInterceptor.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import okhttp3.Interceptor; import okhttp3.Request; @@ -58,7 +59,7 @@ public Response intercept(Chain chain) throws IOException { sb.append(", "); } sb.append(name).append("="); - if (SENSITIVE_HEADERS.contains(name.toLowerCase())) { + if (SENSITIVE_HEADERS.contains(name.toLowerCase(Locale.ROOT))) { sb.append("[REDACTED]"); } else { sb.append(request.header(name)); @@ -83,7 +84,7 @@ public Response intercept(Chain chain) throws IOException { sb.append(", "); } sb.append(name).append("="); - if (SENSITIVE_HEADERS.contains(name.toLowerCase())) { + if (SENSITIVE_HEADERS.contains(name.toLowerCase(Locale.ROOT))) { sb.append("[REDACTED]"); } else { sb.append(response.header(name)); diff --git a/src/main/java/com/newscatcher/catchall/core/PathSegments.java b/src/main/java/com/newscatcher/catchall/core/PathSegments.java new file mode 100644 index 0000000..01726ea --- /dev/null +++ b/src/main/java/com/newscatcher/catchall/core/PathSegments.java @@ -0,0 +1,21 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.newscatcher.catchall.core; + +public final class PathSegments { + + private PathSegments() {} + + /** + * Returns the value unchanged, rejecting "." and "..". These are dot-segments that URL builders resolve, + * which would otherwise change the endpoint a request is sent to. + */ + public static String validate(String value) { + if (".".equals(value) || "..".equals(value)) { + throw new IllegalArgumentException( + "Invalid path parameter value \"" + value + "\": \".\" and \"..\" are not allowed."); + } + return value; + } +} diff --git a/src/main/java/com/newscatcher/catchall/core/RequestOptions.java b/src/main/java/com/newscatcher/catchall/core/RequestOptions.java index a556072..1e0dedb 100644 --- a/src/main/java/com/newscatcher/catchall/core/RequestOptions.java +++ b/src/main/java/com/newscatcher/catchall/core/RequestOptions.java @@ -4,6 +4,7 @@ package com.newscatcher.catchall.core; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -26,6 +27,8 @@ public final class RequestOptions { private final Map> queryParameterSuppliers; + private final Map bodyProperties; + private RequestOptions( String apiKey, Optional timeout, @@ -34,7 +37,8 @@ private RequestOptions( Map headers, Map> headerSuppliers, Map queryParameters, - Map> queryParameterSuppliers) { + Map> queryParameterSuppliers, + Map bodyProperties) { this.apiKey = apiKey; this.timeout = timeout; this.timeoutTimeUnit = timeoutTimeUnit; @@ -43,6 +47,7 @@ private RequestOptions( this.headerSuppliers = headerSuppliers; this.queryParameters = queryParameters; this.queryParameterSuppliers = queryParameterSuppliers; + this.bodyProperties = bodyProperties; } public Optional getTimeout() { @@ -77,6 +82,13 @@ public Map getQueryParameters() { return queryParameters; } + /** + * Additional properties merged into the request body, keyed by their wire names. + */ + public Map getBodyProperties() { + return new LinkedHashMap<>(this.bodyProperties); + } + public static Builder builder() { return new Builder(); } @@ -98,6 +110,8 @@ public static class Builder { private final Map> queryParameterSuppliers = new HashMap<>(); + private final Map bodyProperties = new LinkedHashMap<>(); + public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; @@ -139,6 +153,22 @@ public Builder addQueryParameter(String key, Supplier value) { return this; } + /** + * Adds a property to the JSON or form-urlencoded request body, keyed by its wire name. It overrides any request body property with the same key, and is sent as the whole body for endpoints without one. Multipart (file upload) bodies are not supported. + */ + public Builder addBodyProperty(String key, Object value) { + this.bodyProperties.put(key, value); + return this; + } + + /** + * Adds each entry as a request body property. See {@link #addBodyProperty}. + */ + public Builder bodyProperties(Map bodyProperties) { + this.bodyProperties.putAll(bodyProperties); + return this; + } + public RequestOptions build() { return new RequestOptions( apiKey, @@ -148,7 +178,8 @@ public RequestOptions build() { headers, headerSuppliers, queryParameters, - queryParameterSuppliers); + queryParameterSuppliers, + bodyProperties); } } } diff --git a/src/main/java/com/newscatcher/catchall/core/RetryInterceptor.java b/src/main/java/com/newscatcher/catchall/core/RetryInterceptor.java index 783accd..bf208f2 100644 --- a/src/main/java/com/newscatcher/catchall/core/RetryInterceptor.java +++ b/src/main/java/com/newscatcher/catchall/core/RetryInterceptor.java @@ -4,14 +4,20 @@ package com.newscatcher.catchall.core; import java.io.IOException; +import java.io.InterruptedIOException; import java.time.Duration; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.Optional; import java.util.Random; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import okhttp3.Call; +import okhttp3.Callback; import okhttp3.Interceptor; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; @@ -63,6 +69,10 @@ public RetryInterceptor( @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); + if (request.tag(AsyncAttempt.class) != null) { + // Retries of calls created by newAsyncCall are scheduled off OkHttp's dispatcher threads. + return chain.proceed(request); + } int effectiveMaxRetries = resolveMaxRetries(request); Response response = chain.proceed(request); @@ -88,7 +98,11 @@ private Response retryChain(Response response, Chain chain, int maxRetries) thro Thread.sleep(nextBackoff.get().toMillis()); } catch (InterruptedException e) { response.close(); - throw new IOException("Interrupted while trying request", e); + Thread.currentThread().interrupt(); + InterruptedIOException interrupted = + new InterruptedIOException("Interrupted while waiting to retry request"); + interrupted.initCause(e); + throw interrupted; } finally { callTimeout.ifPresent(AsyncTimeout::enter); } @@ -114,6 +128,229 @@ private Response retryChain(Response response, Chain chain, int maxRetries) thro return response; } + /** + * Creates a call for the async client. If {@code client} has a {@link RetryInterceptor}, retries are scheduled + * after the backoff delay instead of sleeping inside the interceptor, so a call that is waiting to retry does not + * hold one of OkHttp's dispatcher slots (5 per host by default) and stops waiting as soon as it is cancelled. + */ + public static AsyncCall newAsyncCall(OkHttpClient client, Request request) { + for (Interceptor interceptor : client.interceptors()) { + if (interceptor instanceof RetryInterceptor) { + RetryInterceptor retryInterceptor = (RetryInterceptor) interceptor; + return new AsyncRetryingCall( + retryInterceptor, client, request, retryInterceptor.resolveMaxRetries(request)); + } + } + return new AsyncRetryingCall(null, client, request, 0); + } + + /** An async OkHttp call that retries retryable responses without blocking a dispatcher thread. */ + public interface AsyncCall { + void enqueue(Callback callback); + + void cancel(); + } + + /** Marks an attempt of an {@link AsyncCall} so that {@link #intercept(Chain)} does not retry it in place. */ + private static final class AsyncAttempt { + private static final AsyncAttempt INSTANCE = new AsyncAttempt(); + } + + private static final class RetryScheduler { + private static final ScheduledThreadPoolExecutor INSTANCE = create(); + + private static ScheduledThreadPoolExecutor create() { + ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, runnable -> { + Thread thread = new Thread(runnable, "RetryInterceptor-scheduler"); + thread.setDaemon(true); + return thread; + }); + executor.setRemoveOnCancelPolicy(true); + return executor; + } + } + + private static final class AsyncRetryingCall implements AsyncCall, Callback { + private final OkHttpClient client; + private final Request request; + private final ExponentialBackoff backoff; + private final Object lock = new Object(); + + // All fields below are guarded by lock. + private Callback callback; + private Call currentCall; + private ScheduledFuture pendingRetry; + private Response previousResponse; + private boolean executed; + private boolean canceled; + private boolean completed; + + AsyncRetryingCall(RetryInterceptor retryInterceptor, OkHttpClient client, Request request, int maxRetries) { + this.client = client; + this.request = request.newBuilder() + .tag(AsyncAttempt.class, AsyncAttempt.INSTANCE) + .build(); + this.backoff = retryInterceptor != null ? retryInterceptor.new ExponentialBackoff(maxRetries) : null; + } + + @Override + public void enqueue(Callback callback) { + Call call; + boolean wasCanceled; + synchronized (lock) { + if (executed) { + throw new IllegalStateException("Already Executed"); + } + executed = true; + this.callback = callback; + call = client.newCall(request); + currentCall = call; + wasCanceled = canceled; + } + if (wasCanceled) { + failCanceled(); + return; + } + call.enqueue(this); + } + + private void startRetry() { + Call call; + synchronized (lock) { + pendingRetry = null; + if (completed) { + return; + } + if (canceled) { + call = null; + } else { + call = client.newCall(request); + currentCall = call; + } + } + if (call == null) { + failCanceled(); + return; + } + try { + call.enqueue(this); + } catch (RuntimeException e) { + // Runs on the retry scheduler, where an uncaught exception would leave the callback never invoked. + onFailure(call, new IOException("Failed to enqueue retry attempt", e)); + } + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (backoff != null && shouldRetry(response.code())) { + Optional delay = backoff.nextBackoff(response); + if (delay.isPresent()) { + Response buffered = bufferResponse(response); + synchronized (lock) { + if (!canceled && !completed) { + closePreviousResponse(); + previousResponse = buffered; + pendingRetry = RetryScheduler.INSTANCE.schedule( + this::startRetry, delay.get().toMillis(), TimeUnit.MILLISECONDS); + return; + } + } + buffered.close(); + failCanceled(); + return; + } + } + boolean deliver; + synchronized (lock) { + deliver = !canceled && !completed; + if (deliver) { + completed = true; + closePreviousResponse(); + } + } + if (!deliver) { + response.close(); + failCanceled(); + return; + } + callback.onResponse(call, response); + } + + @Override + public void onFailure(Call call, IOException e) { + Response previous; + synchronized (lock) { + if (completed) { + return; + } + completed = true; + // As in the synchronous retry loop, a cancelled attempt (cancel() or the call timeout firing) + // reports its own failure rather than the response received before it. + previous = canceled || call.isCanceled() ? null : previousResponse; + previousResponse = null; + closePreviousResponse(); + } + if (previous == null) { + callback.onFailure(call, e); + return; + } + // A retry attempt failed with a transport error; the response already received from the API is more + // actionable, as in the synchronous retry loop. As with OkHttp, the callback owns the response once it is + // delivered, and is not called again if onResponse throws. + try { + callback.onResponse(call, previous); + } catch (IOException | RuntimeException callbackError) { + previous.close(); + if (callbackError instanceof RuntimeException) { + throw (RuntimeException) callbackError; + } + } + } + + @Override + public void cancel() { + Call call; + boolean wasWaiting; + synchronized (lock) { + if (canceled) { + return; + } + canceled = true; + wasWaiting = pendingRetry != null && pendingRetry.cancel(false); + pendingRetry = null; + closePreviousResponse(); + call = currentCall; + } + if (call != null) { + call.cancel(); + } + if (wasWaiting) { + failCanceled(); + } + } + + /** Completes the call with a cancellation failure, unless the callback has already been invoked. */ + private void failCanceled() { + Call call; + synchronized (lock) { + if (completed) { + return; + } + completed = true; + closePreviousResponse(); + call = currentCall; + } + callback.onFailure(call, new IOException("Canceled")); + } + + private void closePreviousResponse() { + if (previousResponse != null) { + previousResponse.close(); + previousResponse = null; + } + } + } + /** * Pauses the OkHttp call timeout so that it applies to each attempt individually rather than to the whole * retry loop: the backoff wait (e.g. a {@code Retry-After} the size of the call timeout) does not consume the diff --git a/src/main/java/com/newscatcher/catchall/core/SseEventParser.java b/src/main/java/com/newscatcher/catchall/core/SseEventParser.java index 4118d9d..641fc8c 100644 --- a/src/main/java/com/newscatcher/catchall/core/SseEventParser.java +++ b/src/main/java/com/newscatcher/catchall/core/SseEventParser.java @@ -51,6 +51,27 @@ private SseEventParser() { */ public static T parseEventLevelUnion( String eventType, String data, String id, Long retry, Class unionClass, String discriminatorProperty) { + return parseEventLevelUnion(eventType, data, id, retry, unionClass, discriminatorProperty, null); + } + + /** + * Parse an SSE event using event-level discrimination. + *

+ * Events in {@code envelopeEvents} (or every event, if {@code envelopeEvents} is null) are deserialized from the + * SSE envelope ({@code event}, {@code data}, {@code id}, {@code retry}). Other events are deserialized from the + * JSON {@code data} payload with the discriminator injected. + */ + public static T parseEventLevelUnion( + String eventType, + String data, + String id, + Long retry, + Class unionClass, + String discriminatorProperty, + Set envelopeEvents) { + if (envelopeEvents != null && eventType != null && !envelopeEvents.contains(eventType)) { + return parsePayloadWithInjectedDiscriminator(eventType, data, unionClass, discriminatorProperty); + } try { // Determine if data should be parsed as JSON based on the variant's expected type Object parsedData = parseDataForVariant(eventType, data, unionClass, discriminatorProperty); @@ -74,6 +95,21 @@ public static T parseEventLevelUnion( } } + private static T parsePayloadWithInjectedDiscriminator( + String eventType, String data, Class unionClass, String discriminatorProperty) { + try { + Map payload = new HashMap<>(); + if (data != null && !data.isEmpty()) { + payload.putAll(ObjectMappers.JSON_MAPPER.readValue(data, new TypeReference>() {})); + } + payload.putIfAbsent(discriminatorProperty, eventType); + String payloadJson = ObjectMappers.JSON_MAPPER.writeValueAsString(payload); + return ObjectMappers.JSON_MAPPER.readValue(payloadJson, unionClass); + } catch (Exception e) { + throw new RuntimeException("Failed to parse SSE event with event-level discrimination", e); + } + } + /** * Parse an SSE event using data-level discrimination. *

diff --git a/src/main/java/com/newscatcher/catchall/core/Stream.java b/src/main/java/com/newscatcher/catchall/core/Stream.java index d32fa63..433bc43 100644 --- a/src/main/java/com/newscatcher/catchall/core/Stream.java +++ b/src/main/java/com/newscatcher/catchall/core/Stream.java @@ -6,9 +6,12 @@ import java.io.Closeable; import java.io.IOException; import java.io.Reader; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.NoSuchElementException; import java.util.Scanner; +import java.util.Set; /** * The {@code Stream} class implements {@link Iterable} to provide a simple mechanism for reading and parsing @@ -39,6 +42,7 @@ public enum StreamType { private final String streamTerminator; private final Reader sseReader; private final String discriminatorProperty; + private final Set envelopeEvents; private boolean isClosed = false; /** @@ -56,6 +60,7 @@ public Stream(Class valueType, Reader reader, String delimiter) { this.streamTerminator = null; this.sseReader = null; this.discriminatorProperty = null; + this.envelopeEvents = null; } private Stream(Class valueType, StreamType type, Reader reader, String terminator) { @@ -64,9 +69,20 @@ private Stream(Class valueType, StreamType type, Reader reader, String termin private Stream( Class valueType, StreamType type, Reader reader, String terminator, String discriminatorProperty) { + this(valueType, type, reader, terminator, discriminatorProperty, null); + } + + private Stream( + Class valueType, + StreamType type, + Reader reader, + String terminator, + String discriminatorProperty, + Set envelopeEvents) { this.valueType = valueType; this.streamType = type; this.discriminatorProperty = discriminatorProperty; + this.envelopeEvents = envelopeEvents; if (type == StreamType.JSON) { this.scanner = new Scanner(reader).useDelimiter(terminator); this.messageTerminator = terminator; @@ -128,6 +144,36 @@ public static Stream fromSseWithEventDiscrimination( valueType, StreamType.SSE_EVENT_DISCRIMINATED, sseReader, streamTerminator, discriminatorProperty); } + /** + * Creates a stream from SSE data with event-level discrimination support. + *

+ * Events listed in {@code envelopeEvents} are deserialized from {@code {"": event, "data": data}} + * (union variants that model the SSE envelope); all other events are deserialized from the {@code data} payload + * with the discriminator injected. + * + * @param valueType The class of the objects in the stream. + * @param sseReader The reader that provides the SSE data. + * @param discriminatorProperty The property name used for discrimination (e.g., "event"). + * @param streamTerminator The terminator string that signals end of stream, or null. + * @param envelopeEvents The event names whose union variant models the SSE envelope. + * @param The type of objects in the stream. + * @return A new Stream instance configured for SSE with event-level discrimination. + */ + public static Stream fromSseWithEventDiscrimination( + Class valueType, + Reader sseReader, + String discriminatorProperty, + String streamTerminator, + List envelopeEvents) { + return new Stream<>( + valueType, + StreamType.SSE_EVENT_DISCRIMINATED, + sseReader, + streamTerminator, + discriminatorProperty, + new HashSet<>(envelopeEvents)); + } + @Override public void close() throws IOException { if (!isClosed) { @@ -417,7 +463,8 @@ private boolean readNextMessage() { currentEventId, currentRetry, valueType, - discriminatorProperty); + discriminatorProperty, + envelopeEvents); hasNextItem = true; resetEventState(); return true; @@ -483,7 +530,8 @@ private boolean readNextMessage() { currentEventId, currentRetry, valueType, - discriminatorProperty); + discriminatorProperty, + envelopeEvents); hasNextItem = true; resetEventState(); return true; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncDatasetsClient.java b/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncDatasetsClient.java index b479dfb..ba9d180 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncDatasetsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncDatasetsClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.datasets; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.datasets.requests.AddEntitiesToDatasetRequest; @@ -49,21 +50,44 @@ public AsyncRawDatasetsClient withRawResponse() { * Returns a paginated list of datasets belonging to the authenticated organization. Supports filtering by status and sorting by name, status, or creation date. */ public CompletableFuture listDatasets() { - return this.rawClient.listDatasets().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.listDatasets(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of datasets belonging to the authenticated organization. Supports filtering by status and sorting by name, status, or creation date. */ public CompletableFuture listDatasets(RequestOptions requestOptions) { - return this.rawClient.listDatasets(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listDatasets(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of datasets belonging to the authenticated organization. Supports filtering by status and sorting by name, status, or creation date. */ public CompletableFuture listDatasets(ListDatasetsRequest request) { - return this.rawClient.listDatasets(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listDatasets(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -71,7 +95,15 @@ public CompletableFuture listDatasets(ListDatasetsRequest r */ public CompletableFuture listDatasets( ListDatasetsRequest request, RequestOptions requestOptions) { - return this.rawClient.listDatasets(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listDatasets(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -84,7 +116,14 @@ public CompletableFuture listDatasets( * endpoint instead.

*/ public CompletableFuture createDataset(CreateDatasetRequest request) { - return this.rawClient.createDataset(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.createDataset(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -98,7 +137,15 @@ public CompletableFuture createDataset(CreateDatasetRequest req */ public CompletableFuture createDataset( CreateDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient.createDataset(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createDataset(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -113,7 +160,15 @@ public CompletableFuture createDataset( */ public CompletableFuture createDatasetFromCsv( File file, CreateDatasetFromCsvRequest request) { - return this.rawClient.createDatasetFromCsv(file, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createDatasetFromCsv(file, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -128,53 +183,115 @@ public CompletableFuture createDatasetFromCsv( */ public CompletableFuture createDatasetFromCsv( File file, CreateDatasetFromCsvRequest request, RequestOptions requestOptions) { - return this.rawClient - .createDatasetFromCsv(file, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createDatasetFromCsv(file, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } - public CompletableFuture createDatasetFromCsv(InputStream stream, String filename) { - return this.rawClient.createDatasetFromCsv(stream, filename).thenApply(response -> response.body()); + public CompletableFuture createDatasetFromCsv( + CreateDatasetFromCsvRequest request, InputStream stream, String filename) { + CompletableFuture> rawFuture = + this.rawClient.createDatasetFromCsv(request, stream, filename); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType) { - return this.rawClient.createDatasetFromCsv(stream, filename, mediaType).thenApply(response -> response.body()); + CreateDatasetFromCsvRequest request, InputStream stream, String filename, MediaType mediaType) { + CompletableFuture> rawFuture = + this.rawClient.createDatasetFromCsv(request, stream, filename, mediaType); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture createDatasetFromCsv( - InputStream stream, String filename, RequestOptions requestOptions) { - return this.rawClient - .createDatasetFromCsv(stream, filename, requestOptions) - .thenApply(response -> response.body()); + CreateDatasetFromCsvRequest request, InputStream stream, String filename, RequestOptions requestOptions) { + CompletableFuture> rawFuture = + this.rawClient.createDatasetFromCsv(request, stream, filename, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { - return this.rawClient - .createDatasetFromCsv(stream, filename, mediaType, requestOptions) - .thenApply(response -> response.body()); + CreateDatasetFromCsvRequest request, + InputStream stream, + String filename, + MediaType mediaType, + RequestOptions requestOptions) { + CompletableFuture> rawFuture = + this.rawClient.createDatasetFromCsv(request, stream, filename, mediaType, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single dataset by ID including entity count and current status. */ public CompletableFuture getDataset(String datasetId) { - return this.rawClient.getDataset(datasetId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getDataset(datasetId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single dataset by ID including entity count and current status. */ public CompletableFuture getDataset(String datasetId, RequestOptions requestOptions) { - return this.rawClient.getDataset(datasetId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDataset(datasetId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single dataset by ID including entity count and current status. */ public CompletableFuture getDataset(String datasetId, GetDatasetRequest request) { - return this.rawClient.getDataset(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDataset(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -182,7 +299,15 @@ public CompletableFuture getDataset(String datasetId, GetDatase */ public CompletableFuture getDataset( String datasetId, GetDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient.getDataset(datasetId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDataset(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -191,7 +316,14 @@ public CompletableFuture getDataset( * undone. */ public CompletableFuture deleteDataset(String datasetId) { - return this.rawClient.deleteDataset(datasetId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteDataset(datasetId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -200,7 +332,15 @@ public CompletableFuture deleteDataset(String datasetId) { * undone. */ public CompletableFuture deleteDataset(String datasetId, RequestOptions requestOptions) { - return this.rawClient.deleteDataset(datasetId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteDataset(datasetId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -209,7 +349,14 @@ public CompletableFuture deleteDataset(String datasetId, RequestOptions re * undone. */ public CompletableFuture deleteDataset(String datasetId, DeleteDatasetRequest request) { - return this.rawClient.deleteDataset(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteDataset(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -219,28 +366,59 @@ public CompletableFuture deleteDataset(String datasetId, DeleteDatasetRequ */ public CompletableFuture deleteDataset( String datasetId, DeleteDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient.deleteDataset(datasetId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteDataset(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates the name or description of a dataset. */ public CompletableFuture updateDataset(String datasetId) { - return this.rawClient.updateDataset(datasetId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.updateDataset(datasetId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates the name or description of a dataset. */ public CompletableFuture updateDataset(String datasetId, RequestOptions requestOptions) { - return this.rawClient.updateDataset(datasetId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateDataset(datasetId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates the name or description of a dataset. */ public CompletableFuture updateDataset(String datasetId, UpdateDatasetRequest request) { - return this.rawClient.updateDataset(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateDataset(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -248,7 +426,15 @@ public CompletableFuture updateDataset(String datasetId, Update */ public CompletableFuture updateDataset( String datasetId, UpdateDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient.updateDataset(datasetId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateDataset(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -256,7 +442,15 @@ public CompletableFuture updateDataset( */ public CompletableFuture addEntitiesToDataset( String datasetId, AddEntitiesToDatasetRequest request) { - return this.rawClient.addEntitiesToDataset(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.addEntitiesToDataset(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -264,9 +458,15 @@ public CompletableFuture addEntitiesToDataset( */ public CompletableFuture addEntitiesToDataset( String datasetId, AddEntitiesToDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient - .addEntitiesToDataset(datasetId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.addEntitiesToDataset(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -274,7 +474,15 @@ public CompletableFuture addEntitiesToDataset( */ public CompletableFuture removeEntitiesFromDataset( String datasetId, RemoveEntitiesFromDatasetRequest request) { - return this.rawClient.removeEntitiesFromDataset(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeEntitiesFromDataset(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -282,16 +490,30 @@ public CompletableFuture removeEntitiesFromDataset( */ public CompletableFuture removeEntitiesFromDataset( String datasetId, RemoveEntitiesFromDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient - .removeEntitiesFromDataset(datasetId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeEntitiesFromDataset(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of entities in a dataset. Supports filtering by status, entity type, and name search. */ public CompletableFuture listEntitiesInDataset(String datasetId) { - return this.rawClient.listEntitiesInDataset(datasetId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listEntitiesInDataset(datasetId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -299,7 +521,15 @@ public CompletableFuture listEntitiesInDataset(String */ public CompletableFuture listEntitiesInDataset( String datasetId, RequestOptions requestOptions) { - return this.rawClient.listEntitiesInDataset(datasetId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listEntitiesInDataset(datasetId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -307,7 +537,15 @@ public CompletableFuture listEntitiesInDataset( */ public CompletableFuture listEntitiesInDataset( String datasetId, ListDatasetEntitiesRequest request) { - return this.rawClient.listEntitiesInDataset(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listEntitiesInDataset(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -315,16 +553,30 @@ public CompletableFuture listEntitiesInDataset( */ public CompletableFuture listEntitiesInDataset( String datasetId, ListDatasetEntitiesRequest request, RequestOptions requestOptions) { - return this.rawClient - .listEntitiesInDataset(datasetId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listEntitiesInDataset(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns the full status change history for a dataset, ordered chronologically from oldest to newest. */ public CompletableFuture getDatasetStatusHistory(String datasetId) { - return this.rawClient.getDatasetStatusHistory(datasetId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDatasetStatusHistory(datasetId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -332,7 +584,15 @@ public CompletableFuture getDatasetStatusHistory(S */ public CompletableFuture getDatasetStatusHistory( String datasetId, RequestOptions requestOptions) { - return this.rawClient.getDatasetStatusHistory(datasetId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDatasetStatusHistory(datasetId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -340,7 +600,15 @@ public CompletableFuture getDatasetStatusHistory( */ public CompletableFuture getDatasetStatusHistory( String datasetId, GetDatasetStatusHistoryRequest request) { - return this.rawClient.getDatasetStatusHistory(datasetId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDatasetStatusHistory(datasetId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -348,9 +616,15 @@ public CompletableFuture getDatasetStatusHistory( */ public CompletableFuture getDatasetStatusHistory( String datasetId, GetDatasetStatusHistoryRequest request, RequestOptions requestOptions) { - return this.rawClient - .getDatasetStatusHistory(datasetId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getDatasetStatusHistory(datasetId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -359,7 +633,15 @@ public CompletableFuture getDatasetStatusHistory( */ public CompletableFuture uploadCsvToDataset( String datasetId, File file, UploadCsvToDatasetRequest request) { - return this.rawClient.uploadCsvToDataset(datasetId, file, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.uploadCsvToDataset(datasetId, file, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -368,34 +650,66 @@ public CompletableFuture uploadCsvToDataset( */ public CompletableFuture uploadCsvToDataset( String datasetId, File file, UploadCsvToDatasetRequest request, RequestOptions requestOptions) { - return this.rawClient - .uploadCsvToDataset(datasetId, file, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.uploadCsvToDataset(datasetId, file, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture uploadCsvToDataset( String datasetId, InputStream stream, String filename) { - return this.rawClient.uploadCsvToDataset(datasetId, stream, filename).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.uploadCsvToDataset(datasetId, stream, filename); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture uploadCsvToDataset( String datasetId, InputStream stream, String filename, MediaType mediaType) { - return this.rawClient - .uploadCsvToDataset(datasetId, stream, filename, mediaType) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.uploadCsvToDataset(datasetId, stream, filename, mediaType); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture uploadCsvToDataset( String datasetId, InputStream stream, String filename, RequestOptions requestOptions) { - return this.rawClient - .uploadCsvToDataset(datasetId, stream, filename, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.uploadCsvToDataset(datasetId, stream, filename, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } public CompletableFuture uploadCsvToDataset( String datasetId, InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { - return this.rawClient - .uploadCsvToDataset(datasetId, stream, filename, mediaType, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.uploadCsvToDataset(datasetId, stream, filename, mediaType, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncRawDatasetsClient.java b/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncRawDatasetsClient.java index 3b726e8..746cf98 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncRawDatasetsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/AsyncRawDatasetsClient.java @@ -4,6 +4,7 @@ package com.newscatcher.catchall.resources.datasets; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; @@ -11,6 +12,7 @@ import com.newscatcher.catchall.core.FileStream; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -150,7 +152,8 @@ public CompletableFuture> listDatas .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -194,6 +197,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -232,7 +240,9 @@ public CompletableFuture> createDataset RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -257,7 +267,8 @@ public CompletableFuture> createDataset .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -312,6 +323,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -384,7 +400,8 @@ public CompletableFuture> crea .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -434,17 +451,31 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } public CompletableFuture> createDatasetFromCsv( - InputStream stream, String filename) { + CreateDatasetFromCsvRequest request, InputStream stream, String filename) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); FileStream fs = new FileStream(stream, filename, null); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -453,7 +484,8 @@ public CompletableFuture> crea Request okhttpRequest = _requestBuilder.build(); OkHttpClient client = clientOptions.httpClient(); CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -503,17 +535,31 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } public CompletableFuture> createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType) { + CreateDatasetFromCsvRequest request, InputStream stream, String filename, MediaType mediaType) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); FileStream fs = new FileStream(stream, filename, mediaType); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -522,7 +568,8 @@ public CompletableFuture> crea Request okhttpRequest = _requestBuilder.build(); OkHttpClient client = clientOptions.httpClient(); CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -572,11 +619,16 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } public CompletableFuture> createDatasetFromCsv( - InputStream stream, String filename, RequestOptions requestOptions) { + CreateDatasetFromCsvRequest request, InputStream stream, String filename, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); @@ -587,7 +639,16 @@ public CompletableFuture> crea } FileStream fs = new FileStream(stream, filename, null); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -608,7 +669,8 @@ public CompletableFuture> crea .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -658,11 +720,20 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } public CompletableFuture> createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { + CreateDatasetFromCsvRequest request, + InputStream stream, + String filename, + MediaType mediaType, + RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); @@ -673,7 +744,16 @@ public CompletableFuture> crea } FileStream fs = new FileStream(stream, filename, mediaType); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -694,7 +774,8 @@ public CompletableFuture> crea .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -744,6 +825,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -778,7 +864,7 @@ public CompletableFuture> getDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId); + .addPathSegment(PathSegments.validate(datasetId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -804,7 +890,8 @@ public CompletableFuture> getDataset( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -853,6 +940,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -895,7 +987,7 @@ public CompletableFuture> deleteDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId); + .addPathSegment(PathSegments.validate(datasetId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -903,7 +995,10 @@ public CompletableFuture> deleteDataset( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -921,7 +1016,8 @@ public CompletableFuture> deleteDataset( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -968,6 +1064,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1002,7 +1103,7 @@ public CompletableFuture> updateDataset HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId); + .addPathSegment(PathSegments.validate(datasetId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -1011,7 +1112,9 @@ public CompletableFuture> updateDataset RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1036,7 +1139,8 @@ public CompletableFuture> updateDataset .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1091,6 +1195,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1110,7 +1219,7 @@ public CompletableFuture> addEnt HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("entities"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1120,7 +1229,9 @@ public CompletableFuture> addEnt RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request.getBody()), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request.getBody(), requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1145,7 +1256,8 @@ public CompletableFuture> addEnt .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1200,6 +1312,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1219,7 +1336,7 @@ public CompletableFuture> remove HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("entities"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1229,7 +1346,9 @@ public CompletableFuture> remove RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request.getBody()), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request.getBody(), requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1254,7 +1373,8 @@ public CompletableFuture> remove .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1309,6 +1429,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1346,7 +1471,7 @@ public CompletableFuture> lis HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("entities") .addPathSegments("list"); if (requestOptions != null) { @@ -1357,7 +1482,9 @@ public CompletableFuture> lis RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1382,7 +1509,8 @@ public CompletableFuture> lis .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1438,6 +1566,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1475,7 +1608,7 @@ public CompletableFuture> HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("status"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1502,7 +1635,8 @@ public CompletableFuture> .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1552,6 +1686,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1573,7 +1712,7 @@ public CompletableFuture> up HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1609,7 +1748,8 @@ public CompletableFuture> up .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1665,6 +1805,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1673,7 +1818,7 @@ public CompletableFuture> up HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); FileStream fs = new FileStream(stream, filename, null); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); @@ -1686,7 +1831,8 @@ public CompletableFuture> up Request okhttpRequest = _requestBuilder.build(); OkHttpClient client = clientOptions.httpClient(); CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1742,6 +1888,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1750,7 +1901,7 @@ public CompletableFuture> up HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); FileStream fs = new FileStream(stream, filename, mediaType); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); @@ -1763,7 +1914,8 @@ public CompletableFuture> up Request okhttpRequest = _requestBuilder.build(); OkHttpClient client = clientOptions.httpClient(); CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1819,6 +1971,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1827,7 +1984,7 @@ public CompletableFuture> up HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1857,7 +2014,8 @@ public CompletableFuture> up .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1913,6 +2071,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1921,7 +2084,7 @@ public CompletableFuture> up HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1951,7 +2114,8 @@ public CompletableFuture> up .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -2007,6 +2171,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/DatasetsClient.java b/src/main/java/com/newscatcher/catchall/resources/datasets/DatasetsClient.java index bcf5942..984dd8f 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/DatasetsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/DatasetsClient.java @@ -129,25 +129,33 @@ public CreateDatasetCsvResponse createDatasetFromCsv( .body(); } - public CreateDatasetCsvResponse createDatasetFromCsv(InputStream stream, String filename) { - return this.rawClient.createDatasetFromCsv(stream, filename).body(); + public CreateDatasetCsvResponse createDatasetFromCsv( + CreateDatasetFromCsvRequest request, InputStream stream, String filename) { + return this.rawClient.createDatasetFromCsv(request, stream, filename).body(); } - public CreateDatasetCsvResponse createDatasetFromCsv(InputStream stream, String filename, MediaType mediaType) { - return this.rawClient.createDatasetFromCsv(stream, filename, mediaType).body(); + public CreateDatasetCsvResponse createDatasetFromCsv( + CreateDatasetFromCsvRequest request, InputStream stream, String filename, MediaType mediaType) { + return this.rawClient + .createDatasetFromCsv(request, stream, filename, mediaType) + .body(); } public CreateDatasetCsvResponse createDatasetFromCsv( - InputStream stream, String filename, RequestOptions requestOptions) { + CreateDatasetFromCsvRequest request, InputStream stream, String filename, RequestOptions requestOptions) { return this.rawClient - .createDatasetFromCsv(stream, filename, requestOptions) + .createDatasetFromCsv(request, stream, filename, requestOptions) .body(); } public CreateDatasetCsvResponse createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { + CreateDatasetFromCsvRequest request, + InputStream stream, + String filename, + MediaType mediaType, + RequestOptions requestOptions) { return this.rawClient - .createDatasetFromCsv(stream, filename, mediaType, requestOptions) + .createDatasetFromCsv(request, stream, filename, mediaType, requestOptions) .body(); } diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/RawDatasetsClient.java b/src/main/java/com/newscatcher/catchall/resources/datasets/RawDatasetsClient.java index 84b787f..59250a9 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/RawDatasetsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/RawDatasetsClient.java @@ -4,6 +4,7 @@ package com.newscatcher.catchall.resources.datasets; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; @@ -11,6 +12,7 @@ import com.newscatcher.catchall.core.FileStream; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -209,7 +211,9 @@ public CatchAllApiHttpResponse createDataset( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -371,13 +375,23 @@ public CatchAllApiHttpResponse createDatasetFromCsv( } } - public CatchAllApiHttpResponse createDatasetFromCsv(InputStream stream, String filename) { + public CatchAllApiHttpResponse createDatasetFromCsv( + CreateDatasetFromCsvRequest request, InputStream stream, String filename) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); FileStream fs = new FileStream(stream, filename, null); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -420,13 +434,22 @@ public CatchAllApiHttpResponse createDatasetFromCsv(In } public CatchAllApiHttpResponse createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType) { + CreateDatasetFromCsvRequest request, InputStream stream, String filename, MediaType mediaType) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); FileStream fs = new FileStream(stream, filename, mediaType); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -469,7 +492,7 @@ public CatchAllApiHttpResponse createDatasetFromCsv( } public CatchAllApiHttpResponse createDatasetFromCsv( - InputStream stream, String filename, RequestOptions requestOptions) { + CreateDatasetFromCsvRequest request, InputStream stream, String filename, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); @@ -480,7 +503,16 @@ public CatchAllApiHttpResponse createDatasetFromCsv( } FileStream fs = new FileStream(stream, filename, null); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -535,7 +567,11 @@ public CatchAllApiHttpResponse createDatasetFromCsv( } public CatchAllApiHttpResponse createDatasetFromCsv( - InputStream stream, String filename, MediaType mediaType, RequestOptions requestOptions) { + CreateDatasetFromCsvRequest request, + InputStream stream, + String filename, + MediaType mediaType, + RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets/upload"); @@ -546,7 +582,16 @@ public CatchAllApiHttpResponse createDatasetFromCsv( } FileStream fs = new FileStream(stream, filename, mediaType); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); - multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + try { + multipartBodyBuilder.addFormDataPart("file", filename, fs.toRequestBody()); + multipartBodyBuilder.addFormDataPart("name", request.getName()); + if (request.getDescription().isPresent()) { + multipartBodyBuilder.addFormDataPart( + "description", request.getDescription().get()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } RequestBody body = multipartBodyBuilder.build(); Request.Builder _requestBuilder = new Request.Builder(); _requestBuilder.url(httpUrl.build()); @@ -629,7 +674,7 @@ public CatchAllApiHttpResponse getDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId); + .addPathSegment(PathSegments.validate(datasetId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -723,7 +768,7 @@ public CatchAllApiHttpResponse deleteDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId); + .addPathSegment(PathSegments.validate(datasetId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -731,7 +776,10 @@ public CatchAllApiHttpResponse deleteDataset( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -808,7 +856,7 @@ public CatchAllApiHttpResponse updateDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId); + .addPathSegment(PathSegments.validate(datasetId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -817,7 +865,9 @@ public CatchAllApiHttpResponse updateDataset( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -893,7 +943,7 @@ public CatchAllApiHttpResponse addEntitiesToDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("entities"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -903,7 +953,9 @@ public CatchAllApiHttpResponse addEntitiesToDataset( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request.getBody()), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request.getBody(), requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -980,7 +1032,7 @@ public CatchAllApiHttpResponse removeEntitiesFromDataset HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("entities"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -990,7 +1042,9 @@ public CatchAllApiHttpResponse removeEntitiesFromDataset RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request.getBody()), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request.getBody(), requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1084,7 +1138,7 @@ public CatchAllApiHttpResponse listEntitiesInDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("entities") .addPathSegments("list"); if (requestOptions != null) { @@ -1095,7 +1149,9 @@ public CatchAllApiHttpResponse listEntitiesInDataset( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1189,7 +1245,7 @@ public CatchAllApiHttpResponse getDatasetStatusHis HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("status"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1266,7 +1322,7 @@ public CatchAllApiHttpResponse uploadCsvToDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1343,7 +1399,7 @@ public CatchAllApiHttpResponse uploadCsvToDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); FileStream fs = new FileStream(stream, filename, null); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); @@ -1397,7 +1453,7 @@ public CatchAllApiHttpResponse uploadCsvToDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); FileStream fs = new FileStream(stream, filename, mediaType); MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); @@ -1451,7 +1507,7 @@ public CatchAllApiHttpResponse uploadCsvToDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -1522,7 +1578,7 @@ public CatchAllApiHttpResponse uploadCsvToDataset( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/datasets") - .addPathSegment(datasetId) + .addPathSegment(PathSegments.validate(datasetId)) .addPathSegments("upload"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/AddEntitiesToDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/AddEntitiesToDatasetRequest.java index 8b9ede8..4329e7c 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/AddEntitiesToDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/AddEntitiesToDatasetRequest.java @@ -81,7 +81,6 @@ public interface _FinalStage { public static final class Builder implements BodyStage, _FinalStage { private DatasetEntityIdsRequest body; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -104,6 +103,14 @@ public AddEntitiesToDatasetRequest build() { return new AddEntitiesToDatasetRequest(body, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("body")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetFromCsvRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetFromCsvRequest.java index 328f056..27b175b 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetFromCsvRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetFromCsvRequest.java @@ -109,7 +109,6 @@ public static final class Builder implements NameStage, _FinalStage { private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -157,6 +156,14 @@ public CreateDatasetFromCsvRequest build() { return new CreateDatasetFromCsvRequest(name, description, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetRequest.java index e1d572b..13cc948 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/CreateDatasetRequest.java @@ -133,7 +133,6 @@ public static final class Builder implements NameStage, _FinalStage { private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -202,6 +201,16 @@ public CreateDatasetRequest build() { return new CreateDatasetRequest(name, description, entityIds, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("entity_ids")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/DeleteDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/DeleteDatasetRequest.java index 82eaa5e..99ceb5f 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/DeleteDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/DeleteDatasetRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public DeleteDatasetRequest build() { return new DeleteDatasetRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetRequest.java index 20efdbc..582dbcc 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetDatasetRequest build() { return new GetDatasetRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetStatusHistoryRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetStatusHistoryRequest.java index c1cbf9a..21bd4af 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetStatusHistoryRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/GetDatasetStatusHistoryRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetDatasetStatusHistoryRequest build() { return new GetDatasetStatusHistoryRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetEntitiesRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetEntitiesRequest.java index c5ea6e5..deeae25 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetEntitiesRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetEntitiesRequest.java @@ -155,7 +155,6 @@ public static final class Builder { private Optional sortOrder = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -262,6 +261,20 @@ public ListDatasetEntitiesRequest build() { page, pageSize, search, status, entityType, sortBy, sortOrder, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("entity_type") + || key.equalsIgnoreCase("sort_by") + || key.equalsIgnoreCase("sort_order")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetsRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetsRequest.java index bb69160..3ec64f2 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/ListDatasetsRequest.java @@ -180,7 +180,6 @@ public static final class Builder { private Optional projectId = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -313,6 +312,21 @@ public ListDatasetsRequest build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("latest_status") + || key.equalsIgnoreCase("sort_by") + || key.equalsIgnoreCase("sort_order") + || key.equalsIgnoreCase("ownership") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/RemoveEntitiesFromDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/RemoveEntitiesFromDatasetRequest.java index 3afe9ad..83bfb11 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/RemoveEntitiesFromDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/RemoveEntitiesFromDatasetRequest.java @@ -81,7 +81,6 @@ public interface _FinalStage { public static final class Builder implements BodyStage, _FinalStage { private DatasetEntityIdsRequest body; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -104,6 +103,14 @@ public RemoveEntitiesFromDatasetRequest build() { return new RemoveEntitiesFromDatasetRequest(body, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("body")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UpdateDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UpdateDatasetRequest.java index f49a184..2d16dd5 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UpdateDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UpdateDatasetRequest.java @@ -84,7 +84,6 @@ public static final class Builder { private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -127,6 +126,14 @@ public UpdateDatasetRequest build() { return new UpdateDatasetRequest(name, description, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UploadCsvToDatasetRequest.java b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UploadCsvToDatasetRequest.java index f79b961..5731286 100644 --- a/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UploadCsvToDatasetRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/datasets/requests/UploadCsvToDatasetRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public UploadCsvToDatasetRequest build() { return new UploadCsvToDatasetRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/AsyncEntitiesClient.java b/src/main/java/com/newscatcher/catchall/resources/entities/AsyncEntitiesClient.java index 48e52a6..4903aba 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/AsyncEntitiesClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/AsyncEntitiesClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.entities; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.entities.requests.CreateEntitiesBatchRequest; @@ -38,21 +39,43 @@ public AsyncRawEntitiesClient withRawResponse() { * Returns a paginated list of entities belonging to the authenticated organization. Supports filtering by status and entity type, and sorting by name, status, or creation date. */ public CompletableFuture listEntities() { - return this.rawClient.listEntities().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.listEntities(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of entities belonging to the authenticated organization. Supports filtering by status and entity type, and sorting by name, status, or creation date. */ public CompletableFuture listEntities(RequestOptions requestOptions) { - return this.rawClient.listEntities(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listEntities(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of entities belonging to the authenticated organization. Supports filtering by status and entity type, and sorting by name, status, or creation date. */ public CompletableFuture listEntities(ListEntitiesRequest request) { - return this.rawClient.listEntities(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.listEntities(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -60,7 +83,15 @@ public CompletableFuture listEntities(ListEntitiesRequest re */ public CompletableFuture listEntities( ListEntitiesRequest request, RequestOptions requestOptions) { - return this.rawClient.listEntities(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listEntities(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -70,7 +101,15 @@ public CompletableFuture listEntities( * enrichment completes.

*/ public CompletableFuture createEntity(CreateEntityRequest request) { - return this.rawClient.createEntity(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createEntity(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -81,7 +120,15 @@ public CompletableFuture createEntity(CreateEntityRequest */ public CompletableFuture createEntity( CreateEntityRequest request, RequestOptions requestOptions) { - return this.rawClient.createEntity(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createEntity(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -90,7 +137,15 @@ public CompletableFuture createEntity( *

Returns an array of {id, status} objects in the same order as the input array.

*/ public CompletableFuture createEntitiesBatch(CreateEntitiesBatchRequest request) { - return this.rawClient.createEntitiesBatch(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createEntitiesBatch(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -100,28 +155,59 @@ public CompletableFuture createEntitiesBatch(Create */ public CompletableFuture createEntitiesBatch( CreateEntitiesBatchRequest request, RequestOptions requestOptions) { - return this.rawClient.createEntitiesBatch(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createEntitiesBatch(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single entity by ID with all attributes and current status. */ public CompletableFuture getEntity(String entityId) { - return this.rawClient.getEntity(entityId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getEntity(entityId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single entity by ID with all attributes and current status. */ public CompletableFuture getEntity(String entityId, RequestOptions requestOptions) { - return this.rawClient.getEntity(entityId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getEntity(entityId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single entity by ID with all attributes and current status. */ public CompletableFuture getEntity(String entityId, GetEntityRequest request) { - return this.rawClient.getEntity(entityId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getEntity(entityId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -129,7 +215,15 @@ public CompletableFuture getEntity(String entityId, GetEntityReq */ public CompletableFuture getEntity( String entityId, GetEntityRequest request, RequestOptions requestOptions) { - return this.rawClient.getEntity(entityId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getEntity(entityId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -137,7 +231,14 @@ public CompletableFuture getEntity( * datasets and the search index. This operation cannot be undone. */ public CompletableFuture deleteEntity(String entityId) { - return this.rawClient.deleteEntity(entityId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteEntity(entityId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -145,7 +246,15 @@ public CompletableFuture deleteEntity(String entityId) { * datasets and the search index. This operation cannot be undone. */ public CompletableFuture deleteEntity(String entityId, RequestOptions requestOptions) { - return this.rawClient.deleteEntity(entityId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteEntity(entityId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -153,7 +262,14 @@ public CompletableFuture deleteEntity(String entityId, RequestOptions requ * datasets and the search index. This operation cannot be undone. */ public CompletableFuture deleteEntity(String entityId, DeleteEntityRequest request) { - return this.rawClient.deleteEntity(entityId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteEntity(entityId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -162,28 +278,59 @@ public CompletableFuture deleteEntity(String entityId, DeleteEntityRequest */ public CompletableFuture deleteEntity( String entityId, DeleteEntityRequest request, RequestOptions requestOptions) { - return this.rawClient.deleteEntity(entityId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteEntity(entityId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates one or more fields of an existing entity. */ public CompletableFuture updateEntity(String entityId) { - return this.rawClient.updateEntity(entityId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.updateEntity(entityId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates one or more fields of an existing entity. */ public CompletableFuture updateEntity(String entityId, RequestOptions requestOptions) { - return this.rawClient.updateEntity(entityId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateEntity(entityId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates one or more fields of an existing entity. */ public CompletableFuture updateEntity(String entityId, UpdateEntityRequest request) { - return this.rawClient.updateEntity(entityId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateEntity(entityId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -191,6 +338,14 @@ public CompletableFuture updateEntity(String entityId, UpdateEnt */ public CompletableFuture updateEntity( String entityId, UpdateEntityRequest request, RequestOptions requestOptions) { - return this.rawClient.updateEntity(entityId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateEntity(entityId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/AsyncRawEntitiesClient.java b/src/main/java/com/newscatcher/catchall/resources/entities/AsyncRawEntitiesClient.java index c5ffd13..94f9fd5 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/AsyncRawEntitiesClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/AsyncRawEntitiesClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.entities; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -136,7 +138,8 @@ public CompletableFuture> listEntiti .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -191,6 +194,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -223,7 +231,9 @@ public CompletableFuture> createEn RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -248,7 +258,8 @@ public CompletableFuture> createEn .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -297,6 +308,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -328,7 +344,9 @@ public CompletableFuture> c RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -353,7 +371,8 @@ public CompletableFuture> c .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -403,6 +422,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -437,7 +461,7 @@ public CompletableFuture> getEntity( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/entities") - .addPathSegment(entityId); + .addPathSegment(PathSegments.validate(entityId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -463,7 +487,8 @@ public CompletableFuture> getEntity( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -512,6 +537,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -549,7 +579,7 @@ public CompletableFuture> deleteEntity( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/entities") - .addPathSegment(entityId); + .addPathSegment(PathSegments.validate(entityId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -557,7 +587,10 @@ public CompletableFuture> deleteEntity( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -575,7 +608,8 @@ public CompletableFuture> deleteEntity( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -622,6 +656,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -656,7 +695,7 @@ public CompletableFuture> updateEntity( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/entities") - .addPathSegment(entityId); + .addPathSegment(PathSegments.validate(entityId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -665,7 +704,9 @@ public CompletableFuture> updateEntity( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -690,7 +731,8 @@ public CompletableFuture> updateEntity( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -744,6 +786,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/RawEntitiesClient.java b/src/main/java/com/newscatcher/catchall/resources/entities/RawEntitiesClient.java index 9a9657b..ecc95b6 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/RawEntitiesClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/RawEntitiesClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.entities; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -196,7 +198,9 @@ public CatchAllApiHttpResponse createEntity( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -280,7 +284,9 @@ public CatchAllApiHttpResponse createEntitiesBatch( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -366,7 +372,7 @@ public CatchAllApiHttpResponse getEntity( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/entities") - .addPathSegment(entityId); + .addPathSegment(PathSegments.validate(entityId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -456,7 +462,7 @@ public CatchAllApiHttpResponse deleteEntity( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/entities") - .addPathSegment(entityId); + .addPathSegment(PathSegments.validate(entityId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -464,7 +470,10 @@ public CatchAllApiHttpResponse deleteEntity( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -541,7 +550,7 @@ public CatchAllApiHttpResponse updateEntity( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/entities") - .addPathSegment(entityId); + .addPathSegment(PathSegments.validate(entityId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -550,7 +559,9 @@ public CatchAllApiHttpResponse updateEntity( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/requests/CreateEntitiesBatchRequest.java b/src/main/java/com/newscatcher/catchall/resources/entities/requests/CreateEntitiesBatchRequest.java index 72f8e2b..2a68f00 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/requests/CreateEntitiesBatchRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/requests/CreateEntitiesBatchRequest.java @@ -73,7 +73,6 @@ public static Builder builder() { public static final class Builder { private List entities = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -112,6 +111,14 @@ public CreateEntitiesBatchRequest build() { return new CreateEntitiesBatchRequest(entities, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("entities")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/requests/DeleteEntityRequest.java b/src/main/java/com/newscatcher/catchall/resources/entities/requests/DeleteEntityRequest.java index c7b34b6..5a43dd0 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/requests/DeleteEntityRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/requests/DeleteEntityRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public DeleteEntityRequest build() { return new DeleteEntityRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/requests/GetEntityRequest.java b/src/main/java/com/newscatcher/catchall/resources/entities/requests/GetEntityRequest.java index 167f1d7..613bbad 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/requests/GetEntityRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/requests/GetEntityRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetEntityRequest build() { return new GetEntityRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/requests/ListEntitiesRequest.java b/src/main/java/com/newscatcher/catchall/resources/entities/requests/ListEntitiesRequest.java index 78917ba..9a074e1 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/requests/ListEntitiesRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/requests/ListEntitiesRequest.java @@ -177,7 +177,6 @@ public static final class Builder { private Optional projectId = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -299,6 +298,21 @@ public ListEntitiesRequest build() { page, pageSize, search, status, entityType, sortBy, sortOrder, projectId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("entity_type") + || key.equalsIgnoreCase("sort_by") + || key.equalsIgnoreCase("sort_order") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/entities/requests/UpdateEntityRequest.java b/src/main/java/com/newscatcher/catchall/resources/entities/requests/UpdateEntityRequest.java index 667c0cf..934d678 100644 --- a/src/main/java/com/newscatcher/catchall/resources/entities/requests/UpdateEntityRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/entities/requests/UpdateEntityRequest.java @@ -115,7 +115,6 @@ public static final class Builder { private Optional additionalAttributes = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -186,6 +185,17 @@ public UpdateEntityRequest build() { name, description, externalEntityId, additionalAttributes, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("external_entity_id") + || key.equalsIgnoreCase("additional_attributes")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncEventMonitorsClient.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncEventMonitorsClient.java index 23f4a45..5e725af 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncEventMonitorsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncEventMonitorsClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.eventmonitors; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.eventmonitors.requests.CreateMonitorRequestDto; @@ -47,21 +48,44 @@ public AsyncRawEventMonitorsClient withRawResponse() { * Returns all event monitors created by the authenticated user. */ public CompletableFuture listMonitors() { - return this.rawClient.listMonitors().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.listMonitors(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all event monitors created by the authenticated user. */ public CompletableFuture listMonitors(RequestOptions requestOptions) { - return this.rawClient.listMonitors(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitors(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all event monitors created by the authenticated user. */ public CompletableFuture listMonitors(ListMonitorsRequest request) { - return this.rawClient.listMonitors(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitors(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -69,14 +93,30 @@ public CompletableFuture listMonitors(ListMonitorsReque */ public CompletableFuture listMonitors( ListMonitorsRequest request, RequestOptions requestOptions) { - return this.rawClient.listMonitors(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitors(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Create a scheduled event monitor based on a reference job. */ public CompletableFuture createMonitor(CreateMonitorRequestDto request) { - return this.rawClient.createMonitor(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createMonitor(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -84,14 +124,30 @@ public CompletableFuture createMonitor(CreateMonitorRe */ public CompletableFuture createMonitor( CreateMonitorRequestDto request, RequestOptions requestOptions) { - return this.rawClient.createMonitor(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createMonitor(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve aggregated results from all jobs executed by an event monitor. */ public CompletableFuture pullMonitorResults(String monitorId) { - return this.rawClient.pullMonitorResults(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResults(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -99,7 +155,15 @@ public CompletableFuture pullMonitorResults(String monit */ public CompletableFuture pullMonitorResults( String monitorId, RequestOptions requestOptions) { - return this.rawClient.pullMonitorResults(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResults(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -107,7 +171,15 @@ public CompletableFuture pullMonitorResults( */ public CompletableFuture pullMonitorResults( String monitorId, PullMonitorResultsRequest request) { - return this.rawClient.pullMonitorResults(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResults(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -115,9 +187,15 @@ public CompletableFuture pullMonitorResults( */ public CompletableFuture pullMonitorResults( String monitorId, PullMonitorResultsRequest request, RequestOptions requestOptions) { - return this.rawClient - .pullMonitorResults(monitorId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResults(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -125,7 +203,14 @@ public CompletableFuture pullMonitorResults( *

If the event monitor's reference job used connected entity datasets, connected entities are split into event_associated_entities and mention_entities JSON columns. When no entity dataset was used, those two columns are omitted from the export entirely.

*/ public CompletableFuture pullMonitorResultsCsv(String monitorId) { - return this.rawClient.pullMonitorResultsCsv(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.pullMonitorResultsCsv(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -133,7 +218,15 @@ public CompletableFuture pullMonitorResultsCsv(String monitorId) { *

If the event monitor's reference job used connected entity datasets, connected entities are split into event_associated_entities and mention_entities JSON columns. When no entity dataset was used, those two columns are omitted from the export entirely.

*/ public CompletableFuture pullMonitorResultsCsv(String monitorId, RequestOptions requestOptions) { - return this.rawClient.pullMonitorResultsCsv(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResultsCsv(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -141,7 +234,15 @@ public CompletableFuture pullMonitorResultsCsv(String monitorId, Request *

If the event monitor's reference job used connected entity datasets, connected entities are split into event_associated_entities and mention_entities JSON columns. When no entity dataset was used, those two columns are omitted from the export entirely.

*/ public CompletableFuture pullMonitorResultsCsv(String monitorId, PullMonitorResultsCsvRequest request) { - return this.rawClient.pullMonitorResultsCsv(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResultsCsv(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -150,23 +251,45 @@ public CompletableFuture pullMonitorResultsCsv(String monitorId, PullMon */ public CompletableFuture pullMonitorResultsCsv( String monitorId, PullMonitorResultsCsvRequest request, RequestOptions requestOptions) { - return this.rawClient - .pullMonitorResultsCsv(monitorId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.pullMonitorResultsCsv(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Return all jobs executed by an event monitor. */ public CompletableFuture listMonitorJobs(String monitorId) { - return this.rawClient.listMonitorJobs(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitorJobs(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Return all jobs executed by an event monitor. */ public CompletableFuture listMonitorJobs(String monitorId, RequestOptions requestOptions) { - return this.rawClient.listMonitorJobs(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitorJobs(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -174,7 +297,15 @@ public CompletableFuture listMonitorJobs(String monitor */ public CompletableFuture listMonitorJobs( String monitorId, ListMonitorJobsRequest request) { - return this.rawClient.listMonitorJobs(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitorJobs(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -182,16 +313,30 @@ public CompletableFuture listMonitorJobs( */ public CompletableFuture listMonitorJobs( String monitorId, ListMonitorJobsRequest request, RequestOptions requestOptions) { - return this.rawClient - .listMonitorJobs(monitorId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listMonitorJobs(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns the full execution history of an event monitor as a list of status entries, ordered from newest to oldest. */ public CompletableFuture getMonitorStatusHistory(String monitorId) { - return this.rawClient.getMonitorStatusHistory(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getMonitorStatusHistory(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -199,7 +344,15 @@ public CompletableFuture getMonitorStatusHistor */ public CompletableFuture getMonitorStatusHistory( String monitorId, RequestOptions requestOptions) { - return this.rawClient.getMonitorStatusHistory(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getMonitorStatusHistory(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -207,7 +360,15 @@ public CompletableFuture getMonitorStatusHistor */ public CompletableFuture getMonitorStatusHistory( String monitorId, GetMonitorStatusHistoryRequest request) { - return this.rawClient.getMonitorStatusHistory(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getMonitorStatusHistory(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -215,30 +376,60 @@ public CompletableFuture getMonitorStatusHistor */ public CompletableFuture getMonitorStatusHistory( String monitorId, GetMonitorStatusHistoryRequest request, RequestOptions requestOptions) { - return this.rawClient - .getMonitorStatusHistory(monitorId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getMonitorStatusHistory(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Resume scheduled job execution for an event monitor. */ public CompletableFuture enableMonitor(String monitorId) { - return this.rawClient.enableMonitor(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.enableMonitor(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Resume scheduled job execution for an event monitor. */ public CompletableFuture enableMonitor(String monitorId, RequestOptions requestOptions) { - return this.rawClient.enableMonitor(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.enableMonitor(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Resume scheduled job execution for an event monitor. */ public CompletableFuture enableMonitor(String monitorId, EnableMonitorRequestDto request) { - return this.rawClient.enableMonitor(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.enableMonitor(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -246,28 +437,60 @@ public CompletableFuture enableMonitor(String monitorId, */ public CompletableFuture enableMonitor( String monitorId, EnableMonitorRequestDto request, RequestOptions requestOptions) { - return this.rawClient.enableMonitor(monitorId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.enableMonitor(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Stop scheduled job execution for an event monitor. */ public CompletableFuture disableMonitor(String monitorId) { - return this.rawClient.disableMonitor(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.disableMonitor(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Stop scheduled job execution for an event monitor. */ public CompletableFuture disableMonitor(String monitorId, RequestOptions requestOptions) { - return this.rawClient.disableMonitor(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.disableMonitor(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Stop scheduled job execution for an event monitor. */ public CompletableFuture disableMonitor(String monitorId, DisableMonitorRequest request) { - return this.rawClient.disableMonitor(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.disableMonitor(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -275,7 +498,15 @@ public CompletableFuture disableMonitor(String monitorId */ public CompletableFuture disableMonitor( String monitorId, DisableMonitorRequest request, RequestOptions requestOptions) { - return this.rawClient.disableMonitor(monitorId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.disableMonitor(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -287,7 +518,15 @@ public CompletableFuture disableMonitor( *

Deleting an already-deleted event monitor returns 200.

*/ public CompletableFuture deleteMonitor(String monitorId) { - return this.rawClient.deleteMonitor(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteMonitor(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -299,7 +538,15 @@ public CompletableFuture deleteMonitor(String monitorI *

Deleting an already-deleted event monitor returns 200.

*/ public CompletableFuture deleteMonitor(String monitorId, RequestOptions requestOptions) { - return this.rawClient.deleteMonitor(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteMonitor(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -311,7 +558,15 @@ public CompletableFuture deleteMonitor(String monitorI *

Deleting an already-deleted event monitor returns 200.

*/ public CompletableFuture deleteMonitor(String monitorId, DeleteMonitorRequest request) { - return this.rawClient.deleteMonitor(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteMonitor(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -324,7 +579,15 @@ public CompletableFuture deleteMonitor(String monitorI */ public CompletableFuture deleteMonitor( String monitorId, DeleteMonitorRequest request, RequestOptions requestOptions) { - return this.rawClient.deleteMonitor(monitorId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteMonitor(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -335,7 +598,15 @@ public CompletableFuture deleteMonitor( * stops firing. The reference job cannot be changed.

*/ public CompletableFuture updateMonitor(String monitorId) { - return this.rawClient.updateMonitor(monitorId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateMonitor(monitorId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -346,7 +617,15 @@ public CompletableFuture updateMonitor(String monitorI * stops firing. The reference job cannot be changed.

*/ public CompletableFuture updateMonitor(String monitorId, RequestOptions requestOptions) { - return this.rawClient.updateMonitor(monitorId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateMonitor(monitorId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -358,7 +637,15 @@ public CompletableFuture updateMonitor(String monitorI */ public CompletableFuture updateMonitor( String monitorId, UpdateMonitorRequestDto request) { - return this.rawClient.updateMonitor(monitorId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateMonitor(monitorId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -370,6 +657,14 @@ public CompletableFuture updateMonitor( */ public CompletableFuture updateMonitor( String monitorId, UpdateMonitorRequestDto request, RequestOptions requestOptions) { - return this.rawClient.updateMonitor(monitorId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateMonitor(monitorId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncRawEventMonitorsClient.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncRawEventMonitorsClient.java index 43fa108..cd14682 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncRawEventMonitorsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/AsyncRawEventMonitorsClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.eventmonitors; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -134,7 +136,8 @@ public CompletableFuture> listM .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -184,6 +187,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -211,7 +219,9 @@ public CompletableFuture> crea RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -236,7 +246,8 @@ public CompletableFuture> crea .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -281,6 +292,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -315,7 +331,7 @@ public CompletableFuture> pullMo HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors/pull") - .addPathSegment(monitorId); + .addPathSegment(PathSegments.validate(monitorId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -341,7 +357,8 @@ public CompletableFuture> pullMo .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -391,6 +408,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -431,7 +453,7 @@ public CompletableFuture> pullMonitorResultsCsv( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors/pull") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("csv"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -458,7 +480,8 @@ public CompletableFuture> pullMonitorResultsCsv( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -505,6 +528,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -539,7 +567,7 @@ public CompletableFuture> listM HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("jobs"); if (request.getSort().isPresent()) { QueryStringMapper.addQueryParameter( @@ -570,7 +598,8 @@ public CompletableFuture> listM .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -620,6 +649,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -657,7 +691,7 @@ public CompletableFuture { @@ -684,7 +718,8 @@ public CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -729,6 +764,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -763,7 +803,7 @@ public CompletableFuture> enableM HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("enable"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -773,7 +813,9 @@ public CompletableFuture> enableM RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -798,7 +840,8 @@ public CompletableFuture> enableM .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -853,6 +896,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -887,7 +935,7 @@ public CompletableFuture> disabl HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("disable"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -896,7 +944,11 @@ public CompletableFuture> disabl } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("POST", RequestBody.create("", null)) + .method( + "POST", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, + RequestBody.create("", null))) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -914,7 +966,8 @@ public CompletableFuture> disabl .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -969,6 +1022,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1023,7 +1081,7 @@ public CompletableFuture> dele HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId); + .addPathSegment(PathSegments.validate(monitorId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -1031,7 +1089,10 @@ public CompletableFuture> dele } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -1049,7 +1110,8 @@ public CompletableFuture> dele .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1093,6 +1155,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1143,7 +1210,7 @@ public CompletableFuture> upda HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId); + .addPathSegment(PathSegments.validate(monitorId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -1152,7 +1219,9 @@ public CompletableFuture> upda RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -1177,7 +1246,8 @@ public CompletableFuture> upda .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1232,6 +1302,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/RawEventMonitorsClient.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/RawEventMonitorsClient.java index 010048d..bc9c44a 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/RawEventMonitorsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/RawEventMonitorsClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.eventmonitors; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -184,7 +186,9 @@ public CatchAllApiHttpResponse createMonitor( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -270,7 +274,7 @@ public CatchAllApiHttpResponse pullMonitorResults( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors/pull") - .addPathSegment(monitorId); + .addPathSegment(PathSegments.validate(monitorId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -365,7 +369,7 @@ public CatchAllApiHttpResponse pullMonitorResultsCsv( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors/pull") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("csv"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -453,7 +457,7 @@ public CatchAllApiHttpResponse listMonitorJobs( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("jobs"); if (request.getSort().isPresent()) { QueryStringMapper.addQueryParameter( @@ -550,7 +554,7 @@ public CatchAllApiHttpResponse getMonitorStatus HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("status"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -637,7 +641,7 @@ public CatchAllApiHttpResponse enableMonitor( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("enable"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -647,7 +651,9 @@ public CatchAllApiHttpResponse enableMonitor( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -738,7 +744,7 @@ public CatchAllApiHttpResponse disableMonitor( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId) + .addPathSegment(PathSegments.validate(monitorId)) .addPathSegments("disable"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -747,7 +753,11 @@ public CatchAllApiHttpResponse disableMonitor( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("POST", RequestBody.create("", null)) + .method( + "POST", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, + RequestBody.create("", null))) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -852,7 +862,7 @@ public CatchAllApiHttpResponse deleteMonitor( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId); + .addPathSegment(PathSegments.validate(monitorId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -860,7 +870,10 @@ public CatchAllApiHttpResponse deleteMonitor( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -954,7 +967,7 @@ public CatchAllApiHttpResponse updateMonitor( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/monitors") - .addPathSegment(monitorId); + .addPathSegment(PathSegments.validate(monitorId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -963,7 +976,9 @@ public CatchAllApiHttpResponse updateMonitor( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/CreateMonitorRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/CreateMonitorRequestDto.java index 18752e4..b7df846 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/CreateMonitorRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/CreateMonitorRequestDto.java @@ -242,7 +242,6 @@ public static final class Builder implements ReferenceJobIdStage, ScheduleStage, private Optional timezone = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -398,6 +397,20 @@ public CreateMonitorRequestDto build() { referenceJobId, schedule, timezone, webhookIds, limit, backfill, projectId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("reference_job_id") + || key.equalsIgnoreCase("schedule") + || key.equalsIgnoreCase("timezone") + || key.equalsIgnoreCase("webhook_ids") + || key.equalsIgnoreCase("limit") + || key.equalsIgnoreCase("backfill") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DeleteMonitorRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DeleteMonitorRequest.java index 5197b10..234c8d7 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DeleteMonitorRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DeleteMonitorRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public DeleteMonitorRequest build() { return new DeleteMonitorRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DisableMonitorRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DisableMonitorRequest.java index 3c8fb86..6924f0b 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DisableMonitorRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/DisableMonitorRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public DisableMonitorRequest build() { return new DisableMonitorRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/EnableMonitorRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/EnableMonitorRequestDto.java index 03e785b..e8c34ae 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/EnableMonitorRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/EnableMonitorRequestDto.java @@ -71,7 +71,6 @@ public static Builder builder() { public static final class Builder { private Optional backfill = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -100,6 +99,14 @@ public EnableMonitorRequestDto build() { return new EnableMonitorRequestDto(backfill, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("backfill")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/GetMonitorStatusHistoryRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/GetMonitorStatusHistoryRequest.java index 23f51e6..eae8428 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/GetMonitorStatusHistoryRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/GetMonitorStatusHistoryRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetMonitorStatusHistoryRequest build() { return new GetMonitorStatusHistoryRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorJobsRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorJobsRequest.java index e2988b7..601fcb1 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorJobsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorJobsRequest.java @@ -72,7 +72,6 @@ public static Builder builder() { public static final class Builder { private Optional sort = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -100,6 +99,14 @@ public ListMonitorJobsRequest build() { return new ListMonitorJobsRequest(sort, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("sort")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorsRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorsRequest.java index 7a87813..52de763 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/ListMonitorsRequest.java @@ -130,7 +130,6 @@ public static final class Builder { private Optional projectId = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -215,6 +214,18 @@ public ListMonitorsRequest build() { return new ListMonitorsRequest(page, pageSize, search, ownership, projectId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("ownership") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsCsvRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsCsvRequest.java index 9fb8442..987df29 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsCsvRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsCsvRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public PullMonitorResultsCsvRequest build() { return new PullMonitorResultsCsvRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsRequest.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsRequest.java index 9f59e7b..44a17c2 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/PullMonitorResultsRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public PullMonitorResultsRequest build() { return new PullMonitorResultsRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/UpdateMonitorRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/UpdateMonitorRequestDto.java index 2710df8..733b565 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/UpdateMonitorRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/requests/UpdateMonitorRequestDto.java @@ -146,7 +146,6 @@ public static final class Builder { private Optional timezone = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -248,6 +247,17 @@ public UpdateMonitorRequestDto build() { return new UpdateMonitorRequestDto(webhookIds, limit, schedule, timezone, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("webhook_ids") + || key.equalsIgnoreCase("limit") + || key.equalsIgnoreCase("schedule") + || key.equalsIgnoreCase("timezone")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/DisableMonitorResponse.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/DisableMonitorResponse.java index 89f3704..927331b 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/DisableMonitorResponse.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/DisableMonitorResponse.java @@ -127,7 +127,6 @@ public static final class Builder implements SuccessStage, MessageStage, Monitor private String monitorId; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -178,6 +177,16 @@ public DisableMonitorResponse build() { return new DisableMonitorResponse(success, message, monitorId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("monitor_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/EnableMonitorResponse.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/EnableMonitorResponse.java index 03a133d..d87d70c 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/EnableMonitorResponse.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/EnableMonitorResponse.java @@ -127,7 +127,6 @@ public static final class Builder implements SuccessStage, MessageStage, Monitor private String monitorId; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -178,6 +177,16 @@ public EnableMonitorResponse build() { return new EnableMonitorResponse(success, message, monitorId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("monitor_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/ListMonitorJobsResponse.java b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/ListMonitorJobsResponse.java index f45e172..23cf6ce 100644 --- a/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/ListMonitorJobsResponse.java +++ b/src/main/java/com/newscatcher/catchall/resources/eventmonitors/types/ListMonitorJobsResponse.java @@ -160,7 +160,6 @@ public static final class Builder implements MonitorIdStage, SortOrderStage, Tot private List jobs = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -247,6 +246,17 @@ public ListMonitorJobsResponse build() { return new ListMonitorJobsResponse(monitorId, sortOrder, totalJobs, jobs, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("monitor_id") + || key.equalsIgnoreCase("sort_order") + || key.equalsIgnoreCase("total_jobs") + || key.equalsIgnoreCase("jobs")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncJobsClient.java b/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncJobsClient.java index cbab211..29eb101 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncJobsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncJobsClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.jobs; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.jobs.requests.ContinueRequestDto; @@ -47,21 +48,44 @@ public AsyncRawJobsClient withRawResponse() { * Returns all jobs created by the authenticated user. */ public CompletableFuture getUserJobs() { - return this.rawClient.getUserJobs().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getUserJobs(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all jobs created by the authenticated user. */ public CompletableFuture getUserJobs(RequestOptions requestOptions) { - return this.rawClient.getUserJobs(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getUserJobs(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all jobs created by the authenticated user. */ public CompletableFuture getUserJobs(GetUserJobsRequest request) { - return this.rawClient.getUserJobs(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getUserJobs(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -69,7 +93,15 @@ public CompletableFuture getUserJobs(GetUserJobsRequest */ public CompletableFuture getUserJobs( GetUserJobsRequest request, RequestOptions requestOptions) { - return this.rawClient.getUserJobs(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getUserJobs(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -77,7 +109,15 @@ public CompletableFuture getUserJobs( *

Returns a quality assessment with a status level, identified issues, and actionable suggestions.

*/ public CompletableFuture validateQuery(ValidateQueryRequestDto request) { - return this.rawClient.validateQuery(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.validateQuery(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -86,14 +126,30 @@ public CompletableFuture validateQuery(ValidateQueryRe */ public CompletableFuture validateQuery( ValidateQueryRequestDto request, RequestOptions requestOptions) { - return this.rawClient.validateQuery(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.validateQuery(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Get suggested validators, enrichments, and date ranges for a query. */ public CompletableFuture initialize(InitializeRequestDto request) { - return this.rawClient.initialize(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.initialize(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -101,42 +157,88 @@ public CompletableFuture initialize(InitializeRequestDto */ public CompletableFuture initialize( InitializeRequestDto request, RequestOptions requestOptions) { - return this.rawClient.initialize(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.initialize(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Submit a query to create a new processing job. */ public CompletableFuture createJob(SubmitRequestDto request) { - return this.rawClient.createJob(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.createJob(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Submit a query to create a new processing job. */ public CompletableFuture createJob(SubmitRequestDto request, RequestOptions requestOptions) { - return this.rawClient.createJob(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createJob(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve the current processing status of a job. */ public CompletableFuture getJobStatus(String jobId) { - return this.rawClient.getJobStatus(jobId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getJobStatus(jobId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve the current processing status of a job. */ public CompletableFuture getJobStatus(String jobId, RequestOptions requestOptions) { - return this.rawClient.getJobStatus(jobId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobStatus(jobId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve the current processing status of a job. */ public CompletableFuture getJobStatus(String jobId, GetJobStatusRequest request) { - return this.rawClient.getJobStatus(jobId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobStatus(jobId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -144,28 +246,59 @@ public CompletableFuture getJobStatus(String jobId, GetJobSta */ public CompletableFuture getJobStatus( String jobId, GetJobStatusRequest request, RequestOptions requestOptions) { - return this.rawClient.getJobStatus(jobId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobStatus(jobId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve the final results for a completed job. */ public CompletableFuture getJobResults(String jobId) { - return this.rawClient.getJobResults(jobId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getJobResults(jobId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve the final results for a completed job. */ public CompletableFuture getJobResults(String jobId, RequestOptions requestOptions) { - return this.rawClient.getJobResults(jobId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobResults(jobId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Retrieve the final results for a completed job. */ public CompletableFuture getJobResults(String jobId, GetJobResultsRequest request) { - return this.rawClient.getJobResults(jobId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobResults(jobId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -173,7 +306,15 @@ public CompletableFuture getJobResults(String jobId, GetJobR */ public CompletableFuture getJobResults( String jobId, GetJobResultsRequest request, RequestOptions requestOptions) { - return this.rawClient.getJobResults(jobId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobResults(jobId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -181,7 +322,14 @@ public CompletableFuture getJobResults( *

If the job used connected entity datasets, connected entities are split into event_associated_entities and mention_entities JSON columns. When no entity dataset was used, those two columns are omitted from the export entirely.

*/ public CompletableFuture getJobResultsCsv(String jobId) { - return this.rawClient.getJobResultsCsv(jobId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getJobResultsCsv(jobId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -189,7 +337,15 @@ public CompletableFuture getJobResultsCsv(String jobId) { *

If the job used connected entity datasets, connected entities are split into event_associated_entities and mention_entities JSON columns. When no entity dataset was used, those two columns are omitted from the export entirely.

*/ public CompletableFuture getJobResultsCsv(String jobId, RequestOptions requestOptions) { - return this.rawClient.getJobResultsCsv(jobId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobResultsCsv(jobId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -197,7 +353,14 @@ public CompletableFuture getJobResultsCsv(String jobId, RequestOptions r *

If the job used connected entity datasets, connected entities are split into event_associated_entities and mention_entities JSON columns. When no entity dataset was used, those two columns are omitted from the export entirely.

*/ public CompletableFuture getJobResultsCsv(String jobId, GetJobResultsCsvRequest request) { - return this.rawClient.getJobResultsCsv(jobId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getJobResultsCsv(jobId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -206,14 +369,29 @@ public CompletableFuture getJobResultsCsv(String jobId, GetJobResultsCsv */ public CompletableFuture getJobResultsCsv( String jobId, GetJobResultsCsvRequest request, RequestOptions requestOptions) { - return this.rawClient.getJobResultsCsv(jobId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getJobResultsCsv(jobId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Continue an existing job to process more records beyond the initial limit. */ public CompletableFuture continueJob(ContinueRequestDto request) { - return this.rawClient.continueJob(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.continueJob(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -221,7 +399,15 @@ public CompletableFuture continueJob(ContinueRequestDto req */ public CompletableFuture continueJob( ContinueRequestDto request, RequestOptions requestOptions) { - return this.rawClient.continueJob(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.continueJob(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -230,7 +416,14 @@ public CompletableFuture continueJob( *

Deleting an already-deleted job returns 200.

*/ public CompletableFuture deleteJob(String jobId) { - return this.rawClient.deleteJob(jobId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteJob(jobId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -239,7 +432,15 @@ public CompletableFuture deleteJob(String jobId) { *

Deleting an already-deleted job returns 200.

*/ public CompletableFuture deleteJob(String jobId, RequestOptions requestOptions) { - return this.rawClient.deleteJob(jobId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteJob(jobId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -248,7 +449,15 @@ public CompletableFuture deleteJob(String jobId, RequestOp *

Deleting an already-deleted job returns 200.

*/ public CompletableFuture deleteJob(String jobId, DeleteJobRequest request) { - return this.rawClient.deleteJob(jobId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteJob(jobId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -258,7 +467,15 @@ public CompletableFuture deleteJob(String jobId, DeleteJob */ public CompletableFuture deleteJob( String jobId, DeleteJobRequest request, RequestOptions requestOptions) { - return this.rawClient.deleteJob(jobId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteJob(jobId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -271,7 +488,15 @@ public CompletableFuture deleteJob( * been granted access to. Each entry returns slug, name, and description.

*/ public CompletableFuture listSourceGroups() { - return this.rawClient.listSourceGroups().thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listSourceGroups(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -284,7 +509,15 @@ public CompletableFuture listSourceGroups() { * been granted access to. Each entry returns slug, name, and description.

*/ public CompletableFuture listSourceGroups(RequestOptions requestOptions) { - return this.rawClient.listSourceGroups(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listSourceGroups(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -297,7 +530,15 @@ public CompletableFuture listSourceGroups(RequestOp * been granted access to. Each entry returns slug, name, and description.

*/ public CompletableFuture listSourceGroups(ListSourceGroupsRequest request) { - return this.rawClient.listSourceGroups(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listSourceGroups(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -311,6 +552,14 @@ public CompletableFuture listSourceGroups(ListSourc */ public CompletableFuture listSourceGroups( ListSourceGroupsRequest request, RequestOptions requestOptions) { - return this.rawClient.listSourceGroups(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listSourceGroups(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncRawJobsClient.java b/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncRawJobsClient.java index 7683293..f470f71 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncRawJobsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/AsyncRawJobsClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.jobs; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -138,7 +140,8 @@ public CompletableFuture> getUs .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -182,6 +185,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -211,7 +219,9 @@ public CompletableFuture> vali RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -236,7 +246,8 @@ public CompletableFuture> vali .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -286,6 +297,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -312,7 +328,9 @@ public CompletableFuture> initial RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -337,7 +355,8 @@ public CompletableFuture> initial .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -387,6 +406,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -413,7 +437,9 @@ public CompletableFuture> createJob( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -438,7 +464,8 @@ public CompletableFuture> createJob( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -493,6 +520,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -527,7 +559,7 @@ public CompletableFuture> getJobStatu HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/status") - .addPathSegment(jobId); + .addPathSegment(PathSegments.validate(jobId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -553,7 +585,8 @@ public CompletableFuture> getJobStatu .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -602,6 +635,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -636,7 +674,7 @@ public CompletableFuture> getJobResu HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/pull") - .addPathSegment(jobId); + .addPathSegment(PathSegments.validate(jobId)); if (request.getPage().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "page", request.getPage().get(), false); @@ -670,7 +708,8 @@ public CompletableFuture> getJobResu .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -719,6 +758,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -757,7 +801,7 @@ public CompletableFuture> getJobResultsCsv( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/pull") - .addPathSegment(jobId) + .addPathSegment(PathSegments.validate(jobId)) .addPathSegments("csv"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -784,7 +828,8 @@ public CompletableFuture> getJobResultsCsv( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -831,6 +876,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -857,7 +907,9 @@ public CompletableFuture> continueJ RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -882,7 +934,8 @@ public CompletableFuture> continueJ .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -937,6 +990,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -979,7 +1037,7 @@ public CompletableFuture> deleteJo HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/jobs") - .addPathSegment(jobId); + .addPathSegment(PathSegments.validate(jobId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -987,7 +1045,10 @@ public CompletableFuture> deleteJo } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -1005,7 +1066,8 @@ public CompletableFuture> deleteJo .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1049,6 +1111,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1140,7 +1207,8 @@ public CompletableFuture> l .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1186,6 +1254,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/RawJobsClient.java b/src/main/java/com/newscatcher/catchall/resources/jobs/RawJobsClient.java index fae0440..7d45ead 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/RawJobsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/RawJobsClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.jobs; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -187,7 +189,9 @@ public CatchAllApiHttpResponse validateQuery( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -268,7 +272,9 @@ public CatchAllApiHttpResponse initialize( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -348,7 +354,9 @@ public CatchAllApiHttpResponse createJob( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -437,7 +445,7 @@ public CatchAllApiHttpResponse getJobStatus( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/status") - .addPathSegment(jobId); + .addPathSegment(PathSegments.validate(jobId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -523,7 +531,7 @@ public CatchAllApiHttpResponse getJobResults( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/pull") - .addPathSegment(jobId); + .addPathSegment(PathSegments.validate(jobId)); if (request.getPage().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "page", request.getPage().get(), false); @@ -621,7 +629,7 @@ public CatchAllApiHttpResponse getJobResultsCsv( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/pull") - .addPathSegment(jobId) + .addPathSegment(PathSegments.validate(jobId)) .addPathSegments("csv"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -701,7 +709,9 @@ public CatchAllApiHttpResponse continueJob( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -798,7 +808,7 @@ public CatchAllApiHttpResponse deleteJob( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/jobs") - .addPathSegment(jobId); + .addPathSegment(PathSegments.validate(jobId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -806,7 +816,10 @@ public CatchAllApiHttpResponse deleteJob( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ContinueRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ContinueRequestDto.java index 62d4726..754e373 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ContinueRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ContinueRequestDto.java @@ -108,7 +108,6 @@ public static final class Builder implements JobIdStage, _FinalStage { private Optional newLimit = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -156,6 +155,14 @@ public ContinueRequestDto build() { return new ContinueRequestDto(jobId, newLimit, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id") || key.equalsIgnoreCase("new_limit")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/DeleteJobRequest.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/DeleteJobRequest.java index bfd0154..9437b18 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/DeleteJobRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/DeleteJobRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public DeleteJobRequest build() { return new DeleteJobRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsCsvRequest.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsCsvRequest.java index e361b9c..6a6445b 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsCsvRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsCsvRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetJobResultsCsvRequest build() { return new GetJobResultsCsvRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsRequest.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsRequest.java index 0a8a21d..83a888b 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobResultsRequest.java @@ -84,7 +84,6 @@ public static final class Builder { private Optional pageSize = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -127,6 +126,14 @@ public GetJobResultsRequest build() { return new GetJobResultsRequest(page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobStatusRequest.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobStatusRequest.java index b19203c..57dddd3 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobStatusRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetJobStatusRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetJobStatusRequest build() { return new GetJobStatusRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetUserJobsRequest.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetUserJobsRequest.java index 321a4f2..67a7ebc 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetUserJobsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/GetUserJobsRequest.java @@ -146,7 +146,6 @@ public static final class Builder { private Optional mode = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -246,6 +245,19 @@ public GetUserJobsRequest build() { return new GetUserJobsRequest(page, pageSize, search, ownership, projectId, mode, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("ownership") + || key.equalsIgnoreCase("project_id") + || key.equalsIgnoreCase("mode")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/InitializeRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/InitializeRequestDto.java index af82c3b..cb2a4a9 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/InitializeRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/InitializeRequestDto.java @@ -147,7 +147,6 @@ public static final class Builder implements QueryStage, _FinalStage { private Optional context = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -229,6 +228,17 @@ public InitializeRequestDto build() { query, context, connectedDatasetIds, fetchAllWatchlistNews, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("query") + || key.equalsIgnoreCase("context") + || key.equalsIgnoreCase("connected_dataset_ids") + || key.equalsIgnoreCase("fetch_all_watchlist_news")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ListSourceGroupsRequest.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ListSourceGroupsRequest.java index 8e9b923..3fe4c0a 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ListSourceGroupsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ListSourceGroupsRequest.java @@ -84,7 +84,6 @@ public static final class Builder { private Optional pageSize = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -127,6 +126,14 @@ public ListSourceGroupsRequest build() { return new ListSourceGroupsRequest(page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/SubmitRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/SubmitRequestDto.java index aaa80e3..4016cc1 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/SubmitRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/SubmitRequestDto.java @@ -425,7 +425,6 @@ public static final class Builder implements QueryStage, _FinalStage { private Optional context = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -766,6 +765,28 @@ public SubmitRequestDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("query") + || key.equalsIgnoreCase("context") + || key.equalsIgnoreCase("limit") + || key.equalsIgnoreCase("start_date") + || key.equalsIgnoreCase("end_date") + || key.equalsIgnoreCase("validators") + || key.equalsIgnoreCase("enrichments") + || key.equalsIgnoreCase("mode") + || key.equalsIgnoreCase("connected_dataset_ids") + || key.equalsIgnoreCase("ed_score_min") + || key.equalsIgnoreCase("project_id") + || key.equalsIgnoreCase("webhook_ids") + || key.equalsIgnoreCase("fetch_all_watchlist_news") + || key.equalsIgnoreCase("ed_association_type") + || key.equalsIgnoreCase("source_groups")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ValidateQueryRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ValidateQueryRequestDto.java index 46b5ac6..69eac7d 100644 --- a/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ValidateQueryRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/jobs/requests/ValidateQueryRequestDto.java @@ -86,7 +86,6 @@ public interface _FinalStage { public static final class Builder implements QueryStage, _FinalStage { private String query; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -113,6 +112,14 @@ public ValidateQueryRequestDto build() { return new ValidateQueryRequestDto(query, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("query")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/meta/AsyncMetaClient.java b/src/main/java/com/newscatcher/catchall/resources/meta/AsyncMetaClient.java index e2b4e56..da9f455 100644 --- a/src/main/java/com/newscatcher/catchall/resources/meta/AsyncMetaClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/meta/AsyncMetaClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.meta; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.meta.types.GetVersionResponse; @@ -31,41 +32,86 @@ public AsyncRawMetaClient withRawResponse() { * Check API availability. */ public CompletableFuture healthCheck() { - return this.rawClient.healthCheck().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.healthCheck(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Check API availability. */ public CompletableFuture healthCheck(RequestOptions requestOptions) { - return this.rawClient.healthCheck(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.healthCheck(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns current API version. */ public CompletableFuture getVersion() { - return this.rawClient.getVersion().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getVersion(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns current API version. */ public CompletableFuture getVersion(RequestOptions requestOptions) { - return this.rawClient.getVersion(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getVersion(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns plan features and current usage for the authenticated organization. */ public CompletableFuture getPlanLimits() { - return this.rawClient.getPlanLimits().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getPlanLimits(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns plan features and current usage for the authenticated organization. */ public CompletableFuture getPlanLimits(RequestOptions requestOptions) { - return this.rawClient.getPlanLimits(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getPlanLimits(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/meta/AsyncRawMetaClient.java b/src/main/java/com/newscatcher/catchall/resources/meta/AsyncRawMetaClient.java index 661d0f3..7f1e4c9 100644 --- a/src/main/java/com/newscatcher/catchall/resources/meta/AsyncRawMetaClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/meta/AsyncRawMetaClient.java @@ -4,6 +4,7 @@ package com.newscatcher.catchall.resources.meta; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; @@ -76,7 +77,8 @@ public CompletableFuture> healthChe .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -104,6 +106,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -146,7 +153,8 @@ public CompletableFuture> getVersion .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -174,6 +182,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -199,7 +212,11 @@ public CompletableFuture> getP } Request okhttpRequest = new Request.Builder() .url(httpUrl.build()) - .method("POST", RequestBody.create("", null)) + .method( + "POST", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, + RequestBody.create("", null))) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") .build(); @@ -217,7 +234,8 @@ public CompletableFuture> getP .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -261,6 +279,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/meta/RawMetaClient.java b/src/main/java/com/newscatcher/catchall/resources/meta/RawMetaClient.java index 715c321..8c12eb9 100644 --- a/src/main/java/com/newscatcher/catchall/resources/meta/RawMetaClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/meta/RawMetaClient.java @@ -4,6 +4,7 @@ package com.newscatcher.catchall.resources.meta; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; @@ -164,7 +165,11 @@ public CatchAllApiHttpResponse getPlanLimits(RequestOp } Request okhttpRequest = new Request.Builder() .url(httpUrl.build()) - .method("POST", RequestBody.create("", null)) + .method( + "POST", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, + RequestBody.create("", null))) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json") .build(); diff --git a/src/main/java/com/newscatcher/catchall/resources/meta/types/GetVersionResponse.java b/src/main/java/com/newscatcher/catchall/resources/meta/types/GetVersionResponse.java index 8434eaa..e961ccb 100644 --- a/src/main/java/com/newscatcher/catchall/resources/meta/types/GetVersionResponse.java +++ b/src/main/java/com/newscatcher/catchall/resources/meta/types/GetVersionResponse.java @@ -67,7 +67,6 @@ public static Builder builder() { public static final class Builder { private Optional version = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -92,6 +91,14 @@ public GetVersionResponse build() { return new GetVersionResponse(version, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("version")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/meta/types/HealthCheckResponse.java b/src/main/java/com/newscatcher/catchall/resources/meta/types/HealthCheckResponse.java index 5387a09..27777c9 100644 --- a/src/main/java/com/newscatcher/catchall/resources/meta/types/HealthCheckResponse.java +++ b/src/main/java/com/newscatcher/catchall/resources/meta/types/HealthCheckResponse.java @@ -67,7 +67,6 @@ public static Builder builder() { public static final class Builder { private Optional healthy = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -92,6 +91,14 @@ public HealthCheckResponse build() { return new HealthCheckResponse(healthy, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("healthy")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/AsyncProjectsClient.java b/src/main/java/com/newscatcher/catchall/resources/projects/AsyncProjectsClient.java index 0000024..12e0e98 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/AsyncProjectsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/AsyncProjectsClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.projects; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.projects.requests.AddResourceRequestDto; @@ -46,21 +47,44 @@ public AsyncRawProjectsClient withRawResponse() { * Returns all projects visible to the authenticated user. */ public CompletableFuture listProjects() { - return this.rawClient.listProjects().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.listProjects(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all projects visible to the authenticated user. */ public CompletableFuture listProjects(RequestOptions requestOptions) { - return this.rawClient.listProjects(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjects(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all projects visible to the authenticated user. */ public CompletableFuture listProjects(ListProjectsRequest request) { - return this.rawClient.listProjects(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjects(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -68,14 +92,30 @@ public CompletableFuture listProjects(ListProjectsReques */ public CompletableFuture listProjects( ListProjectsRequest request, RequestOptions requestOptions) { - return this.rawClient.listProjects(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjects(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Creates a new project. */ public CompletableFuture createProject(CreateProjectRequestDto request) { - return this.rawClient.createProject(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createProject(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -83,28 +123,59 @@ public CompletableFuture createProject(CreateProjectRe */ public CompletableFuture createProject( CreateProjectRequestDto request, RequestOptions requestOptions) { - return this.rawClient.createProject(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createProject(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single project by ID. */ public CompletableFuture getProject(String projectId) { - return this.rawClient.getProject(projectId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.getProject(projectId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single project by ID. */ public CompletableFuture getProject(String projectId, RequestOptions requestOptions) { - return this.rawClient.getProject(projectId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProject(projectId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a single project by ID. */ public CompletableFuture getProject(String projectId, GetProjectRequest request) { - return this.rawClient.getProject(projectId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProject(projectId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -112,7 +183,15 @@ public CompletableFuture getProject(String projectId, GetPro */ public CompletableFuture getProject( String projectId, GetProjectRequest request, RequestOptions requestOptions) { - return this.rawClient.getProject(projectId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProject(projectId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -120,7 +199,14 @@ public CompletableFuture getProject( *

Webhooks are an exception: they are never deleted by this operation, even when delete_resources is true. Any attached webhook is detached from the project and continues to exist and deliver, because the same webhook may be attached to other projects.

*/ public CompletableFuture deleteProject(String projectId) { - return this.rawClient.deleteProject(projectId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteProject(projectId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -128,7 +214,15 @@ public CompletableFuture deleteProject(String projectId) { *

Webhooks are an exception: they are never deleted by this operation, even when delete_resources is true. Any attached webhook is detached from the project and continues to exist and deliver, because the same webhook may be attached to other projects.

*/ public CompletableFuture deleteProject(String projectId, RequestOptions requestOptions) { - return this.rawClient.deleteProject(projectId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteProject(projectId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -136,7 +230,14 @@ public CompletableFuture deleteProject(String projectId, RequestOptions re *

Webhooks are an exception: they are never deleted by this operation, even when delete_resources is true. Any attached webhook is detached from the project and continues to exist and deliver, because the same webhook may be attached to other projects.

*/ public CompletableFuture deleteProject(String projectId, DeleteProjectRequest request) { - return this.rawClient.deleteProject(projectId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteProject(projectId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -145,21 +246,45 @@ public CompletableFuture deleteProject(String projectId, DeleteProjectRequ */ public CompletableFuture deleteProject( String projectId, DeleteProjectRequest request, RequestOptions requestOptions) { - return this.rawClient.deleteProject(projectId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteProject(projectId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates the name or description of an existing project. */ public CompletableFuture updateProject(String projectId) { - return this.rawClient.updateProject(projectId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateProject(projectId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates the name or description of an existing project. */ public CompletableFuture updateProject(String projectId, RequestOptions requestOptions) { - return this.rawClient.updateProject(projectId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateProject(projectId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -167,7 +292,15 @@ public CompletableFuture updateProject(String projectI */ public CompletableFuture updateProject( String projectId, UpdateProjectRequestDto request) { - return this.rawClient.updateProject(projectId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateProject(projectId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -175,7 +308,15 @@ public CompletableFuture updateProject( */ public CompletableFuture updateProject( String projectId, UpdateProjectRequestDto request, RequestOptions requestOptions) { - return this.rawClient.updateProject(projectId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateProject(projectId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -183,7 +324,15 @@ public CompletableFuture updateProject( *

For jobs and monitors, counts are broken down by status (for example, completed, failed). For datasets, monitor_groups, and webhooks, only a total count is returned.

*/ public CompletableFuture getProjectOverview(String projectId) { - return this.rawClient.getProjectOverview(projectId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProjectOverview(projectId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -192,7 +341,15 @@ public CompletableFuture getProjectOverview(String p */ public CompletableFuture getProjectOverview( String projectId, RequestOptions requestOptions) { - return this.rawClient.getProjectOverview(projectId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProjectOverview(projectId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -201,7 +358,15 @@ public CompletableFuture getProjectOverview( */ public CompletableFuture getProjectOverview( String projectId, GetProjectOverviewRequest request) { - return this.rawClient.getProjectOverview(projectId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProjectOverview(projectId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -210,16 +375,30 @@ public CompletableFuture getProjectOverview( */ public CompletableFuture getProjectOverview( String projectId, GetProjectOverviewRequest request, RequestOptions requestOptions) { - return this.rawClient - .getProjectOverview(projectId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getProjectOverview(projectId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns all resources assigned to a project, with optional filtering by type. */ public CompletableFuture listProjectResources(String projectId) { - return this.rawClient.listProjectResources(projectId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjectResources(projectId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -227,7 +406,15 @@ public CompletableFuture listProjectResources(St */ public CompletableFuture listProjectResources( String projectId, RequestOptions requestOptions) { - return this.rawClient.listProjectResources(projectId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjectResources(projectId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -235,7 +422,15 @@ public CompletableFuture listProjectResources( */ public CompletableFuture listProjectResources( String projectId, ListProjectResourcesRequest request) { - return this.rawClient.listProjectResources(projectId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjectResources(projectId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -243,9 +438,15 @@ public CompletableFuture listProjectResources( */ public CompletableFuture listProjectResources( String projectId, ListProjectResourcesRequest request, RequestOptions requestOptions) { - return this.rawClient - .listProjectResources(projectId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listProjectResources(projectId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -253,7 +454,15 @@ public CompletableFuture listProjectResources( */ public CompletableFuture addResourceToProject( String projectId, AddResourceRequestDto request) { - return this.rawClient.addResourceToProject(projectId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.addResourceToProject(projectId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -261,9 +470,15 @@ public CompletableFuture addResourceToProject( */ public CompletableFuture addResourceToProject( String projectId, AddResourceRequestDto request, RequestOptions requestOptions) { - return this.rawClient - .addResourceToProject(projectId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.addResourceToProject(projectId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -272,9 +487,15 @@ public CompletableFuture addResourceToProject( */ public CompletableFuture removeResourceFromProject( String projectId, ProjectResourceType resourceType, String resourceId) { - return this.rawClient - .removeResourceFromProject(projectId, resourceType, resourceId) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeResourceFromProject(projectId, resourceType, resourceId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -283,9 +504,15 @@ public CompletableFuture removeResourceFromProject( */ public CompletableFuture removeResourceFromProject( String projectId, ProjectResourceType resourceType, String resourceId, RequestOptions requestOptions) { - return this.rawClient - .removeResourceFromProject(projectId, resourceType, resourceId, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeResourceFromProject(projectId, resourceType, resourceId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -297,9 +524,15 @@ public CompletableFuture removeResourceFromProject( ProjectResourceType resourceType, String resourceId, RemoveResourceFromProjectRequest request) { - return this.rawClient - .removeResourceFromProject(projectId, resourceType, resourceId, request) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeResourceFromProject(projectId, resourceType, resourceId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -312,8 +545,14 @@ public CompletableFuture removeResourceFromProject( String resourceId, RemoveResourceFromProjectRequest request, RequestOptions requestOptions) { - return this.rawClient - .removeResourceFromProject(projectId, resourceType, resourceId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeResourceFromProject(projectId, resourceType, resourceId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/AsyncRawProjectsClient.java b/src/main/java/com/newscatcher/catchall/resources/projects/AsyncRawProjectsClient.java index 29542f1..845731e 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/AsyncRawProjectsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/AsyncRawProjectsClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.projects; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -130,7 +132,8 @@ public CompletableFuture> listPr .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -180,6 +183,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -207,7 +215,9 @@ public CompletableFuture> crea RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -232,7 +242,8 @@ public CompletableFuture> crea .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -282,6 +293,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -316,7 +332,7 @@ public CompletableFuture> getProject HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId); + .addPathSegment(PathSegments.validate(projectId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -342,7 +358,8 @@ public CompletableFuture> getProject .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -391,6 +408,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -429,7 +451,7 @@ public CompletableFuture> deleteProject( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId); + .addPathSegment(PathSegments.validate(projectId)); if (request.getDeleteResources().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "delete_resources", request.getDeleteResources().get(), false); @@ -441,7 +463,10 @@ public CompletableFuture> deleteProject( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -459,7 +484,8 @@ public CompletableFuture> deleteProject( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -506,6 +532,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -540,7 +571,7 @@ public CompletableFuture> upda HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId); + .addPathSegment(PathSegments.validate(projectId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -549,7 +580,9 @@ public CompletableFuture> upda RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -574,7 +607,8 @@ public CompletableFuture> upda .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -629,6 +663,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -667,7 +706,7 @@ public CompletableFuture> ge HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("overview"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -694,7 +733,8 @@ public CompletableFuture> ge .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -744,6 +784,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -781,7 +826,7 @@ public CompletableFuture HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("resources"); if (request.getResourceType().isPresent()) { QueryStringMapper.addQueryParameter( @@ -820,7 +865,8 @@ public CompletableFuture .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -876,6 +922,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -895,7 +946,7 @@ public CompletableFuture> addRes HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("resources"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -905,7 +956,9 @@ public CompletableFuture> addRes RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -930,7 +983,8 @@ public CompletableFuture> addRes .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -984,6 +1038,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1039,10 +1098,10 @@ public CompletableFuture> rem HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("resources") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId); + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -1050,7 +1109,10 @@ public CompletableFuture> rem } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -1068,7 +1130,8 @@ public CompletableFuture> rem .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1118,6 +1181,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/RawProjectsClient.java b/src/main/java/com/newscatcher/catchall/resources/projects/RawProjectsClient.java index d1454f3..4ed49a0 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/RawProjectsClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/RawProjectsClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.projects; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -180,7 +182,9 @@ public CatchAllApiHttpResponse createProject( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -267,7 +271,7 @@ public CatchAllApiHttpResponse getProject( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId); + .addPathSegment(PathSegments.validate(projectId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -357,7 +361,7 @@ public CatchAllApiHttpResponse deleteProject( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId); + .addPathSegment(PathSegments.validate(projectId)); if (request.getDeleteResources().isPresent()) { QueryStringMapper.addQueryParameter( httpUrl, "delete_resources", request.getDeleteResources().get(), false); @@ -369,7 +373,10 @@ public CatchAllApiHttpResponse deleteProject( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -448,7 +455,7 @@ public CatchAllApiHttpResponse updateProject( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId); + .addPathSegment(PathSegments.validate(projectId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -457,7 +464,9 @@ public CatchAllApiHttpResponse updateProject( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -553,7 +562,7 @@ public CatchAllApiHttpResponse getProjectOverview( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("overview"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -645,7 +654,7 @@ public CatchAllApiHttpResponse listProjectResour HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("resources"); if (request.getResourceType().isPresent()) { QueryStringMapper.addQueryParameter( @@ -736,7 +745,7 @@ public CatchAllApiHttpResponse addResourceToProject( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("resources"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -746,7 +755,9 @@ public CatchAllApiHttpResponse addResourceToProject( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -858,10 +869,10 @@ public CatchAllApiHttpResponse removeResourceFromProj HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/projects") - .addPathSegment(projectId) + .addPathSegment(PathSegments.validate(projectId)) .addPathSegments("resources") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId); + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -869,7 +880,10 @@ public CatchAllApiHttpResponse removeResourceFromProj } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/AddResourceRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/AddResourceRequestDto.java index b2b72da..51c6013 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/AddResourceRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/AddResourceRequestDto.java @@ -72,7 +72,6 @@ public static Builder builder() { public static final class Builder { private List resources = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -110,6 +109,14 @@ public AddResourceRequestDto build() { return new AddResourceRequestDto(resources, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resources")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/CreateProjectRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/CreateProjectRequestDto.java index 8aa0ec7..116e9d7 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/CreateProjectRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/CreateProjectRequestDto.java @@ -109,7 +109,6 @@ public static final class Builder implements NameStage, _FinalStage { private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -157,6 +156,14 @@ public CreateProjectRequestDto build() { return new CreateProjectRequestDto(name, description, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/DeleteProjectRequest.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/DeleteProjectRequest.java index 6130053..dcf7fd0 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/DeleteProjectRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/DeleteProjectRequest.java @@ -71,7 +71,6 @@ public static Builder builder() { public static final class Builder { private Optional deleteResources = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -100,6 +99,14 @@ public DeleteProjectRequest build() { return new DeleteProjectRequest(deleteResources, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("delete_resources")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectOverviewRequest.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectOverviewRequest.java index 7a9d875..23805e1 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectOverviewRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectOverviewRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetProjectOverviewRequest build() { return new GetProjectOverviewRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectRequest.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectRequest.java index 90cb26c..00e9829 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/GetProjectRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetProjectRequest build() { return new GetProjectRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectResourcesRequest.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectResourcesRequest.java index 6f6b71c..311ff30 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectResourcesRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectResourcesRequest.java @@ -98,7 +98,6 @@ public static final class Builder { private Optional pageSize = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -153,6 +152,16 @@ public ListProjectResourcesRequest build() { return new ListProjectResourcesRequest(resourceType, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectsRequest.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectsRequest.java index 726c0d7..5f2d985 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectsRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/ListProjectsRequest.java @@ -115,7 +115,6 @@ public static final class Builder { private Optional ownership = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -185,6 +184,17 @@ public ListProjectsRequest build() { return new ListProjectsRequest(page, pageSize, search, ownership, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("ownership")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/RemoveResourceFromProjectRequest.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/RemoveResourceFromProjectRequest.java index 714f061..914414e 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/RemoveResourceFromProjectRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/RemoveResourceFromProjectRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public RemoveResourceFromProjectRequest build() { return new RemoveResourceFromProjectRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/projects/requests/UpdateProjectRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/projects/requests/UpdateProjectRequestDto.java index 215c005..26f1f9c 100644 --- a/src/main/java/com/newscatcher/catchall/resources/projects/requests/UpdateProjectRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/projects/requests/UpdateProjectRequestDto.java @@ -84,7 +84,6 @@ public static final class Builder { private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -127,6 +126,14 @@ public UpdateProjectRequestDto build() { return new UpdateProjectRequestDto(name, description, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncRawWebhooksClient.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncRawWebhooksClient.java index 589f6c0..d1b438c 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncRawWebhooksClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncRawWebhooksClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.webhooks; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -133,7 +135,8 @@ public CompletableFuture> listW .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -188,6 +191,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -217,7 +225,9 @@ public CompletableFuture> crea RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -242,7 +252,8 @@ public CompletableFuture> crea .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -297,6 +308,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -331,7 +347,7 @@ public CompletableFuture> getWebh HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId); + .addPathSegment(PathSegments.validate(webhookId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -357,7 +373,8 @@ public CompletableFuture> getWebh .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -412,6 +429,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -450,7 +472,7 @@ public CompletableFuture> deleteWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId); + .addPathSegment(PathSegments.validate(webhookId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -458,7 +480,10 @@ public CompletableFuture> deleteWebhook( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -476,7 +501,8 @@ public CompletableFuture> deleteWebhook( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -523,6 +549,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -557,7 +588,7 @@ public CompletableFuture> upda HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId); + .addPathSegment(PathSegments.validate(webhookId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -566,7 +597,9 @@ public CompletableFuture> upda RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -591,7 +624,8 @@ public CompletableFuture> upda .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -646,6 +680,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -684,7 +723,7 @@ public CompletableFuture> testWe HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId) + .addPathSegment(PathSegments.validate(webhookId)) .addPathSegments("test"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -694,7 +733,9 @@ public CompletableFuture> testWe RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -719,7 +760,8 @@ public CompletableFuture> testWe .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -774,6 +816,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -811,7 +858,7 @@ public CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -906,6 +954,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -931,7 +984,7 @@ public CompletableFuture { @@ -941,7 +994,9 @@ public CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1027,6 +1083,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1082,10 +1143,10 @@ public CompletableFuture> removeWebhookResource( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId) + .addPathSegment(PathSegments.validate(webhookId)) .addPathSegments("resources") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId); + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -1093,7 +1154,10 @@ public CompletableFuture> removeWebhookResource( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -1111,7 +1175,8 @@ public CompletableFuture> removeWebhookResource( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1158,6 +1223,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1203,8 +1273,8 @@ public CompletableFuture> listW HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/resources") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId) + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)) .addPathSegments("webhooks"); if (request.getIsActive().isPresent()) { QueryStringMapper.addQueryParameter( @@ -1243,7 +1313,8 @@ public CompletableFuture> listW .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1298,6 +1369,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1328,8 +1404,8 @@ public CompletableFuture> triggerWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhook/trigger") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId); + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)); QueryStringMapper.addQueryParameter(httpUrl, "webhook_id", request.getWebhookId(), false); if (request.getJobId().isPresent()) { QueryStringMapper.addQueryParameter( @@ -1342,7 +1418,11 @@ public CompletableFuture> triggerWebhook( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("POST", RequestBody.create("", null)) + .method( + "POST", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, + RequestBody.create("", null))) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -1360,7 +1440,8 @@ public CompletableFuture> triggerWebhook( .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1413,6 +1494,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } @@ -1469,7 +1555,8 @@ public CompletableFuture> ge .build(); } CompletableFuture> future = new CompletableFuture<>(); - client.newCall(okhttpRequest).enqueue(new Callback() { + RetryInterceptor.AsyncCall okhttpCall = RetryInterceptor.newAsyncCall(client, okhttpRequest); + okhttpCall.enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { @@ -1525,6 +1612,11 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { future.completeExceptionally(new CatchAllApiException("Network error executing HTTP request", e)); } }); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + okhttpCall.cancel(); + } + }); return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncWebhooksClient.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncWebhooksClient.java index 715a0e1..93e27c5 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncWebhooksClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/AsyncWebhooksClient.java @@ -3,6 +3,7 @@ */ package com.newscatcher.catchall.resources.webhooks; +import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.resources.webhooks.requests.AssignWebhookResourceRequestDto; @@ -49,21 +50,44 @@ public AsyncRawWebhooksClient withRawResponse() { * Returns a paginated list of webhooks belonging to the organization. */ public CompletableFuture listWebhooks() { - return this.rawClient.listWebhooks().thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.listWebhooks(); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of webhooks belonging to the organization. */ public CompletableFuture listWebhooks(RequestOptions requestOptions) { - return this.rawClient.listWebhooks(requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooks(requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of webhooks belonging to the organization. */ public CompletableFuture listWebhooks(ListWebhooksRequest request) { - return this.rawClient.listWebhooks(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooks(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -71,7 +95,15 @@ public CompletableFuture listWebhooks(ListWebhooksReque */ public CompletableFuture listWebhooks( ListWebhooksRequest request, RequestOptions requestOptions) { - return this.rawClient.listWebhooks(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooks(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -79,7 +111,15 @@ public CompletableFuture listWebhooks( *

Optionally pass project_id to attach the webhook to a project in the same request.

*/ public CompletableFuture createWebhook(CreateWebhookRequestDto request) { - return this.rawClient.createWebhook(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createWebhook(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -88,28 +128,60 @@ public CompletableFuture createWebhook(CreateWebhookRe */ public CompletableFuture createWebhook( CreateWebhookRequestDto request, RequestOptions requestOptions) { - return this.rawClient.createWebhook(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.createWebhook(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns the full configuration of a single webhook by ID. */ public CompletableFuture getWebhook(String webhookId) { - return this.rawClient.getWebhook(webhookId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getWebhook(webhookId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns the full configuration of a single webhook by ID. */ public CompletableFuture getWebhook(String webhookId, RequestOptions requestOptions) { - return this.rawClient.getWebhook(webhookId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getWebhook(webhookId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns the full configuration of a single webhook by ID. */ public CompletableFuture getWebhook(String webhookId, GetWebhookRequest request) { - return this.rawClient.getWebhook(webhookId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getWebhook(webhookId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -117,7 +189,15 @@ public CompletableFuture getWebhook(String webhookId, Get */ public CompletableFuture getWebhook( String webhookId, GetWebhookRequest request, RequestOptions requestOptions) { - return this.rawClient.getWebhook(webhookId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getWebhook(webhookId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -125,7 +205,14 @@ public CompletableFuture getWebhook( *

Assigned jobs and event monitors no longer trigger delivery to this webhook. This operation cannot be undone.

*/ public CompletableFuture deleteWebhook(String webhookId) { - return this.rawClient.deleteWebhook(webhookId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteWebhook(webhookId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -133,7 +220,15 @@ public CompletableFuture deleteWebhook(String webhookId) { *

Assigned jobs and event monitors no longer trigger delivery to this webhook. This operation cannot be undone.

*/ public CompletableFuture deleteWebhook(String webhookId, RequestOptions requestOptions) { - return this.rawClient.deleteWebhook(webhookId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteWebhook(webhookId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -141,7 +236,14 @@ public CompletableFuture deleteWebhook(String webhookId, RequestOptions re *

Assigned jobs and event monitors no longer trigger delivery to this webhook. This operation cannot be undone.

*/ public CompletableFuture deleteWebhook(String webhookId, DeleteWebhookRequest request) { - return this.rawClient.deleteWebhook(webhookId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = this.rawClient.deleteWebhook(webhookId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -150,21 +252,45 @@ public CompletableFuture deleteWebhook(String webhookId, DeleteWebhookRequ */ public CompletableFuture deleteWebhook( String webhookId, DeleteWebhookRequest request, RequestOptions requestOptions) { - return this.rawClient.deleteWebhook(webhookId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.deleteWebhook(webhookId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates one or more fields of an existing webhook. */ public CompletableFuture updateWebhook(String webhookId) { - return this.rawClient.updateWebhook(webhookId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateWebhook(webhookId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Updates one or more fields of an existing webhook. */ public CompletableFuture updateWebhook(String webhookId, RequestOptions requestOptions) { - return this.rawClient.updateWebhook(webhookId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateWebhook(webhookId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -172,7 +298,15 @@ public CompletableFuture updateWebhook(String webhookI */ public CompletableFuture updateWebhook( String webhookId, UpdateWebhookRequestDto request) { - return this.rawClient.updateWebhook(webhookId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateWebhook(webhookId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -180,7 +314,15 @@ public CompletableFuture updateWebhook( */ public CompletableFuture updateWebhook( String webhookId, UpdateWebhookRequestDto request, RequestOptions requestOptions) { - return this.rawClient.updateWebhook(webhookId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.updateWebhook(webhookId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -188,7 +330,15 @@ public CompletableFuture updateWebhook( *

Use this to verify URL reachability and authentication before attaching the webhook to a live job or event monitor.

*/ public CompletableFuture testWebhook(String webhookId) { - return this.rawClient.testWebhook(webhookId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.testWebhook(webhookId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -196,7 +346,15 @@ public CompletableFuture testWebhook(String webhookId) { *

Use this to verify URL reachability and authentication before attaching the webhook to a live job or event monitor.

*/ public CompletableFuture testWebhook(String webhookId, RequestOptions requestOptions) { - return this.rawClient.testWebhook(webhookId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.testWebhook(webhookId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -204,7 +362,15 @@ public CompletableFuture testWebhook(String webhookId, R *

Use this to verify URL reachability and authentication before attaching the webhook to a live job or event monitor.

*/ public CompletableFuture testWebhook(String webhookId, TestWebhookRequestDto request) { - return this.rawClient.testWebhook(webhookId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.testWebhook(webhookId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -213,14 +379,30 @@ public CompletableFuture testWebhook(String webhookId, T */ public CompletableFuture testWebhook( String webhookId, TestWebhookRequestDto request, RequestOptions requestOptions) { - return this.rawClient.testWebhook(webhookId, request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.testWebhook(webhookId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** * Returns a paginated list of resources currently assigned to this webhook. */ public CompletableFuture listWebhookResources(String webhookId) { - return this.rawClient.listWebhookResources(webhookId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhookResources(webhookId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -228,7 +410,15 @@ public CompletableFuture listWebhookResources(S */ public CompletableFuture listWebhookResources( String webhookId, RequestOptions requestOptions) { - return this.rawClient.listWebhookResources(webhookId, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhookResources(webhookId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -236,7 +426,15 @@ public CompletableFuture listWebhookResources( */ public CompletableFuture listWebhookResources( String webhookId, ListWebhookResourcesRequest request) { - return this.rawClient.listWebhookResources(webhookId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhookResources(webhookId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -244,9 +442,15 @@ public CompletableFuture listWebhookResources( */ public CompletableFuture listWebhookResources( String webhookId, ListWebhookResourcesRequest request, RequestOptions requestOptions) { - return this.rawClient - .listWebhookResources(webhookId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhookResources(webhookId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -257,7 +461,15 @@ public CompletableFuture listWebhookResources( */ public CompletableFuture assignWebhookResource( String webhookId, AssignWebhookResourceRequestDto request) { - return this.rawClient.assignWebhookResource(webhookId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.assignWebhookResource(webhookId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -268,9 +480,15 @@ public CompletableFuture assignWebhookResource */ public CompletableFuture assignWebhookResource( String webhookId, AssignWebhookResourceRequestDto request, RequestOptions requestOptions) { - return this.rawClient - .assignWebhookResource(webhookId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.assignWebhookResource(webhookId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -279,9 +497,15 @@ public CompletableFuture assignWebhookResource */ public CompletableFuture removeWebhookResource( String webhookId, MappableResourceType resourceType, String resourceId) { - return this.rawClient - .removeWebhookResource(webhookId, resourceType, resourceId) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeWebhookResource(webhookId, resourceType, resourceId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -290,9 +514,15 @@ public CompletableFuture removeWebhookResource( */ public CompletableFuture removeWebhookResource( String webhookId, MappableResourceType resourceType, String resourceId, RequestOptions requestOptions) { - return this.rawClient - .removeWebhookResource(webhookId, resourceType, resourceId, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeWebhookResource(webhookId, resourceType, resourceId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -304,9 +534,15 @@ public CompletableFuture removeWebhookResource( MappableResourceType resourceType, String resourceId, RemoveWebhookResourceRequest request) { - return this.rawClient - .removeWebhookResource(webhookId, resourceType, resourceId, request) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeWebhookResource(webhookId, resourceType, resourceId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -319,9 +555,15 @@ public CompletableFuture removeWebhookResource( String resourceId, RemoveWebhookResourceRequest request, RequestOptions requestOptions) { - return this.rawClient - .removeWebhookResource(webhookId, resourceType, resourceId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.removeWebhookResource(webhookId, resourceType, resourceId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -329,7 +571,15 @@ public CompletableFuture removeWebhookResource( */ public CompletableFuture listWebhooksForResource( MappableResourceType resourceType, String resourceId) { - return this.rawClient.listWebhooksForResource(resourceType, resourceId).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooksForResource(resourceType, resourceId); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -337,9 +587,15 @@ public CompletableFuture listWebhooksForResource( */ public CompletableFuture listWebhooksForResource( MappableResourceType resourceType, String resourceId, RequestOptions requestOptions) { - return this.rawClient - .listWebhooksForResource(resourceType, resourceId, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooksForResource(resourceType, resourceId, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -347,9 +603,15 @@ public CompletableFuture listWebhooksForResource( */ public CompletableFuture listWebhooksForResource( MappableResourceType resourceType, String resourceId, ListWebhooksForResourceRequest request) { - return this.rawClient - .listWebhooksForResource(resourceType, resourceId, request) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooksForResource(resourceType, resourceId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -360,9 +622,15 @@ public CompletableFuture listWebhooksForResource( String resourceId, ListWebhooksForResourceRequest request, RequestOptions requestOptions) { - return this.rawClient - .listWebhooksForResource(resourceType, resourceId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.listWebhooksForResource(resourceType, resourceId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -374,7 +642,15 @@ public CompletableFuture listWebhooksForResource( */ public CompletableFuture triggerWebhook( MappableResourceType resourceType, String resourceId, TriggerWebhookRequest request) { - return this.rawClient.triggerWebhook(resourceType, resourceId, request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.triggerWebhook(resourceType, resourceId, request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -389,9 +665,15 @@ public CompletableFuture triggerWebhook( String resourceId, TriggerWebhookRequest request, RequestOptions requestOptions) { - return this.rawClient - .triggerWebhook(resourceType, resourceId, request, requestOptions) - .thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.triggerWebhook(resourceType, resourceId, request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -400,7 +682,15 @@ public CompletableFuture triggerWebhook( */ public CompletableFuture getWebhookDeliveryHistory( GetWebhookDeliveryHistoryRequest request) { - return this.rawClient.getWebhookDeliveryHistory(request).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getWebhookDeliveryHistory(request); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } /** @@ -409,6 +699,14 @@ public CompletableFuture getWebhookDeliveryHistory( */ public CompletableFuture getWebhookDeliveryHistory( GetWebhookDeliveryHistoryRequest request, RequestOptions requestOptions) { - return this.rawClient.getWebhookDeliveryHistory(request, requestOptions).thenApply(response -> response.body()); + CompletableFuture> rawFuture = + this.rawClient.getWebhookDeliveryHistory(request, requestOptions); + CompletableFuture future = rawFuture.thenApply(response -> response.body()); + future.whenComplete((result_, throwable_) -> { + if (future.isCancelled()) { + rawFuture.cancel(true); + } + }); + return future; } } diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/RawWebhooksClient.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/RawWebhooksClient.java index eff2608..41e5e1d 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/RawWebhooksClient.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/RawWebhooksClient.java @@ -4,12 +4,14 @@ package com.newscatcher.catchall.resources.webhooks; import com.fasterxml.jackson.core.JsonProcessingException; +import com.newscatcher.catchall.core.BodyProperties; import com.newscatcher.catchall.core.CatchAllApiApiException; import com.newscatcher.catchall.core.CatchAllApiException; import com.newscatcher.catchall.core.CatchAllApiHttpResponse; import com.newscatcher.catchall.core.ClientOptions; import com.newscatcher.catchall.core.MediaTypes; import com.newscatcher.catchall.core.ObjectMappers; +import com.newscatcher.catchall.core.PathSegments; import com.newscatcher.catchall.core.QueryStringMapper; import com.newscatcher.catchall.core.RequestOptions; import com.newscatcher.catchall.core.RetryInterceptor; @@ -188,7 +190,9 @@ public CatchAllApiHttpResponse createWebhook( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -278,7 +282,7 @@ public CatchAllApiHttpResponse getWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId); + .addPathSegment(PathSegments.validate(webhookId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -372,7 +376,7 @@ public CatchAllApiHttpResponse deleteWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId); + .addPathSegment(PathSegments.validate(webhookId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -380,7 +384,10 @@ public CatchAllApiHttpResponse deleteWebhook( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -459,7 +466,7 @@ public CatchAllApiHttpResponse updateWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId); + .addPathSegment(PathSegments.validate(webhookId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -468,7 +475,9 @@ public CatchAllApiHttpResponse updateWebhook( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -564,7 +573,7 @@ public CatchAllApiHttpResponse testWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId) + .addPathSegment(PathSegments.validate(webhookId)) .addPathSegments("test"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -574,7 +583,9 @@ public CatchAllApiHttpResponse testWebhook( RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -668,7 +679,7 @@ public CatchAllApiHttpResponse listWebhookResou HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId) + .addPathSegment(PathSegments.validate(webhookId)) .addPathSegments("resources"); if (request.getResourceType().isPresent()) { QueryStringMapper.addQueryParameter( @@ -765,7 +776,7 @@ public CatchAllApiHttpResponse assignWebhookRe HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId) + .addPathSegment(PathSegments.validate(webhookId)) .addPathSegments("resources"); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { @@ -775,7 +786,9 @@ public CatchAllApiHttpResponse assignWebhookRe RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(BodyProperties.merge( + request, requestOptions != null ? requestOptions.getBodyProperties() : null)), + MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { throw new CatchAllApiException("Failed to serialize request", e); } @@ -891,10 +904,10 @@ public CatchAllApiHttpResponse removeWebhookResource( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhooks") - .addPathSegment(webhookId) + .addPathSegment(PathSegments.validate(webhookId)) .addPathSegments("resources") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId); + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)); if (requestOptions != null) { requestOptions.getQueryParameters().forEach((_key, _value) -> { httpUrl.addQueryParameter(_key, _value); @@ -902,7 +915,10 @@ public CatchAllApiHttpResponse removeWebhookResource( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("DELETE", null) + .method( + "DELETE", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, null)) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); @@ -992,8 +1008,8 @@ public CatchAllApiHttpResponse listWebhooksForResource( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/resources") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId) + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)) .addPathSegments("webhooks"); if (request.getIsActive().isPresent()) { QueryStringMapper.addQueryParameter( @@ -1095,8 +1111,8 @@ public CatchAllApiHttpResponse triggerWebhook( HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("catchAll/webhook/trigger") - .addPathSegment(resourceType.toString()) - .addPathSegment(resourceId); + .addPathSegment(PathSegments.validate(resourceType.toString())) + .addPathSegment(PathSegments.validate(resourceId)); QueryStringMapper.addQueryParameter(httpUrl, "webhook_id", request.getWebhookId(), false); if (request.getJobId().isPresent()) { QueryStringMapper.addQueryParameter( @@ -1109,7 +1125,11 @@ public CatchAllApiHttpResponse triggerWebhook( } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) - .method("POST", RequestBody.create("", null)) + .method( + "POST", + BodyProperties.toRequestBody( + requestOptions != null ? requestOptions.getBodyProperties() : null, + RequestBody.create("", null))) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); Request okhttpRequest = _requestBuilder.build(); diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/AssignWebhookResourceRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/AssignWebhookResourceRequestDto.java index 1685f9b..d5f7c23 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/AssignWebhookResourceRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/AssignWebhookResourceRequestDto.java @@ -108,7 +108,6 @@ public static final class Builder implements ResourceTypeStage, ResourceIdStage, private String resourceId; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -147,6 +146,14 @@ public AssignWebhookResourceRequestDto build() { return new AssignWebhookResourceRequestDto(resourceType, resourceId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") || key.equalsIgnoreCase("resource_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/CreateWebhookRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/CreateWebhookRequestDto.java index e4ef4e9..dfe4c9d 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/CreateWebhookRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/CreateWebhookRequestDto.java @@ -344,7 +344,6 @@ public static final class Builder implements NameStage, UrlStage, _FinalStage { private Optional type = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -603,6 +602,23 @@ public CreateWebhookRequestDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("url") + || key.equalsIgnoreCase("type") + || key.equalsIgnoreCase("delivery_mode") + || key.equalsIgnoreCase("method") + || key.equalsIgnoreCase("headers") + || key.equalsIgnoreCase("params") + || key.equalsIgnoreCase("auth") + || key.equalsIgnoreCase("formatter_config") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/DeleteWebhookRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/DeleteWebhookRequest.java index c091afe..815d7da 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/DeleteWebhookRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/DeleteWebhookRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public DeleteWebhookRequest build() { return new DeleteWebhookRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookDeliveryHistoryRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookDeliveryHistoryRequest.java index 7ba6294..702692a 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookDeliveryHistoryRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookDeliveryHistoryRequest.java @@ -157,7 +157,6 @@ public static final class Builder implements ResourceTypeStage, ResourceIdStage, private Optional page = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -238,6 +237,17 @@ public GetWebhookDeliveryHistoryRequest build() { return new GetWebhookDeliveryHistoryRequest(resourceType, resourceId, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("resource_id") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookRequest.java index 14ec186..e754b2f 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/GetWebhookRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public GetWebhookRequest build() { return new GetWebhookRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhookResourcesRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhookResourcesRequest.java index 2a267e9..641f869 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhookResourcesRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhookResourcesRequest.java @@ -98,7 +98,6 @@ public static final class Builder { private Optional pageSize = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -153,6 +152,16 @@ public ListWebhookResourcesRequest build() { return new ListWebhookResourcesRequest(resourceType, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksForResourceRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksForResourceRequest.java index c27c392..2bca05d 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksForResourceRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksForResourceRequest.java @@ -100,7 +100,6 @@ public static final class Builder { private Optional pageSize = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -158,6 +157,16 @@ public ListWebhooksForResourceRequest build() { return new ListWebhooksForResourceRequest(isActive, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("is_active") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksRequest.java index f40bd1f..0c4e512 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/ListWebhooksRequest.java @@ -117,7 +117,6 @@ public static final class Builder { private Optional projectId = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -190,6 +189,17 @@ public ListWebhooksRequest build() { return new ListWebhooksRequest(page, pageSize, search, projectId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("search") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/RemoveWebhookResourceRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/RemoveWebhookResourceRequest.java index 2a6ef83..3adbe8a 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/RemoveWebhookResourceRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/RemoveWebhookResourceRequest.java @@ -43,7 +43,6 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -56,6 +55,11 @@ public RemoveWebhookResourceRequest build() { return new RemoveWebhookResourceRequest(additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TestWebhookRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TestWebhookRequestDto.java index 7787030..bac1389 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TestWebhookRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TestWebhookRequestDto.java @@ -71,7 +71,6 @@ public static Builder builder() { public static final class Builder { private Optional> payload = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -100,6 +99,14 @@ public TestWebhookRequestDto build() { return new TestWebhookRequestDto(payload, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("payload")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TriggerWebhookRequest.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TriggerWebhookRequest.java index de6d624..83374cf 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TriggerWebhookRequest.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/TriggerWebhookRequest.java @@ -112,7 +112,6 @@ public static final class Builder implements WebhookIdStage, _FinalStage { private Optional jobId = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -164,6 +163,14 @@ public TriggerWebhookRequest build() { return new TriggerWebhookRequest(webhookId, jobId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("webhook_id") || key.equalsIgnoreCase("job_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/UpdateWebhookRequestDto.java b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/UpdateWebhookRequestDto.java index 715b43a..83fd992 100644 --- a/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/UpdateWebhookRequestDto.java +++ b/src/main/java/com/newscatcher/catchall/resources/webhooks/requests/UpdateWebhookRequestDto.java @@ -225,7 +225,6 @@ public static final class Builder { private Optional isActive = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -401,6 +400,23 @@ public UpdateWebhookRequestDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("url") + || key.equalsIgnoreCase("type") + || key.equalsIgnoreCase("delivery_mode") + || key.equalsIgnoreCase("method") + || key.equalsIgnoreCase("headers") + || key.equalsIgnoreCase("params") + || key.equalsIgnoreCase("auth") + || key.equalsIgnoreCase("formatter_config") + || key.equalsIgnoreCase("is_active")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/AddResourceResponseDto.java b/src/main/java/com/newscatcher/catchall/types/AddResourceResponseDto.java index aafe018..546f364 100644 --- a/src/main/java/com/newscatcher/catchall/types/AddResourceResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/AddResourceResponseDto.java @@ -135,7 +135,6 @@ public static final class Builder implements SuccessStage, MessageStage, _FinalS private List results = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -210,6 +209,14 @@ public AddResourceResponseDto build() { return new AddResourceResponseDto(success, message, results, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") || key.equalsIgnoreCase("message") || key.equalsIgnoreCase("results")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/AdditionalAttributes.java b/src/main/java/com/newscatcher/catchall/types/AdditionalAttributes.java index de938d9..1c433e1 100644 --- a/src/main/java/com/newscatcher/catchall/types/AdditionalAttributes.java +++ b/src/main/java/com/newscatcher/catchall/types/AdditionalAttributes.java @@ -68,7 +68,6 @@ public static Builder builder() { public static final class Builder { private Optional companyAttributes = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -93,6 +92,14 @@ public AdditionalAttributes build() { return new AdditionalAttributes(companyAttributes, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("company_attributes")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthDto.java b/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthDto.java index 7490261..063d7f5 100644 --- a/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthDto.java @@ -106,7 +106,6 @@ public static final class Builder implements HeaderStage, ValueStage, _FinalStag private String value; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -145,6 +144,14 @@ public ApiKeyAuthDto build() { return new ApiKeyAuthDto(header, value, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("header") || key.equalsIgnoreCase("value")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthResponseDto.java index 3cd8a59..46e667c 100644 --- a/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ApiKeyAuthResponseDto.java @@ -105,7 +105,6 @@ public static final class Builder { private Optional value = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -170,6 +169,14 @@ public ApiKeyAuthResponseDto build() { return new ApiKeyAuthResponseDto(header, value, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("header") || key.equalsIgnoreCase("value")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/AssignWebhookResourceResponseDto.java b/src/main/java/com/newscatcher/catchall/types/AssignWebhookResourceResponseDto.java index 7965689..747baf4 100644 --- a/src/main/java/com/newscatcher/catchall/types/AssignWebhookResourceResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/AssignWebhookResourceResponseDto.java @@ -155,7 +155,6 @@ public static final class Builder implements SuccessStage, _FinalStage { private Optional message = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -246,6 +245,17 @@ public AssignWebhookResourceResponseDto build() { success, message, alreadyExisted, mapping, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("already_existed") + || key.equalsIgnoreCase("mapping")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/BaseRecord.java b/src/main/java/com/newscatcher/catchall/types/BaseRecord.java index c5c3515..bb8e020 100644 --- a/src/main/java/com/newscatcher/catchall/types/BaseRecord.java +++ b/src/main/java/com/newscatcher/catchall/types/BaseRecord.java @@ -138,7 +138,6 @@ public static final class Builder implements RecordIdStage, RecordTitleStage, En private BaseRecordEnrichment enrichment; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -191,6 +190,16 @@ public BaseRecord build() { return new BaseRecord(recordId, recordTitle, enrichment, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("record_id") + || key.equalsIgnoreCase("record_title") + || key.equalsIgnoreCase("enrichment")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/BaseRecordEnrichment.java b/src/main/java/com/newscatcher/catchall/types/BaseRecordEnrichment.java index 57c24a6..c76cf14 100644 --- a/src/main/java/com/newscatcher/catchall/types/BaseRecordEnrichment.java +++ b/src/main/java/com/newscatcher/catchall/types/BaseRecordEnrichment.java @@ -84,7 +84,6 @@ public static Builder builder() { public static final class Builder { private Optional enrichmentConfidence = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -123,6 +122,14 @@ public BaseRecordEnrichment build() { return new BaseRecordEnrichment(enrichmentConfidence, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("enrichment_confidence")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/BasicAuthDto.java b/src/main/java/com/newscatcher/catchall/types/BasicAuthDto.java index 5ed459f..dd18368 100644 --- a/src/main/java/com/newscatcher/catchall/types/BasicAuthDto.java +++ b/src/main/java/com/newscatcher/catchall/types/BasicAuthDto.java @@ -106,7 +106,6 @@ public static final class Builder implements UsernameStage, PasswordStage, _Fina private String password; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -145,6 +144,14 @@ public BasicAuthDto build() { return new BasicAuthDto(username, password, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("username") || key.equalsIgnoreCase("password")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/BasicAuthResponseDto.java b/src/main/java/com/newscatcher/catchall/types/BasicAuthResponseDto.java index a2430f3..4a0f870 100644 --- a/src/main/java/com/newscatcher/catchall/types/BasicAuthResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/BasicAuthResponseDto.java @@ -105,7 +105,6 @@ public static final class Builder { private Optional password = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -170,6 +169,14 @@ public BasicAuthResponseDto build() { return new BasicAuthResponseDto(username, password, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("username") || key.equalsIgnoreCase("password")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/BearerAuthDto.java b/src/main/java/com/newscatcher/catchall/types/BearerAuthDto.java index e323b39..f7ace7f 100644 --- a/src/main/java/com/newscatcher/catchall/types/BearerAuthDto.java +++ b/src/main/java/com/newscatcher/catchall/types/BearerAuthDto.java @@ -86,7 +86,6 @@ public interface _FinalStage { public static final class Builder implements TokenStage, _FinalStage { private String token; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -113,6 +112,14 @@ public BearerAuthDto build() { return new BearerAuthDto(token, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("token")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/BearerAuthResponseDto.java b/src/main/java/com/newscatcher/catchall/types/BearerAuthResponseDto.java index 30cad14..bb54505 100644 --- a/src/main/java/com/newscatcher/catchall/types/BearerAuthResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/BearerAuthResponseDto.java @@ -82,7 +82,6 @@ public static Builder builder() { public static final class Builder { private Optional token = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -121,6 +120,14 @@ public BearerAuthResponseDto build() { return new BearerAuthResponseDto(token, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("token")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/Citation.java b/src/main/java/com/newscatcher/catchall/types/Citation.java index 86aeba9..7a45ee9 100644 --- a/src/main/java/com/newscatcher/catchall/types/Citation.java +++ b/src/main/java/com/newscatcher/catchall/types/Citation.java @@ -131,7 +131,6 @@ public static final class Builder implements TitleStage, LinkStage, PublishedDat private OffsetDateTime publishedDate; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -182,6 +181,16 @@ public Citation build() { return new Citation(title, link, publishedDate, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("title") + || key.equalsIgnoreCase("link") + || key.equalsIgnoreCase("published_date")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CompanyAttributes.java b/src/main/java/com/newscatcher/catchall/types/CompanyAttributes.java index 9ef8303..57f29e6 100644 --- a/src/main/java/com/newscatcher/catchall/types/CompanyAttributes.java +++ b/src/main/java/com/newscatcher/catchall/types/CompanyAttributes.java @@ -134,7 +134,6 @@ public static final class Builder { private Optional> alternativeNames = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -226,6 +225,16 @@ public CompanyAttributes build() { return new CompanyAttributes(domain, keyPersons, alternativeNames, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("domain") + || key.equalsIgnoreCase("key_persons") + || key.equalsIgnoreCase("alternative_names")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutput.java b/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutput.java index 5a49145..30c1391 100644 --- a/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutput.java +++ b/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutput.java @@ -124,7 +124,6 @@ public static final class Builder implements SourceTextStage, ConfidenceStage, M private CompanyEnrichmentOutputMetadata metadata; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -171,6 +170,16 @@ public CompanyEnrichmentOutput build() { return new CompanyEnrichmentOutput(sourceText, confidence, metadata, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("source_text") + || key.equalsIgnoreCase("confidence") + || key.equalsIgnoreCase("metadata")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutputMetadata.java b/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutputMetadata.java index 4568775..fe064bf 100644 --- a/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutputMetadata.java +++ b/src/main/java/com/newscatcher/catchall/types/CompanyEnrichmentOutputMetadata.java @@ -161,7 +161,6 @@ public static final class Builder implements NameStage, _FinalStage { private Optional domainUrl = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -264,6 +263,16 @@ public CompanyEnrichmentOutputMetadata build() { return new CompanyEnrichmentOutputMetadata(name, domainUrl, domainUrlConfidence, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("domain_url") + || key.equalsIgnoreCase("domain_url_confidence")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ConnectedDataset.java b/src/main/java/com/newscatcher/catchall/types/ConnectedDataset.java index 7330802..378adfe 100644 --- a/src/main/java/com/newscatcher/catchall/types/ConnectedDataset.java +++ b/src/main/java/com/newscatcher/catchall/types/ConnectedDataset.java @@ -129,7 +129,6 @@ public static final class Builder implements IdStage, NameStage, _FinalStage { private Optional isDeleted = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -189,6 +188,14 @@ public ConnectedDataset build() { return new ConnectedDataset(id, name, isDeleted, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") || key.equalsIgnoreCase("name") || key.equalsIgnoreCase("is_deleted")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ConnectedEntity.java b/src/main/java/com/newscatcher/catchall/types/ConnectedEntity.java index af30735..4bde016 100644 --- a/src/main/java/com/newscatcher/catchall/types/ConnectedEntity.java +++ b/src/main/java/com/newscatcher/catchall/types/ConnectedEntity.java @@ -281,7 +281,6 @@ public static final class Builder private Optional associationType = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -452,6 +451,21 @@ public ConnectedEntity build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("entity_id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("ed_score") + || key.equalsIgnoreCase("relation") + || key.equalsIgnoreCase("association_type") + || key.equalsIgnoreCase("type") + || key.equalsIgnoreCase("external_entity_id") + || key.equalsIgnoreCase("company")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ContinueResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ContinueResponseDto.java index 640ed31..4353a37 100644 --- a/src/main/java/com/newscatcher/catchall/types/ContinueResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ContinueResponseDto.java @@ -156,7 +156,6 @@ public static final class Builder implements JobIdStage, NewLimitStage, StatusSt private Optional previousLimit = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -228,6 +227,17 @@ public ContinueResponseDto build() { return new ContinueResponseDto(jobId, previousLimit, newLimit, status, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id") + || key.equalsIgnoreCase("previous_limit") + || key.equalsIgnoreCase("new_limit") + || key.equalsIgnoreCase("status")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateDatasetCsvResponse.java b/src/main/java/com/newscatcher/catchall/types/CreateDatasetCsvResponse.java index f2d7836..93a8101 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateDatasetCsvResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateDatasetCsvResponse.java @@ -149,7 +149,6 @@ public static final class Builder private ValidationReport validationReport; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -209,6 +208,17 @@ public CreateDatasetCsvResponse build() { datasetId, datasetName, entitiesCreated, validationReport, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("dataset_id") + || key.equalsIgnoreCase("dataset_name") + || key.equalsIgnoreCase("entities_created") + || key.equalsIgnoreCase("validation_report")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateEntitiesBatchResponse.java b/src/main/java/com/newscatcher/catchall/types/CreateEntitiesBatchResponse.java index 6317813..c97f61c 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateEntitiesBatchResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateEntitiesBatchResponse.java @@ -111,7 +111,6 @@ public static final class Builder implements CountStage, _FinalStage { private List entities = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -174,6 +173,14 @@ public CreateEntitiesBatchResponse build() { return new CreateEntitiesBatchResponse(entities, count, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("entities") || key.equalsIgnoreCase("count")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateEntityRequest.java b/src/main/java/com/newscatcher/catchall/types/CreateEntityRequest.java index 0264d6b..eb96ad2 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateEntityRequest.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateEntityRequest.java @@ -167,7 +167,6 @@ public static final class Builder implements NameStage, _FinalStage { private Optional entityType = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -265,6 +264,18 @@ public CreateEntityRequest build() { name, entityType, description, externalEntityId, additionalAttributes, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("entity_type") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("external_entity_id") + || key.equalsIgnoreCase("additional_attributes")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateEntityResponse.java b/src/main/java/com/newscatcher/catchall/types/CreateEntityResponse.java index e7c01b5..775a038 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateEntityResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateEntityResponse.java @@ -106,7 +106,6 @@ public static final class Builder implements IdStage, StatusStage, _FinalStage { private String status; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -145,6 +144,14 @@ public CreateEntityResponse build() { return new CreateEntityResponse(id, status, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") || key.equalsIgnoreCase("status")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateMonitorResponseDto.java b/src/main/java/com/newscatcher/catchall/types/CreateMonitorResponseDto.java index 7b1129b..fdaf1e2 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateMonitorResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateMonitorResponseDto.java @@ -123,7 +123,6 @@ public static final class Builder implements StatusStage, _FinalStage { private Optional monitorId = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -187,6 +186,14 @@ public CreateMonitorResponseDto build() { return new CreateMonitorResponseDto(monitorId, status, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("monitor_id") || key.equalsIgnoreCase("status")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateProjectResponseDto.java b/src/main/java/com/newscatcher/catchall/types/CreateProjectResponseDto.java index 7e60d99..3d6ef6a 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateProjectResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateProjectResponseDto.java @@ -150,7 +150,6 @@ public static final class Builder implements SuccessStage, MessageStage, Project private String name; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -213,6 +212,17 @@ public CreateProjectResponseDto build() { return new CreateProjectResponseDto(success, message, projectId, name, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("project_id") + || key.equalsIgnoreCase("name")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/CreateWebhookResponseDto.java b/src/main/java/com/newscatcher/catchall/types/CreateWebhookResponseDto.java index 482354f..0d3c927 100644 --- a/src/main/java/com/newscatcher/catchall/types/CreateWebhookResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/CreateWebhookResponseDto.java @@ -132,7 +132,6 @@ public static final class Builder implements SuccessStage, MessageStage, _FinalS private Optional webhook = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -192,6 +191,14 @@ public CreateWebhookResponseDto build() { return new CreateWebhookResponseDto(success, message, webhook, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") || key.equalsIgnoreCase("message") || key.equalsIgnoreCase("webhook")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DatasetEntityIdsRequest.java b/src/main/java/com/newscatcher/catchall/types/DatasetEntityIdsRequest.java index 36b79f1..51ae3ad 100644 --- a/src/main/java/com/newscatcher/catchall/types/DatasetEntityIdsRequest.java +++ b/src/main/java/com/newscatcher/catchall/types/DatasetEntityIdsRequest.java @@ -71,7 +71,6 @@ public static Builder builder() { public static final class Builder { private List entityIds = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -109,6 +108,14 @@ public DatasetEntityIdsRequest build() { return new DatasetEntityIdsRequest(entityIds, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("entity_ids")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/DatasetEntityListResponse.java b/src/main/java/com/newscatcher/catchall/types/DatasetEntityListResponse.java index 80a72c0..20ff0be 100644 --- a/src/main/java/com/newscatcher/catchall/types/DatasetEntityListResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/DatasetEntityListResponse.java @@ -154,7 +154,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List entities = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -241,6 +240,17 @@ public DatasetEntityListResponse build() { return new DatasetEntityListResponse(entities, total, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("entities") + || key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DatasetListResponse.java b/src/main/java/com/newscatcher/catchall/types/DatasetListResponse.java index 87088f5..75fc193 100644 --- a/src/main/java/com/newscatcher/catchall/types/DatasetListResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/DatasetListResponse.java @@ -158,7 +158,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List datasets = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -245,6 +244,17 @@ public DatasetListResponse build() { return new DatasetListResponse(datasets, total, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("datasets") + || key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DatasetResponse.java b/src/main/java/com/newscatcher/catchall/types/DatasetResponse.java index b759280..0722770 100644 --- a/src/main/java/com/newscatcher/catchall/types/DatasetResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/DatasetResponse.java @@ -359,7 +359,6 @@ public static final class Builder implements IdStage, OrganizationIdStage, NameS private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -627,6 +626,25 @@ public DatasetResponse build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("organization_id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("entity_count") + || key.equalsIgnoreCase("entity_status_breakdown") + || key.equalsIgnoreCase("health_score") + || key.equalsIgnoreCase("health_breakdown") + || key.equalsIgnoreCase("latest_status") + || key.equalsIgnoreCase("created_by_user_id") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("updated_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DatasetStatusEntry.java b/src/main/java/com/newscatcher/catchall/types/DatasetStatusEntry.java index a78fbf1..62019d8 100644 --- a/src/main/java/com/newscatcher/catchall/types/DatasetStatusEntry.java +++ b/src/main/java/com/newscatcher/catchall/types/DatasetStatusEntry.java @@ -143,7 +143,6 @@ public static final class Builder implements StatusStage, _FinalStage { private Optional> additionalInformation = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -224,6 +223,16 @@ public DatasetStatusEntry build() { return new DatasetStatusEntry(status, additionalInformation, createdAt, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("additional_information") + || key.equalsIgnoreCase("created_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DatasetStatusHistoryResponse.java b/src/main/java/com/newscatcher/catchall/types/DatasetStatusHistoryResponse.java index 76227be..a4a267d 100644 --- a/src/main/java/com/newscatcher/catchall/types/DatasetStatusHistoryResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/DatasetStatusHistoryResponse.java @@ -112,7 +112,6 @@ public static final class Builder implements DatasetIdStage, _FinalStage { private List history = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -175,6 +174,14 @@ public DatasetStatusHistoryResponse build() { return new DatasetStatusHistoryResponse(datasetId, history, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("dataset_id") || key.equalsIgnoreCase("history")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DeleteJobResponseDto.java b/src/main/java/com/newscatcher/catchall/types/DeleteJobResponseDto.java index 4a632e2..b7c900e 100644 --- a/src/main/java/com/newscatcher/catchall/types/DeleteJobResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/DeleteJobResponseDto.java @@ -156,7 +156,6 @@ public static final class Builder implements SuccessStage, _FinalStage { private Optional message = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -257,6 +256,14 @@ public DeleteJobResponseDto build() { return new DeleteJobResponseDto(success, message, jobId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") || key.equalsIgnoreCase("message") || key.equalsIgnoreCase("job_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DeleteMonitorResponseDto.java b/src/main/java/com/newscatcher/catchall/types/DeleteMonitorResponseDto.java index eace4c5..ce7ab03 100644 --- a/src/main/java/com/newscatcher/catchall/types/DeleteMonitorResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/DeleteMonitorResponseDto.java @@ -156,7 +156,6 @@ public static final class Builder implements SuccessStage, _FinalStage { private Optional message = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -257,6 +256,16 @@ public DeleteMonitorResponseDto build() { return new DeleteMonitorResponseDto(success, message, monitorId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("monitor_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryItemDto.java b/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryItemDto.java index 8a58809..348fd39 100644 --- a/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryItemDto.java +++ b/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryItemDto.java @@ -356,7 +356,6 @@ public static final class Builder private Optional> additionalInfo = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -574,6 +573,24 @@ public DeliveryHistoryItemDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("webhook_id") + || key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("resource_id") + || key.equalsIgnoreCase("additional_info") + || key.equalsIgnoreCase("status_code") + || key.equalsIgnoreCase("attempt_number") + || key.equalsIgnoreCase("timestamp") + || key.equalsIgnoreCase("delivery_status") + || key.equalsIgnoreCase("error_message") + || key.equalsIgnoreCase("warning_message")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryResponseDto.java b/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryResponseDto.java index e140239..84d5795 100644 --- a/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/DeliveryHistoryResponseDto.java @@ -233,7 +233,6 @@ public static final class Builder private List items = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -357,6 +356,20 @@ public DeliveryHistoryResponseDto build() { resourceType, resourceId, total, page, pageSize, totalPages, items, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("resource_id") + || key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("items")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/EnrichmentSchema.java b/src/main/java/com/newscatcher/catchall/types/EnrichmentSchema.java index b53399d..8764fd1 100644 --- a/src/main/java/com/newscatcher/catchall/types/EnrichmentSchema.java +++ b/src/main/java/com/newscatcher/catchall/types/EnrichmentSchema.java @@ -121,7 +121,6 @@ public static final class Builder implements NameStage, DescriptionStage, TypeSt private EnrichmentType type; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -168,6 +167,14 @@ public EnrichmentSchema build() { return new EnrichmentSchema(name, description, type, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description") || key.equalsIgnoreCase("type")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/EntityListResponse.java b/src/main/java/com/newscatcher/catchall/types/EntityListResponse.java index 9089af9..55cecd5 100644 --- a/src/main/java/com/newscatcher/catchall/types/EntityListResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/EntityListResponse.java @@ -158,7 +158,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List entities = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -245,6 +244,17 @@ public EntityListResponse build() { return new EntityListResponse(entities, total, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("entities") + || key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/EntityResponse.java b/src/main/java/com/newscatcher/catchall/types/EntityResponse.java index dbe8d5f..837f088 100644 --- a/src/main/java/com/newscatcher/catchall/types/EntityResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/EntityResponse.java @@ -330,7 +330,6 @@ public static final class Builder private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -560,6 +559,24 @@ public EntityResponse build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("entity_type") + || key.equalsIgnoreCase("organization_id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("external_entity_id") + || key.equalsIgnoreCase("additional_attributes") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("created_by_user_id") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("updated_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/EntitySummary.java b/src/main/java/com/newscatcher/catchall/types/EntitySummary.java index 28faf38..8c99cfe 100644 --- a/src/main/java/com/newscatcher/catchall/types/EntitySummary.java +++ b/src/main/java/com/newscatcher/catchall/types/EntitySummary.java @@ -236,7 +236,6 @@ public static final class Builder implements IdStage, NameStage, EntityTypeStage private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -380,6 +379,20 @@ public EntitySummary build() { id, name, entityType, status, description, externalEntityId, attributes, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("entity_type") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("external_entity_id") + || key.equalsIgnoreCase("attributes")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/EntityValidationErrorBody.java b/src/main/java/com/newscatcher/catchall/types/EntityValidationErrorBody.java index 073850f..01dd9cd 100644 --- a/src/main/java/com/newscatcher/catchall/types/EntityValidationErrorBody.java +++ b/src/main/java/com/newscatcher/catchall/types/EntityValidationErrorBody.java @@ -129,7 +129,6 @@ public static final class Builder implements MessageStage, StatusStage, StatusCo private int statusCode; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -181,6 +180,16 @@ public EntityValidationErrorBody build() { return new EntityValidationErrorBody(message, status, statusCode, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("status_code")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/Error.java b/src/main/java/com/newscatcher/catchall/types/Error.java index 37591e5..a32b62e 100644 --- a/src/main/java/com/newscatcher/catchall/types/Error.java +++ b/src/main/java/com/newscatcher/catchall/types/Error.java @@ -70,7 +70,6 @@ public static Builder builder() { public static final class Builder { private Optional detail = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -98,6 +97,14 @@ public Error build() { return new Error(detail, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("detail")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/EventTags.java b/src/main/java/com/newscatcher/catchall/types/EventTags.java index ce6fa9d..dd44f8e 100644 --- a/src/main/java/com/newscatcher/catchall/types/EventTags.java +++ b/src/main/java/com/newscatcher/catchall/types/EventTags.java @@ -106,7 +106,6 @@ public static final class Builder { private Optional sector = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -173,6 +172,14 @@ public EventTags build() { return new EventTags(eventType, sector, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("event_type") || key.equalsIgnoreCase("sector")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/FormatterConfigDto.java b/src/main/java/com/newscatcher/catchall/types/FormatterConfigDto.java index 73557f1..5bf9c04 100644 --- a/src/main/java/com/newscatcher/catchall/types/FormatterConfigDto.java +++ b/src/main/java/com/newscatcher/catchall/types/FormatterConfigDto.java @@ -113,7 +113,6 @@ public static final class Builder implements TemplateStage, _FinalStage { private Optional contentType = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -165,6 +164,14 @@ public FormatterConfigDto build() { return new FormatterConfigDto(template, contentType, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("template") || key.equalsIgnoreCase("content_type")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/GetPlanLimitsResponseDto.java b/src/main/java/com/newscatcher/catchall/types/GetPlanLimitsResponseDto.java index 49a4492..0df698b 100644 --- a/src/main/java/com/newscatcher/catchall/types/GetPlanLimitsResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/GetPlanLimitsResponseDto.java @@ -71,7 +71,6 @@ public static Builder builder() { public static final class Builder { private List features = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -109,6 +108,14 @@ public GetPlanLimitsResponseDto build() { return new GetPlanLimitsResponseDto(features, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("features")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/GetWebhookResponseDto.java b/src/main/java/com/newscatcher/catchall/types/GetWebhookResponseDto.java index dfacd88..1133ba9 100644 --- a/src/main/java/com/newscatcher/catchall/types/GetWebhookResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/GetWebhookResponseDto.java @@ -132,7 +132,6 @@ public static final class Builder implements SuccessStage, MessageStage, _FinalS private Optional webhook = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -192,6 +191,14 @@ public GetWebhookResponseDto build() { return new GetWebhookResponseDto(success, message, webhook, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") || key.equalsIgnoreCase("message") || key.equalsIgnoreCase("webhook")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/InitializeResponseDto.java b/src/main/java/com/newscatcher/catchall/types/InitializeResponseDto.java index 19832fa..21f07ef 100644 --- a/src/main/java/com/newscatcher/catchall/types/InitializeResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/InitializeResponseDto.java @@ -246,7 +246,6 @@ public static final class Builder implements QueryStage, _FinalStage { private Optional context = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -450,6 +449,20 @@ public InitializeResponseDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("query") + || key.equalsIgnoreCase("context") + || key.equalsIgnoreCase("validators") + || key.equalsIgnoreCase("enrichments") + || key.equalsIgnoreCase("start_date") + || key.equalsIgnoreCase("end_date") + || key.equalsIgnoreCase("date_modification_message")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/JobStep.java b/src/main/java/com/newscatcher/catchall/types/JobStep.java index d47687f..3f05627 100644 --- a/src/main/java/com/newscatcher/catchall/types/JobStep.java +++ b/src/main/java/com/newscatcher/catchall/types/JobStep.java @@ -120,7 +120,6 @@ public static final class Builder implements StatusStage, OrderStage, CompletedS private boolean completed; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -167,6 +166,14 @@ public JobStep build() { return new JobStep(status, order, completed, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("status") || key.equalsIgnoreCase("order") || key.equalsIgnoreCase("completed")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ListMonitorsResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ListMonitorsResponseDto.java index 76da96f..fe768f7 100644 --- a/src/main/java/com/newscatcher/catchall/types/ListMonitorsResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ListMonitorsResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List monitors = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -279,6 +278,18 @@ public ListMonitorsResponseDto build() { return new ListMonitorsResponseDto(total, page, pageSize, totalPages, monitors, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("monitors")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ListSourceGroupsResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ListSourceGroupsResponseDto.java index 01d7e71..4fe20d8 100644 --- a/src/main/java/com/newscatcher/catchall/types/ListSourceGroupsResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ListSourceGroupsResponseDto.java @@ -158,7 +158,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List sourceGroups = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -245,6 +244,17 @@ public ListSourceGroupsResponseDto build() { return new ListSourceGroupsResponseDto(sourceGroups, total, page, pageSize, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("source_groups") + || key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ListUserJobsResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ListUserJobsResponseDto.java index ec7d515..ec426a0 100644 --- a/src/main/java/com/newscatcher/catchall/types/ListUserJobsResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ListUserJobsResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List jobs = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -279,6 +278,18 @@ public ListUserJobsResponseDto build() { return new ListUserJobsResponseDto(total, page, pageSize, totalPages, jobs, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("jobs")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ListWebhookResourcesResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ListWebhookResourcesResponseDto.java index 2fd181d..09a3bf0 100644 --- a/src/main/java/com/newscatcher/catchall/types/ListWebhookResourcesResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ListWebhookResourcesResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List resources = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -280,6 +279,18 @@ public ListWebhookResourcesResponseDto build() { total, page, pageSize, totalPages, resources, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("resources")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ListWebhooksResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ListWebhooksResponseDto.java index 1d46dd2..66131f6 100644 --- a/src/main/java/com/newscatcher/catchall/types/ListWebhooksResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ListWebhooksResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List webhooks = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -279,6 +278,18 @@ public ListWebhooksResponseDto build() { return new ListWebhooksResponseDto(total, page, pageSize, totalPages, webhooks, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("webhooks")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ManageEntitiesResponse.java b/src/main/java/com/newscatcher/catchall/types/ManageEntitiesResponse.java index c544e0e..f738a2e 100644 --- a/src/main/java/com/newscatcher/catchall/types/ManageEntitiesResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/ManageEntitiesResponse.java @@ -106,7 +106,6 @@ public static final class Builder implements DatasetIdStage, AffectedCountStage, private int affectedCount; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -145,6 +144,14 @@ public ManageEntitiesResponse build() { return new ManageEntitiesResponse(datasetId, affectedCount, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("dataset_id") || key.equalsIgnoreCase("affected_count")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/MonitorCitation.java b/src/main/java/com/newscatcher/catchall/types/MonitorCitation.java index d4d4271..d1d68cd 100644 --- a/src/main/java/com/newscatcher/catchall/types/MonitorCitation.java +++ b/src/main/java/com/newscatcher/catchall/types/MonitorCitation.java @@ -203,7 +203,6 @@ public static final class Builder private OffsetDateTime addedOn; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -290,6 +289,19 @@ public MonitorCitation build() { return new MonitorCitation(title, link, publishedDate, id, jobId, addedOn, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("title") + || key.equalsIgnoreCase("link") + || key.equalsIgnoreCase("published_date") + || key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("job_id") + || key.equalsIgnoreCase("added_on")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/MonitorJobItem.java b/src/main/java/com/newscatcher/catchall/types/MonitorJobItem.java index 7939abd..9046ffe 100644 --- a/src/main/java/com/newscatcher/catchall/types/MonitorJobItem.java +++ b/src/main/java/com/newscatcher/catchall/types/MonitorJobItem.java @@ -128,7 +128,6 @@ public static final class Builder implements JobIdStage, StartDateStage, EndDate private OffsetDateTime endDate; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -179,6 +178,16 @@ public MonitorJobItem build() { return new MonitorJobItem(jobId, startDate, endDate, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id") + || key.equalsIgnoreCase("start_date") + || key.equalsIgnoreCase("end_date")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/MonitorListItemDto.java b/src/main/java/com/newscatcher/catchall/types/MonitorListItemDto.java index 5b531bd..9e298bb 100644 --- a/src/main/java/com/newscatcher/catchall/types/MonitorListItemDto.java +++ b/src/main/java/com/newscatcher/catchall/types/MonitorListItemDto.java @@ -337,7 +337,6 @@ public static final class Builder private Optional schedule = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -575,6 +574,24 @@ public MonitorListItemDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("monitor_id") + || key.equalsIgnoreCase("reference_job_id") + || key.equalsIgnoreCase("reference_job_query") + || key.equalsIgnoreCase("enabled") + || key.equalsIgnoreCase("schedule") + || key.equalsIgnoreCase("schedule_human_readable") + || key.equalsIgnoreCase("timezone") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("webhook") + || key.equalsIgnoreCase("user_key") + || key.equalsIgnoreCase("sharing_info")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/MonitorRecord.java b/src/main/java/com/newscatcher/catchall/types/MonitorRecord.java index 9cf7059..cedaaca 100644 --- a/src/main/java/com/newscatcher/catchall/types/MonitorRecord.java +++ b/src/main/java/com/newscatcher/catchall/types/MonitorRecord.java @@ -212,7 +212,6 @@ public static final class Builder implements RecordIdStage, RecordTitleStage, En private List citations = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -344,6 +343,19 @@ public MonitorRecord build() { recordId, recordTitle, enrichment, citations, addedOn, updatedOn, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("record_id") + || key.equalsIgnoreCase("record_title") + || key.equalsIgnoreCase("enrichment") + || key.equalsIgnoreCase("citations") + || key.equalsIgnoreCase("added_on") + || key.equalsIgnoreCase("updated_on")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/MonitorStatusEntry.java b/src/main/java/com/newscatcher/catchall/types/MonitorStatusEntry.java index d311f04..983e654 100644 --- a/src/main/java/com/newscatcher/catchall/types/MonitorStatusEntry.java +++ b/src/main/java/com/newscatcher/catchall/types/MonitorStatusEntry.java @@ -209,7 +209,6 @@ public static final class Builder implements StatusStage, CreatedAtStage, _Final private Optional> additionalInformation = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -353,6 +352,16 @@ public MonitorStatusEntry build() { return new MonitorStatusEntry(status, createdAt, additionalInformation, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("additional_information")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/MonitorStatusHistoryResponseDto.java b/src/main/java/com/newscatcher/catchall/types/MonitorStatusHistoryResponseDto.java index 8860e20..f987e92 100644 --- a/src/main/java/com/newscatcher/catchall/types/MonitorStatusHistoryResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/MonitorStatusHistoryResponseDto.java @@ -225,7 +225,6 @@ public static final class Builder implements SuccessStage, _FinalStage { private Optional message = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -401,6 +400,18 @@ public MonitorStatusHistoryResponseDto build() { success, message, monitorId, totalStatuses, statuses, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("monitor_id") + || key.equalsIgnoreCase("total_statuses") + || key.equalsIgnoreCase("statuses")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/PlanFeature.java b/src/main/java/com/newscatcher/catchall/types/PlanFeature.java index c7096c2..bf55a7d 100644 --- a/src/main/java/com/newscatcher/catchall/types/PlanFeature.java +++ b/src/main/java/com/newscatcher/catchall/types/PlanFeature.java @@ -178,7 +178,6 @@ public static final class Builder implements NameStage, CodeStage, _FinalStage { private Optional valueType = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -280,6 +279,18 @@ public PlanFeature build() { return new PlanFeature(name, code, valueType, value, currentUsage, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("code") + || key.equalsIgnoreCase("value_type") + || key.equalsIgnoreCase("value") + || key.equalsIgnoreCase("current_usage")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectListResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ProjectListResponseDto.java index 502f7cc..cf73e5c 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectListResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectListResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List projects = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -279,6 +278,18 @@ public ProjectListResponseDto build() { return new ProjectListResponseDto(total, page, pageSize, totalPages, projects, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("projects")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDto.java index 0e7c72b..e46aa95 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDto.java @@ -107,7 +107,6 @@ public static final class Builder implements ProjectIdStage, OverviewStage, _Fin private ProjectOverviewResponseDtoOverview overview; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -146,6 +145,14 @@ public ProjectOverviewResponseDto build() { return new ProjectOverviewResponseDto(projectId, overview, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("project_id") || key.equalsIgnoreCase("overview")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDtoOverview.java b/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDtoOverview.java index 88dd730..b34a1e1 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDtoOverview.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectOverviewResponseDtoOverview.java @@ -118,7 +118,6 @@ public static final class Builder { private Map webhooks = new LinkedHashMap<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -242,6 +241,18 @@ public ProjectOverviewResponseDtoOverview build() { jobs, monitors, datasets, monitorGroups, webhooks, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("jobs") + || key.equalsIgnoreCase("monitors") + || key.equalsIgnoreCase("datasets") + || key.equalsIgnoreCase("monitor_groups") + || key.equalsIgnoreCase("webhooks")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectResourceDto.java b/src/main/java/com/newscatcher/catchall/types/ProjectResourceDto.java index 46e5e72..b513be9 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectResourceDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectResourceDto.java @@ -175,7 +175,6 @@ public static final class Builder implements ResourceTypeStage, ResourceIdStage, private Optional name = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -275,6 +274,18 @@ public ProjectResourceDto build() { return new ProjectResourceDto(resourceType, resourceId, name, createdAt, metadata, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("resource_id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("metadata")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectResourceListResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ProjectResourceListResponseDto.java index da0e3ae..43c67b0 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectResourceListResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectResourceListResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder implements TotalStage, PageStage, PageSizeStag private List resources = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -280,6 +279,18 @@ public ProjectResourceListResponseDto build() { total, page, pageSize, totalPages, resources, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("resources")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ProjectResponseDto.java index c4b7a8a..0913206 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectResponseDto.java @@ -267,7 +267,6 @@ public static final class Builder implements SuccessStage, MessageStage, Project private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -439,6 +438,21 @@ public ProjectResponseDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("project_id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("resources_count") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("updated_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ProjectSummaryDto.java b/src/main/java/com/newscatcher/catchall/types/ProjectSummaryDto.java index a661113..28f03a2 100644 --- a/src/main/java/com/newscatcher/catchall/types/ProjectSummaryDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ProjectSummaryDto.java @@ -216,7 +216,6 @@ public static final class Builder implements ProjectIdStage, NameStage, _FinalSt private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -356,6 +355,19 @@ public ProjectSummaryDto build() { projectId, name, description, resourcesCount, createdAt, updatedAt, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("project_id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("resources_count") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("updated_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/PullJobResponseDto.java b/src/main/java/com/newscatcher/catchall/types/PullJobResponseDto.java index 53dff2a..bbe4288 100644 --- a/src/main/java/com/newscatcher/catchall/types/PullJobResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/PullJobResponseDto.java @@ -620,7 +620,6 @@ public static final class Builder implements JobIdStage, _FinalStage { private Optional query = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -1174,6 +1173,35 @@ public PullJobResponseDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id") + || key.equalsIgnoreCase("query") + || key.equalsIgnoreCase("context") + || key.equalsIgnoreCase("validators") + || key.equalsIgnoreCase("enrichments") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("error") + || key.equalsIgnoreCase("limit") + || key.equalsIgnoreCase("duration") + || key.equalsIgnoreCase("candidate_records") + || key.equalsIgnoreCase("valid_records") + || key.equalsIgnoreCase("progress_validated") + || key.equalsIgnoreCase("date_range") + || key.equalsIgnoreCase("page") + || key.equalsIgnoreCase("page_size") + || key.equalsIgnoreCase("total_pages") + || key.equalsIgnoreCase("mode") + || key.equalsIgnoreCase("connected_datasets") + || key.equalsIgnoreCase("source_groups") + || key.equalsIgnoreCase("is_all_news_query") + || key.equalsIgnoreCase("sharing_info") + || key.equalsIgnoreCase("all_records")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/PullJobResponseDtoDateRange.java b/src/main/java/com/newscatcher/catchall/types/PullJobResponseDtoDateRange.java index bd79177..350b871 100644 --- a/src/main/java/com/newscatcher/catchall/types/PullJobResponseDtoDateRange.java +++ b/src/main/java/com/newscatcher/catchall/types/PullJobResponseDtoDateRange.java @@ -81,7 +81,6 @@ public static final class Builder { private Optional endDate = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -118,6 +117,14 @@ public PullJobResponseDtoDateRange build() { return new PullJobResponseDtoDateRange(startDate, endDate, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("start_date") || key.equalsIgnoreCase("end_date")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDto.java b/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDto.java index acdbd31..83b4372 100644 --- a/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDto.java @@ -332,7 +332,6 @@ public static final class Builder implements MonitorIdStage, ReferenceJobStage, private Optional cronExpression = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -577,6 +576,24 @@ public PullMonitorResponseDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("monitor_id") + || key.equalsIgnoreCase("cron_expression") + || key.equalsIgnoreCase("timezone") + || key.equalsIgnoreCase("reference_job") + || key.equalsIgnoreCase("run_info") + || key.equalsIgnoreCase("records") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("all_records") + || key.equalsIgnoreCase("limit") + || key.equalsIgnoreCase("connected_datasets") + || key.equalsIgnoreCase("is_all_news_query")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDtoRunInfo.java b/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDtoRunInfo.java index 64ffe59..5413f0b 100644 --- a/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDtoRunInfo.java +++ b/src/main/java/com/newscatcher/catchall/types/PullMonitorResponseDtoRunInfo.java @@ -87,7 +87,6 @@ public static final class Builder { private Optional lastRun = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -130,6 +129,14 @@ public PullMonitorResponseDtoRunInfo build() { return new PullMonitorResponseDtoRunInfo(firstRun, lastRun, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("first_run") || key.equalsIgnoreCase("last_run")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/Record.java b/src/main/java/com/newscatcher/catchall/types/Record.java index e0d1155..cd08aff 100644 --- a/src/main/java/com/newscatcher/catchall/types/Record.java +++ b/src/main/java/com/newscatcher/catchall/types/Record.java @@ -233,7 +233,6 @@ public static final class Builder implements RecordIdStage, RecordTitleStage, En private List citations = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -392,6 +391,19 @@ public Record build() { recordId, recordTitle, enrichment, citations, connectedEntities, tags, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("record_id") + || key.equalsIgnoreCase("record_title") + || key.equalsIgnoreCase("enrichment") + || key.equalsIgnoreCase("citations") + || key.equalsIgnoreCase("connected_entities") + || key.equalsIgnoreCase("tags")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ReferenceJob.java b/src/main/java/com/newscatcher/catchall/types/ReferenceJob.java index 96dc147..260a75a 100644 --- a/src/main/java/com/newscatcher/catchall/types/ReferenceJob.java +++ b/src/main/java/com/newscatcher/catchall/types/ReferenceJob.java @@ -114,7 +114,6 @@ public static final class Builder { private Optional> sourceGroups = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -184,6 +183,16 @@ public ReferenceJob build() { return new ReferenceJob(query, context, sourceGroups, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("query") + || key.equalsIgnoreCase("context") + || key.equalsIgnoreCase("source_groups")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/RemoveResourceResponseDto.java b/src/main/java/com/newscatcher/catchall/types/RemoveResourceResponseDto.java index 5d0caae..5ace657 100644 --- a/src/main/java/com/newscatcher/catchall/types/RemoveResourceResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/RemoveResourceResponseDto.java @@ -106,7 +106,6 @@ public static final class Builder implements SuccessStage, MessageStage, _FinalS private String message; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -145,6 +144,14 @@ public RemoveResourceResponseDto build() { return new RemoveResourceResponseDto(success, message, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") || key.equalsIgnoreCase("message")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ResourceItemDto.java b/src/main/java/com/newscatcher/catchall/types/ResourceItemDto.java index c3ab9e4..a23f0e1 100644 --- a/src/main/java/com/newscatcher/catchall/types/ResourceItemDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ResourceItemDto.java @@ -101,7 +101,6 @@ public static final class Builder implements ResourceTypeStage, ResourceIdStage, private String resourceId; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -136,6 +135,14 @@ public ResourceItemDto build() { return new ResourceItemDto(resourceType, resourceId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") || key.equalsIgnoreCase("resource_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ResourceResultDto.java b/src/main/java/com/newscatcher/catchall/types/ResourceResultDto.java index c235710..84ef2a9 100644 --- a/src/main/java/com/newscatcher/catchall/types/ResourceResultDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ResourceResultDto.java @@ -179,7 +179,6 @@ public static final class Builder private Optional alreadyExists = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -264,6 +263,18 @@ public ResourceResultDto build() { resourceType, resourceId, success, message, alreadyExists, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("resource_id") + || key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("already_exists")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/SharingInfo.java b/src/main/java/com/newscatcher/catchall/types/SharingInfo.java index 9547e80..0a936a0 100644 --- a/src/main/java/com/newscatcher/catchall/types/SharingInfo.java +++ b/src/main/java/com/newscatcher/catchall/types/SharingInfo.java @@ -135,7 +135,6 @@ public static final class Builder implements SharedAtStage, PermissionStage, Sha private String sharedBy; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -187,6 +186,16 @@ public SharingInfo build() { return new SharingInfo(sharedAt, permission, sharedBy, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("shared_at") + || key.equalsIgnoreCase("permission") + || key.equalsIgnoreCase("shared_by")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/SkippedRow.java b/src/main/java/com/newscatcher/catchall/types/SkippedRow.java index 7b7413e..a1f680a 100644 --- a/src/main/java/com/newscatcher/catchall/types/SkippedRow.java +++ b/src/main/java/com/newscatcher/catchall/types/SkippedRow.java @@ -108,7 +108,6 @@ public static final class Builder implements RowStage, ReasonStage, _FinalStage private String reason; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -148,6 +147,14 @@ public SkippedRow build() { return new SkippedRow(row, reason, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("row") || key.equalsIgnoreCase("reason")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/SourceGroupRef.java b/src/main/java/com/newscatcher/catchall/types/SourceGroupRef.java index 8592848..86773f7 100644 --- a/src/main/java/com/newscatcher/catchall/types/SourceGroupRef.java +++ b/src/main/java/com/newscatcher/catchall/types/SourceGroupRef.java @@ -145,7 +145,6 @@ public static final class Builder implements SlugStage, NameStage, _FinalStage { private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -222,6 +221,14 @@ public SourceGroupRef build() { return new SourceGroupRef(slug, name, description, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("slug") || key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/StatusResponseDto.java b/src/main/java/com/newscatcher/catchall/types/StatusResponseDto.java index e72c8a1..4fc80fd 100644 --- a/src/main/java/com/newscatcher/catchall/types/StatusResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/StatusResponseDto.java @@ -133,7 +133,6 @@ public static final class Builder implements JobIdStage, _FinalStage { private Optional status = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -202,6 +201,14 @@ public StatusResponseDto build() { return new StatusResponseDto(jobId, status, steps, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id") || key.equalsIgnoreCase("status") || key.equalsIgnoreCase("steps")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/SubmitResponseDto.java b/src/main/java/com/newscatcher/catchall/types/SubmitResponseDto.java index 7fb3fc3..8fa0b23 100644 --- a/src/main/java/com/newscatcher/catchall/types/SubmitResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/SubmitResponseDto.java @@ -86,7 +86,6 @@ public interface _FinalStage { public static final class Builder implements JobIdStage, _FinalStage { private String jobId; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -113,6 +112,14 @@ public SubmitResponseDto build() { return new SubmitResponseDto(jobId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/Suggestion.java b/src/main/java/com/newscatcher/catchall/types/Suggestion.java index e41e7cb..6a2b375 100644 --- a/src/main/java/com/newscatcher/catchall/types/Suggestion.java +++ b/src/main/java/com/newscatcher/catchall/types/Suggestion.java @@ -129,7 +129,6 @@ public static final class Builder implements IssueStage, MessageStage, _FinalSta private Optional example = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -189,6 +188,14 @@ public Suggestion build() { return new Suggestion(issue, message, example, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("issue") || key.equalsIgnoreCase("message") || key.equalsIgnoreCase("example")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/TestWebhookResponseDto.java b/src/main/java/com/newscatcher/catchall/types/TestWebhookResponseDto.java index 8147b61..700f9cc 100644 --- a/src/main/java/com/newscatcher/catchall/types/TestWebhookResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/TestWebhookResponseDto.java @@ -156,7 +156,6 @@ public static final class Builder implements SuccessStage, MessageStage, _FinalS private Optional httpStatusCode = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -237,6 +236,17 @@ public TestWebhookResponseDto build() { return new TestWebhookResponseDto(success, message, httpStatusCode, responseBody, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("http_status_code") + || key.equalsIgnoreCase("response_body")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/UpdateMonitorResponseDto.java b/src/main/java/com/newscatcher/catchall/types/UpdateMonitorResponseDto.java index c17385d..be2ede3 100644 --- a/src/main/java/com/newscatcher/catchall/types/UpdateMonitorResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/UpdateMonitorResponseDto.java @@ -106,7 +106,6 @@ public static final class Builder implements MonitorIdStage, StatusStage, _Final private String status; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -145,6 +144,14 @@ public UpdateMonitorResponseDto build() { return new UpdateMonitorResponseDto(monitorId, status, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("monitor_id") || key.equalsIgnoreCase("status")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/UpdateProjectResponseDto.java b/src/main/java/com/newscatcher/catchall/types/UpdateProjectResponseDto.java index 6bf0bc7..16e051c 100644 --- a/src/main/java/com/newscatcher/catchall/types/UpdateProjectResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/UpdateProjectResponseDto.java @@ -127,7 +127,6 @@ public static final class Builder implements SuccessStage, MessageStage, Project private String projectId; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -178,6 +177,16 @@ public UpdateProjectResponseDto build() { return new UpdateProjectResponseDto(success, message, projectId, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") + || key.equalsIgnoreCase("message") + || key.equalsIgnoreCase("project_id")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/UpdateWebhookResponseDto.java b/src/main/java/com/newscatcher/catchall/types/UpdateWebhookResponseDto.java index cd35cfa..d9575d4 100644 --- a/src/main/java/com/newscatcher/catchall/types/UpdateWebhookResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/UpdateWebhookResponseDto.java @@ -132,7 +132,6 @@ public static final class Builder implements SuccessStage, MessageStage, _FinalS private Optional webhook = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -192,6 +191,14 @@ public UpdateWebhookResponseDto build() { return new UpdateWebhookResponseDto(success, message, webhook, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("success") || key.equalsIgnoreCase("message") || key.equalsIgnoreCase("webhook")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/UploadCsvToDatasetResponse.java b/src/main/java/com/newscatcher/catchall/types/UploadCsvToDatasetResponse.java index 81e2d75..96ab505 100644 --- a/src/main/java/com/newscatcher/catchall/types/UploadCsvToDatasetResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/UploadCsvToDatasetResponse.java @@ -127,7 +127,6 @@ public static final class Builder private ValidationReport validationReport; - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -174,6 +173,16 @@ public UploadCsvToDatasetResponse build() { return new UploadCsvToDatasetResponse(datasetId, entitiesCreated, validationReport, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("dataset_id") + || key.equalsIgnoreCase("entities_created") + || key.equalsIgnoreCase("validation_report")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/UserJob.java b/src/main/java/com/newscatcher/catchall/types/UserJob.java index e8fd824..7b1342c 100644 --- a/src/main/java/com/newscatcher/catchall/types/UserJob.java +++ b/src/main/java/com/newscatcher/catchall/types/UserJob.java @@ -224,7 +224,6 @@ public static final class Builder implements JobIdStage, QueryStage, CreatedAtSt private Optional mode = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -350,6 +349,20 @@ public UserJob build() { return new UserJob(jobId, query, createdAt, status, mode, sharingInfo, userKey, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("job_id") + || key.equalsIgnoreCase("query") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("mode") + || key.equalsIgnoreCase("sharing_info") + || key.equalsIgnoreCase("user_key")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ValidateQueryResponseDto.java b/src/main/java/com/newscatcher/catchall/types/ValidateQueryResponseDto.java index 82d6d42..ae0dfcc 100644 --- a/src/main/java/com/newscatcher/catchall/types/ValidateQueryResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/ValidateQueryResponseDto.java @@ -201,7 +201,6 @@ public static final class Builder implements StatusStage, TitleStage, Confidence private Optional description = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -316,6 +315,19 @@ public ValidateQueryResponseDto build() { status, title, description, issues, suggestions, confidence, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("status") + || key.equalsIgnoreCase("title") + || key.equalsIgnoreCase("description") + || key.equalsIgnoreCase("issues") + || key.equalsIgnoreCase("suggestions") + || key.equalsIgnoreCase("confidence")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ValidationErrorDetail.java b/src/main/java/com/newscatcher/catchall/types/ValidationErrorDetail.java index 9da621d..1743b47 100644 --- a/src/main/java/com/newscatcher/catchall/types/ValidationErrorDetail.java +++ b/src/main/java/com/newscatcher/catchall/types/ValidationErrorDetail.java @@ -101,7 +101,6 @@ public static final class Builder { private Optional type = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -159,6 +158,14 @@ public ValidationErrorDetail build() { return new ValidationErrorDetail(loc, msg, type, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("loc") || key.equalsIgnoreCase("msg") || key.equalsIgnoreCase("type")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/ValidationErrorResponse.java b/src/main/java/com/newscatcher/catchall/types/ValidationErrorResponse.java index eb2a051..b49d8f5 100644 --- a/src/main/java/com/newscatcher/catchall/types/ValidationErrorResponse.java +++ b/src/main/java/com/newscatcher/catchall/types/ValidationErrorResponse.java @@ -69,7 +69,6 @@ public static Builder builder() { public static final class Builder { private Optional> detail = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -94,6 +93,14 @@ public ValidationErrorResponse build() { return new ValidationErrorResponse(detail, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("detail")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/ValidationReport.java b/src/main/java/com/newscatcher/catchall/types/ValidationReport.java index 818dcf0..278aa7c 100644 --- a/src/main/java/com/newscatcher/catchall/types/ValidationReport.java +++ b/src/main/java/com/newscatcher/catchall/types/ValidationReport.java @@ -160,7 +160,6 @@ public static final class Builder implements TotalRowsStage, ValidRowsStage, Ski private List skippedRows = new ArrayList<>(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -248,6 +247,17 @@ public ValidationReport build() { return new ValidationReport(totalRows, validRows, skippedCount, skippedRows, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("total_rows") + || key.equalsIgnoreCase("valid_rows") + || key.equalsIgnoreCase("skipped_count") + || key.equalsIgnoreCase("skipped_rows")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/ValidatorSchema.java b/src/main/java/com/newscatcher/catchall/types/ValidatorSchema.java index 24d51f9..b41e6c4 100644 --- a/src/main/java/com/newscatcher/catchall/types/ValidatorSchema.java +++ b/src/main/java/com/newscatcher/catchall/types/ValidatorSchema.java @@ -129,7 +129,6 @@ public static final class Builder implements NameStage, DescriptionStage, _Final private Optional type = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -189,6 +188,14 @@ public ValidatorSchema build() { return new ValidatorSchema(name, description, type, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("name") || key.equalsIgnoreCase("description") || key.equalsIgnoreCase("type")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/WebhookDto.java b/src/main/java/com/newscatcher/catchall/types/WebhookDto.java index 37294d4..35d5ee7 100644 --- a/src/main/java/com/newscatcher/catchall/types/WebhookDto.java +++ b/src/main/java/com/newscatcher/catchall/types/WebhookDto.java @@ -179,7 +179,6 @@ public static final class Builder implements UrlStage, _FinalStage { private Optional method = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -290,6 +289,18 @@ public WebhookDto build() { return new WebhookDto(url, method, headers, params, auth, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("url") + || key.equalsIgnoreCase("method") + || key.equalsIgnoreCase("headers") + || key.equalsIgnoreCase("params") + || key.equalsIgnoreCase("auth")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/WebhookPayload.java b/src/main/java/com/newscatcher/catchall/types/WebhookPayload.java index c63f1c9..31e16f3 100644 --- a/src/main/java/com/newscatcher/catchall/types/WebhookPayload.java +++ b/src/main/java/com/newscatcher/catchall/types/WebhookPayload.java @@ -203,7 +203,6 @@ public static final class Builder { private Optional> records = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -361,6 +360,22 @@ public WebhookPayload build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("monitor_id") + || key.equalsIgnoreCase("reference_job_id") + || key.equalsIgnoreCase("latest_job_id") + || key.equalsIgnoreCase("records_count") + || key.equalsIgnoreCase("jobs_processed") + || key.equalsIgnoreCase("updated_at") + || key.equalsIgnoreCase("cron_expression") + || key.equalsIgnoreCase("timezone") + || key.equalsIgnoreCase("records")) { + return; + } + this.additionalProperties.put(key, value); + } + public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); return this; diff --git a/src/main/java/com/newscatcher/catchall/types/WebhookResourceMappingResponseDto.java b/src/main/java/com/newscatcher/catchall/types/WebhookResourceMappingResponseDto.java index 11c11e9..25e9d31 100644 --- a/src/main/java/com/newscatcher/catchall/types/WebhookResourceMappingResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/WebhookResourceMappingResponseDto.java @@ -180,7 +180,6 @@ public static final class Builder private Optional assignedAt = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -265,6 +264,18 @@ public WebhookResourceMappingResponseDto build() { id, webhookId, resourceType, resourceId, assignedAt, additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("webhook_id") + || key.equalsIgnoreCase("resource_type") + || key.equalsIgnoreCase("resource_id") + || key.equalsIgnoreCase("assigned_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/main/java/com/newscatcher/catchall/types/WebhookResponseDto.java b/src/main/java/com/newscatcher/catchall/types/WebhookResponseDto.java index 3fd1358..8e98813 100644 --- a/src/main/java/com/newscatcher/catchall/types/WebhookResponseDto.java +++ b/src/main/java/com/newscatcher/catchall/types/WebhookResponseDto.java @@ -433,7 +433,6 @@ public static final class Builder private Optional> headers = Optional.empty(); - @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @@ -742,6 +741,28 @@ public WebhookResponseDto build() { additionalProperties); } + @JsonAnySetter + private void putAdditionalPropertyFromJson(String key, Object value) { + if (key.equalsIgnoreCase("id") + || key.equalsIgnoreCase("name") + || key.equalsIgnoreCase("url") + || key.equalsIgnoreCase("type") + || key.equalsIgnoreCase("delivery_mode") + || key.equalsIgnoreCase("method") + || key.equalsIgnoreCase("headers") + || key.equalsIgnoreCase("params") + || key.equalsIgnoreCase("auth") + || key.equalsIgnoreCase("formatter_config") + || key.equalsIgnoreCase("is_active") + || key.equalsIgnoreCase("organization_id") + || key.equalsIgnoreCase("created_by_user_id") + || key.equalsIgnoreCase("created_at") + || key.equalsIgnoreCase("updated_at")) { + return; + } + this.additionalProperties.put(key, value); + } + @java.lang.Override public Builder additionalProperty(String key, Object value) { this.additionalProperties.put(key, value); diff --git a/src/test/java/com/newscatcher/catchall/core/PathSegmentsTest.java b/src/test/java/com/newscatcher/catchall/core/PathSegmentsTest.java new file mode 100644 index 0000000..389251f --- /dev/null +++ b/src/test/java/com/newscatcher/catchall/core/PathSegmentsTest.java @@ -0,0 +1,36 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.newscatcher.catchall.core; + +import okhttp3.HttpUrl; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public final class PathSegmentsTest { + + @Test + public void testRejectsDotSegments() { + Assertions.assertThrows(IllegalArgumentException.class, () -> PathSegments.validate(".")); + Assertions.assertThrows(IllegalArgumentException.class, () -> PathSegments.validate("..")); + } + + @Test + public void testAllowsValuesContainingDots() { + Assertions.assertEquals("...", PathSegments.validate("...")); + Assertions.assertEquals("v1.2", PathSegments.validate("v1.2")); + Assertions.assertEquals("../plants", PathSegments.validate("../plants")); + } + + @Test + public void testValueStaysWithinOneSegment() { + HttpUrl url = HttpUrl.parse("https://api.example.com") + .newBuilder() + .addPathSegments("plants") + .addPathSegment(PathSegments.validate("../leaves?x#y")) + .addPathSegments("leaves") + .addPathSegment(PathSegments.validate("L1")) + .build(); + Assertions.assertEquals("/plants/..%2Fleaves%3Fx%23y/leaves/L1", url.encodedPath()); + } +} From 7cb73e38620c734110f5844cf1d5388949df08ec Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:39:10 +0000 Subject: [PATCH 2/3] [fern-autoversion] feat!: add required CreateDatasetFromCsvRequest param to InputStream overloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `createDatasetFromCsv` InputStream overloads in both `DatasetsClient` and `AsyncDatasetsClient` now require a `CreateDatasetFromCsvRequest` as the first parameter. Callers using the old `(InputStream, String)` or `(InputStream, String, MediaType/RequestOptions)` signatures must update their call sites to pass a `CreateDatasetFromCsvRequest` object as the first argument. Additionally, all async methods in `AsyncDatasetsClient` now properly propagate cancellation from the derived future back to the underlying raw HTTP future, improving resource cleanup on cancellation. Key changes: - `DatasetsClient.createDatasetFromCsv(InputStream, String[, ...])` — now requires `CreateDatasetFromCsvRequest` as first parameter (breaking) - `AsyncDatasetsClient.createDatasetFromCsv(InputStream, String[, ...])` — same signature change (breaking) - All `AsyncDatasetsClient` async methods now propagate `cancel()` to the underlying raw future via `whenComplete` 🌿 Generated with Fern --- .fern/metadata.json | 2 +- README.md | 4 ++-- build.gradle | 4 ++-- changelog.md | 18 ++++++++++++++++++ .../catchall/core/ClientOptions.java | 4 ++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.fern/metadata.json b/.fern/metadata.json index e1eaff9..2dc8f1c 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -12,5 +12,5 @@ "invokedBy": "ci", "requestedVersion": "AUTO", "ciProvider": "unknown", - "sdkVersion": "0.0.0-fern-placeholder" + "sdkVersion": "4.0.0" } \ No newline at end of file diff --git a/README.md b/README.md index 1baa2be..ade4769 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Add the dependency in your `build.gradle` file: ```groovy dependencies { - implementation 'com.newscatcherapi:newscatcher-catchall-sdk:0.0.0-fern-placeholder' + implementation 'com.newscatcherapi:newscatcher-catchall-sdk:4.0.0' } ``` @@ -48,7 +48,7 @@ Add the dependency in your `pom.xml` file: com.newscatcherapi newscatcher-catchall-sdk - 0.0.0-fern-placeholder + 4.0.0 ``` diff --git a/build.gradle b/build.gradle index 50f8a68..e3ff372 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ java { group = 'com.newscatcherapi' -version = '0.0.0-fern-placeholder' +version = '4.0.0' jar { dependsOn(":generatePomFileForMavenPublication") @@ -88,7 +88,7 @@ publishing { maven(MavenPublication) { groupId = 'com.newscatcherapi' artifactId = 'newscatcher-catchall-sdk' - version = '0.0.0-fern-placeholder' + version = '4.0.0' from components.java pom { name = 'newscatcher' diff --git a/changelog.md b/changelog.md index 7d99624..334fd90 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,21 @@ +## [4.0.0] - 2026-10-22 +### Breaking Changes +- **`DatasetsClient.createDatasetFromCsv()`** — all InputStream overloads now require a `CreateDatasetFromCsvRequest` as the first argument; replace `createDatasetFromCsv(stream, filename, ...)` with `createDatasetFromCsv(request, stream, filename, ...)`. +- **`AsyncDatasetsClient.createDatasetFromCsv()`** — same signature change as the synchronous client; prepend a `CreateDatasetFromCsvRequest` argument before `stream` and `filename` at every call site. +- **`RawDatasetsClient.createDatasetFromCsv()`** — all four overloads now require a leading `CreateDatasetFromCsvRequest` parameter so that `name` and `description` are sent as multipart form fields; add a `CreateDatasetFromCsvRequest` as the first argument to every call site. +- **`AsyncRawDatasetsClient.createDatasetFromCsv()`** — all four overloads now require a leading `CreateDatasetFromCsvRequest` parameter; update every call site to prepend a `CreateDatasetFromCsvRequest` argument. + +### Added +- **`RequestOptions.Builder.addBodyProperty()` / `bodyProperties()`** — new builder methods that inject arbitrary key/value pairs into the JSON or form-urlencoded request body, overriding any existing property with the same key. +- **`RetryInterceptor.newAsyncCall()`** — new static factory that creates a non-blocking async call with built-in retry support, preventing OkHttp dispatcher slot exhaustion and enabling immediate cancellation. +- **`Stream.fromSseWithEventDiscrimination()`** — new static factory for SSE streams that supports envelope-level event discrimination, deserializing specified event names from the full SSE envelope rather than just the `data` payload. +- **`PathSegments.validate()`** — new core utility that rejects `"."` and `".."` as path parameter values, preventing silent URL path traversal. + +### Changed +- **`AsyncDatasetsClient`** — all async methods now propagate `CompletableFuture` cancellation to the underlying HTTP call, ensuring in-flight requests are properly cancelled. +- **Request builder classes** — `@JsonAnySetter` now filters out known property keys on all request types (e.g., `CreateDatasetRequest`, `UpdateDatasetRequest`, `ListDatasetsRequest`, and others), preventing typed fields from being silently overwritten during deserialization. +- **`RawDatasetsClient`** — path segment values for `datasetId` are now validated via `PathSegments.validate()` and extra body properties from `RequestOptions` are merged into every JSON request body. + ## [3.0.5] - 2026-09-30 ## [3.0.4] - 2026-08-04 diff --git a/src/main/java/com/newscatcher/catchall/core/ClientOptions.java b/src/main/java/com/newscatcher/catchall/core/ClientOptions.java index 3aa651e..a3a1655 100644 --- a/src/main/java/com/newscatcher/catchall/core/ClientOptions.java +++ b/src/main/java/com/newscatcher/catchall/core/ClientOptions.java @@ -60,10 +60,10 @@ private ClientOptions( this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.newscatcherapi.newscatcher-catchall-sdk/0.0.0-fern-placeholder"); + put("User-Agent", "com.newscatcherapi.newscatcher-catchall-sdk/4.0.0"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.newscatcherapi:newscatcher-catchall-sdk"); - put("X-Fern-SDK-Version", "0.0.0-fern-placeholder"); + put("X-Fern-SDK-Version", "4.0.0"); } }); this.headerSuppliers = headerSuppliers; From ebfd1c8b4f4a78730d26a5d96afc1354d8d5df82 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:39:10 +0000 Subject: [PATCH 3/3] [fern-replay] advance lockfile --- .fern/replay.lock | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.fern/replay.lock b/.fern/replay.lock index 39d42b2..c909f6c 100644 --- a/.fern/replay.lock +++ b/.fern/replay.lock @@ -18,5 +18,11 @@ generations: cli_version: unknown generator_versions: fernapi/fern-java-sdk: 4.23.1 -current_generation: b2be01153a63a951ba3db45c87ebd0d44d6b696d + - commit_sha: 799bb58627612f83a19eb44e11e4552d5186d6f0 + tree_hash: c186d73dcee3e42a9f475589faf75c5260d64f30 + timestamp: 2026-10-22T15:37:56.670Z + cli_version: unknown + generator_versions: + fernapi/fern-java-sdk: 4.32.4 +current_generation: 799bb58627612f83a19eb44e11e4552d5186d6f0 patches: []