diff --git a/.fern/metadata.json b/.fern/metadata.json index 0f0f30e0..da4b1ac1 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -1,10 +1,10 @@ { - "cliVersion": "3.51.2", + "cliVersion": "3.56.8", "generatorName": "fernapi/fern-java-sdk", - "generatorVersion": "3.29.1", + "generatorVersion": "3.34.6", "generatorConfig": { "client-class-name": "Lattice", "package-prefix": "com.anduril" }, - "sdkVersion": "5.2.0" + "sdkVersion": "5.3.0" } \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 50dd7ca3..00000000 --- a/README.md +++ /dev/null @@ -1,290 +0,0 @@ -# Lattice SDK Java Library - -![](https://www.anduril.com/lattice-sdk/) - -[![Maven Central](https://img.shields.io/maven-central/v/com.anduril/lattice-sdk)](https://central.sonatype.com/artifact/com.anduril/lattice-sdk) - -The Lattice SDK Java library provides convenient access to the Lattice SDK APIs from Java. - -## Table of Contents - -- [Documentation](#documentation) -- [Requirements](#requirements) -- [Installation](#installation) -- [Support](#support) -- [Usage](#usage) -- [Authentication](#authentication) -- [Environments](#environments) -- [Base Url](#base-url) -- [Exception Handling](#exception-handling) -- [Advanced](#advanced) - - [Custom Client](#custom-client) - - [Retries](#retries) - - [Timeouts](#timeouts) - - [Custom Headers](#custom-headers) - - [Access Raw Response Data](#access-raw-response-data) -- [Reference](#reference) - -## Documentation - -API reference documentation is available [here](https://developer.anduril.com/). - -## Requirements - -This repository is tested against Java 1.8 or later. - -## Installation - -### Gradle - -Add the dependency in your `build.gradle` file: - -```groovy -dependencies { - implementation 'com.anduril:lattice-sdk' -} -``` - -### Maven - -Add the dependency in your `pom.xml` file: - -```xml - - com.anduril - lattice-sdk - 5.2.0 - -``` - -## Support - -For support with this library please reach out to your Anduril representative. - -## Usage - -Instantiate and use the client with the following: - -```java -package com.example.usage; - -import com.anduril.Lattice; -import com.anduril.resources.entities.requests.EntityEventRequest; - -public class Example { - public static void main(String[] args) { - Lattice client = Lattice.withCredentials("", "") - .build() - ; - - client.entities().longPollEntityEvents( - EntityEventRequest - .builder() - .sessionToken("sessionToken") - .build() - ); - } -} -``` -## Authentication - -This SDK supports two authentication methods: - -### Option 1: Direct Bearer Token - -If you already have a valid access token, you can use it directly: - -```java -Lattice client = Lattice.builder() - .token("your-access-token") - .url("https://api.example.com") - .build(); -``` - -### Option 2: OAuth Client Credentials - -The SDK can automatically handle token acquisition and refresh: - -```java -Lattice client = Lattice.builder() - .credentials("client-id", "client-secret") - .url("https://api.example.com") - .build(); -``` - -## Authentication - -This SDK supports two authentication methods: - -### Option 1: Direct Bearer Token - -If you already have a valid access token, you can use it directly: - -```java -Lattice client = Lattice.builder() - .token("your-access-token") - .url("https://api.example.com") - .build(); -``` - -### Option 2: OAuth Client Credentials - -The SDK can automatically handle token acquisition and refresh: - -```java -Lattice client = Lattice.builder() - .credentials("client-id", "client-secret") - .url("https://api.example.com") - .build(); -``` - -## Environments - -This SDK allows you to configure different environments for API requests. - -```java -import com.anduril.Lattice; -import com.anduril.core.Environment; - -Lattice client = Lattice - .builder() - .environment(Environment.Default) - .build(); -``` - -## Base Url - -You can set a custom base URL when constructing the client. - -```java -import com.anduril.Lattice; - -Lattice client = Lattice - .builder() - .url("https://example.com") - .build(); -``` - -## Exception Handling - -When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown. - -```java -import com.anduril.core.AndurilApiApiException; - -try{ - client.entities().longPollEntityEvents(...); -} catch (AndurilApiApiException e){ - // Do something with the API exception... -} -``` - -## Advanced - -### Custom Client - -This SDK is built to work with any instance of `OkHttpClient`. By default, if no client is provided, the SDK will construct one. -However, you can pass your own client like so: - -```java -import com.anduril.Lattice; -import okhttp3.OkHttpClient; - -OkHttpClient customClient = ...; - -Lattice client = Lattice - .builder() - .httpClient(customClient) - .build(); -``` - -### Retries - -The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long -as the request is deemed retryable and the number of retry attempts has not grown larger than the configured -retry limit (default: 2). Before defaulting to exponential backoff, the SDK will first attempt to respect -the `Retry-After` header (as either in seconds or as an HTTP date), and then the `X-RateLimit-Reset` header -(as a Unix timestamp in epoch seconds); failing both of those, it will fall back to exponential backoff. - -A request is deemed retryable when any of the following HTTP status codes is returned: - -- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout) -- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests) -- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors) - -Use the `maxRetries` client option to configure this behavior. - -```java -import com.anduril.Lattice; - -Lattice client = Lattice - .builder() - .maxRetries(1) - .build(); -``` - -### Timeouts - -The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level. -```java -import com.anduril.Lattice; -import com.anduril.core.RequestOptions; - -// Client level -Lattice client = Lattice - .builder() - .timeout(60) - .build(); - -// Request level -client.entities().longPollEntityEvents( - ..., - RequestOptions - .builder() - .timeout(60) - .build() -); -``` - -### Custom Headers - -The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level. - -```java -import com.anduril.Lattice; -import com.anduril.core.RequestOptions; - -// Client level -Lattice client = Lattice - .builder() - .addHeader("X-Custom-Header", "custom-value") - .addHeader("X-Request-Id", "abc-123") - .build(); -; - -// Request level -client.entities().longPollEntityEvents( - ..., - RequestOptions - .builder() - .addHeader("X-Request-Header", "request-value") - .build() -); -``` - -### Access Raw Response Data - -The SDK provides access to raw response data, including headers, through the `withRawResponse()` method. -The `withRawResponse()` method returns a raw client that wraps all responses with `body()` and `headers()` methods. -(A normal client's `response` is identical to a raw client's `response.body()`.) - -```java -LongPollEntityEventsHttpResponse response = client.entities().withRawResponse().longPollEntityEvents(...); - -System.out.println(response.body()); -System.out.println(response.headers().get("X-My-Header")); -``` - -## Reference - -A full reference for this library is available [here](https://github.com/anduril/lattice-sdk-java/blob/HEAD/./reference.md). diff --git a/build.gradle b/build.gradle index 078fd98e..04322a25 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ java { group = 'com.anduril' -version = '5.2.0' +version = '5.3.0' jar { dependsOn(":generatePomFileForMavenPublication") @@ -78,21 +78,21 @@ publishing { maven(MavenPublication) { groupId = 'com.anduril' artifactId = 'lattice-sdk' - version = '5.2.0' + version = '5.3.0' from components.java pom { - name = 'Anduril Industries, Inc.' - description = 'Anduril Lattice SDK for Java' - url = 'https://developer.anduril.com' + name = 'anduril' + description = 'The official SDK of anduril' + url = 'https://buildwithfern.com' licenses { license { - name = 'Anduril Lattice Software Development Kit License Agreement' + name = 'Custom License (LICENSE)' } } developers { developer { - name = 'Anduril Industries, Inc.' - email = 'lattice-developers@anduril.com' + name = 'anduril' + email = 'developers@anduril.com' } } scm { diff --git a/reference.md b/reference.md index 8386af5b..6e6f2517 100644 --- a/reference.md +++ b/reference.md @@ -1159,6 +1159,14 @@ client.objects().listObjects( **allObjectsInMesh:** `Optional` — Lists objects across all environment nodes in a Lattice Mesh. + + + +
+
+ +**maxPageSize:** `Optional` — Sets the maximum number of items that should be returned on a single page. +
diff --git a/src/main/java/com/anduril/core/ClientOptions.java b/src/main/java/com/anduril/core/ClientOptions.java index b8861c9d..971031df 100644 --- a/src/main/java/com/anduril/core/ClientOptions.java +++ b/src/main/java/com/anduril/core/ClientOptions.java @@ -35,10 +35,10 @@ private ClientOptions( this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.anduril:lattice-sdk/5.2.0"); + put("User-Agent", "com.anduril:lattice-sdk/5.3.0"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.anduril.fern:api-sdk"); - put("X-Fern-SDK-Version", "5.2.0"); + put("X-Fern-SDK-Version", "5.3.0"); } }); this.headerSuppliers = headerSuppliers; diff --git a/src/main/java/com/anduril/core/RequestOptions.java b/src/main/java/com/anduril/core/RequestOptions.java index f0fe01ef..e6a9bffe 100644 --- a/src/main/java/com/anduril/core/RequestOptions.java +++ b/src/main/java/com/anduril/core/RequestOptions.java @@ -18,15 +18,23 @@ public final class RequestOptions { private final Map> headerSuppliers; + private final Map queryParameters; + + private final Map> queryParameterSuppliers; + private RequestOptions( Optional timeout, TimeUnit timeoutTimeUnit, Map headers, - Map> headerSuppliers) { + Map> headerSuppliers, + Map queryParameters, + Map> queryParameterSuppliers) { this.timeout = timeout; this.timeoutTimeUnit = timeoutTimeUnit; this.headers = headers; this.headerSuppliers = headerSuppliers; + this.queryParameters = queryParameters; + this.queryParameterSuppliers = queryParameterSuppliers; } public Optional getTimeout() { @@ -46,6 +54,14 @@ public Map getHeaders() { return headers; } + public Map getQueryParameters() { + Map queryParameters = new HashMap<>(this.queryParameters); + this.queryParameterSuppliers.forEach((key, supplier) -> { + queryParameters.put(key, supplier.get()); + }); + return queryParameters; + } + public static Builder builder() { return new Builder(); } @@ -59,6 +75,10 @@ public static class Builder { private final Map> headerSuppliers = new HashMap<>(); + private final Map queryParameters = new HashMap<>(); + + private final Map> queryParameterSuppliers = new HashMap<>(); + public Builder timeout(Integer timeout) { this.timeout = Optional.of(timeout); return this; @@ -80,8 +100,19 @@ public Builder addHeader(String key, Supplier value) { return this; } + public Builder addQueryParameter(String key, String value) { + this.queryParameters.put(key, value); + return this; + } + + public Builder addQueryParameter(String key, Supplier value) { + this.queryParameterSuppliers.put(key, value); + return this; + } + public RequestOptions build() { - return new RequestOptions(timeout, timeoutTimeUnit, headers, headerSuppliers); + return new RequestOptions( + timeout, timeoutTimeUnit, headers, headerSuppliers, queryParameters, queryParameterSuppliers); } } } diff --git a/src/main/java/com/anduril/errors/ContentTooLargeError.java b/src/main/java/com/anduril/errors/ContentTooLargeError.java index 7968bc85..499cbc0a 100644 --- a/src/main/java/com/anduril/errors/ContentTooLargeError.java +++ b/src/main/java/com/anduril/errors/ContentTooLargeError.java @@ -4,20 +4,21 @@ package com.anduril.errors; import com.anduril.core.LatticeApiException; +import com.anduril.resources.object.types.Error; import okhttp3.Response; public final class ContentTooLargeError extends LatticeApiException { /** * The body of the response that triggered the exception. */ - private final Object body; + private final Error body; - public ContentTooLargeError(Object body) { + public ContentTooLargeError(Error body) { super("ContentTooLargeError", 413, body); this.body = body; } - public ContentTooLargeError(Object body, Response rawResponse) { + public ContentTooLargeError(Error body, Response rawResponse) { super("ContentTooLargeError", 413, body, rawResponse); this.body = body; } @@ -26,7 +27,7 @@ public ContentTooLargeError(Object body, Response rawResponse) { * @return the body */ @java.lang.Override - public Object body() { + public Error body() { return this.body; } } diff --git a/src/main/java/com/anduril/errors/InsufficientStorageError.java b/src/main/java/com/anduril/errors/InsufficientStorageError.java index feda2244..6f99a90c 100644 --- a/src/main/java/com/anduril/errors/InsufficientStorageError.java +++ b/src/main/java/com/anduril/errors/InsufficientStorageError.java @@ -4,20 +4,21 @@ package com.anduril.errors; import com.anduril.core.LatticeApiException; +import com.anduril.resources.object.types.Error; import okhttp3.Response; public final class InsufficientStorageError extends LatticeApiException { /** * The body of the response that triggered the exception. */ - private final Object body; + private final Error body; - public InsufficientStorageError(Object body) { + public InsufficientStorageError(Error body) { super("InsufficientStorageError", 507, body); this.body = body; } - public InsufficientStorageError(Object body, Response rawResponse) { + public InsufficientStorageError(Error body, Response rawResponse) { super("InsufficientStorageError", 507, body, rawResponse); this.body = body; } @@ -26,7 +27,7 @@ public InsufficientStorageError(Object body, Response rawResponse) { * @return the body */ @java.lang.Override - public Object body() { + public Error body() { return this.body; } } diff --git a/src/main/java/com/anduril/errors/RequestTimeoutError.java b/src/main/java/com/anduril/errors/RequestTimeoutError.java index 3b64d920..2cc98b5d 100644 --- a/src/main/java/com/anduril/errors/RequestTimeoutError.java +++ b/src/main/java/com/anduril/errors/RequestTimeoutError.java @@ -4,20 +4,21 @@ package com.anduril.errors; import com.anduril.core.LatticeApiException; +import com.anduril.resources.entity.types.Error; import okhttp3.Response; public final class RequestTimeoutError extends LatticeApiException { /** * The body of the response that triggered the exception. */ - private final Object body; + private final Error body; - public RequestTimeoutError(Object body) { + public RequestTimeoutError(Error body) { super("RequestTimeoutError", 408, body); this.body = body; } - public RequestTimeoutError(Object body, Response rawResponse) { + public RequestTimeoutError(Error body, Response rawResponse) { super("RequestTimeoutError", 408, body, rawResponse); this.body = body; } @@ -26,7 +27,7 @@ public RequestTimeoutError(Object body, Response rawResponse) { * @return the body */ @java.lang.Override - public Object body() { + public Error body() { return this.body; } } diff --git a/src/main/java/com/anduril/errors/TooManyRequestsError.java b/src/main/java/com/anduril/errors/TooManyRequestsError.java index 16d26e35..9ce489c8 100644 --- a/src/main/java/com/anduril/errors/TooManyRequestsError.java +++ b/src/main/java/com/anduril/errors/TooManyRequestsError.java @@ -4,20 +4,21 @@ package com.anduril.errors; import com.anduril.core.LatticeApiException; +import com.anduril.resources.entity.types.Error; import okhttp3.Response; public final class TooManyRequestsError extends LatticeApiException { /** * The body of the response that triggered the exception. */ - private final Object body; + private final Error body; - public TooManyRequestsError(Object body) { + public TooManyRequestsError(Error body) { super("TooManyRequestsError", 429, body); this.body = body; } - public TooManyRequestsError(Object body, Response rawResponse) { + public TooManyRequestsError(Error body, Response rawResponse) { super("TooManyRequestsError", 429, body, rawResponse); this.body = body; } @@ -26,7 +27,7 @@ public TooManyRequestsError(Object body, Response rawResponse) { * @return the body */ @java.lang.Override - public Object body() { + public Error body() { return this.body; } } diff --git a/src/main/java/com/anduril/resources/entities/AsyncRawEntitiesClient.java b/src/main/java/com/anduril/resources/entities/AsyncRawEntitiesClient.java index d3a814ad..c2aa9247 100644 --- a/src/main/java/com/anduril/resources/entities/AsyncRawEntitiesClient.java +++ b/src/main/java/com/anduril/resources/entities/AsyncRawEntitiesClient.java @@ -23,6 +23,7 @@ import com.anduril.resources.entities.requests.GetEntityRequest; import com.anduril.resources.entities.requests.RemoveEntityOverrideRequest; import com.anduril.resources.entities.types.StreamEntitiesResponse; +import com.anduril.resources.entity.types.Error; import com.anduril.types.Entity; import com.anduril.types.EntityEventResponse; import com.fasterxml.jackson.core.JsonProcessingException; @@ -91,10 +92,14 @@ public CompletableFuture> publishEntity(Entity reque * provenance.sourceUpdateTime is greater than the provenance.sourceUpdateTime of the existing entity.

*/ public CompletableFuture> publishEntity(Entity request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/entities") - .build(); + .addPathSegments("api/v1/entities"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -103,7 +108,7 @@ public CompletableFuture> publishEntity(Entity reque throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PUT", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -171,13 +176,17 @@ public CompletableFuture> getEntity(String entityId, public CompletableFuture> getEntity( String entityId, GetEntityRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/entities") - .addPathSegment(entityId) - .build(); + .addPathSegment(entityId); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("GET", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -283,13 +292,17 @@ public CompletableFuture> overrideEntity( */ public CompletableFuture> overrideEntity( String entityId, String fieldPath, EntityOverride request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/entities") .addPathSegment(entityId) .addPathSegments("override") - .addPathSegment(fieldPath) - .build(); + .addPathSegment(fieldPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -298,7 +311,7 @@ public CompletableFuture> overrideEntity( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PUT", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -387,15 +400,19 @@ public CompletableFuture> removeEntityOverride( */ public CompletableFuture> removeEntityOverride( String entityId, String fieldPath, RemoveEntityOverrideRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/entities") .addPathSegment(entityId) .addPathSegments("override") - .addPathSegment(fieldPath) - .build(); + .addPathSegment(fieldPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -482,10 +499,14 @@ public CompletableFuture> longPollEntit */ public CompletableFuture> longPollEntityEvents( EntityEventRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/entities/events") - .build(); + .addPathSegments("api/v1/entities/events"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -494,7 +515,7 @@ public CompletableFuture> longPollEntit throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -535,12 +556,12 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO return; case 408: future.completeExceptionally(new RequestTimeoutError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response)); return; case 429: future.completeExceptionally(new TooManyRequestsError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response)); return; } @@ -644,10 +665,14 @@ public CompletableFuture>> */ public CompletableFuture>> streamEntities( EntityStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/entities/stream") - .build(); + .addPathSegments("api/v1/entities/stream"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -656,11 +681,10 @@ public CompletableFuture>> throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") .build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { diff --git a/src/main/java/com/anduril/resources/entities/RawEntitiesClient.java b/src/main/java/com/anduril/resources/entities/RawEntitiesClient.java index 4dae53fd..889da9c8 100644 --- a/src/main/java/com/anduril/resources/entities/RawEntitiesClient.java +++ b/src/main/java/com/anduril/resources/entities/RawEntitiesClient.java @@ -23,6 +23,7 @@ import com.anduril.resources.entities.requests.GetEntityRequest; import com.anduril.resources.entities.requests.RemoveEntityOverrideRequest; import com.anduril.resources.entities.types.StreamEntitiesResponse; +import com.anduril.resources.entity.types.Error; import com.anduril.types.Entity; import com.anduril.types.EntityEventResponse; import com.fasterxml.jackson.core.JsonProcessingException; @@ -87,10 +88,14 @@ public LatticeHttpResponse publishEntity(Entity request) { * provenance.sourceUpdateTime is greater than the provenance.sourceUpdateTime of the existing entity.

*/ public LatticeHttpResponse publishEntity(Entity request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/entities") - .build(); + .addPathSegments("api/v1/entities"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -99,7 +104,7 @@ public LatticeHttpResponse publishEntity(Entity request, RequestOptions throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PUT", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -150,13 +155,17 @@ public LatticeHttpResponse getEntity(String entityId, GetEntityRequest r public LatticeHttpResponse getEntity( String entityId, GetEntityRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/entities") - .addPathSegment(entityId) - .build(); + .addPathSegment(entityId); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("GET", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -242,13 +251,17 @@ public LatticeHttpResponse overrideEntity(String entityId, String fieldP */ public LatticeHttpResponse overrideEntity( String entityId, String fieldPath, EntityOverride request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/entities") .addPathSegment(entityId) .addPathSegments("override") - .addPathSegment(fieldPath) - .build(); + .addPathSegment(fieldPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -257,7 +270,7 @@ public LatticeHttpResponse overrideEntity( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PUT", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -327,15 +340,19 @@ public LatticeHttpResponse removeEntityOverride( */ public LatticeHttpResponse removeEntityOverride( String entityId, String fieldPath, RemoveEntityOverrideRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/entities") .addPathSegment(entityId) .addPathSegments("override") - .addPathSegment(fieldPath) - .build(); + .addPathSegment(fieldPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -402,10 +419,14 @@ public LatticeHttpResponse longPollEntityEvents(EntityEvent */ public LatticeHttpResponse longPollEntityEvents( EntityEventRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/entities/events") - .build(); + .addPathSegments("api/v1/entities/events"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -414,7 +435,7 @@ public LatticeHttpResponse longPollEntityEvents( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -444,10 +465,10 @@ public LatticeHttpResponse longPollEntityEvents( ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); case 408: throw new RequestTimeoutError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response); case 429: throw new TooManyRequestsError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response); } } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error @@ -538,10 +559,14 @@ public LatticeHttpResponse> streamEntities(Enti */ public LatticeHttpResponse> streamEntities( EntityStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/entities/stream") - .build(); + .addPathSegments("api/v1/entities/stream"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -550,11 +575,10 @@ public LatticeHttpResponse> streamEntities( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") .build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { diff --git a/src/main/java/com/anduril/resources/oauth/AsyncRawOauthClient.java b/src/main/java/com/anduril/resources/oauth/AsyncRawOauthClient.java index e4405824..d7199427 100644 --- a/src/main/java/com/anduril/resources/oauth/AsyncRawOauthClient.java +++ b/src/main/java/com/anduril/resources/oauth/AsyncRawOauthClient.java @@ -46,10 +46,14 @@ public CompletableFuture> getToken(GetToke */ public CompletableFuture> getToken( GetTokenRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/oauth/token") - .build(); + .addPathSegments("api/v1/oauth/token"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } FormBody.Builder body = new FormBody.Builder(); try { body.add("grant_type", String.valueOf(request.getGrantType())); @@ -65,7 +69,7 @@ public CompletableFuture> getToken( throw new RuntimeException(e); } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/x-www-form-urlencoded") diff --git a/src/main/java/com/anduril/resources/oauth/RawOauthClient.java b/src/main/java/com/anduril/resources/oauth/RawOauthClient.java index abb5ea07..543660fa 100644 --- a/src/main/java/com/anduril/resources/oauth/RawOauthClient.java +++ b/src/main/java/com/anduril/resources/oauth/RawOauthClient.java @@ -41,10 +41,14 @@ public LatticeHttpResponse getToken(GetTokenRequest request) { * Gets a new short-lived token using the specified client credentials */ public LatticeHttpResponse getToken(GetTokenRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/oauth/token") - .build(); + .addPathSegments("api/v1/oauth/token"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } FormBody.Builder body = new FormBody.Builder(); try { body.add("grant_type", String.valueOf(request.getGrantType())); @@ -60,7 +64,7 @@ public LatticeHttpResponse getToken(GetTokenRequest request, R throw new RuntimeException(e); } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body.build()) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/x-www-form-urlencoded") diff --git a/src/main/java/com/anduril/resources/objects/AsyncRawObjectsClient.java b/src/main/java/com/anduril/resources/objects/AsyncRawObjectsClient.java index 73e1f001..8df5c612 100644 --- a/src/main/java/com/anduril/resources/objects/AsyncRawObjectsClient.java +++ b/src/main/java/com/anduril/resources/objects/AsyncRawObjectsClient.java @@ -19,6 +19,7 @@ import com.anduril.errors.InternalServerError; import com.anduril.errors.NotFoundError; import com.anduril.errors.UnauthorizedError; +import com.anduril.resources.object.types.Error; import com.anduril.resources.objects.requests.DeleteObjectRequest; import com.anduril.resources.objects.requests.GetObjectMetadataRequest; import com.anduril.resources.objects.requests.GetObjectRequest; @@ -99,6 +100,15 @@ public CompletableFuture>> QueryStringMapper.addQueryParameter( httpUrl, "allObjectsInMesh", request.getAllObjectsInMesh().get(), false); } + if (request.getMaxPageSize().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "maxPageSize", request.getMaxPageSize().get(), false); + } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) .method("GET", null) @@ -203,13 +213,17 @@ public CompletableFuture> getObject(String obje */ public CompletableFuture> getObject( String objectPath, GetObjectRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("GET", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -291,14 +305,18 @@ public CompletableFuture> uploadObject(String */ public CompletableFuture> uploadObject( String objectPath, InputStream request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body = new InputStreamRequestBody(MediaType.parse("application/octet-stream"), request); Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); @@ -331,7 +349,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO return; case 413: future.completeExceptionally(new ContentTooLargeError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response)); return; case 500: @@ -341,7 +359,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO return; case 507: future.completeExceptionally(new InsufficientStorageError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response)); return; } @@ -406,13 +424,17 @@ public CompletableFuture> deleteObject(String objectPa */ public CompletableFuture> deleteObject( String objectPath, DeleteObjectRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -502,13 +524,17 @@ public CompletableFuture> getObjectMetadata( */ public CompletableFuture> getObjectMetadata( String objectPath, GetObjectMetadataRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("HEAD", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); diff --git a/src/main/java/com/anduril/resources/objects/RawObjectsClient.java b/src/main/java/com/anduril/resources/objects/RawObjectsClient.java index 290e4680..25c05c4d 100644 --- a/src/main/java/com/anduril/resources/objects/RawObjectsClient.java +++ b/src/main/java/com/anduril/resources/objects/RawObjectsClient.java @@ -19,6 +19,7 @@ import com.anduril.errors.InternalServerError; import com.anduril.errors.NotFoundError; import com.anduril.errors.UnauthorizedError; +import com.anduril.resources.object.types.Error; import com.anduril.resources.objects.requests.DeleteObjectRequest; import com.anduril.resources.objects.requests.GetObjectMetadataRequest; import com.anduril.resources.objects.requests.GetObjectRequest; @@ -92,6 +93,15 @@ public LatticeHttpResponse> listObjects( QueryStringMapper.addQueryParameter( httpUrl, "allObjectsInMesh", request.getAllObjectsInMesh().get(), false); } + if (request.getMaxPageSize().isPresent()) { + QueryStringMapper.addQueryParameter( + httpUrl, "maxPageSize", request.getMaxPageSize().get(), false); + } + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) .method("GET", null) @@ -170,13 +180,17 @@ public LatticeHttpResponse getObject(String objectPath, GetObjectRe */ public LatticeHttpResponse getObject( String objectPath, GetObjectRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("GET", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -237,14 +251,18 @@ public LatticeHttpResponse uploadObject(String objectPath, InputSt */ public LatticeHttpResponse uploadObject( String objectPath, InputStream request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body = new InputStreamRequestBody(MediaType.parse("application/octet-stream"), request); Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); @@ -269,13 +287,13 @@ public LatticeHttpResponse uploadObject( ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); case 413: throw new ContentTooLargeError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response); case 500: throw new InternalServerError( ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); case 507: throw new InsufficientStorageError( - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Error.class), response); } } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error @@ -329,13 +347,17 @@ public LatticeHttpResponse deleteObject(String objectPath, DeleteObjectReq */ public LatticeHttpResponse deleteObject( String objectPath, DeleteObjectRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("DELETE", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -402,13 +424,17 @@ public LatticeHttpResponse getObjectMetadata(String objectPath, GetObjectM */ public LatticeHttpResponse getObjectMetadata( String objectPath, GetObjectMetadataRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/objects") - .addPathSegment(objectPath) - .build(); + .addPathSegment(objectPath); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("HEAD", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); diff --git a/src/main/java/com/anduril/resources/objects/requests/ListObjectsRequest.java b/src/main/java/com/anduril/resources/objects/requests/ListObjectsRequest.java index 0057fd1e..71c9b39e 100644 --- a/src/main/java/com/anduril/resources/objects/requests/ListObjectsRequest.java +++ b/src/main/java/com/anduril/resources/objects/requests/ListObjectsRequest.java @@ -29,6 +29,8 @@ public final class ListObjectsRequest { private final Optional allObjectsInMesh; + private final Optional maxPageSize; + private final Map additionalProperties; private ListObjectsRequest( @@ -36,11 +38,13 @@ private ListObjectsRequest( Optional sinceTimestamp, Optional pageToken, Optional allObjectsInMesh, + Optional maxPageSize, Map additionalProperties) { this.prefix = prefix; this.sinceTimestamp = sinceTimestamp; this.pageToken = pageToken; this.allObjectsInMesh = allObjectsInMesh; + this.maxPageSize = maxPageSize; this.additionalProperties = additionalProperties; } @@ -76,6 +80,14 @@ public Optional getAllObjectsInMesh() { return allObjectsInMesh; } + /** + * @return Sets the maximum number of items that should be returned on a single page. + */ + @JsonProperty("maxPageSize") + public Optional getMaxPageSize() { + return maxPageSize; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -91,12 +103,13 @@ private boolean equalTo(ListObjectsRequest other) { return prefix.equals(other.prefix) && sinceTimestamp.equals(other.sinceTimestamp) && pageToken.equals(other.pageToken) - && allObjectsInMesh.equals(other.allObjectsInMesh); + && allObjectsInMesh.equals(other.allObjectsInMesh) + && maxPageSize.equals(other.maxPageSize); } @java.lang.Override public int hashCode() { - return Objects.hash(this.prefix, this.sinceTimestamp, this.pageToken, this.allObjectsInMesh); + return Objects.hash(this.prefix, this.sinceTimestamp, this.pageToken, this.allObjectsInMesh, this.maxPageSize); } @java.lang.Override @@ -118,6 +131,8 @@ public static final class Builder { private Optional allObjectsInMesh = Optional.empty(); + private Optional maxPageSize = Optional.empty(); + @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -128,6 +143,7 @@ public Builder from(ListObjectsRequest other) { sinceTimestamp(other.getSinceTimestamp()); pageToken(other.getPageToken()); allObjectsInMesh(other.getAllObjectsInMesh()); + maxPageSize(other.getMaxPageSize()); return this; } @@ -187,8 +203,23 @@ public Builder allObjectsInMesh(Boolean allObjectsInMesh) { return this; } + /** + *

Sets the maximum number of items that should be returned on a single page.

+ */ + @JsonSetter(value = "maxPageSize", nulls = Nulls.SKIP) + public Builder maxPageSize(Optional maxPageSize) { + this.maxPageSize = maxPageSize; + return this; + } + + public Builder maxPageSize(Integer maxPageSize) { + this.maxPageSize = Optional.ofNullable(maxPageSize); + return this; + } + public ListObjectsRequest build() { - return new ListObjectsRequest(prefix, sinceTimestamp, pageToken, allObjectsInMesh, additionalProperties); + return new ListObjectsRequest( + prefix, sinceTimestamp, pageToken, allObjectsInMesh, maxPageSize, additionalProperties); } } } diff --git a/src/main/java/com/anduril/resources/tasks/AsyncRawTasksClient.java b/src/main/java/com/anduril/resources/tasks/AsyncRawTasksClient.java index 86cece54..d0742da9 100644 --- a/src/main/java/com/anduril/resources/tasks/AsyncRawTasksClient.java +++ b/src/main/java/com/anduril/resources/tasks/AsyncRawTasksClient.java @@ -94,10 +94,14 @@ public CompletableFuture> createTask(TaskCreation requ */ public CompletableFuture> createTask( TaskCreation request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/tasks") - .build(); + .addPathSegments("api/v1/tasks"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -106,7 +110,7 @@ public CompletableFuture> createTask( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -206,13 +210,17 @@ public CompletableFuture> getTask(String taskId, GetTa */ public CompletableFuture> getTask( String taskId, GetTaskRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/tasks") - .addPathSegment(taskId) - .build(); + .addPathSegment(taskId); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("GET", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -324,12 +332,16 @@ public CompletableFuture> updateTaskStatus(String task */ public CompletableFuture> updateTaskStatus( String taskId, TaskStatusUpdate request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/tasks") .addPathSegment(taskId) - .addPathSegments("status") - .build(); + .addPathSegments("status"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -338,7 +350,7 @@ public CompletableFuture> updateTaskStatus( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PUT", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -475,10 +487,14 @@ public CompletableFuture> queryTasks(TaskQ */ public CompletableFuture> queryTasks( TaskQuery request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/tasks/query") - .build(); + .addPathSegments("api/v1/tasks/query"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -487,7 +503,7 @@ public CompletableFuture> queryTasks( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -583,10 +599,14 @@ public CompletableFuture>> str */ public CompletableFuture>> streamTasks( TaskStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/tasks/stream") - .build(); + .addPathSegments("api/v1/tasks/stream"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -595,11 +615,10 @@ public CompletableFuture>> str throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") .build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { @@ -740,10 +759,14 @@ public CompletableFuture> listenAsAgent(AgentL */ public CompletableFuture> listenAsAgent( AgentListener request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/agent/listen") - .build(); + .addPathSegments("api/v1/agent/listen"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -752,7 +775,7 @@ public CompletableFuture> listenAsAgent( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -886,10 +909,14 @@ public CompletableFuture>> s */ public CompletableFuture>> streamAsAgent( AgentStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/agent/stream") - .build(); + .addPathSegments("api/v1/agent/stream"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -898,11 +925,10 @@ public CompletableFuture>> s throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") .build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { diff --git a/src/main/java/com/anduril/resources/tasks/RawTasksClient.java b/src/main/java/com/anduril/resources/tasks/RawTasksClient.java index 5d7b75a4..3c5e4fe0 100644 --- a/src/main/java/com/anduril/resources/tasks/RawTasksClient.java +++ b/src/main/java/com/anduril/resources/tasks/RawTasksClient.java @@ -89,10 +89,14 @@ public LatticeHttpResponse createTask(TaskCreation request) { * through other Tasks API endpoints.

*/ public LatticeHttpResponse createTask(TaskCreation request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/tasks") - .build(); + .addPathSegments("api/v1/tasks"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -101,7 +105,7 @@ public LatticeHttpResponse createTask(TaskCreation request, RequestOptions throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -183,13 +187,17 @@ public LatticeHttpResponse getTask(String taskId, GetTaskRequest request) * perspective.

*/ public LatticeHttpResponse getTask(String taskId, GetTaskRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/tasks") - .addPathSegment(taskId) - .build(); + .addPathSegment(taskId); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } Request.Builder _requestBuilder = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("GET", null) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Accept", "application/json"); @@ -282,12 +290,16 @@ public LatticeHttpResponse updateTaskStatus(String taskId, TaskStatusUpdat */ public LatticeHttpResponse updateTaskStatus( String taskId, TaskStatusUpdate request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("api/v1/tasks") .addPathSegment(taskId) - .addPathSegments("status") - .build(); + .addPathSegments("status"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -296,7 +308,7 @@ public LatticeHttpResponse updateTaskStatus( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("PUT", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -413,10 +425,14 @@ public LatticeHttpResponse queryTasks(TaskQuery request) { *

By default, this returns the latest task version for each matching task from the manager's perspective.

*/ public LatticeHttpResponse queryTasks(TaskQuery request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/tasks/query") - .build(); + .addPathSegments("api/v1/tasks/query"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -425,7 +441,7 @@ public LatticeHttpResponse queryTasks(TaskQuery request, Reque throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -499,10 +515,14 @@ public LatticeHttpResponse> streamTasks(TaskStream */ public LatticeHttpResponse> streamTasks( TaskStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/tasks/stream") - .build(); + .addPathSegments("api/v1/tasks/stream"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -511,11 +531,10 @@ public LatticeHttpResponse> streamTasks( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") .build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { @@ -638,10 +657,14 @@ public LatticeHttpResponse listenAsAgent(AgentListener request) { * period you will be expected to reinitiate a new request.

*/ public LatticeHttpResponse listenAsAgent(AgentListener request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/agent/listen") - .build(); + .addPathSegments("api/v1/agent/listen"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -650,7 +673,7 @@ public LatticeHttpResponse listenAsAgent(AgentListener request, Re throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") @@ -765,10 +788,14 @@ public LatticeHttpResponse> streamAsAgent(AgentS */ public LatticeHttpResponse> streamAsAgent( AgentStreamRequest request, RequestOptions requestOptions) { - HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() - .addPathSegments("api/v1/agent/stream") - .build(); + .addPathSegments("api/v1/agent/stream"); + if (requestOptions != null) { + requestOptions.getQueryParameters().forEach((_key, _value) -> { + httpUrl.addQueryParameter(_key, _value); + }); + } RequestBody body; try { body = RequestBody.create( @@ -777,11 +804,10 @@ public LatticeHttpResponse> streamAsAgent( throw new LatticeException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() - .url(httpUrl) + .url(httpUrl.build()) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") .build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) {