diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 112e32b3..180ef9e3 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "6.0.0" + ".": "7.0.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index d004027c..9cbd6b8d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 45 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-f09e5f2c555d7ee764478b7bc73e92cd21f403d6ec189be14574c8367bc131ce.yml -openapi_spec_hash: bd0a8e001f14132c105992d40149909a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-5b00a0bc705b1d5bfcb5ea79c7af544766d51ec12ccc4721825664ab397789d8.yml +openapi_spec_hash: 34891659cff31395ba7683a8153b1db5 config_hash: 53778a0b839c4f6ad34fbba051f5e8a6 diff --git a/CHANGELOG.md b/CHANGELOG.md index 38ebf293..a9ad4b1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## 7.0.0 (2025-05-16) + +Full Changelog: [v6.0.0...v7.0.0](https://github.com/Finch-API/finch-api-java/compare/v6.0.0...v7.0.0) + +### ⚠ BREAKING CHANGES + +* **client:** extract auto pagination to shared classes +* **client:** **Migration:** - If you were referencing the `AutoPager` class on a specific `*Page` or `*PageAsync` type, then you should instead reference the shared `AutoPager` and `AutoPagerAsync` types, under the `core` package + - `AutoPagerAsync` now has different usage. You can call `.subscribe(...)` on the returned object instead to get called back each page item. You can also call `onCompleteFuture()` to get a future that completes when all items have been processed. Finally, you can call `.close()` on the returned object to stop auto-paginating early + - If you were referencing `getNextPage` or `getNextPageParams`: + - Swap to `nextPage()` and `nextPageParams()` + - Note that these both now return non-optional types (use `hasNextPage()` before calling these, since they will throw if it's impossible to get another page) + +### Features + +* **api:** api update ([f226da9](https://github.com/Finch-API/finch-api-java/commit/f226da9c89911bb4f3f39f3657c2f725d0773e7a)) +* **api:** api update ([7932861](https://github.com/Finch-API/finch-api-java/commit/79328615d98546e904f7cf99c222f7645ecd9131)) +* **api:** api update ([17bd5c1](https://github.com/Finch-API/finch-api-java/commit/17bd5c172f3ef94e68846f5b18670b42560e1fce)) +* **client:** allow providing some params positionally ([ec6fa40](https://github.com/Finch-API/finch-api-java/commit/ec6fa40e9be337318708f336e853b3f9e551dd47)) +* **client:** extract auto pagination to shared classes ([c4a8874](https://github.com/Finch-API/finch-api-java/commit/c4a8874a3f7799b0d689beaafd00cf1a3727f0ea)) + ## 6.0.0 (2025-05-08) Full Changelog: [v5.5.0...v6.0.0](https://github.com/Finch-API/finch-api-java/compare/v5.5.0...v6.0.0) diff --git a/README.md b/README.md index fe0a5e8d..4ac5dff0 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/6.0.0) -[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/6.0.0/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/6.0.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/7.0.0) +[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/7.0.0/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.0.0) @@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [developer.tryfinch.com](https://developer.tryfinch.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.tryfinch.api/finch-java/6.0.0). +The REST API documentation can be found on [developer.tryfinch.com](https://developer.tryfinch.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.0.0). @@ -26,7 +26,7 @@ The REST API documentation can be found on [developer.tryfinch.com](https://deve ### Gradle ```kotlin -implementation("com.tryfinch.api:finch-java:6.0.0") +implementation("com.tryfinch.api:finch-java:7.0.0") ``` ### Maven @@ -35,7 +35,7 @@ implementation("com.tryfinch.api:finch-java:6.0.0") com.tryfinch.api finch-java - 6.0.0 + 7.0.0 ``` @@ -219,53 +219,101 @@ The SDK throws custom unchecked exception types: ## Pagination -For methods that return a paginated list of results, this library provides convenient ways access the results either one page at a time, or item-by-item across all pages. +The SDK defines methods that return a paginated lists of results. It provides convenient ways to access the results either one page at a time or item-by-item across all pages. ### Auto-pagination -To iterate through all results across all pages, you can use `autoPager`, which automatically handles fetching more pages for you: +To iterate through all results across all pages, use the `autoPager()` method, which automatically fetches more pages as needed. -### Synchronous +When using the synchronous client, the method returns an [`Iterable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html) ```java import com.tryfinch.api.models.HrisDirectoryListPage; import com.tryfinch.api.models.IndividualInDirectory; -// As an Iterable: -HrisDirectoryListPage page = client.hris().directory().list(params); +HrisDirectoryListPage page = client.hris().directory().list(); + +// Process as an Iterable for (IndividualInDirectory directory : page.autoPager()) { System.out.println(directory); -}; +} -// As a Stream: -client.hris().directory().list(params).autoPager().stream() +// Process as a Stream +page.autoPager() + .stream() .limit(50) .forEach(directory -> System.out.println(directory)); ``` -### Asynchronous +When using the asynchronous client, the method returns an [`AsyncStreamResponse`](finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt): ```java -// Using forEach, which returns CompletableFuture: -asyncClient.hris().directory().list(params).autoPager() - .forEach(directory -> System.out.println(directory), executor); +import com.tryfinch.api.core.http.AsyncStreamResponse; +import com.tryfinch.api.models.HrisDirectoryListPageAsync; +import com.tryfinch.api.models.IndividualInDirectory; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +CompletableFuture pageFuture = client.async().hris().directory().list(); + +pageFuture.thenRun(page -> page.autoPager().subscribe(directory -> { + System.out.println(directory); +})); + +// If you need to handle errors or completion of the stream +pageFuture.thenRun(page -> page.autoPager().subscribe(new AsyncStreamResponse.Handler<>() { + @Override + public void onNext(IndividualInDirectory directory) { + System.out.println(directory); + } + + @Override + public void onComplete(Optional error) { + if (error.isPresent()) { + System.out.println("Something went wrong!"); + throw new RuntimeException(error.get()); + } else { + System.out.println("No more!"); + } + } +})); + +// Or use futures +pageFuture.thenRun(page -> page.autoPager() + .subscribe(directory -> { + System.out.println(directory); + }) + .onCompleteFuture() + .whenComplete((unused, error) -> { + if (error != null) { + System.out.println("Something went wrong!"); + throw new RuntimeException(error); + } else { + System.out.println("No more!"); + } + })); ``` ### Manual pagination -If none of the above helpers meet your needs, you can also manually request pages one-by-one. A page of results has a `data()` method to fetch the list of objects, as well as top-level `response` and other methods to fetch top-level data about the page. It also has methods `hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination. +To access individual page items and manually request the next page, use the `items()`, +`hasNextPage()`, and `nextPage()` methods: ```java import com.tryfinch.api.models.HrisDirectoryListPage; import com.tryfinch.api.models.IndividualInDirectory; -HrisDirectoryListPage page = client.hris().directory().list(params); -while (page != null) { - for (IndividualInDirectory directory : page.individuals()) { +HrisDirectoryListPage page = client.hris().directory().list(); +while (true) { + for (IndividualInDirectory directory : page.items()) { System.out.println(directory); } - page = page.getNextPage().orElse(null); + if (!page.hasNextPage()) { + break; + } + + page = page.nextPage(); } ``` @@ -343,7 +391,6 @@ To set a custom timeout, configure the method call using the `timeout` method: ```java import com.tryfinch.api.models.HrisDirectoryListPage; -import com.tryfinch.api.models.HrisDirectoryListParams; HrisDirectoryListPage page = client.hris().directory().list(RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()); ``` @@ -573,7 +620,6 @@ Or configure the method call to validate the response using the `responseValidat ```java import com.tryfinch.api.models.HrisDirectoryListPage; -import com.tryfinch.api.models.HrisDirectoryListParams; HrisDirectoryListPage page = client.hris().directory().list(RequestOptions.builder().responseValidation(true).build()); ``` diff --git a/build.gradle.kts b/build.gradle.kts index dcfcd84d..7d01d9e2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.tryfinch.api" - version = "6.0.0" // x-release-please-version + version = "7.0.0" // x-release-please-version } subprojects { diff --git a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt index 625e6cac..21e1d896 100644 --- a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt +++ b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt @@ -13,6 +13,7 @@ import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull class FinchOkHttpClient private constructor() { @@ -47,6 +48,10 @@ class FinchOkHttpClient private constructor() { fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + clientOptions.streamHandlerExecutor(streamHandlerExecutor) + } + fun clock(clock: Clock) = apply { clientOptions.clock(clock) } fun headers(headers: Headers) = apply { clientOptions.headers(headers) } diff --git a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt index b8aac548..ecfb663d 100644 --- a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt +++ b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt @@ -13,6 +13,7 @@ import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull class FinchOkHttpClientAsync private constructor() { @@ -47,6 +48,10 @@ class FinchOkHttpClientAsync private constructor() { fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + clientOptions.streamHandlerExecutor(streamHandlerExecutor) + } + fun clock(clock: Clock) = apply { clientOptions.clock(clock) } fun headers(headers: Headers) = apply { clientOptions.headers(headers) } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt new file mode 100644 index 00000000..4ec6210a --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt @@ -0,0 +1,21 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class AutoPager private constructor(private val firstPage: Page) : Iterable { + + companion object { + + fun from(firstPage: Page): AutoPager = AutoPager(firstPage) + } + + override fun iterator(): Iterator = + generateSequence(firstPage) { if (it.hasNextPage()) it.nextPage() else null } + .flatMap { it.items() } + .iterator() + + fun stream(): Stream = StreamSupport.stream(spliterator(), false) +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt new file mode 100644 index 00000000..a2b37a0b --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import com.tryfinch.api.core.http.AsyncStreamResponse +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.CompletionException +import java.util.concurrent.Executor +import java.util.concurrent.atomic.AtomicReference + +class AutoPagerAsync +private constructor(private val firstPage: PageAsync, private val defaultExecutor: Executor) : + AsyncStreamResponse { + + companion object { + + fun from(firstPage: PageAsync, defaultExecutor: Executor): AutoPagerAsync = + AutoPagerAsync(firstPage, defaultExecutor) + } + + private val onCompleteFuture = CompletableFuture() + private val state = AtomicReference(State.NEW) + + override fun subscribe(handler: AsyncStreamResponse.Handler): AsyncStreamResponse = + subscribe(handler, defaultExecutor) + + override fun subscribe( + handler: AsyncStreamResponse.Handler, + executor: Executor, + ): AsyncStreamResponse = apply { + // TODO(JDK): Use `compareAndExchange` once targeting JDK 9. + check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) { + if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once" + else "Cannot subscribe after the response is closed" + } + + fun PageAsync.handle(): CompletableFuture { + if (state.get() == State.CLOSED) { + return CompletableFuture.completedFuture(null) + } + + items().forEach { handler.onNext(it) } + return if (hasNextPage()) nextPage().thenCompose { it.handle() } + else CompletableFuture.completedFuture(null) + } + + executor.execute { + firstPage.handle().whenComplete { _, error -> + val actualError = + if (error is CompletionException && error.cause != null) error.cause else error + try { + handler.onComplete(Optional.ofNullable(actualError)) + } finally { + try { + if (actualError == null) { + onCompleteFuture.complete(null) + } else { + onCompleteFuture.completeExceptionally(actualError) + } + } finally { + close() + } + } + } + } + } + + override fun onCompleteFuture(): CompletableFuture = onCompleteFuture + + override fun close() { + val previousState = state.getAndSet(State.CLOSED) + if (previousState == State.CLOSED) { + return + } + + // When the stream is closed, we should always consider it closed. If it closed due + // to an error, then we will have already completed the future earlier, and this + // will be a no-op. + onCompleteFuture.complete(null) + } +} + +private enum class State { + NEW, + SUBSCRIBED, + CLOSED, +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt index b228e69d..817890bb 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt @@ -5,6 +5,9 @@ package com.tryfinch.api.core import com.fasterxml.jackson.core.Version import com.fasterxml.jackson.core.util.VersionUtil +fun checkRequired(name: String, condition: Boolean) = + check(condition) { "`$name` is required, but was not set" } + fun checkRequired(name: String, value: T?): T = checkNotNull(value) { "`$name` is required, but was not set" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt index 8a9abd9c..cfdb5e56 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt @@ -11,6 +11,10 @@ import com.tryfinch.api.core.http.RetryingHttpClient import java.time.Clock import java.util.Base64 import java.util.Optional +import java.util.concurrent.Executor +import java.util.concurrent.Executors +import java.util.concurrent.ThreadFactory +import java.util.concurrent.atomic.AtomicLong import kotlin.jvm.optionals.getOrNull class ClientOptions @@ -19,6 +23,7 @@ private constructor( @get:JvmName("httpClient") val httpClient: HttpClient, @get:JvmName("checkJacksonVersionCompatibility") val checkJacksonVersionCompatibility: Boolean, @get:JvmName("jsonMapper") val jsonMapper: JsonMapper, + @get:JvmName("streamHandlerExecutor") val streamHandlerExecutor: Executor, @get:JvmName("clock") val clock: Clock, @get:JvmName("baseUrl") val baseUrl: String, @get:JvmName("headers") val headers: Headers, @@ -71,6 +76,7 @@ private constructor( private var httpClient: HttpClient? = null private var checkJacksonVersionCompatibility: Boolean = true private var jsonMapper: JsonMapper = jsonMapper() + private var streamHandlerExecutor: Executor? = null private var clock: Clock = Clock.systemUTC() private var baseUrl: String = PRODUCTION_URL private var headers: Headers.Builder = Headers.builder() @@ -88,6 +94,7 @@ private constructor( httpClient = clientOptions.originalHttpClient checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility jsonMapper = clientOptions.jsonMapper + streamHandlerExecutor = clientOptions.streamHandlerExecutor clock = clientOptions.clock baseUrl = clientOptions.baseUrl headers = clientOptions.headers.toBuilder() @@ -109,6 +116,10 @@ private constructor( fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + fun clock(clock: Clock) = apply { this.clock = clock } fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl } @@ -285,6 +296,21 @@ private constructor( ), checkJacksonVersionCompatibility, jsonMapper, + streamHandlerExecutor + ?: Executors.newCachedThreadPool( + object : ThreadFactory { + + private val threadFactory: ThreadFactory = + Executors.defaultThreadFactory() + private val count = AtomicLong(0) + + override fun newThread(runnable: Runnable): Thread = + threadFactory.newThread(runnable).also { + it.name = + "finch-stream-handler-thread-${count.getAndIncrement()}" + } + } + ), clock, baseUrl, headers.build(), diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt new file mode 100644 index 00000000..456d2b6f --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +/** + * An interface representing a single page, with items of type [T], from a paginated endpoint + * response. + * + * Implementations of this interface are expected to request additional pages synchronously. For + * asynchronous pagination, see the [PageAsync] interface. + */ +interface Page { + + /** + * Returns whether there's another page after this one. + * + * The method generally doesn't make requests so the result depends entirely on the data in this + * page. If a significant amount of time has passed between requesting this page and calling + * this method, then the result could be stale. + */ + fun hasNextPage(): Boolean + + /** + * Returns the page after this one by making another request. + * + * @throws IllegalStateException if it's impossible to get the next page. This exception is + * avoidable by calling [hasNextPage] first. + */ + fun nextPage(): Page + + /** Returns the items in this page. */ + fun items(): List +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt new file mode 100644 index 00000000..366bfede --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import java.util.concurrent.CompletableFuture + +/** + * An interface representing a single page, with items of type [T], from a paginated endpoint + * response. + * + * Implementations of this interface are expected to request additional pages asynchronously. For + * synchronous pagination, see the [Page] interface. + */ +interface PageAsync { + + /** + * Returns whether there's another page after this one. + * + * The method generally doesn't make requests so the result depends entirely on the data in this + * page. If a significant amount of time has passed between requesting this page and calling + * this method, then the result could be stale. + */ + fun hasNextPage(): Boolean + + /** + * Returns the page after this one by making another request. + * + * @throws IllegalStateException if it's impossible to get the next page. This exception is + * avoidable by calling [hasNextPage] first. + */ + fun nextPage(): CompletableFuture> + + /** Returns the items in this page. */ + fun items(): List +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt new file mode 100644 index 00000000..a86ddffd --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt @@ -0,0 +1,157 @@ +package com.tryfinch.api.core.http + +import com.tryfinch.api.core.http.AsyncStreamResponse.Handler +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.concurrent.atomic.AtomicReference + +/** + * A class providing access to an API response as an asynchronous stream of chunks of type [T], + * where each chunk can be individually processed as soon as it arrives instead of waiting on the + * full response. + */ +interface AsyncStreamResponse { + + /** + * Registers [handler] to be called for events of this stream. + * + * [handler]'s methods will be called in the client's configured or default thread pool. + * + * @throws IllegalStateException if [subscribe] has already been called. + */ + fun subscribe(handler: Handler): AsyncStreamResponse + + /** + * Registers [handler] to be called for events of this stream. + * + * [handler]'s methods will be called in the given [executor]. + * + * @throws IllegalStateException if [subscribe] has already been called. + */ + fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse + + /** + * Returns a future that completes when a stream is fully consumed, errors, or gets closed + * early. + */ + fun onCompleteFuture(): CompletableFuture + + /** + * Closes this resource, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because this response should not be + * synchronously closed via try-with-resources. + */ + fun close() + + /** A class for handling streaming events. */ + fun interface Handler { + + /** Called whenever a chunk is received. */ + fun onNext(value: T) + + /** + * Called when a stream is fully consumed, errors, or gets closed early. + * + * [onNext] will not be called once this method is called. + * + * @param error Non-empty if the stream completed due to an error. + */ + fun onComplete(error: Optional) {} + } +} + +@JvmSynthetic +internal fun CompletableFuture>.toAsync(streamHandlerExecutor: Executor) = + PhantomReachableClosingAsyncStreamResponse( + object : AsyncStreamResponse { + + private val onCompleteFuture = CompletableFuture() + private val state = AtomicReference(State.NEW) + + init { + this@toAsync.whenComplete { _, error -> + // If an error occurs from the original future, then we should resolve the + // `onCompleteFuture` even if `subscribe` has not been called. + error?.let(onCompleteFuture::completeExceptionally) + } + } + + override fun subscribe(handler: Handler): AsyncStreamResponse = + subscribe(handler, streamHandlerExecutor) + + override fun subscribe( + handler: Handler, + executor: Executor, + ): AsyncStreamResponse = apply { + // TODO(JDK): Use `compareAndExchange` once targeting JDK 9. + check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) { + if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once" + else "Cannot subscribe after the response is closed" + } + + this@toAsync.whenCompleteAsync( + { streamResponse, futureError -> + if (state.get() == State.CLOSED) { + // Avoid doing any work if `close` was called before the future + // completed. + return@whenCompleteAsync + } + + if (futureError != null) { + // An error occurred before we started passing chunks to the handler. + handler.onComplete(Optional.of(futureError)) + return@whenCompleteAsync + } + + var streamError: Throwable? = null + try { + streamResponse.stream().forEach(handler::onNext) + } catch (e: Throwable) { + streamError = e + } + + try { + handler.onComplete(Optional.ofNullable(streamError)) + } finally { + try { + // Notify completion via the `onCompleteFuture` as well. This is in + // a separate `try-finally` block so that we still complete the + // future if `handler.onComplete` throws. + if (streamError == null) { + onCompleteFuture.complete(null) + } else { + onCompleteFuture.completeExceptionally(streamError) + } + } finally { + close() + } + } + }, + executor, + ) + } + + override fun onCompleteFuture(): CompletableFuture = onCompleteFuture + + override fun close() { + val previousState = state.getAndSet(State.CLOSED) + if (previousState == State.CLOSED) { + return + } + + this@toAsync.whenComplete { streamResponse, error -> streamResponse?.close() } + // When the stream is closed, we should always consider it closed. If it closed due + // to an error, then we will have already completed the future earlier, and this + // will be a no-op. + onCompleteFuture.complete(null) + } + } + ) + +private enum class State { + NEW, + SUBSCRIBED, + CLOSED, +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt new file mode 100644 index 00000000..deca7d02 --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt @@ -0,0 +1,56 @@ +package com.tryfinch.api.core.http + +import com.tryfinch.api.core.closeWhenPhantomReachable +import com.tryfinch.api.core.http.AsyncStreamResponse.Handler +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor + +/** + * A delegating wrapper around an `AsyncStreamResponse` that closes it once it's only phantom + * reachable. + * + * This class ensures the `AsyncStreamResponse` is closed even if the user forgets to close it. + */ +internal class PhantomReachableClosingAsyncStreamResponse( + private val asyncStreamResponse: AsyncStreamResponse +) : AsyncStreamResponse { + + /** + * An object used for keeping `asyncStreamResponse` open while the object is still reachable. + */ + private val reachabilityTracker = Object() + + init { + closeWhenPhantomReachable(reachabilityTracker, asyncStreamResponse::close) + } + + override fun subscribe(handler: Handler): AsyncStreamResponse = apply { + asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker)) + } + + override fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse = + apply { + asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker), executor) + } + + override fun onCompleteFuture(): CompletableFuture = + asyncStreamResponse.onCompleteFuture() + + override fun close() = asyncStreamResponse.close() +} + +/** + * A wrapper around a `Handler` that also references a `reachabilityTracker` object. + * + * Referencing the `reachabilityTracker` object prevents it from getting reclaimed while the handler + * is still reachable. + */ +private class TrackedHandler( + private val handler: Handler, + private val reachabilityTracker: Any, +) : Handler { + override fun onNext(value: T) = handler.onNext(value) + + override fun onComplete(error: Optional) = handler.onComplete(error) +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt new file mode 100644 index 00000000..f23638aa --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt @@ -0,0 +1,21 @@ +package com.tryfinch.api.core.http + +import com.tryfinch.api.core.closeWhenPhantomReachable +import java.util.stream.Stream + +/** + * A delegating wrapper around a `StreamResponse` that closes it once it's only phantom reachable. + * + * This class ensures the `StreamResponse` is closed even if the user forgets to close it. + */ +internal class PhantomReachableClosingStreamResponse( + private val streamResponse: StreamResponse +) : StreamResponse { + init { + closeWhenPhantomReachable(this, streamResponse) + } + + override fun stream(): Stream = streamResponse.stream() + + override fun close() = streamResponse.close() +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt new file mode 100644 index 00000000..89acf0ef --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt @@ -0,0 +1,19 @@ +package com.tryfinch.api.core.http + +import java.util.stream.Stream + +interface StreamResponse : AutoCloseable { + + fun stream(): Stream + + /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */ + override fun close() +} + +@JvmSynthetic +internal fun StreamResponse.map(transform: (T) -> R): StreamResponse = + object : StreamResponse { + override fun stream(): Stream = this@map.stream().map(transform) + + override fun close() = this@map.close() + } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt index ed8fb88a..bdd47916 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Lists individuals currently enrolled in a given deduction. */ class HrisBenefitIndividualEnrolledIdsParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,14 +27,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitIndividualEnrolledIdsParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisBenefitIndividualEnrolledIdsParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -55,7 +53,10 @@ private constructor( hrisBenefitIndividualEnrolledIdsParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -159,17 +160,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitIndividualEnrolledIdsParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitIndividualEnrolledIdsParams = HrisBenefitIndividualEnrolledIdsParams( - checkRequired("benefitId", benefitId), + benefitId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -177,7 +171,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt index b5773d4e..dfc47dd0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.benefits.IndividualService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [IndividualService.retrieveManyBenefits] */ class HrisBenefitIndividualRetrieveManyBenefitsPage @@ -16,23 +14,23 @@ private constructor( private val service: IndividualService, private val params: HrisBenefitIndividualRetrieveManyBenefitsParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = - Optional.empty() + fun nextPageParams(): HrisBenefitIndividualRetrieveManyBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveManyBenefits(it) } + override fun nextPage(): HrisBenefitIndividualRetrieveManyBenefitsPage = + service.retrieveManyBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisBenefitIndividualRetrieveManyBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -101,26 +99,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisBenefitIndividualRetrieveManyBenefitsPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt index 1d164078..85f9ba74 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt @@ -2,40 +2,39 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.benefits.IndividualServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [IndividualServiceAsync.retrieveManyBenefits] */ class HrisBenefitIndividualRetrieveManyBenefitsPageAsync private constructor( private val service: IndividualServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisBenefitIndividualRetrieveManyBenefitsParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = - Optional.empty() + fun nextPageParams(): HrisBenefitIndividualRetrieveManyBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): - CompletableFuture> = - getNextPageParams() - .map { service.retrieveManyBenefits(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.retrieveManyBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisBenefitIndividualRetrieveManyBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -48,6 +47,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -59,6 +59,7 @@ private constructor( class Builder internal constructor() { private var service: IndividualServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisBenefitIndividualRetrieveManyBenefitsParams? = null private var items: List? = null @@ -68,12 +69,18 @@ private constructor( HrisBenefitIndividualRetrieveManyBenefitsPageAsync ) = apply { service = hrisBenefitIndividualRetrieveManyBenefitsPageAsync.service + streamHandlerExecutor = + hrisBenefitIndividualRetrieveManyBenefitsPageAsync.streamHandlerExecutor params = hrisBenefitIndividualRetrieveManyBenefitsPageAsync.params items = hrisBenefitIndividualRetrieveManyBenefitsPageAsync.items } fun service(service: IndividualServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisBenefitIndividualRetrieveManyBenefitsParams) = apply { this.params = params @@ -90,6 +97,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -99,51 +107,22 @@ private constructor( fun build(): HrisBenefitIndividualRetrieveManyBenefitsPageAsync = HrisBenefitIndividualRetrieveManyBenefitsPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: HrisBenefitIndividualRetrieveManyBenefitsPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture> - .forEach( - action: (IndividualBenefit) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisBenefitIndividualRetrieveManyBenefitsPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisBenefitIndividualRetrieveManyBenefitsPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisBenefitIndividualRetrieveManyBenefitsPageAsync{service=$service, params=$params, items=$items}" + "HrisBenefitIndividualRetrieveManyBenefitsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt index dd2e70a8..7c6e196e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt @@ -3,7 +3,6 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects @@ -13,13 +12,13 @@ import kotlin.jvm.optionals.getOrNull /** Get enrollment information for the given individuals. */ class HrisBenefitIndividualRetrieveManyBenefitsParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val individualIds: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) /** * comma-delimited list of stable Finch uuids for each individual. If empty, defaults to all @@ -35,14 +34,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitIndividualRetrieveManyBenefitsParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisBenefitIndividualRetrieveManyBenefitsParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -68,7 +64,10 @@ private constructor( hrisBenefitIndividualRetrieveManyBenefitsParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) /** * comma-delimited list of stable Finch uuids for each individual. If empty, defaults to all @@ -182,17 +181,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitIndividualRetrieveManyBenefitsParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitIndividualRetrieveManyBenefitsParams = HrisBenefitIndividualRetrieveManyBenefitsParams( - checkRequired("benefitId", benefitId), + benefitId, individualIds, additionalHeaders.build(), additionalQueryParams.build(), @@ -201,7 +193,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt index da3f66cd..45431317 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt @@ -12,7 +12,6 @@ import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params import com.tryfinch.api.core.checkKnown -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -25,13 +24,13 @@ import kotlin.jvm.optionals.getOrNull /** Unenroll individuals from a deduction or contribution */ class HrisBenefitIndividualUnenrollManyParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) /** * Array of individual_ids to unenroll. @@ -58,14 +57,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitIndividualUnenrollManyParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisBenefitIndividualUnenrollManyParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -90,7 +86,10 @@ private constructor( hrisBenefitIndividualUnenrollManyParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) /** * Sets the entire request body. @@ -243,17 +242,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitIndividualUnenrollManyParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitIndividualUnenrollManyParams = HrisBenefitIndividualUnenrollManyParams( - checkRequired("benefitId", benefitId), + benefitId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -264,7 +256,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt index 7b00ce90..fbcf2ff6 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.BenefitService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [BenefitService.list] */ class HrisBenefitListPage @@ -16,21 +14,22 @@ private constructor( private val service: BenefitService, private val params: HrisBenefitListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): HrisBenefitListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -93,25 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisBenefitListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt index f49f49a4..9cd78291 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt @@ -2,38 +2,39 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.BenefitServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [BenefitServiceAsync.list] */ class HrisBenefitListPageAsync private constructor( private val service: BenefitServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisBenefitListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +46,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +58,24 @@ private constructor( class Builder internal constructor() { private var service: BenefitServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisBenefitListParams? = null private var items: List? = null @JvmSynthetic internal fun from(hrisBenefitListPageAsync: HrisBenefitListPageAsync) = apply { service = hrisBenefitListPageAsync.service + streamHandlerExecutor = hrisBenefitListPageAsync.streamHandlerExecutor params = hrisBenefitListPageAsync.params items = hrisBenefitListPageAsync.items } fun service(service: BenefitServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisBenefitListParams) = apply { this.params = params } @@ -82,6 +90,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,50 +100,22 @@ private constructor( fun build(): HrisBenefitListPageAsync = HrisBenefitListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: HrisBenefitListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (CompanyBenefit) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisBenefitListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisBenefitListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisBenefitListPageAsync{service=$service, params=$params, items=$items}" + "HrisBenefitListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt index 147d1698..3409c4b3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt @@ -2,12 +2,12 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.BenefitService import java.util.Objects import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [BenefitService.listSupportedBenefits] */ @@ -16,22 +16,23 @@ private constructor( private val service: BenefitService, private val params: HrisBenefitListSupportedBenefitsParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListSupportedBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = - getNextPageParams().map { service.listSupportedBenefits(it) } + override fun nextPage(): HrisBenefitListSupportedBenefitsPage = + service.listSupportedBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListSupportedBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -99,26 +100,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisBenefitListSupportedBenefitsPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt index 859239d8..3f3abf51 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt @@ -2,39 +2,41 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.BenefitServiceAsync import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [BenefitServiceAsync.listSupportedBenefits] */ class HrisBenefitListSupportedBenefitsPageAsync private constructor( private val service: BenefitServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisBenefitListSupportedBenefitsParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListSupportedBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.listSupportedBenefits(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.listSupportedBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListSupportedBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -47,6 +49,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -58,6 +61,7 @@ private constructor( class Builder internal constructor() { private var service: BenefitServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisBenefitListSupportedBenefitsParams? = null private var items: Optional>? = null @@ -66,12 +70,17 @@ private constructor( hrisBenefitListSupportedBenefitsPageAsync: HrisBenefitListSupportedBenefitsPageAsync ) = apply { service = hrisBenefitListSupportedBenefitsPageAsync.service + streamHandlerExecutor = hrisBenefitListSupportedBenefitsPageAsync.streamHandlerExecutor params = hrisBenefitListSupportedBenefitsPageAsync.params items = Optional.of(hrisBenefitListSupportedBenefitsPageAsync.items) } fun service(service: BenefitServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisBenefitListSupportedBenefitsParams) = apply { this.params = params } @@ -88,6 +97,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -97,52 +107,22 @@ private constructor( fun build(): HrisBenefitListSupportedBenefitsPageAsync = HrisBenefitListSupportedBenefitsPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items).getOrNull() ?: emptyList(), ) } - class AutoPager(private val firstPage: HrisBenefitListSupportedBenefitsPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (BenefitListSupportedBenefitsResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList( - executor: Executor - ): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisBenefitListSupportedBenefitsPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisBenefitListSupportedBenefitsPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisBenefitListSupportedBenefitsPageAsync{service=$service, params=$params, items=$items}" + "HrisBenefitListSupportedBenefitsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt index 0167113d..c6fa8c33 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Lists deductions and contributions information for a given item */ class HrisBenefitRetrieveParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,13 +27,10 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [HrisBenefitRetrieveParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -51,7 +49,10 @@ private constructor( additionalQueryParams = hrisBenefitRetrieveParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -155,17 +156,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitRetrieveParams = HrisBenefitRetrieveParams( - checkRequired("benefitId", benefitId), + benefitId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -173,7 +167,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt index 91bc5f13..90b691f3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt @@ -11,24 +11,24 @@ import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Updates an existing company-wide deduction or contribution */ class HrisBenefitUpdateParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) /** * Updated name or description. @@ -55,14 +55,9 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [HrisBenefitUpdateParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - */ + @JvmStatic fun none(): HrisBenefitUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [HrisBenefitUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -82,7 +77,10 @@ private constructor( additionalQueryParams = hrisBenefitUpdateParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) /** * Sets the entire request body. @@ -226,17 +224,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitUpdateParams = HrisBenefitUpdateParams( - checkRequired("benefitId", benefitId), + benefitId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -247,7 +238,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt index 00bcd8fa..823bce21 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.company.PayStatementItemService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [PayStatementItemService.list] */ @@ -16,7 +15,7 @@ private constructor( private val service: PayStatementItemService, private val params: HrisCompanyPayStatementItemListParams, private val response: HrisCompanyPayStatementItemListPageResponse, -) { +) : Page { /** * Delegates to [HrisCompanyPayStatementItemListPageResponse], but gracefully handles missing @@ -27,14 +26,16 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + fun nextPageParams(): HrisCompanyPayStatementItemListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisCompanyPayStatementItemListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemListParams = params @@ -108,26 +109,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt index 8a50507b..a39ed6ef 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.company.PayStatementItemServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [PayStatementItemServiceAsync.list] */ class HrisCompanyPayStatementItemListPageAsync private constructor( private val service: PayStatementItemServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisCompanyPayStatementItemListParams, private val response: HrisCompanyPayStatementItemListPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisCompanyPayStatementItemListPageResponse], but gracefully handles missing @@ -28,16 +29,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisCompanyPayStatementItemListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemListParams = params @@ -56,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -67,6 +71,7 @@ private constructor( class Builder internal constructor() { private var service: PayStatementItemServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisCompanyPayStatementItemListParams? = null private var response: HrisCompanyPayStatementItemListPageResponse? = null @@ -75,12 +80,17 @@ private constructor( hrisCompanyPayStatementItemListPageAsync: HrisCompanyPayStatementItemListPageAsync ) = apply { service = hrisCompanyPayStatementItemListPageAsync.service + streamHandlerExecutor = hrisCompanyPayStatementItemListPageAsync.streamHandlerExecutor params = hrisCompanyPayStatementItemListPageAsync.params response = hrisCompanyPayStatementItemListPageAsync.response } fun service(service: PayStatementItemServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisCompanyPayStatementItemListParams) = apply { this.params = params } @@ -97,6 +107,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -106,50 +117,22 @@ private constructor( fun build(): HrisCompanyPayStatementItemListPageAsync = HrisCompanyPayStatementItemListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (PayStatementItemListResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisCompanyPayStatementItemListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisCompanyPayStatementItemListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisCompanyPayStatementItemListPageAsync{service=$service, params=$params, response=$response}" + "HrisCompanyPayStatementItemListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt index a9f7f64d..1f47cbe2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt @@ -4,12 +4,12 @@ package com.tryfinch.api.models import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical @@ -17,13 +17,13 @@ import java.util.Optional */ class HrisCompanyPayStatementItemRuleDeleteParams private constructor( - private val ruleId: String, + private val ruleId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { - fun ruleId(): String = ruleId + fun ruleId(): Optional = Optional.ofNullable(ruleId) fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -35,14 +35,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisCompanyPayStatementItemRuleDeleteParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisCompanyPayStatementItemRuleDeleteParams]. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -68,7 +65,10 @@ private constructor( hrisCompanyPayStatementItemRuleDeleteParams.additionalBodyProperties.toMutableMap() } - fun ruleId(ruleId: String) = apply { this.ruleId = ruleId } + fun ruleId(ruleId: String?) = apply { this.ruleId = ruleId } + + /** Alias for calling [Builder.ruleId] with `ruleId.orElse(null)`. */ + fun ruleId(ruleId: Optional) = ruleId(ruleId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -194,17 +194,10 @@ private constructor( * Returns an immutable instance of [HrisCompanyPayStatementItemRuleDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisCompanyPayStatementItemRuleDeleteParams = HrisCompanyPayStatementItemRuleDeleteParams( - checkRequired("ruleId", ruleId), + ruleId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -216,7 +209,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> ruleId + 0 -> ruleId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt index cb2c5147..580d9169 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.company.payStatementItem.RuleService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [RuleService.list] */ @@ -16,7 +15,7 @@ private constructor( private val service: RuleService, private val params: HrisCompanyPayStatementItemRuleListParams, private val response: HrisCompanyPayStatementItemRuleListPageResponse, -) { +) : Page { /** * Delegates to [HrisCompanyPayStatementItemRuleListPageResponse], but gracefully handles @@ -27,14 +26,17 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + fun nextPageParams(): HrisCompanyPayStatementItemRuleListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisCompanyPayStatementItemRuleListPage = + service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemRuleListParams = params @@ -110,26 +112,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemRuleListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt index 269318ac..1a083316 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.company.payStatementItem.RuleServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [RuleServiceAsync.list] */ class HrisCompanyPayStatementItemRuleListPageAsync private constructor( private val service: RuleServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisCompanyPayStatementItemRuleListParams, private val response: HrisCompanyPayStatementItemRuleListPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisCompanyPayStatementItemRuleListPageResponse], but gracefully handles @@ -28,16 +29,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisCompanyPayStatementItemRuleListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemRuleListParams = params @@ -56,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -67,6 +71,7 @@ private constructor( class Builder internal constructor() { private var service: RuleServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisCompanyPayStatementItemRuleListParams? = null private var response: HrisCompanyPayStatementItemRuleListPageResponse? = null @@ -76,12 +81,18 @@ private constructor( HrisCompanyPayStatementItemRuleListPageAsync ) = apply { service = hrisCompanyPayStatementItemRuleListPageAsync.service + streamHandlerExecutor = + hrisCompanyPayStatementItemRuleListPageAsync.streamHandlerExecutor params = hrisCompanyPayStatementItemRuleListPageAsync.params response = hrisCompanyPayStatementItemRuleListPageAsync.response } fun service(service: RuleServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisCompanyPayStatementItemRuleListParams) = apply { this.params = params @@ -100,6 +111,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -109,50 +121,22 @@ private constructor( fun build(): HrisCompanyPayStatementItemRuleListPageAsync = HrisCompanyPayStatementItemRuleListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemRuleListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (RuleListResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisCompanyPayStatementItemRuleListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisCompanyPayStatementItemRuleListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisCompanyPayStatementItemRuleListPageAsync{service=$service, params=$params, response=$response}" + "HrisCompanyPayStatementItemRuleListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt index 0ec80b82..e509e8bf 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt @@ -10,12 +10,13 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical @@ -23,13 +24,13 @@ import java.util.Objects */ class HrisCompanyPayStatementItemRuleUpdateParams private constructor( - private val ruleId: String, + private val ruleId: String?, private val body: UpdateRuleRequest, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun ruleId(): String = ruleId + fun ruleId(): Optional = Optional.ofNullable(ruleId) fun _optionalProperty(): JsonValue = body._optionalProperty() @@ -43,14 +44,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisCompanyPayStatementItemRuleUpdateParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisCompanyPayStatementItemRuleUpdateParams]. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -75,7 +73,10 @@ private constructor( hrisCompanyPayStatementItemRuleUpdateParams.additionalQueryParams.toBuilder() } - fun ruleId(ruleId: String) = apply { this.ruleId = ruleId } + fun ruleId(ruleId: String?) = apply { this.ruleId = ruleId } + + /** Alias for calling [Builder.ruleId] with `ruleId.orElse(null)`. */ + fun ruleId(ruleId: Optional) = ruleId(ruleId.getOrNull()) /** * Sets the entire request body. @@ -211,17 +212,10 @@ private constructor( * Returns an immutable instance of [HrisCompanyPayStatementItemRuleUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisCompanyPayStatementItemRuleUpdateParams = HrisCompanyPayStatementItemRuleUpdateParams( - checkRequired("ruleId", ruleId), + ruleId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -232,7 +226,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> ruleId + 0 -> ruleId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt index eeafc093..8f3c042a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt @@ -2,12 +2,12 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.DirectoryService import java.util.Objects import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -18,7 +18,7 @@ private constructor( private val service: DirectoryService, private val params: HrisDirectoryListIndividualsParams, private val response: HrisDirectoryListIndividualsPageResponse, -) { +) : Page { /** * Delegates to [HrisDirectoryListIndividualsPageResponse], but gracefully handles missing data. @@ -35,30 +35,28 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListIndividualsParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): Optional = - getNextPageParams().map { service.listIndividuals(it) } + override fun nextPage(): HrisDirectoryListIndividualsPage = + service.listIndividuals(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListIndividualsParams = params @@ -131,26 +129,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisDirectoryListIndividualsPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.individuals().size) { - yield(page.individuals()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt index e7480379..1a20863f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt @@ -2,13 +2,14 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.DirectoryServiceAsync import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -17,9 +18,10 @@ import kotlin.jvm.optionals.getOrNull class HrisDirectoryListIndividualsPageAsync private constructor( private val service: DirectoryServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisDirectoryListIndividualsParams, private val response: HrisDirectoryListIndividualsPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisDirectoryListIndividualsPageResponse], but gracefully handles missing data. @@ -36,32 +38,29 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListIndividualsParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.listIndividuals(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.listIndividuals(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListIndividualsParams = params @@ -80,6 +79,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -91,6 +91,7 @@ private constructor( class Builder internal constructor() { private var service: DirectoryServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisDirectoryListIndividualsParams? = null private var response: HrisDirectoryListIndividualsPageResponse? = null @@ -99,12 +100,17 @@ private constructor( hrisDirectoryListIndividualsPageAsync: HrisDirectoryListIndividualsPageAsync ) = apply { service = hrisDirectoryListIndividualsPageAsync.service + streamHandlerExecutor = hrisDirectoryListIndividualsPageAsync.streamHandlerExecutor params = hrisDirectoryListIndividualsPageAsync.params response = hrisDirectoryListIndividualsPageAsync.response } fun service(service: DirectoryServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisDirectoryListIndividualsParams) = apply { this.params = params } @@ -121,6 +127,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -130,50 +137,22 @@ private constructor( fun build(): HrisDirectoryListIndividualsPageAsync = HrisDirectoryListIndividualsPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisDirectoryListIndividualsPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (IndividualInDirectory) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.individuals().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisDirectoryListIndividualsPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisDirectoryListIndividualsPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisDirectoryListIndividualsPageAsync{service=$service, params=$params, response=$response}" + "HrisDirectoryListIndividualsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt index 36eff6a0..f30e6e3c 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt @@ -2,12 +2,12 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.DirectoryService import java.util.Objects import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -17,7 +17,7 @@ private constructor( private val service: DirectoryService, private val params: HrisDirectoryListParams, private val response: HrisDirectoryListPageResponse, -) { +) : Page { /** * Delegates to [HrisDirectoryListPageResponse], but gracefully handles missing data. @@ -34,30 +34,27 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + override fun nextPage(): HrisDirectoryListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListParams = params @@ -126,26 +123,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisDirectoryListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.individuals().size) { - yield(page.individuals()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt index bc8d9645..06b6ee3a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt @@ -2,13 +2,14 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.DirectoryServiceAsync import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -16,9 +17,10 @@ import kotlin.jvm.optionals.getOrNull class HrisDirectoryListPageAsync private constructor( private val service: DirectoryServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisDirectoryListParams, private val response: HrisDirectoryListPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisDirectoryListPageResponse], but gracefully handles missing data. @@ -35,32 +37,29 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListParams = params @@ -78,6 +77,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -89,18 +89,24 @@ private constructor( class Builder internal constructor() { private var service: DirectoryServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisDirectoryListParams? = null private var response: HrisDirectoryListPageResponse? = null @JvmSynthetic internal fun from(hrisDirectoryListPageAsync: HrisDirectoryListPageAsync) = apply { service = hrisDirectoryListPageAsync.service + streamHandlerExecutor = hrisDirectoryListPageAsync.streamHandlerExecutor params = hrisDirectoryListPageAsync.params response = hrisDirectoryListPageAsync.response } fun service(service: DirectoryServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisDirectoryListParams) = apply { this.params = params } @@ -115,6 +121,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -124,50 +131,22 @@ private constructor( fun build(): HrisDirectoryListPageAsync = HrisDirectoryListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisDirectoryListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (IndividualInDirectory) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.individuals().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisDirectoryListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisDirectoryListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisDirectoryListPageAsync{service=$service, params=$params, response=$response}" + "HrisDirectoryListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt index 5de75843..c0d046d1 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt @@ -3,10 +3,11 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * **Beta:** This endpoint is in beta and may change. Retrieve details of a specific document by its @@ -14,12 +15,12 @@ import java.util.Objects */ class HrisDocumentRetreiveParams private constructor( - private val documentId: String, + private val documentId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun documentId(): String = documentId + fun documentId(): Optional = Optional.ofNullable(documentId) fun _additionalHeaders(): Headers = additionalHeaders @@ -29,13 +30,10 @@ private constructor( companion object { + @JvmStatic fun none(): HrisDocumentRetreiveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [HrisDocumentRetreiveParams]. - * - * The following fields are required: - * ```java - * .documentId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -54,7 +52,10 @@ private constructor( additionalQueryParams = hrisDocumentRetreiveParams.additionalQueryParams.toBuilder() } - fun documentId(documentId: String) = apply { this.documentId = documentId } + fun documentId(documentId: String?) = apply { this.documentId = documentId } + + /** Alias for calling [Builder.documentId] with `documentId.orElse(null)`. */ + fun documentId(documentId: Optional) = documentId(documentId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -158,17 +159,10 @@ private constructor( * Returns an immutable instance of [HrisDocumentRetreiveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .documentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisDocumentRetreiveParams = HrisDocumentRetreiveParams( - checkRequired("documentId", documentId), + documentId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -176,7 +170,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> documentId + 0 -> documentId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt index 9987671a..a4fb48cd 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.EmploymentService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [EmploymentService.retrieveMany] */ @@ -16,7 +15,7 @@ private constructor( private val service: EmploymentService, private val params: HrisEmploymentRetrieveManyParams, private val response: HrisEmploymentRetrieveManyPageResponse, -) { +) : Page { /** * Delegates to [HrisEmploymentRetrieveManyPageResponse], but gracefully handles missing data. @@ -26,14 +25,16 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveMany(it) } + fun nextPageParams(): HrisEmploymentRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisEmploymentRetrieveManyPage = service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisEmploymentRetrieveManyParams = params @@ -105,26 +106,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisEmploymentRetrieveManyPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt index 83f3ed95..91ccab5d 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.EmploymentServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [EmploymentServiceAsync.retrieveMany] */ class HrisEmploymentRetrieveManyPageAsync private constructor( private val service: EmploymentServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisEmploymentRetrieveManyParams, private val response: HrisEmploymentRetrieveManyPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisEmploymentRetrieveManyPageResponse], but gracefully handles missing data. @@ -27,16 +28,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.retrieveMany(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisEmploymentRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisEmploymentRetrieveManyParams = params @@ -55,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -66,6 +70,7 @@ private constructor( class Builder internal constructor() { private var service: EmploymentServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisEmploymentRetrieveManyParams? = null private var response: HrisEmploymentRetrieveManyPageResponse? = null @@ -74,12 +79,17 @@ private constructor( hrisEmploymentRetrieveManyPageAsync: HrisEmploymentRetrieveManyPageAsync ) = apply { service = hrisEmploymentRetrieveManyPageAsync.service + streamHandlerExecutor = hrisEmploymentRetrieveManyPageAsync.streamHandlerExecutor params = hrisEmploymentRetrieveManyPageAsync.params response = hrisEmploymentRetrieveManyPageAsync.response } fun service(service: EmploymentServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisEmploymentRetrieveManyParams) = apply { this.params = params } @@ -96,6 +106,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -105,50 +116,22 @@ private constructor( fun build(): HrisEmploymentRetrieveManyPageAsync = HrisEmploymentRetrieveManyPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisEmploymentRetrieveManyPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (EmploymentDataResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisEmploymentRetrieveManyPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisEmploymentRetrieveManyPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisEmploymentRetrieveManyPageAsync{service=$service, params=$params, response=$response}" + "HrisEmploymentRetrieveManyPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt index e9c57c27..ac6fca75 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.IndividualService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [IndividualService.retrieveMany] */ @@ -16,7 +15,7 @@ private constructor( private val service: IndividualService, private val params: HrisIndividualRetrieveManyParams, private val response: HrisIndividualRetrieveManyPageResponse, -) { +) : Page { /** * Delegates to [HrisIndividualRetrieveManyPageResponse], but gracefully handles missing data. @@ -26,14 +25,16 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveMany(it) } + fun nextPageParams(): HrisIndividualRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisIndividualRetrieveManyPage = service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisIndividualRetrieveManyParams = params @@ -105,26 +106,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisIndividualRetrieveManyPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt index 77678253..efacc397 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.IndividualServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [IndividualServiceAsync.retrieveMany] */ class HrisIndividualRetrieveManyPageAsync private constructor( private val service: IndividualServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisIndividualRetrieveManyParams, private val response: HrisIndividualRetrieveManyPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisIndividualRetrieveManyPageResponse], but gracefully handles missing data. @@ -27,16 +28,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.retrieveMany(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisIndividualRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisIndividualRetrieveManyParams = params @@ -55,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -66,6 +70,7 @@ private constructor( class Builder internal constructor() { private var service: IndividualServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisIndividualRetrieveManyParams? = null private var response: HrisIndividualRetrieveManyPageResponse? = null @@ -74,12 +79,17 @@ private constructor( hrisIndividualRetrieveManyPageAsync: HrisIndividualRetrieveManyPageAsync ) = apply { service = hrisIndividualRetrieveManyPageAsync.service + streamHandlerExecutor = hrisIndividualRetrieveManyPageAsync.streamHandlerExecutor params = hrisIndividualRetrieveManyPageAsync.params response = hrisIndividualRetrieveManyPageAsync.response } fun service(service: IndividualServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisIndividualRetrieveManyParams) = apply { this.params = params } @@ -96,6 +106,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -105,50 +116,22 @@ private constructor( fun build(): HrisIndividualRetrieveManyPageAsync = HrisIndividualRetrieveManyPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisIndividualRetrieveManyPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (IndividualResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisIndividualRetrieveManyPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisIndividualRetrieveManyPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisIndividualRetrieveManyPageAsync{service=$service, params=$params, response=$response}" + "HrisIndividualRetrieveManyPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt index f8a43307..ce24980a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.PayStatementService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [PayStatementService.retrieveMany] */ @@ -16,7 +15,7 @@ private constructor( private val service: PayStatementService, private val params: HrisPayStatementRetrieveManyParams, private val response: HrisPayStatementRetrieveManyPageResponse, -) { +) : Page { /** * Delegates to [HrisPayStatementRetrieveManyPageResponse], but gracefully handles missing data. @@ -26,14 +25,17 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveMany(it) } + fun nextPageParams(): HrisPayStatementRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisPayStatementRetrieveManyPage = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisPayStatementRetrieveManyParams = params @@ -106,26 +108,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisPayStatementRetrieveManyPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt index 2ec1929c..ff0099a3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.PayStatementServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [PayStatementServiceAsync.retrieveMany] */ class HrisPayStatementRetrieveManyPageAsync private constructor( private val service: PayStatementServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisPayStatementRetrieveManyParams, private val response: HrisPayStatementRetrieveManyPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisPayStatementRetrieveManyPageResponse], but gracefully handles missing data. @@ -27,16 +28,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.retrieveMany(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisPayStatementRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisPayStatementRetrieveManyParams = params @@ -55,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -66,6 +70,7 @@ private constructor( class Builder internal constructor() { private var service: PayStatementServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisPayStatementRetrieveManyParams? = null private var response: HrisPayStatementRetrieveManyPageResponse? = null @@ -74,12 +79,17 @@ private constructor( hrisPayStatementRetrieveManyPageAsync: HrisPayStatementRetrieveManyPageAsync ) = apply { service = hrisPayStatementRetrieveManyPageAsync.service + streamHandlerExecutor = hrisPayStatementRetrieveManyPageAsync.streamHandlerExecutor params = hrisPayStatementRetrieveManyPageAsync.params response = hrisPayStatementRetrieveManyPageAsync.response } fun service(service: PayStatementServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisPayStatementRetrieveManyParams) = apply { this.params = params } @@ -96,6 +106,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -105,50 +116,22 @@ private constructor( fun build(): HrisPayStatementRetrieveManyPageAsync = HrisPayStatementRetrieveManyPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisPayStatementRetrieveManyPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (PayStatementResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisPayStatementRetrieveManyPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisPayStatementRetrieveManyPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisPayStatementRetrieveManyPageAsync{service=$service, params=$params, response=$response}" + "HrisPayStatementRetrieveManyPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt index 82892fa1..9cf9d9a5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.PaymentService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [PaymentService.list] */ class HrisPaymentListPage @@ -16,21 +14,22 @@ private constructor( private val service: PaymentService, private val params: HrisPaymentListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisPaymentListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): HrisPaymentListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisPaymentListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -93,25 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisPaymentListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt index 236a00f1..ee77147a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt @@ -2,38 +2,38 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.PaymentServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [PaymentServiceAsync.list] */ class HrisPaymentListPageAsync private constructor( private val service: PaymentServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisPaymentListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisPaymentListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisPaymentListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +45,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +57,24 @@ private constructor( class Builder internal constructor() { private var service: PaymentServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisPaymentListParams? = null private var items: List? = null @JvmSynthetic internal fun from(hrisPaymentListPageAsync: HrisPaymentListPageAsync) = apply { service = hrisPaymentListPageAsync.service + streamHandlerExecutor = hrisPaymentListPageAsync.streamHandlerExecutor params = hrisPaymentListPageAsync.params items = hrisPaymentListPageAsync.items } fun service(service: PaymentServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisPaymentListParams) = apply { this.params = params } @@ -82,6 +89,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,47 +99,22 @@ private constructor( fun build(): HrisPaymentListPageAsync = HrisPaymentListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: HrisPaymentListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Payment) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisPaymentListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisPaymentListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisPaymentListPageAsync{service=$service, params=$params, items=$items}" + "HrisPaymentListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt index ac519b49..220a5b3b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an automated job by `job_id`. */ class JobAutomatedRetrieveParams private constructor( - private val jobId: String, + private val jobId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun jobId(): String = jobId + fun jobId(): Optional = Optional.ofNullable(jobId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,13 +27,10 @@ private constructor( companion object { + @JvmStatic fun none(): JobAutomatedRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [JobAutomatedRetrieveParams]. - * - * The following fields are required: - * ```java - * .jobId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -51,7 +49,10 @@ private constructor( additionalQueryParams = jobAutomatedRetrieveParams.additionalQueryParams.toBuilder() } - fun jobId(jobId: String) = apply { this.jobId = jobId } + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -155,17 +156,10 @@ private constructor( * Returns an immutable instance of [JobAutomatedRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .jobId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): JobAutomatedRetrieveParams = JobAutomatedRetrieveParams( - checkRequired("jobId", jobId), + jobId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -173,7 +167,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> jobId + 0 -> jobId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt index a1833b8c..0ec08bb9 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt @@ -3,10 +3,11 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * Get a manual job by `job_id`. Manual jobs are completed by a human and include Assisted Benefits @@ -14,12 +15,12 @@ import java.util.Objects */ class JobManualRetrieveParams private constructor( - private val jobId: String, + private val jobId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun jobId(): String = jobId + fun jobId(): Optional = Optional.ofNullable(jobId) fun _additionalHeaders(): Headers = additionalHeaders @@ -29,14 +30,9 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [JobManualRetrieveParams]. - * - * The following fields are required: - * ```java - * .jobId() - * ``` - */ + @JvmStatic fun none(): JobManualRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [JobManualRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -54,7 +50,10 @@ private constructor( additionalQueryParams = jobManualRetrieveParams.additionalQueryParams.toBuilder() } - fun jobId(jobId: String) = apply { this.jobId = jobId } + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -158,25 +157,14 @@ private constructor( * Returns an immutable instance of [JobManualRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .jobId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): JobManualRetrieveParams = - JobManualRetrieveParams( - checkRequired("jobId", jobId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + JobManualRetrieveParams(jobId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> jobId + 0 -> jobId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt index ae0b753f..805ed50b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt @@ -3075,6 +3075,8 @@ private constructor( @JvmField val DIRECT_DEPOSIT = of("direct_deposit") + @JvmField val OTHER = of("other") + @JvmStatic fun of(value: String) = PaymentMethod(JsonField.of(value)) } @@ -3082,6 +3084,7 @@ private constructor( enum class Known { CHECK, DIRECT_DEPOSIT, + OTHER, } /** @@ -3096,6 +3099,7 @@ private constructor( enum class Value { CHECK, DIRECT_DEPOSIT, + OTHER, /** * An enum member indicating that [PaymentMethod] was instantiated with an unknown * value. @@ -3114,6 +3118,7 @@ private constructor( when (this) { CHECK -> Value.CHECK DIRECT_DEPOSIT -> Value.DIRECT_DEPOSIT + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -3129,6 +3134,7 @@ private constructor( when (this) { CHECK -> Known.CHECK DIRECT_DEPOSIT -> Known.DIRECT_DEPOSIT + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PaymentMethod: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt index a6556ac8..9287b371 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.payroll.PayGroupService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [PayGroupService.list] */ class PayrollPayGroupListPage @@ -16,22 +14,22 @@ private constructor( private val service: PayGroupService, private val params: PayrollPayGroupListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): PayrollPayGroupListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + override fun nextPage(): PayrollPayGroupListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): PayrollPayGroupListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -94,26 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: PayrollPayGroupListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt index 98a97b4f..9b790ca2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt @@ -2,38 +2,39 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.payroll.PayGroupServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [PayGroupServiceAsync.list] */ class PayrollPayGroupListPageAsync private constructor( private val service: PayGroupServiceAsync, + private val streamHandlerExecutor: Executor, private val params: PayrollPayGroupListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): PayrollPayGroupListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): PayrollPayGroupListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +46,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +58,24 @@ private constructor( class Builder internal constructor() { private var service: PayGroupServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: PayrollPayGroupListParams? = null private var items: List? = null @JvmSynthetic internal fun from(payrollPayGroupListPageAsync: PayrollPayGroupListPageAsync) = apply { service = payrollPayGroupListPageAsync.service + streamHandlerExecutor = payrollPayGroupListPageAsync.streamHandlerExecutor params = payrollPayGroupListPageAsync.params items = payrollPayGroupListPageAsync.items } fun service(service: PayGroupServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: PayrollPayGroupListParams) = apply { this.params = params } @@ -82,6 +90,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,50 +100,22 @@ private constructor( fun build(): PayrollPayGroupListPageAsync = PayrollPayGroupListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: PayrollPayGroupListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (PayGroupListResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PayrollPayGroupListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is PayrollPayGroupListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "PayrollPayGroupListPageAsync{service=$service, params=$params, items=$items}" + "PayrollPayGroupListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt index 129a9287..f64580b6 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Read information from a single pay group */ class PayrollPayGroupRetrieveParams private constructor( - private val payGroupId: String, + private val payGroupId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun payGroupId(): String = payGroupId + fun payGroupId(): Optional = Optional.ofNullable(payGroupId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,14 +27,11 @@ private constructor( companion object { + @JvmStatic fun none(): PayrollPayGroupRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [PayrollPayGroupRetrieveParams]. - * - * The following fields are required: - * ```java - * .payGroupId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -52,7 +50,10 @@ private constructor( additionalQueryParams = payrollPayGroupRetrieveParams.additionalQueryParams.toBuilder() } - fun payGroupId(payGroupId: String) = apply { this.payGroupId = payGroupId } + fun payGroupId(payGroupId: String?) = apply { this.payGroupId = payGroupId } + + /** Alias for calling [Builder.payGroupId] with `payGroupId.orElse(null)`. */ + fun payGroupId(payGroupId: Optional) = payGroupId(payGroupId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -156,17 +157,10 @@ private constructor( * Returns an immutable instance of [PayrollPayGroupRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .payGroupId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams( - checkRequired("payGroupId", payGroupId), + payGroupId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -174,7 +168,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> payGroupId + 0 -> payGroupId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt index fddd8a63..e3c2524a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.ProviderService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [ProviderService.list] */ class ProviderListPage @@ -16,21 +14,22 @@ private constructor( private val service: ProviderService, private val params: ProviderListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): ProviderListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ProviderListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ProviderListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -93,25 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: ProviderListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt index bdb79fb7..c23a65e2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt @@ -2,38 +2,38 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.ProviderServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [ProviderServiceAsync.list] */ class ProviderListPageAsync private constructor( private val service: ProviderServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ProviderListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): ProviderListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ProviderListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +45,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +57,24 @@ private constructor( class Builder internal constructor() { private var service: ProviderServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ProviderListParams? = null private var items: List? = null @JvmSynthetic internal fun from(providerListPageAsync: ProviderListPageAsync) = apply { service = providerListPageAsync.service + streamHandlerExecutor = providerListPageAsync.streamHandlerExecutor params = providerListPageAsync.params items = providerListPageAsync.items } fun service(service: ProviderServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ProviderListParams) = apply { this.params = params } @@ -82,6 +89,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,47 +99,22 @@ private constructor( fun build(): ProviderListPageAsync = ProviderListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: ProviderListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Provider) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProviderListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is ProviderListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "ProviderListPageAsync{service=$service, params=$params, items=$items}" + "ProviderListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt index ef2be056..ce9ed3e1 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt @@ -13,7 +13,6 @@ import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params import com.tryfinch.api.core.checkKnown -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -26,13 +25,13 @@ import kotlin.jvm.optionals.getOrNull /** Update sandbox employment */ class SandboxEmploymentUpdateParams private constructor( - private val individualId: String, + private val individualId: String?, private val body: EmploymentWithoutId, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun individualId(): String = individualId + fun individualId(): Optional = Optional.ofNullable(individualId) /** * Worker's compensation classification code for this employee @@ -311,14 +310,11 @@ private constructor( companion object { + @JvmStatic fun none(): SandboxEmploymentUpdateParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [SandboxEmploymentUpdateParams]. - * - * The following fields are required: - * ```java - * .individualId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -339,7 +335,10 @@ private constructor( additionalQueryParams = sandboxEmploymentUpdateParams.additionalQueryParams.toBuilder() } - fun individualId(individualId: String) = apply { this.individualId = individualId } + fun individualId(individualId: String?) = apply { this.individualId = individualId } + + /** Alias for calling [Builder.individualId] with `individualId.orElse(null)`. */ + fun individualId(individualId: Optional) = individualId(individualId.getOrNull()) /** * Sets the entire request body. @@ -777,17 +776,10 @@ private constructor( * Returns an immutable instance of [SandboxEmploymentUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .individualId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams( - checkRequired("individualId", individualId), + individualId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -798,7 +790,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> individualId + 0 -> individualId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt index 8349ea86..7d886f90 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt @@ -13,7 +13,6 @@ import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params import com.tryfinch.api.core.checkKnown -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -26,13 +25,13 @@ import kotlin.jvm.optionals.getOrNull /** Update sandbox individual */ class SandboxIndividualUpdateParams private constructor( - private val individualId: String, + private val individualId: String?, private val body: IndividualWithoutId, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun individualId(): String = individualId + fun individualId(): Optional = Optional.ofNullable(individualId) /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -220,14 +219,11 @@ private constructor( companion object { + @JvmStatic fun none(): SandboxIndividualUpdateParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [SandboxIndividualUpdateParams]. - * - * The following fields are required: - * ```java - * .individualId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -248,7 +244,10 @@ private constructor( additionalQueryParams = sandboxIndividualUpdateParams.additionalQueryParams.toBuilder() } - fun individualId(individualId: String) = apply { this.individualId = individualId } + fun individualId(individualId: String?) = apply { this.individualId = individualId } + + /** Alias for calling [Builder.individualId] with `individualId.orElse(null)`. */ + fun individualId(individualId: Optional) = individualId(individualId.getOrNull()) /** * Sets the entire request body. @@ -589,17 +588,10 @@ private constructor( * Returns an immutable instance of [SandboxIndividualUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .individualId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SandboxIndividualUpdateParams = SandboxIndividualUpdateParams( - checkRequired("individualId", individualId), + individualId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -610,7 +602,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> individualId + 0 -> individualId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt index 480911e5..82188e32 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt @@ -3650,6 +3650,8 @@ private constructor( @JvmField val DIRECT_DEPOSIT = of("direct_deposit") + @JvmField val OTHER = of("other") + @JvmStatic fun of(value: String) = PaymentMethod(JsonField.of(value)) } @@ -3657,6 +3659,7 @@ private constructor( enum class Known { CHECK, DIRECT_DEPOSIT, + OTHER, } /** @@ -3671,6 +3674,7 @@ private constructor( enum class Value { CHECK, DIRECT_DEPOSIT, + OTHER, /** * An enum member indicating that [PaymentMethod] was instantiated with an unknown * value. @@ -3689,6 +3693,7 @@ private constructor( when (this) { CHECK -> Value.CHECK DIRECT_DEPOSIT -> Value.DIRECT_DEPOSIT + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -3705,6 +3710,7 @@ private constructor( when (this) { CHECK -> Known.CHECK DIRECT_DEPOSIT -> Known.DIRECT_DEPOSIT + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PaymentMethod: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt index faaef5e4..9de04dba 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt @@ -68,6 +68,7 @@ class ProviderServiceAsyncImpl internal constructor(private val clientOptions: C .let { ProviderListPageAsync.builder() .service(ProviderServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt index 0ebd8f70..78490ed2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt @@ -50,8 +50,22 @@ interface BenefitServiceAsync { create(HrisBenefitCreateParams.none(), requestOptions) /** Lists deductions and contributions information for a given item */ - fun retrieve(params: HrisBenefitRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(benefitId: String): CompletableFuture = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): CompletableFuture = retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -59,9 +73,35 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve(params: HrisBenefitRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** Updates an existing company-wide deduction or contribution */ - fun update(params: HrisBenefitUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(benefitId: String): CompletableFuture = + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): CompletableFuture = + update(benefitId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -69,6 +109,17 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update(params: HrisBenefitUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** List all company-wide deductions and contributions. */ fun list(): CompletableFuture = list(HrisBenefitListParams.none()) @@ -152,10 +203,25 @@ interface BenefitServiceAsync { * the same as [BenefitServiceAsync.retrieve]. */ @MustBeClosed + fun retrieve(benefitId: String): CompletableFuture> = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: HrisBenefitRetrieveParams + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): CompletableFuture> = + retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -164,15 +230,47 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: HrisBenefitRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /employer/benefits/{benefit_id}`, but is otherwise * the same as [BenefitServiceAsync.update]. */ @MustBeClosed fun update( - params: HrisBenefitUpdateParams + benefitId: String ): CompletableFuture> = - update(params, RequestOptions.none()) + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): CompletableFuture> = + update(benefitId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -181,6 +279,21 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [update] */ + @MustBeClosed + fun update( + params: HrisBenefitUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits`, but is otherwise the same as * [BenefitServiceAsync.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt index 3eefa17d..1e38a525 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -30,6 +31,7 @@ import com.tryfinch.api.services.async.hris.benefits.IndividualServiceAsync import com.tryfinch.api.services.async.hris.benefits.IndividualServiceAsyncImpl import java.util.Optional import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class BenefitServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : BenefitServiceAsync { @@ -130,6 +132,9 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl params: HrisBenefitRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -160,6 +165,9 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl params: HrisBenefitUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) @@ -212,6 +220,7 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { HrisBenefitListPageAsync.builder() .service(BenefitServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() @@ -252,6 +261,7 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { HrisBenefitListSupportedBenefitsPageAsync.builder() .service(BenefitServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt index dfe58374..737aeac0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt @@ -80,6 +80,7 @@ class DirectoryServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisDirectoryListPageAsync.builder() .service(DirectoryServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -118,6 +119,7 @@ class DirectoryServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisDirectoryListIndividualsPageAsync.builder() .service(DirectoryServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt index a25175a1..5688823e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt @@ -42,8 +42,23 @@ interface DocumentServiceAsync { * **Beta:** This endpoint is in beta and may change. Retrieve details of a specific document by * its ID. */ - fun retreive(params: HrisDocumentRetreiveParams): CompletableFuture = - retreive(params, RequestOptions.none()) + fun retreive(documentId: String): CompletableFuture = + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): CompletableFuture = + retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ fun retreive( @@ -51,6 +66,17 @@ interface DocumentServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retreive] */ + fun retreive(params: HrisDocumentRetreiveParams): CompletableFuture = + retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + fun retreive( + documentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) + /** * A view of [DocumentServiceAsync] that provides access to raw HTTP responses for each method. */ @@ -91,9 +117,26 @@ interface DocumentServiceAsync { */ @MustBeClosed fun retreive( - params: HrisDocumentRetreiveParams + documentId: String ): CompletableFuture> = - retreive(params, RequestOptions.none()) + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): CompletableFuture> = + retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ @MustBeClosed @@ -101,5 +144,20 @@ interface DocumentServiceAsync { params: HrisDocumentRetreiveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + params: HrisDocumentRetreiveParams + ): CompletableFuture> = + retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt index 7f6e4636..cd75084e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -19,6 +20,7 @@ import com.tryfinch.api.models.DocumentRetreiveResponse import com.tryfinch.api.models.HrisDocumentListParams import com.tryfinch.api.models.HrisDocumentRetreiveParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class DocumentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : DocumentServiceAsync { @@ -86,6 +88,9 @@ class DocumentServiceAsyncImpl internal constructor(private val clientOptions: C params: HrisDocumentRetreiveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("documentId", params.documentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt index 395a53ff..a9c72d89 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt @@ -71,6 +71,7 @@ class EmploymentServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisEmploymentRetrieveManyPageAsync.builder() .service(EmploymentServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt index 20b0435f..26a7925a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt @@ -71,6 +71,7 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisIndividualRetrieveManyPageAsync.builder() .service(IndividualServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt index cfae8dc4..6a682d8f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt @@ -71,6 +71,7 @@ class PayStatementServiceAsyncImpl internal constructor(private val clientOption .let { HrisPayStatementRetrieveManyPageAsync.builder() .service(PayStatementServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt index 35690383..c8b13fea 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt @@ -68,6 +68,7 @@ class PaymentServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { HrisPaymentListPageAsync.builder() .service(PaymentServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt index 5999c68e..12b6ea0f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt @@ -21,9 +21,25 @@ interface IndividualServiceAsync { fun withRawResponse(): WithRawResponse /** Lists individuals currently enrolled in a given deduction. */ + fun enrolledIds(benefitId: String): CompletableFuture = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ fun enrolledIds( - params: HrisBenefitIndividualEnrolledIdsParams - ): CompletableFuture = enrolledIds(params, RequestOptions.none()) + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): CompletableFuture = + enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ fun enrolledIds( @@ -31,11 +47,40 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [enrolledIds] */ + fun enrolledIds( + params: HrisBenefitIndividualEnrolledIdsParams + ): CompletableFuture = enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** Get enrollment information for the given individuals. */ fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String ): CompletableFuture = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): CompletableFuture = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ fun retrieveManyBenefits( @@ -43,11 +88,43 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): CompletableFuture = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** Unenroll individuals from a deduction or contribution */ + fun unenrollMany(benefitId: String): CompletableFuture = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture = - unenrollMany(params, RequestOptions.none()) + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): CompletableFuture = + unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ fun unenrollMany( @@ -55,6 +132,19 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [unenrollMany] */ + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): CompletableFuture = + unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) + /** * A view of [IndividualServiceAsync] that provides access to raw HTTP responses for each * method. @@ -67,9 +157,28 @@ interface IndividualServiceAsync { */ @MustBeClosed fun enrolledIds( - params: HrisBenefitIndividualEnrolledIdsParams + benefitId: String ): CompletableFuture> = - enrolledIds(params, RequestOptions.none()) + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): CompletableFuture> = + enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ @MustBeClosed @@ -78,15 +187,49 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + params: HrisBenefitIndividualEnrolledIdsParams + ): CompletableFuture> = + enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits/{benefit_id}/individuals`, but is * otherwise the same as [IndividualServiceAsync.retrieveManyBenefits]. */ @MustBeClosed fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String ): CompletableFuture> = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): CompletableFuture> = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ @MustBeClosed @@ -95,15 +238,53 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): CompletableFuture> = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** * Returns a raw HTTP response for `delete /employer/benefits/{benefit_id}/individuals`, but * is otherwise the same as [IndividualServiceAsync.unenrollMany]. */ @MustBeClosed fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams + benefitId: String ): CompletableFuture> = - unenrollMany(params, RequestOptions.none()) + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): CompletableFuture> = + unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ @MustBeClosed @@ -111,5 +292,20 @@ interface IndividualServiceAsync { params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): CompletableFuture> = + unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt index 0fa6358a..959a36b0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris.benefits import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -23,6 +24,7 @@ import com.tryfinch.api.models.IndividualBenefit import com.tryfinch.api.models.IndividualEnrolledIdsResponse import com.tryfinch.api.models.UnenrolledIndividualBenefitResponse import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class IndividualServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : IndividualServiceAsync { @@ -67,6 +69,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: HrisBenefitIndividualEnrolledIdsParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -97,6 +102,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: HrisBenefitIndividualRetrieveManyBenefitsParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -118,6 +126,7 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisBenefitIndividualRetrieveManyBenefitsPageAsync.builder() .service(IndividualServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() @@ -134,6 +143,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt index c7b25159..6c1131c8 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt @@ -81,6 +81,7 @@ internal constructor(private val clientOptions: ClientOptions) : PayStatementIte .let { HrisCompanyPayStatementItemListPageAsync.builder() .service(PayStatementItemServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt index e19add98..613b9577 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt @@ -53,9 +53,24 @@ interface RuleServiceAsync { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Update a rule for a pay statement item. */ + fun update(ruleId: String): CompletableFuture = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ fun update( - params: HrisCompanyPayStatementItemRuleUpdateParams - ): CompletableFuture = update(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): CompletableFuture = update(ruleId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -63,6 +78,18 @@ interface RuleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update( + params: HrisCompanyPayStatementItemRuleUpdateParams + ): CompletableFuture = update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon List all rules of a connection account. @@ -94,9 +121,24 @@ interface RuleServiceAsync { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Delete a rule for a pay statement item. */ + fun delete(ruleId: String): CompletableFuture = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ fun delete( - params: HrisCompanyPayStatementItemRuleDeleteParams - ): CompletableFuture = delete(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): CompletableFuture = delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ fun delete( @@ -104,6 +146,18 @@ interface RuleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [delete] */ + fun delete( + params: HrisCompanyPayStatementItemRuleDeleteParams + ): CompletableFuture = delete(params, RequestOptions.none()) + + /** @see [delete] */ + fun delete( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) + /** A view of [RuleServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -143,10 +197,27 @@ interface RuleServiceAsync { * otherwise the same as [RuleServiceAsync.update]. */ @MustBeClosed + fun update(ruleId: String): CompletableFuture> = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: HrisCompanyPayStatementItemRuleUpdateParams + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - update(params, RequestOptions.none()) + update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): CompletableFuture> = + update(ruleId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -155,6 +226,21 @@ interface RuleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [update] */ + @MustBeClosed + fun update( + params: HrisCompanyPayStatementItemRuleUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-statement-item/rule`, but is otherwise * the same as [RuleServiceAsync.list]. @@ -192,10 +278,27 @@ interface RuleServiceAsync { * is otherwise the same as [RuleServiceAsync.delete]. */ @MustBeClosed + fun delete(ruleId: String): CompletableFuture> = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ + @MustBeClosed fun delete( - params: HrisCompanyPayStatementItemRuleDeleteParams + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - delete(params, RequestOptions.none()) + delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): CompletableFuture> = + delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ @MustBeClosed @@ -203,5 +306,20 @@ interface RuleServiceAsync { params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [delete] */ + @MustBeClosed + fun delete( + params: HrisCompanyPayStatementItemRuleDeleteParams + ): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt index 3d5e6225..71f908a0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris.company.payStatementItem import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -25,6 +26,7 @@ import com.tryfinch.api.models.RuleCreateResponse import com.tryfinch.api.models.RuleDeleteResponse import com.tryfinch.api.models.RuleUpdateResponse import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class RuleServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : RuleServiceAsync { @@ -105,6 +107,9 @@ class RuleServiceAsyncImpl internal constructor(private val clientOptions: Clien params: HrisCompanyPayStatementItemRuleUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) @@ -157,6 +162,7 @@ class RuleServiceAsyncImpl internal constructor(private val clientOptions: Clien .let { HrisCompanyPayStatementItemRuleListPageAsync.builder() .service(RuleServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -172,6 +178,9 @@ class RuleServiceAsyncImpl internal constructor(private val clientOptions: Clien params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt index 374f8672..90fc195c 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt @@ -54,8 +54,22 @@ interface AutomatedServiceAsync { create(JobAutomatedCreateParams.none(), requestOptions) /** Get an automated job by `job_id`. */ - fun retrieve(params: JobAutomatedRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): CompletableFuture = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): CompletableFuture = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -63,6 +77,17 @@ interface AutomatedServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve(params: JobAutomatedRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Get all automated jobs. Automated jobs are completed by a machine. By default, jobs are * sorted in descending order by submission time. For scheduled jobs such as data syncs, only @@ -124,10 +149,25 @@ interface AutomatedServiceAsync { * as [AutomatedServiceAsync.retrieve]. */ @MustBeClosed + fun retrieve(jobId: String): CompletableFuture> = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: JobAutomatedRetrieveParams + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): CompletableFuture> = + retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -136,6 +176,21 @@ interface AutomatedServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: JobAutomatedRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /jobs/automated`, but is otherwise the same as * [AutomatedServiceAsync.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt index 486c207e..77de2441 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -22,6 +23,7 @@ import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams import com.tryfinch.api.models.JobAutomatedRetrieveParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class AutomatedServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : AutomatedServiceAsync { @@ -96,6 +98,9 @@ class AutomatedServiceAsyncImpl internal constructor(private val clientOptions: params: JobAutomatedRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt index 0d51c731..9d131db4 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt @@ -20,8 +20,22 @@ interface ManualServiceAsync { * Get a manual job by `job_id`. Manual jobs are completed by a human and include Assisted * Benefits jobs. */ - fun retrieve(params: JobManualRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): CompletableFuture = + retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): CompletableFuture = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -29,6 +43,14 @@ interface ManualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve(params: JobManualRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(jobId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) + /** * A view of [ManualServiceAsync] that provides access to raw HTTP responses for each method. */ @@ -39,10 +61,25 @@ interface ManualServiceAsync { * [ManualServiceAsync.retrieve]. */ @MustBeClosed + fun retrieve(jobId: String): CompletableFuture> = + retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: JobManualRetrieveParams + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): CompletableFuture> = + retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -50,5 +87,20 @@ interface ManualServiceAsync { params: JobManualRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: JobManualRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt index 29425dfd..f52bfd4e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -17,6 +18,7 @@ import com.tryfinch.api.core.prepareAsync import com.tryfinch.api.models.JobManualRetrieveParams import com.tryfinch.api.models.ManualAsyncJob import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class ManualServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ManualServiceAsync { @@ -46,6 +48,9 @@ class ManualServiceAsyncImpl internal constructor(private val clientOptions: Cli params: JobManualRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt index 837276f5..303f01d7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt @@ -19,9 +19,23 @@ interface PayGroupServiceAsync { fun withRawResponse(): WithRawResponse /** Read information from a single pay group */ + fun retrieve(payGroupId: String): CompletableFuture = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ fun retrieve( - params: PayrollPayGroupRetrieveParams - ): CompletableFuture = retrieve(params, RequestOptions.none()) + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): CompletableFuture = + retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -29,6 +43,18 @@ interface PayGroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve( + params: PayrollPayGroupRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** Read company pay groups and frequencies */ fun list(): CompletableFuture = list(PayrollPayGroupListParams.none()) @@ -59,9 +85,26 @@ interface PayGroupServiceAsync { */ @MustBeClosed fun retrieve( - params: PayrollPayGroupRetrieveParams + payGroupId: String ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): CompletableFuture> = + retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -70,6 +113,21 @@ interface PayGroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: PayrollPayGroupRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-groups`, but is otherwise the same as * [PayGroupServiceAsync.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt index 1807f79b..2e8dacac 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.payroll import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -20,6 +21,7 @@ import com.tryfinch.api.models.PayrollPayGroupListPageAsync import com.tryfinch.api.models.PayrollPayGroupListParams import com.tryfinch.api.models.PayrollPayGroupRetrieveParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class PayGroupServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : PayGroupServiceAsync { @@ -57,6 +59,9 @@ class PayGroupServiceAsyncImpl internal constructor(private val clientOptions: C params: PayrollPayGroupRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("payGroupId", params.payGroupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -108,6 +113,7 @@ class PayGroupServiceAsyncImpl internal constructor(private val clientOptions: C .let { PayrollPayGroupListPageAsync.builder() .service(PayGroupServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt index ad8fabfa..1828a047 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt @@ -17,8 +17,23 @@ interface EmploymentServiceAsync { fun withRawResponse(): WithRawResponse /** Update sandbox employment */ - fun update(params: SandboxEmploymentUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(individualId: String): CompletableFuture = + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): CompletableFuture = + update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -26,6 +41,17 @@ interface EmploymentServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update(params: SandboxEmploymentUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) + /** * A view of [EmploymentServiceAsync] that provides access to raw HTTP responses for each * method. @@ -38,9 +64,26 @@ interface EmploymentServiceAsync { */ @MustBeClosed fun update( - params: SandboxEmploymentUpdateParams + individualId: String ): CompletableFuture> = - update(params, RequestOptions.none()) + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): CompletableFuture> = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -48,5 +91,20 @@ interface EmploymentServiceAsync { params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxEmploymentUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt index 212d7652..9534d121 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -18,6 +19,7 @@ import com.tryfinch.api.core.prepareAsync import com.tryfinch.api.models.EmploymentUpdateResponse import com.tryfinch.api.models.SandboxEmploymentUpdateParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class EmploymentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : EmploymentServiceAsync { @@ -48,6 +50,9 @@ class EmploymentServiceAsyncImpl internal constructor(private val clientOptions: params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt index 47d38c4e..74ba9437 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt @@ -17,8 +17,23 @@ interface IndividualServiceAsync { fun withRawResponse(): WithRawResponse /** Update sandbox individual */ - fun update(params: SandboxIndividualUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(individualId: String): CompletableFuture = + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): CompletableFuture = + update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -26,6 +41,17 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update(params: SandboxIndividualUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) + /** * A view of [IndividualServiceAsync] that provides access to raw HTTP responses for each * method. @@ -38,9 +64,26 @@ interface IndividualServiceAsync { */ @MustBeClosed fun update( - params: SandboxIndividualUpdateParams + individualId: String ): CompletableFuture> = - update(params, RequestOptions.none()) + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): CompletableFuture> = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -48,5 +91,20 @@ interface IndividualServiceAsync { params: SandboxIndividualUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxIndividualUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt index 7cdca716..fca58ca0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -18,6 +19,7 @@ import com.tryfinch.api.core.prepareAsync import com.tryfinch.api.models.IndividualUpdateResponse import com.tryfinch.api.models.SandboxIndividualUpdateParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class IndividualServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : IndividualServiceAsync { @@ -48,6 +50,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: SandboxIndividualUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt index 0625d51a..43c93d72 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt @@ -48,8 +48,21 @@ interface BenefitService { create(HrisBenefitCreateParams.none(), requestOptions) /** Lists deductions and contributions information for a given item */ - fun retrieve(params: HrisBenefitRetrieveParams): CompanyBenefit = - retrieve(params, RequestOptions.none()) + fun retrieve(benefitId: String): CompanyBenefit = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompanyBenefit = retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): CompanyBenefit = retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -57,9 +70,31 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): CompanyBenefit + /** @see [retrieve] */ + fun retrieve(params: HrisBenefitRetrieveParams): CompanyBenefit = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(benefitId: String, requestOptions: RequestOptions): CompanyBenefit = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** Updates an existing company-wide deduction or contribution */ - fun update(params: HrisBenefitUpdateParams): UpdateCompanyBenefitResponse = - update(params, RequestOptions.none()) + fun update(benefitId: String): UpdateCompanyBenefitResponse = + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): UpdateCompanyBenefitResponse = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): UpdateCompanyBenefitResponse = update(benefitId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -67,6 +102,14 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): UpdateCompanyBenefitResponse + /** @see [update] */ + fun update(params: HrisBenefitUpdateParams): UpdateCompanyBenefitResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(benefitId: String, requestOptions: RequestOptions): UpdateCompanyBenefitResponse = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** List all company-wide deductions and contributions. */ fun list(): HrisBenefitListPage = list(HrisBenefitListParams.none()) @@ -143,8 +186,24 @@ interface BenefitService { * the same as [BenefitService.retrieve]. */ @MustBeClosed - fun retrieve(params: HrisBenefitRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(benefitId: String): HttpResponseFor = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): HttpResponseFor = retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -153,13 +212,43 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieve] */ + @MustBeClosed + fun retrieve(params: HrisBenefitRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /employer/benefits/{benefit_id}`, but is otherwise * the same as [BenefitService.update]. */ @MustBeClosed - fun update(params: HrisBenefitUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(benefitId: String): HttpResponseFor = + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): HttpResponseFor = + update(benefitId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -168,6 +257,19 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [update] */ + @MustBeClosed + fun update(params: HrisBenefitUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits`, but is otherwise the same as * [BenefitService.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt index 98cd9792..3fc43430 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -29,6 +30,7 @@ import com.tryfinch.api.models.UpdateCompanyBenefitResponse import com.tryfinch.api.services.blocking.hris.benefits.IndividualService import com.tryfinch.api.services.blocking.hris.benefits.IndividualServiceImpl import java.util.Optional +import kotlin.jvm.optionals.getOrNull class BenefitServiceImpl internal constructor(private val clientOptions: ClientOptions) : BenefitService { @@ -124,6 +126,9 @@ class BenefitServiceImpl internal constructor(private val clientOptions: ClientO params: HrisBenefitRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -151,6 +156,9 @@ class BenefitServiceImpl internal constructor(private val clientOptions: ClientO params: HrisBenefitUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt index 2688fe07..0fb3dc39 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt @@ -40,8 +40,22 @@ interface DocumentService { * **Beta:** This endpoint is in beta and may change. Retrieve details of a specific document by * its ID. */ - fun retreive(params: HrisDocumentRetreiveParams): DocumentRetreiveResponse = - retreive(params, RequestOptions.none()) + fun retreive(documentId: String): DocumentRetreiveResponse = + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): DocumentRetreiveResponse = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): DocumentRetreiveResponse = retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ fun retreive( @@ -49,6 +63,14 @@ interface DocumentService { requestOptions: RequestOptions = RequestOptions.none(), ): DocumentRetreiveResponse + /** @see [retreive] */ + fun retreive(params: HrisDocumentRetreiveParams): DocumentRetreiveResponse = + retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + fun retreive(documentId: String, requestOptions: RequestOptions): DocumentRetreiveResponse = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) + /** A view of [DocumentService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -82,9 +104,25 @@ interface DocumentService { * the same as [DocumentService.retreive]. */ @MustBeClosed + fun retreive(documentId: String): HttpResponseFor = + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + @MustBeClosed fun retreive( - params: HrisDocumentRetreiveParams - ): HttpResponseFor = retreive(params, RequestOptions.none()) + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): HttpResponseFor = + retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ @MustBeClosed @@ -92,5 +130,19 @@ interface DocumentService { params: HrisDocumentRetreiveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + params: HrisDocumentRetreiveParams + ): HttpResponseFor = retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt index 8ddf997d..2f11fac7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -18,6 +19,7 @@ import com.tryfinch.api.models.DocumentListResponse import com.tryfinch.api.models.DocumentRetreiveResponse import com.tryfinch.api.models.HrisDocumentListParams import com.tryfinch.api.models.HrisDocumentRetreiveParams +import kotlin.jvm.optionals.getOrNull class DocumentServiceImpl internal constructor(private val clientOptions: ClientOptions) : DocumentService { @@ -82,6 +84,9 @@ class DocumentServiceImpl internal constructor(private val clientOptions: Client params: HrisDocumentRetreiveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("documentId", params.documentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt index 5352666e..9a306ff3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt @@ -20,8 +20,24 @@ interface IndividualService { fun withRawResponse(): WithRawResponse /** Lists individuals currently enrolled in a given deduction. */ - fun enrolledIds(params: HrisBenefitIndividualEnrolledIdsParams): IndividualEnrolledIdsResponse = - enrolledIds(params, RequestOptions.none()) + fun enrolledIds(benefitId: String): IndividualEnrolledIdsResponse = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndividualEnrolledIdsResponse = + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): IndividualEnrolledIdsResponse = enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ fun enrolledIds( @@ -29,11 +45,37 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): IndividualEnrolledIdsResponse + /** @see [enrolledIds] */ + fun enrolledIds(params: HrisBenefitIndividualEnrolledIdsParams): IndividualEnrolledIdsResponse = + enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): IndividualEnrolledIdsResponse = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** Get enrollment information for the given individuals. */ + fun retrieveManyBenefits(benefitId: String): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HrisBenefitIndividualRetrieveManyBenefitsPage = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ fun retrieveManyBenefits( @@ -41,10 +83,42 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): HrisBenefitIndividualRetrieveManyBenefitsPage + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** Unenroll individuals from a deduction or contribution */ + fun unenrollMany(benefitId: String): UnenrolledIndividualBenefitResponse = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams - ): UnenrolledIndividualBenefitResponse = unenrollMany(params, RequestOptions.none()) + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): UnenrolledIndividualBenefitResponse = + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): UnenrolledIndividualBenefitResponse = unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ fun unenrollMany( @@ -52,6 +126,18 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): UnenrolledIndividualBenefitResponse + /** @see [unenrollMany] */ + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): UnenrolledIndividualBenefitResponse = unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): UnenrolledIndividualBenefitResponse = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) + /** A view of [IndividualService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -60,10 +146,27 @@ interface IndividualService { * otherwise the same as [IndividualService.enrolledIds]. */ @MustBeClosed + fun enrolledIds(benefitId: String): HttpResponseFor = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ + @MustBeClosed fun enrolledIds( - params: HrisBenefitIndividualEnrolledIdsParams + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor = - enrolledIds(params, RequestOptions.none()) + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): HttpResponseFor = + enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ @MustBeClosed @@ -72,15 +175,49 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + params: HrisBenefitIndividualEnrolledIdsParams + ): HttpResponseFor = + enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits/{benefit_id}/individuals`, but is * otherwise the same as [IndividualService.retrieveManyBenefits]. */ @MustBeClosed fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String ): HttpResponseFor = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): HttpResponseFor = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ @MustBeClosed @@ -89,15 +226,51 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): HttpResponseFor = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** * Returns a raw HTTP response for `delete /employer/benefits/{benefit_id}/individuals`, but * is otherwise the same as [IndividualService.unenrollMany]. */ @MustBeClosed + fun unenrollMany(benefitId: String): HttpResponseFor = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ + @MustBeClosed fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor = - unenrollMany(params, RequestOptions.none()) + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): HttpResponseFor = + unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ @MustBeClosed @@ -105,5 +278,20 @@ interface IndividualService { params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): HttpResponseFor = + unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt index 403030dd..9fc38484 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris.benefits import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -22,6 +23,7 @@ import com.tryfinch.api.models.HrisBenefitIndividualUnenrollManyParams import com.tryfinch.api.models.IndividualBenefit import com.tryfinch.api.models.IndividualEnrolledIdsResponse import com.tryfinch.api.models.UnenrolledIndividualBenefitResponse +import kotlin.jvm.optionals.getOrNull class IndividualServiceImpl internal constructor(private val clientOptions: ClientOptions) : IndividualService { @@ -66,6 +68,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: HrisBenefitIndividualEnrolledIdsParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -93,6 +98,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: HrisBenefitIndividualRetrieveManyBenefitsParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -127,6 +135,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt index 34a2124d..288e3791 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt @@ -51,8 +51,23 @@ interface RuleService { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Update a rule for a pay statement item. */ - fun update(params: HrisCompanyPayStatementItemRuleUpdateParams): RuleUpdateResponse = - update(params, RequestOptions.none()) + fun update(ruleId: String): RuleUpdateResponse = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): RuleUpdateResponse = update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): RuleUpdateResponse = update(ruleId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -60,6 +75,14 @@ interface RuleService { requestOptions: RequestOptions = RequestOptions.none(), ): RuleUpdateResponse + /** @see [update] */ + fun update(params: HrisCompanyPayStatementItemRuleUpdateParams): RuleUpdateResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(ruleId: String, requestOptions: RequestOptions): RuleUpdateResponse = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon List all rules of a connection account. @@ -88,8 +111,23 @@ interface RuleService { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Delete a rule for a pay statement item. */ - fun delete(params: HrisCompanyPayStatementItemRuleDeleteParams): RuleDeleteResponse = - delete(params, RequestOptions.none()) + fun delete(ruleId: String): RuleDeleteResponse = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): RuleDeleteResponse = delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): RuleDeleteResponse = delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ fun delete( @@ -97,6 +135,14 @@ interface RuleService { requestOptions: RequestOptions = RequestOptions.none(), ): RuleDeleteResponse + /** @see [delete] */ + fun delete(params: HrisCompanyPayStatementItemRuleDeleteParams): RuleDeleteResponse = + delete(params, RequestOptions.none()) + + /** @see [delete] */ + fun delete(ruleId: String, requestOptions: RequestOptions): RuleDeleteResponse = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) + /** A view of [RuleService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -133,9 +179,26 @@ interface RuleService { * otherwise the same as [RuleService.update]. */ @MustBeClosed + fun update(ruleId: String): HttpResponseFor = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: HrisCompanyPayStatementItemRuleUpdateParams - ): HttpResponseFor = update(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): HttpResponseFor = update(ruleId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -144,6 +207,20 @@ interface RuleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [update] */ + @MustBeClosed + fun update( + params: HrisCompanyPayStatementItemRuleUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-statement-item/rule`, but is otherwise * the same as [RuleService.list]. @@ -180,9 +257,26 @@ interface RuleService { * is otherwise the same as [RuleService.delete]. */ @MustBeClosed + fun delete(ruleId: String): HttpResponseFor = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ + @MustBeClosed fun delete( - params: HrisCompanyPayStatementItemRuleDeleteParams - ): HttpResponseFor = delete(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): HttpResponseFor = delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ @MustBeClosed @@ -190,5 +284,19 @@ interface RuleService { params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [delete] */ + @MustBeClosed + fun delete( + params: HrisCompanyPayStatementItemRuleDeleteParams + ): HttpResponseFor = delete(params, RequestOptions.none()) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt index 370263d4..c829f537 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris.company.payStatementItem import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -24,6 +25,7 @@ import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleUpdateParams import com.tryfinch.api.models.RuleCreateResponse import com.tryfinch.api.models.RuleDeleteResponse import com.tryfinch.api.models.RuleUpdateResponse +import kotlin.jvm.optionals.getOrNull class RuleServiceImpl internal constructor(private val clientOptions: ClientOptions) : RuleService { @@ -100,6 +102,9 @@ class RuleServiceImpl internal constructor(private val clientOptions: ClientOpti params: HrisCompanyPayStatementItemRuleUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) @@ -161,6 +166,9 @@ class RuleServiceImpl internal constructor(private val clientOptions: ClientOpti params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt index fafcfff9..4bc55fe3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt @@ -52,8 +52,21 @@ interface AutomatedService { create(JobAutomatedCreateParams.none(), requestOptions) /** Get an automated job by `job_id`. */ - fun retrieve(params: JobAutomatedRetrieveParams): AutomatedAsyncJob = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): AutomatedAsyncJob = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AutomatedAsyncJob = retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): AutomatedAsyncJob = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -61,6 +74,14 @@ interface AutomatedService { requestOptions: RequestOptions = RequestOptions.none(), ): AutomatedAsyncJob + /** @see [retrieve] */ + fun retrieve(params: JobAutomatedRetrieveParams): AutomatedAsyncJob = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(jobId: String, requestOptions: RequestOptions): AutomatedAsyncJob = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Get all automated jobs. Automated jobs are completed by a machine. By default, jobs are * sorted in descending order by submission time. For scheduled jobs such as data syncs, only @@ -117,8 +138,24 @@ interface AutomatedService { * as [AutomatedService.retrieve]. */ @MustBeClosed - fun retrieve(params: JobAutomatedRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): HttpResponseFor = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): HttpResponseFor = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -127,6 +164,19 @@ interface AutomatedService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieve] */ + @MustBeClosed + fun retrieve(params: JobAutomatedRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /jobs/automated`, but is otherwise the same as * [AutomatedService.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt index 3d20fb5e..87e961d5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -21,6 +22,7 @@ import com.tryfinch.api.models.AutomatedListResponse import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams import com.tryfinch.api.models.JobAutomatedRetrieveParams +import kotlin.jvm.optionals.getOrNull class AutomatedServiceImpl internal constructor(private val clientOptions: ClientOptions) : AutomatedService { @@ -92,6 +94,9 @@ class AutomatedServiceImpl internal constructor(private val clientOptions: Clien params: JobAutomatedRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt index 66de50ae..4e0334df 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt @@ -19,8 +19,20 @@ interface ManualService { * Get a manual job by `job_id`. Manual jobs are completed by a human and include Assisted * Benefits jobs. */ - fun retrieve(params: JobManualRetrieveParams): ManualAsyncJob = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): ManualAsyncJob = retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ManualAsyncJob = retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): ManualAsyncJob = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -28,6 +40,14 @@ interface ManualService { requestOptions: RequestOptions = RequestOptions.none(), ): ManualAsyncJob + /** @see [retrieve] */ + fun retrieve(params: JobManualRetrieveParams): ManualAsyncJob = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(jobId: String, requestOptions: RequestOptions): ManualAsyncJob = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) + /** A view of [ManualService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -36,8 +56,24 @@ interface ManualService { * [ManualService.retrieve]. */ @MustBeClosed - fun retrieve(params: JobManualRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): HttpResponseFor = + retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): HttpResponseFor = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -45,5 +81,18 @@ interface ManualService { params: JobManualRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve(params: JobManualRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt index b055b8e6..373dabf5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -16,6 +17,7 @@ import com.tryfinch.api.core.http.parseable import com.tryfinch.api.core.prepare import com.tryfinch.api.models.JobManualRetrieveParams import com.tryfinch.api.models.ManualAsyncJob +import kotlin.jvm.optionals.getOrNull class ManualServiceImpl internal constructor(private val clientOptions: ClientOptions) : ManualService { @@ -45,6 +47,9 @@ class ManualServiceImpl internal constructor(private val clientOptions: ClientOp params: JobManualRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt index dfbd5bb3..05717f0b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt @@ -18,8 +18,22 @@ interface PayGroupService { fun withRawResponse(): WithRawResponse /** Read information from a single pay group */ - fun retrieve(params: PayrollPayGroupRetrieveParams): PayGroupRetrieveResponse = - retrieve(params, RequestOptions.none()) + fun retrieve(payGroupId: String): PayGroupRetrieveResponse = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PayGroupRetrieveResponse = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): PayGroupRetrieveResponse = retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -27,6 +41,14 @@ interface PayGroupService { requestOptions: RequestOptions = RequestOptions.none(), ): PayGroupRetrieveResponse + /** @see [retrieve] */ + fun retrieve(params: PayrollPayGroupRetrieveParams): PayGroupRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(payGroupId: String, requestOptions: RequestOptions): PayGroupRetrieveResponse = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** Read company pay groups and frequencies */ fun list(): PayrollPayGroupListPage = list(PayrollPayGroupListParams.none()) @@ -53,9 +75,25 @@ interface PayGroupService { * otherwise the same as [PayGroupService.retrieve]. */ @MustBeClosed + fun retrieve(payGroupId: String): HttpResponseFor = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: PayrollPayGroupRetrieveParams - ): HttpResponseFor = retrieve(params, RequestOptions.none()) + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): HttpResponseFor = + retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -64,6 +102,20 @@ interface PayGroupService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: PayrollPayGroupRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-groups`, but is otherwise the same as * [PayGroupService.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt index 085c2bc4..fffb28b5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.payroll import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -19,6 +20,7 @@ import com.tryfinch.api.models.PayGroupRetrieveResponse import com.tryfinch.api.models.PayrollPayGroupListPage import com.tryfinch.api.models.PayrollPayGroupListParams import com.tryfinch.api.models.PayrollPayGroupRetrieveParams +import kotlin.jvm.optionals.getOrNull class PayGroupServiceImpl internal constructor(private val clientOptions: ClientOptions) : PayGroupService { @@ -56,6 +58,9 @@ class PayGroupServiceImpl internal constructor(private val clientOptions: Client params: PayrollPayGroupRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("payGroupId", params.payGroupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt index d1af16fb..8c83ae62 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt @@ -16,8 +16,22 @@ interface EmploymentService { fun withRawResponse(): WithRawResponse /** Update sandbox employment */ - fun update(params: SandboxEmploymentUpdateParams): EmploymentUpdateResponse = - update(params, RequestOptions.none()) + fun update(individualId: String): EmploymentUpdateResponse = + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): EmploymentUpdateResponse = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): EmploymentUpdateResponse = update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -25,6 +39,14 @@ interface EmploymentService { requestOptions: RequestOptions = RequestOptions.none(), ): EmploymentUpdateResponse + /** @see [update] */ + fun update(params: SandboxEmploymentUpdateParams): EmploymentUpdateResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(individualId: String, requestOptions: RequestOptions): EmploymentUpdateResponse = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) + /** A view of [EmploymentService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -33,9 +55,25 @@ interface EmploymentService { * otherwise the same as [EmploymentService.update]. */ @MustBeClosed + fun update(individualId: String): HttpResponseFor = + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: SandboxEmploymentUpdateParams - ): HttpResponseFor = update(params, RequestOptions.none()) + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): HttpResponseFor = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -43,5 +81,19 @@ interface EmploymentService { params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxEmploymentUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt index da766444..e956fc67 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -17,6 +18,7 @@ import com.tryfinch.api.core.http.parseable import com.tryfinch.api.core.prepare import com.tryfinch.api.models.EmploymentUpdateResponse import com.tryfinch.api.models.SandboxEmploymentUpdateParams +import kotlin.jvm.optionals.getOrNull class EmploymentServiceImpl internal constructor(private val clientOptions: ClientOptions) : EmploymentService { @@ -47,6 +49,9 @@ class EmploymentServiceImpl internal constructor(private val clientOptions: Clie params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt index 8be711cb..e8c5faef 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt @@ -16,8 +16,22 @@ interface IndividualService { fun withRawResponse(): WithRawResponse /** Update sandbox individual */ - fun update(params: SandboxIndividualUpdateParams): IndividualUpdateResponse = - update(params, RequestOptions.none()) + fun update(individualId: String): IndividualUpdateResponse = + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndividualUpdateResponse = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): IndividualUpdateResponse = update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -25,6 +39,14 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): IndividualUpdateResponse + /** @see [update] */ + fun update(params: SandboxIndividualUpdateParams): IndividualUpdateResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(individualId: String, requestOptions: RequestOptions): IndividualUpdateResponse = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) + /** A view of [IndividualService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -33,9 +55,25 @@ interface IndividualService { * otherwise the same as [IndividualService.update]. */ @MustBeClosed + fun update(individualId: String): HttpResponseFor = + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: SandboxIndividualUpdateParams - ): HttpResponseFor = update(params, RequestOptions.none()) + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): HttpResponseFor = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -43,5 +81,19 @@ interface IndividualService { params: SandboxIndividualUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxIndividualUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt index 0570df24..df8ba4b5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -17,6 +18,7 @@ import com.tryfinch.api.core.http.parseable import com.tryfinch.api.core.prepare import com.tryfinch.api.models.IndividualUpdateResponse import com.tryfinch.api.models.SandboxIndividualUpdateParams +import kotlin.jvm.optionals.getOrNull class IndividualServiceImpl internal constructor(private val clientOptions: ClientOptions) : IndividualService { @@ -47,6 +49,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: SandboxIndividualUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt new file mode 100644 index 00000000..4c8940bc --- /dev/null +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt @@ -0,0 +1,182 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import com.tryfinch.api.core.http.AsyncStreamResponse +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.any +import org.mockito.kotlin.clearInvocations +import org.mockito.kotlin.doAnswer +import org.mockito.kotlin.inOrder +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.spy +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +@ExtendWith(MockitoExtension::class) +internal class AutoPagerAsyncTest { + + companion object { + + private val ERROR = RuntimeException("ERROR!") + } + + private class PageAsyncImpl( + private val items: List, + private val hasNext: Boolean = true, + ) : PageAsync { + + val nextPageFuture: CompletableFuture> = CompletableFuture() + + override fun hasNextPage(): Boolean = hasNext + + override fun nextPage(): CompletableFuture> = nextPageFuture + + override fun items(): List = items + } + + private val executor = + spy { + doAnswer { invocation -> invocation.getArgument(0).run() } + .whenever(it) + .execute(any()) + } + private val handler = mock>() + + @Test + fun subscribe_whenAlreadySubscribed_throws() { + val autoPagerAsync = AutoPagerAsync.from(PageAsyncImpl(emptyList()), executor) + autoPagerAsync.subscribe {} + clearInvocations(executor) + + val throwable = catchThrowable { autoPagerAsync.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe more than once") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenClosed_throws() { + val autoPagerAsync = AutoPagerAsync.from(PageAsyncImpl(emptyList()), executor) + autoPagerAsync.close() + + val throwable = catchThrowable { autoPagerAsync.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe after the response is closed") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenFirstPageNonEmpty_runsHandler() { + val page = PageAsyncImpl(listOf("item1", "item2", "item3"), hasNext = false) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + + autoPagerAsync.subscribe(handler) + + inOrder(executor, handler) { + verify(executor, times(1)).execute(any()) + verify(handler, times(1)).onNext("item1") + verify(handler, times(1)).onNext("item2") + verify(handler, times(1)).onNext("item3") + verify(handler, times(1)).onComplete(Optional.empty()) + } + } + + @Test + fun subscribe_whenFutureCompletesAfterClose_doesNothing() { + val page = PageAsyncImpl(listOf("page1")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe(handler) + autoPagerAsync.close() + + page.nextPageFuture.complete(PageAsyncImpl(listOf("page2"))) + + verify(handler, times(1)).onNext("page1") + verify(handler, never()).onNext("page2") + verify(handler, times(1)).onComplete(Optional.empty()) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureErrors_callsOnComplete() { + val page = PageAsyncImpl(emptyList()) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe(handler) + + page.nextPageFuture.completeExceptionally(ERROR) + + verify(executor, times(1)).execute(any()) + verify(handler, never()).onNext(any()) + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + } + + @Test + fun subscribe_whenFutureCompletes_runsHandler() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + + autoPagerAsync.subscribe(handler) + + verify(handler, never()).onComplete(any()) + inOrder(executor, handler) { + verify(executor, times(1)).execute(any()) + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + } + clearInvocations(executor, handler) + + page.nextPageFuture.complete(PageAsyncImpl(listOf("chunk3", "chunk4"), hasNext = false)) + + verify(executor, never()).execute(any()) + inOrder(handler) { + verify(handler, times(1)).onNext("chunk3") + verify(handler, times(1)).onNext("chunk4") + verify(handler, times(1)).onComplete(Optional.empty()) + } + } + + @Test + fun onCompleteFuture_whenNextPageFutureNotCompleted_onCompleteFutureNotCompleted() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenNextPageFutureErrors_onCompleteFutureCompletedExceptionally() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + page.nextPageFuture.completeExceptionally(ERROR) + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenNoNextPage_onCompleteFutureCompleted() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2"), hasNext = false) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } +} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt new file mode 100644 index 00000000..7ffdfe17 --- /dev/null +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AutoPagerTest { + + private class PageImpl( + private val items: List, + private val nextPage: Page? = null, + ) : Page { + + override fun hasNextPage(): Boolean = nextPage != null + + override fun nextPage(): Page = nextPage!! + + override fun items(): List = items + } + + @Test + fun iterator() { + val firstPage = + PageImpl(listOf("chunk1", "chunk2"), nextPage = PageImpl(listOf("chunk3", "chunk4"))) + + val autoPager = AutoPager.from(firstPage) + + assertThat(autoPager).containsExactly("chunk1", "chunk2", "chunk3", "chunk4") + } + + @Test + fun stream() { + val firstPage = + PageImpl(listOf("chunk1", "chunk2"), nextPage = PageImpl(listOf("chunk3", "chunk4"))) + + val autoPager = AutoPager.from(firstPage) + + assertThat(autoPager.stream()).containsExactly("chunk1", "chunk2", "chunk3", "chunk4") + } +} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt new file mode 100644 index 00000000..96c472b6 --- /dev/null +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt @@ -0,0 +1,268 @@ +package com.tryfinch.api.core.http + +import java.util.* +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.stream.Stream +import kotlin.streams.asStream +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.* + +@ExtendWith(MockitoExtension::class) +internal class AsyncStreamResponseTest { + + companion object { + private val ERROR = RuntimeException("ERROR!") + } + + private val streamResponse = + spy> { + doReturn(Stream.of("chunk1", "chunk2", "chunk3")).whenever(it).stream() + } + private val erroringStreamResponse = + spy> { + doReturn( + sequence { + yield("chunk1") + yield("chunk2") + throw ERROR + } + .asStream() + ) + .whenever(it) + .stream() + } + private val executor = + spy { + doAnswer { invocation -> invocation.getArgument(0).run() } + .whenever(it) + .execute(any()) + } + private val handler = mock>() + + @Test + fun subscribe_whenAlreadySubscribed_throws() { + val asyncStreamResponse = CompletableFuture>().toAsync(executor) + asyncStreamResponse.subscribe {} + + val throwable = catchThrowable { asyncStreamResponse.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe more than once") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenClosed_throws() { + val asyncStreamResponse = CompletableFuture>().toAsync(executor) + asyncStreamResponse.close() + + val throwable = catchThrowable { asyncStreamResponse.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe after the response is closed") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenFutureCompletesAfterClose_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + asyncStreamResponse.close() + + future.complete(streamResponse) + + verify(handler, never()).onNext(any()) + verify(handler, never()).onComplete(any()) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureErrors_callsOnComplete() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.completeExceptionally(ERROR) + + verify(handler, never()).onNext(any()) + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureCompletes_runsHandler() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.complete(streamResponse) + + inOrder(handler, streamResponse) { + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + verify(handler, times(1)).onNext("chunk3") + verify(handler, times(1)).onComplete(Optional.empty()) + verify(streamResponse, times(1)).close() + } + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenStreamErrors_callsOnCompleteEarly() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.complete(erroringStreamResponse) + + inOrder(handler, erroringStreamResponse) { + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + verify(erroringStreamResponse, times(1)).close() + } + verify(executor, times(1)).execute(any()) + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureNotCompleted_onCompleteFutureNotCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureErrors_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + future.completeExceptionally(ERROR) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedButStillStreaming_onCompleteFutureNotCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedAndStreamErrors_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + future.complete(erroringStreamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedAndStreamCompleted_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun onCompleteFuture_whenHandlerOnCompleteWithoutThrowableThrows_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe( + object : AsyncStreamResponse.Handler { + override fun onNext(value: String) {} + + override fun onComplete(error: Optional) = throw ERROR + } + ) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun onCompleteFuture_whenHandlerOnCompleteWithThrowableThrows_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe( + object : AsyncStreamResponse.Handler { + override fun onNext(value: String) {} + + override fun onComplete(error: Optional) = throw ERROR + } + ) + future.complete(erroringStreamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenClosed_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun close_whenNotClosed_closesStreamResponse() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + + asyncStreamResponse.close() + future.complete(streamResponse) + + verify(streamResponse, times(1)).close() + } + + @Test + fun close_whenAlreadyClosed_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + future.complete(streamResponse) + + asyncStreamResponse.close() + + verify(streamResponse, times(1)).close() + } + + @Test + fun close_whenFutureErrors_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + + assertDoesNotThrow { future.completeExceptionally(ERROR) } + } +} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt index 861af561..9d4af287 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt @@ -7,7 +7,6 @@ import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.models.BenefitFrequency import com.tryfinch.api.models.BenefitType import com.tryfinch.api.models.HrisBenefitCreateParams -import com.tryfinch.api.models.HrisBenefitRetrieveParams import com.tryfinch.api.models.HrisBenefitUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -60,10 +59,7 @@ internal class BenefitServiceAsyncTest { .build() val benefitServiceAsync = client.hris().benefits() - val companyBenefitFuture = - benefitServiceAsync.retrieve( - HrisBenefitRetrieveParams.builder().benefitId("benefit_id").build() - ) + val companyBenefitFuture = benefitServiceAsync.retrieve("benefit_id") val companyBenefit = companyBenefitFuture.get() companyBenefit.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt index 5dce15e3..f74a13f5 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt @@ -5,7 +5,6 @@ package com.tryfinch.api.services.async.hris import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.models.HrisDocumentListParams -import com.tryfinch.api.models.HrisDocumentRetreiveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -44,10 +43,7 @@ internal class DocumentServiceAsyncTest { .build() val documentServiceAsync = client.hris().documents() - val responseFuture = - documentServiceAsync.retreive( - HrisDocumentRetreiveParams.builder().documentId("document_id").build() - ) + val responseFuture = documentServiceAsync.retreive("document_id") val response = responseFuture.get() response.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt index 84962f36..f0b0c033 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt @@ -4,8 +4,6 @@ package com.tryfinch.api.services.async.hris.benefits import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync -import com.tryfinch.api.models.HrisBenefitIndividualEnrolledIdsParams -import com.tryfinch.api.models.HrisBenefitIndividualRetrieveManyBenefitsParams import com.tryfinch.api.models.HrisBenefitIndividualUnenrollManyParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -22,10 +20,7 @@ internal class IndividualServiceAsyncTest { .build() val individualServiceAsync = client.hris().benefits().individuals() - val responseFuture = - individualServiceAsync.enrolledIds( - HrisBenefitIndividualEnrolledIdsParams.builder().benefitId("benefit_id").build() - ) + val responseFuture = individualServiceAsync.enrolledIds("benefit_id") val response = responseFuture.get() response.validate() @@ -40,12 +35,7 @@ internal class IndividualServiceAsyncTest { .build() val individualServiceAsync = client.hris().benefits().individuals() - val pageFuture = - individualServiceAsync.retrieveManyBenefits( - HrisBenefitIndividualRetrieveManyBenefitsParams.builder() - .benefitId("benefit_id") - .build() - ) + val pageFuture = individualServiceAsync.retrieveManyBenefits("benefit_id") val page = pageFuture.get() page.items().forEach { it.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt index d2089357..6ffc6ebb 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.core.JsonValue import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleCreateParams -import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleDeleteParams import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -103,10 +102,7 @@ internal class RuleServiceAsyncTest { .build() val ruleServiceAsync = client.hris().company().payStatementItem().rules() - val ruleFuture = - ruleServiceAsync.delete( - HrisCompanyPayStatementItemRuleDeleteParams.builder().ruleId("rule_id").build() - ) + val ruleFuture = ruleServiceAsync.delete("rule_id") val rule = ruleFuture.get() rule.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt index ac39efe6..68909572 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams -import com.tryfinch.api.models.JobAutomatedRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -40,10 +39,7 @@ internal class AutomatedServiceAsyncTest { .build() val automatedServiceAsync = client.jobs().automated() - val automatedAsyncJobFuture = - automatedServiceAsync.retrieve( - JobAutomatedRetrieveParams.builder().jobId("job_id").build() - ) + val automatedAsyncJobFuture = automatedServiceAsync.retrieve("job_id") val automatedAsyncJob = automatedAsyncJobFuture.get() automatedAsyncJob.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt index 5a095fad..87d73cfa 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.async.jobs import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync -import com.tryfinch.api.models.JobManualRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,8 +19,7 @@ internal class ManualServiceAsyncTest { .build() val manualServiceAsync = client.jobs().manual() - val manualAsyncJobFuture = - manualServiceAsync.retrieve(JobManualRetrieveParams.builder().jobId("job_id").build()) + val manualAsyncJobFuture = manualServiceAsync.retrieve("job_id") val manualAsyncJob = manualAsyncJobFuture.get() manualAsyncJob.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt index 6e52fb2f..c280c299 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.async.payroll import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync -import com.tryfinch.api.models.PayrollPayGroupRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,10 +19,7 @@ internal class PayGroupServiceAsyncTest { .build() val payGroupServiceAsync = client.payroll().payGroups() - val payGroupFuture = - payGroupServiceAsync.retrieve( - PayrollPayGroupRetrieveParams.builder().payGroupId("pay_group_id").build() - ) + val payGroupFuture = payGroupServiceAsync.retrieve("pay_group_id") val payGroup = payGroupFuture.get() payGroup.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt index bdcc2d7f..ff54482a 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt @@ -7,7 +7,6 @@ import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.models.BenefitFrequency import com.tryfinch.api.models.BenefitType import com.tryfinch.api.models.HrisBenefitCreateParams -import com.tryfinch.api.models.HrisBenefitRetrieveParams import com.tryfinch.api.models.HrisBenefitUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -59,10 +58,7 @@ internal class BenefitServiceTest { .build() val benefitService = client.hris().benefits() - val companyBenefit = - benefitService.retrieve( - HrisBenefitRetrieveParams.builder().benefitId("benefit_id").build() - ) + val companyBenefit = benefitService.retrieve("benefit_id") companyBenefit.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt index 4faa8f0a..b5a9adbe 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt @@ -5,7 +5,6 @@ package com.tryfinch.api.services.blocking.hris import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.models.HrisDocumentListParams -import com.tryfinch.api.models.HrisDocumentRetreiveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -43,10 +42,7 @@ internal class DocumentServiceTest { .build() val documentService = client.hris().documents() - val response = - documentService.retreive( - HrisDocumentRetreiveParams.builder().documentId("document_id").build() - ) + val response = documentService.retreive("document_id") response.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt index 911b8d1e..123e975c 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt @@ -4,8 +4,6 @@ package com.tryfinch.api.services.blocking.hris.benefits import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.HrisBenefitIndividualEnrolledIdsParams -import com.tryfinch.api.models.HrisBenefitIndividualRetrieveManyBenefitsParams import com.tryfinch.api.models.HrisBenefitIndividualUnenrollManyParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -22,10 +20,7 @@ internal class IndividualServiceTest { .build() val individualService = client.hris().benefits().individuals() - val response = - individualService.enrolledIds( - HrisBenefitIndividualEnrolledIdsParams.builder().benefitId("benefit_id").build() - ) + val response = individualService.enrolledIds("benefit_id") response.validate() } @@ -39,12 +34,7 @@ internal class IndividualServiceTest { .build() val individualService = client.hris().benefits().individuals() - val page = - individualService.retrieveManyBenefits( - HrisBenefitIndividualRetrieveManyBenefitsParams.builder() - .benefitId("benefit_id") - .build() - ) + val page = individualService.retrieveManyBenefits("benefit_id") page.items().forEach { it.validate() } } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt index be36e133..079a3329 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.core.JsonValue import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleCreateParams -import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleDeleteParams import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -100,10 +99,7 @@ internal class RuleServiceTest { .build() val ruleService = client.hris().company().payStatementItem().rules() - val rule = - ruleService.delete( - HrisCompanyPayStatementItemRuleDeleteParams.builder().ruleId("rule_id").build() - ) + val rule = ruleService.delete("rule_id") rule.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt index e6ff60ac..e4121bc5 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams -import com.tryfinch.api.models.JobAutomatedRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -37,8 +36,7 @@ internal class AutomatedServiceTest { .build() val automatedService = client.jobs().automated() - val automatedAsyncJob = - automatedService.retrieve(JobAutomatedRetrieveParams.builder().jobId("job_id").build()) + val automatedAsyncJob = automatedService.retrieve("job_id") automatedAsyncJob.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt index 3ad62102..3ee64260 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.blocking.jobs import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.JobManualRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,8 +19,7 @@ internal class ManualServiceTest { .build() val manualService = client.jobs().manual() - val manualAsyncJob = - manualService.retrieve(JobManualRetrieveParams.builder().jobId("job_id").build()) + val manualAsyncJob = manualService.retrieve("job_id") manualAsyncJob.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt index b64d3e99..f8581c22 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.blocking.payroll import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.PayrollPayGroupRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,10 +19,7 @@ internal class PayGroupServiceTest { .build() val payGroupService = client.payroll().payGroups() - val payGroup = - payGroupService.retrieve( - PayrollPayGroupRetrieveParams.builder().payGroupId("pay_group_id").build() - ) + val payGroup = payGroupService.retrieve("pay_group_id") payGroup.validate() }