From dbd9927602122fa14462fd86b74bb559e7796e31 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 19:27:38 +0000 Subject: [PATCH] feat(api): add endpoint to retrieve commit by id (#77) --- .github/workflows/create-releases.yml | 49 - .github/workflows/publish-sonatype.yml | 8 +- .github/workflows/release-doctor.yml | 1 - .stats.yml | 2 +- bin/check-release-environment | 4 - .../api/models/CommitRetrieveParams.kt | 181 +++ .../api/models/CommitRetrieveResponse.kt | 1083 +++++++++++++++++ .../api/services/async/CommitServiceAsync.kt | 13 + .../services/async/CommitServiceAsyncImpl.kt | 41 + .../api/services/blocking/CommitService.kt | 12 + .../services/blocking/CommitServiceImpl.kt | 37 + .../api/models/CommitRetrieveParamsTest.kt | 29 + .../api/models/CommitRetrieveResponseTest.kt | 101 ++ .../services/async/CommitServiceAsyncTest.kt | 33 + .../services/blocking/CommitServiceTest.kt | 32 + 15 files changed, 1569 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/create-releases.yml create mode 100644 openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveParams.kt create mode 100644 openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveResponse.kt create mode 100644 openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveParamsTest.kt create mode 100644 openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveResponseTest.kt create mode 100644 openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/CommitServiceAsyncTest.kt create mode 100644 openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/CommitServiceTest.kt diff --git a/.github/workflows/create-releases.yml b/.github/workflows/create-releases.yml deleted file mode 100644 index 16e7e0eb..00000000 --- a/.github/workflows/create-releases.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Create releases -on: - schedule: - - cron: '0 5 * * *' # every day at 5am UTC - push: - branches: - - main - -jobs: - release: - name: release - if: github.ref == 'refs/heads/main' && github.repository == 'openlayer-ai/openlayer-java' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - uses: stainless-api/trigger-release-please@v1 - id: release - with: - repo: ${{ github.event.repository.full_name }} - stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} - - - name: Set up Java - if: ${{ steps.release.outputs.releases_created }} - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: | - 8 - 17 - cache: gradle - - - name: Set up Gradle - if: ${{ steps.release.outputs.releases_created }} - uses: gradle/gradle-build-action@v2 - - - name: Publish to Sonatype - if: ${{ steps.release.outputs.releases_created }} - run: |- - export -- GPG_SIGNING_KEY_ID - printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD" - GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')" - ./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" - env: - SONATYPE_USERNAME: ${{ secrets.OPENLAYER_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.OPENLAYER_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} - GPG_SIGNING_KEY: ${{ secrets.OPENLAYER_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} - GPG_SIGNING_PASSWORD: ${{ secrets.OPENLAYER_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml index d852c899..de1b147f 100644 --- a/.github/workflows/publish-sonatype.yml +++ b/.github/workflows/publish-sonatype.yml @@ -1,9 +1,13 @@ -# workflow for re-running publishing to Sonatype in case it fails for some reason -# you can run this workflow by navigating to https://www.github.com/openlayer-ai/openlayer-java/actions/workflows/publish-sonatype.yml +# This workflow is triggered when a GitHub release is created. +# It can also be run manually to re-publish to Sonatype in case it failed for some reason. +# You can run this workflow by navigating to https://www.github.com/openlayer-ai/openlayer-java/actions/workflows/publish-sonatype.yml name: Publish Sonatype on: workflow_dispatch: + release: + types: [published] + jobs: publish: name: publish diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index d2c76fa2..b4ed7fd0 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -18,7 +18,6 @@ jobs: run: | bash ./bin/check-release-environment env: - STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }} SONATYPE_USERNAME: ${{ secrets.OPENLAYER_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.OPENLAYER_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} GPG_SIGNING_KEY: ${{ secrets.OPENLAYER_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} diff --git a/.stats.yml b/.stats.yml index dd473053..c2549479 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 14 +configured_endpoints: 15 diff --git a/bin/check-release-environment b/bin/check-release-environment index c393cdbb..14a9e4dc 100644 --- a/bin/check-release-environment +++ b/bin/check-release-environment @@ -2,10 +2,6 @@ errors=() -if [ -z "${STAINLESS_API_KEY}" ]; then - errors+=("The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.") -fi - if [ -z "${SONATYPE_USERNAME}" ]; then errors+=("The OPENLAYER_SONATYPE_USERNAME secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveParams.kt new file mode 100644 index 00000000..1cf69247 --- /dev/null +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveParams.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models + +import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.Params +import com.openlayer.api.core.checkRequired +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams +import java.util.Objects + +/** Retrieve a project version (commit) by its id. */ +class CommitRetrieveParams +private constructor( + private val projectVersionId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun projectVersionId(): String = projectVersionId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> projectVersionId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CommitRetrieveParams]. */ + @NoAutoDetect + class Builder internal constructor() { + + private var projectVersionId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(commitRetrieveParams: CommitRetrieveParams) = apply { + projectVersionId = commitRetrieveParams.projectVersionId + additionalHeaders = commitRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = commitRetrieveParams.additionalQueryParams.toBuilder() + } + + fun projectVersionId(projectVersionId: String) = apply { + this.projectVersionId = projectVersionId + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): CommitRetrieveParams = + CommitRetrieveParams( + checkRequired("projectVersionId", projectVersionId), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CommitRetrieveParams && projectVersionId == other.projectVersionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectVersionId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "CommitRetrieveParams{projectVersionId=$projectVersionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveResponse.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveResponse.kt new file mode 100644 index 00000000..5a3a6888 --- /dev/null +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitRetrieveResponse.kt @@ -0,0 +1,1083 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.openlayer.api.core.Enum +import com.openlayer.api.core.ExcludeMissing +import com.openlayer.api.core.JsonField +import com.openlayer.api.core.JsonMissing +import com.openlayer.api.core.JsonValue +import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.checkRequired +import com.openlayer.api.core.immutableEmptyMap +import com.openlayer.api.core.toImmutable +import com.openlayer.api.errors.OpenlayerInvalidDataException +import java.time.OffsetDateTime +import java.util.Objects +import java.util.Optional + +@NoAutoDetect +class CommitRetrieveResponse +@JsonCreator +private constructor( + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("commit") + @ExcludeMissing + private val commit: JsonField = JsonMissing.of(), + @JsonProperty("dateArchived") + @ExcludeMissing + private val dateArchived: JsonField = JsonMissing.of(), + @JsonProperty("dateCreated") + @ExcludeMissing + private val dateCreated: JsonField = JsonMissing.of(), + @JsonProperty("failingGoalCount") + @ExcludeMissing + private val failingGoalCount: JsonField = JsonMissing.of(), + @JsonProperty("mlModelId") + @ExcludeMissing + private val mlModelId: JsonField = JsonMissing.of(), + @JsonProperty("passingGoalCount") + @ExcludeMissing + private val passingGoalCount: JsonField = JsonMissing.of(), + @JsonProperty("projectId") + @ExcludeMissing + private val projectId: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("statusMessage") + @ExcludeMissing + private val statusMessage: JsonField = JsonMissing.of(), + @JsonProperty("storageUri") + @ExcludeMissing + private val storageUri: JsonField = JsonMissing.of(), + @JsonProperty("totalGoalCount") + @ExcludeMissing + private val totalGoalCount: JsonField = JsonMissing.of(), + @JsonProperty("trainingDatasetId") + @ExcludeMissing + private val trainingDatasetId: JsonField = JsonMissing.of(), + @JsonProperty("validationDatasetId") + @ExcludeMissing + private val validationDatasetId: JsonField = JsonMissing.of(), + @JsonProperty("archived") + @ExcludeMissing + private val archived: JsonField = JsonMissing.of(), + @JsonProperty("deploymentStatus") + @ExcludeMissing + private val deploymentStatus: JsonField = JsonMissing.of(), + @JsonProperty("links") @ExcludeMissing private val links: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), +) { + + /** The project version (commit) id. */ + fun id(): String = id.getRequired("id") + + /** The details of a commit (project version). */ + fun commit(): Commit = commit.getRequired("commit") + + /** The commit archive date. */ + fun dateArchived(): Optional = + Optional.ofNullable(dateArchived.getNullable("dateArchived")) + + /** The project version (commit) creation date. */ + fun dateCreated(): OffsetDateTime = dateCreated.getRequired("dateCreated") + + /** The number of tests that are failing for the commit. */ + fun failingGoalCount(): Long = failingGoalCount.getRequired("failingGoalCount") + + /** The model id. */ + fun mlModelId(): Optional = Optional.ofNullable(mlModelId.getNullable("mlModelId")) + + /** The number of tests that are passing for the commit. */ + fun passingGoalCount(): Long = passingGoalCount.getRequired("passingGoalCount") + + /** The project id. */ + fun projectId(): String = projectId.getRequired("projectId") + + /** + * The commit status. Initially, the commit is `queued`, then, it switches to `running`. + * Finally, it can be `paused`, `failed`, or `completed`. + */ + fun status(): Status = status.getRequired("status") + + /** The commit status message. */ + fun statusMessage(): Optional = + Optional.ofNullable(statusMessage.getNullable("statusMessage")) + + /** The storage URI where the commit bundle is stored. */ + fun storageUri(): String = storageUri.getRequired("storageUri") + + /** The total number of tests for the commit. */ + fun totalGoalCount(): Long = totalGoalCount.getRequired("totalGoalCount") + + /** The training dataset id. */ + fun trainingDatasetId(): Optional = + Optional.ofNullable(trainingDatasetId.getNullable("trainingDatasetId")) + + /** The validation dataset id. */ + fun validationDatasetId(): Optional = + Optional.ofNullable(validationDatasetId.getNullable("validationDatasetId")) + + /** Whether the commit is archived. */ + fun archived(): Optional = Optional.ofNullable(archived.getNullable("archived")) + + /** The deployment status associated with the commit's model. */ + fun deploymentStatus(): Optional = + Optional.ofNullable(deploymentStatus.getNullable("deploymentStatus")) + + fun links(): Optional = Optional.ofNullable(links.getNullable("links")) + + /** The project version (commit) id. */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** The details of a commit (project version). */ + @JsonProperty("commit") @ExcludeMissing fun _commit(): JsonField = commit + + /** The commit archive date. */ + @JsonProperty("dateArchived") + @ExcludeMissing + fun _dateArchived(): JsonField = dateArchived + + /** The project version (commit) creation date. */ + @JsonProperty("dateCreated") + @ExcludeMissing + fun _dateCreated(): JsonField = dateCreated + + /** The number of tests that are failing for the commit. */ + @JsonProperty("failingGoalCount") + @ExcludeMissing + fun _failingGoalCount(): JsonField = failingGoalCount + + /** The model id. */ + @JsonProperty("mlModelId") @ExcludeMissing fun _mlModelId(): JsonField = mlModelId + + /** The number of tests that are passing for the commit. */ + @JsonProperty("passingGoalCount") + @ExcludeMissing + fun _passingGoalCount(): JsonField = passingGoalCount + + /** The project id. */ + @JsonProperty("projectId") @ExcludeMissing fun _projectId(): JsonField = projectId + + /** + * The commit status. Initially, the commit is `queued`, then, it switches to `running`. + * Finally, it can be `paused`, `failed`, or `completed`. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** The commit status message. */ + @JsonProperty("statusMessage") + @ExcludeMissing + fun _statusMessage(): JsonField = statusMessage + + /** The storage URI where the commit bundle is stored. */ + @JsonProperty("storageUri") @ExcludeMissing fun _storageUri(): JsonField = storageUri + + /** The total number of tests for the commit. */ + @JsonProperty("totalGoalCount") + @ExcludeMissing + fun _totalGoalCount(): JsonField = totalGoalCount + + /** The training dataset id. */ + @JsonProperty("trainingDatasetId") + @ExcludeMissing + fun _trainingDatasetId(): JsonField = trainingDatasetId + + /** The validation dataset id. */ + @JsonProperty("validationDatasetId") + @ExcludeMissing + fun _validationDatasetId(): JsonField = validationDatasetId + + /** Whether the commit is archived. */ + @JsonProperty("archived") @ExcludeMissing fun _archived(): JsonField = archived + + /** The deployment status associated with the commit's model. */ + @JsonProperty("deploymentStatus") + @ExcludeMissing + fun _deploymentStatus(): JsonField = deploymentStatus + + @JsonProperty("links") @ExcludeMissing fun _links(): JsonField = links + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): CommitRetrieveResponse = apply { + if (validated) { + return@apply + } + + id() + commit().validate() + dateArchived() + dateCreated() + failingGoalCount() + mlModelId() + passingGoalCount() + projectId() + status() + statusMessage() + storageUri() + totalGoalCount() + trainingDatasetId() + validationDatasetId() + archived() + deploymentStatus() + links().ifPresent { it.validate() } + validated = true + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CommitRetrieveResponse]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var commit: JsonField? = null + private var dateArchived: JsonField? = null + private var dateCreated: JsonField? = null + private var failingGoalCount: JsonField? = null + private var mlModelId: JsonField? = null + private var passingGoalCount: JsonField? = null + private var projectId: JsonField? = null + private var status: JsonField? = null + private var statusMessage: JsonField? = null + private var storageUri: JsonField? = null + private var totalGoalCount: JsonField? = null + private var trainingDatasetId: JsonField? = null + private var validationDatasetId: JsonField? = null + private var archived: JsonField = JsonMissing.of() + private var deploymentStatus: JsonField = JsonMissing.of() + private var links: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(commitRetrieveResponse: CommitRetrieveResponse) = apply { + id = commitRetrieveResponse.id + commit = commitRetrieveResponse.commit + dateArchived = commitRetrieveResponse.dateArchived + dateCreated = commitRetrieveResponse.dateCreated + failingGoalCount = commitRetrieveResponse.failingGoalCount + mlModelId = commitRetrieveResponse.mlModelId + passingGoalCount = commitRetrieveResponse.passingGoalCount + projectId = commitRetrieveResponse.projectId + status = commitRetrieveResponse.status + statusMessage = commitRetrieveResponse.statusMessage + storageUri = commitRetrieveResponse.storageUri + totalGoalCount = commitRetrieveResponse.totalGoalCount + trainingDatasetId = commitRetrieveResponse.trainingDatasetId + validationDatasetId = commitRetrieveResponse.validationDatasetId + archived = commitRetrieveResponse.archived + deploymentStatus = commitRetrieveResponse.deploymentStatus + links = commitRetrieveResponse.links + additionalProperties = commitRetrieveResponse.additionalProperties.toMutableMap() + } + + /** The project version (commit) id. */ + fun id(id: String) = id(JsonField.of(id)) + + /** The project version (commit) id. */ + fun id(id: JsonField) = apply { this.id = id } + + /** The details of a commit (project version). */ + fun commit(commit: Commit) = commit(JsonField.of(commit)) + + /** The details of a commit (project version). */ + fun commit(commit: JsonField) = apply { this.commit = commit } + + /** The commit archive date. */ + fun dateArchived(dateArchived: OffsetDateTime?) = + dateArchived(JsonField.ofNullable(dateArchived)) + + /** The commit archive date. */ + fun dateArchived(dateArchived: Optional) = + dateArchived(dateArchived.orElse(null)) + + /** The commit archive date. */ + fun dateArchived(dateArchived: JsonField) = apply { + this.dateArchived = dateArchived + } + + /** The project version (commit) creation date. */ + fun dateCreated(dateCreated: OffsetDateTime) = dateCreated(JsonField.of(dateCreated)) + + /** The project version (commit) creation date. */ + fun dateCreated(dateCreated: JsonField) = apply { + this.dateCreated = dateCreated + } + + /** The number of tests that are failing for the commit. */ + fun failingGoalCount(failingGoalCount: Long) = + failingGoalCount(JsonField.of(failingGoalCount)) + + /** The number of tests that are failing for the commit. */ + fun failingGoalCount(failingGoalCount: JsonField) = apply { + this.failingGoalCount = failingGoalCount + } + + /** The model id. */ + fun mlModelId(mlModelId: String?) = mlModelId(JsonField.ofNullable(mlModelId)) + + /** The model id. */ + fun mlModelId(mlModelId: Optional) = mlModelId(mlModelId.orElse(null)) + + /** The model id. */ + fun mlModelId(mlModelId: JsonField) = apply { this.mlModelId = mlModelId } + + /** The number of tests that are passing for the commit. */ + fun passingGoalCount(passingGoalCount: Long) = + passingGoalCount(JsonField.of(passingGoalCount)) + + /** The number of tests that are passing for the commit. */ + fun passingGoalCount(passingGoalCount: JsonField) = apply { + this.passingGoalCount = passingGoalCount + } + + /** The project id. */ + fun projectId(projectId: String) = projectId(JsonField.of(projectId)) + + /** The project id. */ + fun projectId(projectId: JsonField) = apply { this.projectId = projectId } + + /** + * The commit status. Initially, the commit is `queued`, then, it switches to `running`. + * Finally, it can be `paused`, `failed`, or `completed`. + */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * The commit status. Initially, the commit is `queued`, then, it switches to `running`. + * Finally, it can be `paused`, `failed`, or `completed`. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The commit status message. */ + fun statusMessage(statusMessage: String?) = + statusMessage(JsonField.ofNullable(statusMessage)) + + /** The commit status message. */ + fun statusMessage(statusMessage: Optional) = + statusMessage(statusMessage.orElse(null)) + + /** The commit status message. */ + fun statusMessage(statusMessage: JsonField) = apply { + this.statusMessage = statusMessage + } + + /** The storage URI where the commit bundle is stored. */ + fun storageUri(storageUri: String) = storageUri(JsonField.of(storageUri)) + + /** The storage URI where the commit bundle is stored. */ + fun storageUri(storageUri: JsonField) = apply { this.storageUri = storageUri } + + /** The total number of tests for the commit. */ + fun totalGoalCount(totalGoalCount: Long) = totalGoalCount(JsonField.of(totalGoalCount)) + + /** The total number of tests for the commit. */ + fun totalGoalCount(totalGoalCount: JsonField) = apply { + this.totalGoalCount = totalGoalCount + } + + /** The training dataset id. */ + fun trainingDatasetId(trainingDatasetId: String?) = + trainingDatasetId(JsonField.ofNullable(trainingDatasetId)) + + /** The training dataset id. */ + fun trainingDatasetId(trainingDatasetId: Optional) = + trainingDatasetId(trainingDatasetId.orElse(null)) + + /** The training dataset id. */ + fun trainingDatasetId(trainingDatasetId: JsonField) = apply { + this.trainingDatasetId = trainingDatasetId + } + + /** The validation dataset id. */ + fun validationDatasetId(validationDatasetId: String?) = + validationDatasetId(JsonField.ofNullable(validationDatasetId)) + + /** The validation dataset id. */ + fun validationDatasetId(validationDatasetId: Optional) = + validationDatasetId(validationDatasetId.orElse(null)) + + /** The validation dataset id. */ + fun validationDatasetId(validationDatasetId: JsonField) = apply { + this.validationDatasetId = validationDatasetId + } + + /** Whether the commit is archived. */ + fun archived(archived: Boolean?) = archived(JsonField.ofNullable(archived)) + + /** Whether the commit is archived. */ + fun archived(archived: Boolean) = archived(archived as Boolean?) + + /** Whether the commit is archived. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun archived(archived: Optional) = archived(archived.orElse(null) as Boolean?) + + /** Whether the commit is archived. */ + fun archived(archived: JsonField) = apply { this.archived = archived } + + /** The deployment status associated with the commit's model. */ + fun deploymentStatus(deploymentStatus: String) = + deploymentStatus(JsonField.of(deploymentStatus)) + + /** The deployment status associated with the commit's model. */ + fun deploymentStatus(deploymentStatus: JsonField) = apply { + this.deploymentStatus = deploymentStatus + } + + fun links(links: Links) = links(JsonField.of(links)) + + fun links(links: JsonField) = apply { this.links = links } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): CommitRetrieveResponse = + CommitRetrieveResponse( + checkRequired("id", id), + checkRequired("commit", commit), + checkRequired("dateArchived", dateArchived), + checkRequired("dateCreated", dateCreated), + checkRequired("failingGoalCount", failingGoalCount), + checkRequired("mlModelId", mlModelId), + checkRequired("passingGoalCount", passingGoalCount), + checkRequired("projectId", projectId), + checkRequired("status", status), + checkRequired("statusMessage", statusMessage), + checkRequired("storageUri", storageUri), + checkRequired("totalGoalCount", totalGoalCount), + checkRequired("trainingDatasetId", trainingDatasetId), + checkRequired("validationDatasetId", validationDatasetId), + archived, + deploymentStatus, + links, + additionalProperties.toImmutable(), + ) + } + + /** The details of a commit (project version). */ + @NoAutoDetect + class Commit + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("authorId") + @ExcludeMissing + private val authorId: JsonField = JsonMissing.of(), + @JsonProperty("fileSize") + @ExcludeMissing + private val fileSize: JsonField = JsonMissing.of(), + @JsonProperty("message") + @ExcludeMissing + private val message: JsonField = JsonMissing.of(), + @JsonProperty("mlModelId") + @ExcludeMissing + private val mlModelId: JsonField = JsonMissing.of(), + @JsonProperty("storageUri") + @ExcludeMissing + private val storageUri: JsonField = JsonMissing.of(), + @JsonProperty("trainingDatasetId") + @ExcludeMissing + private val trainingDatasetId: JsonField = JsonMissing.of(), + @JsonProperty("validationDatasetId") + @ExcludeMissing + private val validationDatasetId: JsonField = JsonMissing.of(), + @JsonProperty("dateCreated") + @ExcludeMissing + private val dateCreated: JsonField = JsonMissing.of(), + @JsonProperty("gitCommitRef") + @ExcludeMissing + private val gitCommitRef: JsonField = JsonMissing.of(), + @JsonProperty("gitCommitSha") + @ExcludeMissing + private val gitCommitSha: JsonField = JsonMissing.of(), + @JsonProperty("gitCommitUrl") + @ExcludeMissing + private val gitCommitUrl: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The commit id. */ + fun id(): String = id.getRequired("id") + + /** The author id of the commit. */ + fun authorId(): String = authorId.getRequired("authorId") + + /** The size of the commit bundle in bytes. */ + fun fileSize(): Optional = Optional.ofNullable(fileSize.getNullable("fileSize")) + + /** The commit message. */ + fun message(): String = message.getRequired("message") + + /** The model id. */ + fun mlModelId(): Optional = Optional.ofNullable(mlModelId.getNullable("mlModelId")) + + /** The storage URI where the commit bundle is stored. */ + fun storageUri(): String = storageUri.getRequired("storageUri") + + /** The training dataset id. */ + fun trainingDatasetId(): Optional = + Optional.ofNullable(trainingDatasetId.getNullable("trainingDatasetId")) + + /** The validation dataset id. */ + fun validationDatasetId(): Optional = + Optional.ofNullable(validationDatasetId.getNullable("validationDatasetId")) + + /** The commit creation date. */ + fun dateCreated(): Optional = + Optional.ofNullable(dateCreated.getNullable("dateCreated")) + + /** The ref of the corresponding git commit. */ + fun gitCommitRef(): Optional = + Optional.ofNullable(gitCommitRef.getNullable("gitCommitRef")) + + /** The SHA of the corresponding git commit. */ + fun gitCommitSha(): Optional = + Optional.ofNullable(gitCommitSha.getNullable("gitCommitSha")) + + /** The URL of the corresponding git commit. */ + fun gitCommitUrl(): Optional = + Optional.ofNullable(gitCommitUrl.getNullable("gitCommitUrl")) + + /** The commit id. */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** The author id of the commit. */ + @JsonProperty("authorId") @ExcludeMissing fun _authorId(): JsonField = authorId + + /** The size of the commit bundle in bytes. */ + @JsonProperty("fileSize") @ExcludeMissing fun _fileSize(): JsonField = fileSize + + /** The commit message. */ + @JsonProperty("message") @ExcludeMissing fun _message(): JsonField = message + + /** The model id. */ + @JsonProperty("mlModelId") @ExcludeMissing fun _mlModelId(): JsonField = mlModelId + + /** The storage URI where the commit bundle is stored. */ + @JsonProperty("storageUri") + @ExcludeMissing + fun _storageUri(): JsonField = storageUri + + /** The training dataset id. */ + @JsonProperty("trainingDatasetId") + @ExcludeMissing + fun _trainingDatasetId(): JsonField = trainingDatasetId + + /** The validation dataset id. */ + @JsonProperty("validationDatasetId") + @ExcludeMissing + fun _validationDatasetId(): JsonField = validationDatasetId + + /** The commit creation date. */ + @JsonProperty("dateCreated") + @ExcludeMissing + fun _dateCreated(): JsonField = dateCreated + + /** The ref of the corresponding git commit. */ + @JsonProperty("gitCommitRef") + @ExcludeMissing + fun _gitCommitRef(): JsonField = gitCommitRef + + /** The SHA of the corresponding git commit. */ + @JsonProperty("gitCommitSha") + @ExcludeMissing + fun _gitCommitSha(): JsonField = gitCommitSha + + /** The URL of the corresponding git commit. */ + @JsonProperty("gitCommitUrl") + @ExcludeMissing + fun _gitCommitUrl(): JsonField = gitCommitUrl + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): Commit = apply { + if (validated) { + return@apply + } + + id() + authorId() + fileSize() + message() + mlModelId() + storageUri() + trainingDatasetId() + validationDatasetId() + dateCreated() + gitCommitRef() + gitCommitSha() + gitCommitUrl() + validated = true + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Commit]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var authorId: JsonField? = null + private var fileSize: JsonField? = null + private var message: JsonField? = null + private var mlModelId: JsonField? = null + private var storageUri: JsonField? = null + private var trainingDatasetId: JsonField? = null + private var validationDatasetId: JsonField? = null + private var dateCreated: JsonField = JsonMissing.of() + private var gitCommitRef: JsonField = JsonMissing.of() + private var gitCommitSha: JsonField = JsonMissing.of() + private var gitCommitUrl: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(commit: Commit) = apply { + id = commit.id + authorId = commit.authorId + fileSize = commit.fileSize + message = commit.message + mlModelId = commit.mlModelId + storageUri = commit.storageUri + trainingDatasetId = commit.trainingDatasetId + validationDatasetId = commit.validationDatasetId + dateCreated = commit.dateCreated + gitCommitRef = commit.gitCommitRef + gitCommitSha = commit.gitCommitSha + gitCommitUrl = commit.gitCommitUrl + additionalProperties = commit.additionalProperties.toMutableMap() + } + + /** The commit id. */ + fun id(id: String) = id(JsonField.of(id)) + + /** The commit id. */ + fun id(id: JsonField) = apply { this.id = id } + + /** The author id of the commit. */ + fun authorId(authorId: String) = authorId(JsonField.of(authorId)) + + /** The author id of the commit. */ + fun authorId(authorId: JsonField) = apply { this.authorId = authorId } + + /** The size of the commit bundle in bytes. */ + fun fileSize(fileSize: Long?) = fileSize(JsonField.ofNullable(fileSize)) + + /** The size of the commit bundle in bytes. */ + fun fileSize(fileSize: Long) = fileSize(fileSize as Long?) + + /** The size of the commit bundle in bytes. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun fileSize(fileSize: Optional) = fileSize(fileSize.orElse(null) as Long?) + + /** The size of the commit bundle in bytes. */ + fun fileSize(fileSize: JsonField) = apply { this.fileSize = fileSize } + + /** The commit message. */ + fun message(message: String) = message(JsonField.of(message)) + + /** The commit message. */ + fun message(message: JsonField) = apply { this.message = message } + + /** The model id. */ + fun mlModelId(mlModelId: String?) = mlModelId(JsonField.ofNullable(mlModelId)) + + /** The model id. */ + fun mlModelId(mlModelId: Optional) = mlModelId(mlModelId.orElse(null)) + + /** The model id. */ + fun mlModelId(mlModelId: JsonField) = apply { this.mlModelId = mlModelId } + + /** The storage URI where the commit bundle is stored. */ + fun storageUri(storageUri: String) = storageUri(JsonField.of(storageUri)) + + /** The storage URI where the commit bundle is stored. */ + fun storageUri(storageUri: JsonField) = apply { this.storageUri = storageUri } + + /** The training dataset id. */ + fun trainingDatasetId(trainingDatasetId: String?) = + trainingDatasetId(JsonField.ofNullable(trainingDatasetId)) + + /** The training dataset id. */ + fun trainingDatasetId(trainingDatasetId: Optional) = + trainingDatasetId(trainingDatasetId.orElse(null)) + + /** The training dataset id. */ + fun trainingDatasetId(trainingDatasetId: JsonField) = apply { + this.trainingDatasetId = trainingDatasetId + } + + /** The validation dataset id. */ + fun validationDatasetId(validationDatasetId: String?) = + validationDatasetId(JsonField.ofNullable(validationDatasetId)) + + /** The validation dataset id. */ + fun validationDatasetId(validationDatasetId: Optional) = + validationDatasetId(validationDatasetId.orElse(null)) + + /** The validation dataset id. */ + fun validationDatasetId(validationDatasetId: JsonField) = apply { + this.validationDatasetId = validationDatasetId + } + + /** The commit creation date. */ + fun dateCreated(dateCreated: OffsetDateTime) = dateCreated(JsonField.of(dateCreated)) + + /** The commit creation date. */ + fun dateCreated(dateCreated: JsonField) = apply { + this.dateCreated = dateCreated + } + + /** The ref of the corresponding git commit. */ + fun gitCommitRef(gitCommitRef: String) = gitCommitRef(JsonField.of(gitCommitRef)) + + /** The ref of the corresponding git commit. */ + fun gitCommitRef(gitCommitRef: JsonField) = apply { + this.gitCommitRef = gitCommitRef + } + + /** The SHA of the corresponding git commit. */ + fun gitCommitSha(gitCommitSha: Long) = gitCommitSha(JsonField.of(gitCommitSha)) + + /** The SHA of the corresponding git commit. */ + fun gitCommitSha(gitCommitSha: JsonField) = apply { + this.gitCommitSha = gitCommitSha + } + + /** The URL of the corresponding git commit. */ + fun gitCommitUrl(gitCommitUrl: String) = gitCommitUrl(JsonField.of(gitCommitUrl)) + + /** The URL of the corresponding git commit. */ + fun gitCommitUrl(gitCommitUrl: JsonField) = apply { + this.gitCommitUrl = gitCommitUrl + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): Commit = + Commit( + checkRequired("id", id), + checkRequired("authorId", authorId), + checkRequired("fileSize", fileSize), + checkRequired("message", message), + checkRequired("mlModelId", mlModelId), + checkRequired("storageUri", storageUri), + checkRequired("trainingDatasetId", trainingDatasetId), + checkRequired("validationDatasetId", validationDatasetId), + dateCreated, + gitCommitRef, + gitCommitSha, + gitCommitUrl, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Commit && id == other.id && authorId == other.authorId && fileSize == other.fileSize && message == other.message && mlModelId == other.mlModelId && storageUri == other.storageUri && trainingDatasetId == other.trainingDatasetId && validationDatasetId == other.validationDatasetId && dateCreated == other.dateCreated && gitCommitRef == other.gitCommitRef && gitCommitSha == other.gitCommitSha && gitCommitUrl == other.gitCommitUrl && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, authorId, fileSize, message, mlModelId, storageUri, trainingDatasetId, validationDatasetId, dateCreated, gitCommitRef, gitCommitSha, gitCommitUrl, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Commit{id=$id, authorId=$authorId, fileSize=$fileSize, message=$message, mlModelId=$mlModelId, storageUri=$storageUri, trainingDatasetId=$trainingDatasetId, validationDatasetId=$validationDatasetId, dateCreated=$dateCreated, gitCommitRef=$gitCommitRef, gitCommitSha=$gitCommitSha, gitCommitUrl=$gitCommitUrl, additionalProperties=$additionalProperties}" + } + + /** + * The commit status. Initially, the commit is `queued`, then, it switches to `running`. + * Finally, it can be `paused`, `failed`, or `completed`. + */ + class Status @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val QUEUED = of("queued") + + @JvmField val RUNNING = of("running") + + @JvmField val PAUSED = of("paused") + + @JvmField val FAILED = of("failed") + + @JvmField val COMPLETED = of("completed") + + @JvmField val UNKNOWN = of("unknown") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + QUEUED, + RUNNING, + PAUSED, + FAILED, + COMPLETED, + UNKNOWN, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + QUEUED, + RUNNING, + PAUSED, + FAILED, + COMPLETED, + UNKNOWN, + /** An enum member indicating that [Status] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + QUEUED -> Value.QUEUED + RUNNING -> Value.RUNNING + PAUSED -> Value.PAUSED + FAILED -> Value.FAILED + COMPLETED -> Value.COMPLETED + UNKNOWN -> Value.UNKNOWN + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OpenlayerInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + QUEUED -> Known.QUEUED + RUNNING -> Known.RUNNING + PAUSED -> Known.PAUSED + FAILED -> Known.FAILED + COMPLETED -> Known.COMPLETED + UNKNOWN -> Known.UNKNOWN + else -> throw OpenlayerInvalidDataException("Unknown Status: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws OpenlayerInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + OpenlayerInvalidDataException("Value is not a String") + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @NoAutoDetect + class Links + @JsonCreator + private constructor( + @JsonProperty("app") @ExcludeMissing private val app: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun app(): String = app.getRequired("app") + + @JsonProperty("app") @ExcludeMissing fun _app(): JsonField = app + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): Links = apply { + if (validated) { + return@apply + } + + app() + validated = true + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Links]. */ + class Builder internal constructor() { + + private var app: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(links: Links) = apply { + app = links.app + additionalProperties = links.additionalProperties.toMutableMap() + } + + fun app(app: String) = app(JsonField.of(app)) + + fun app(app: JsonField) = apply { this.app = app } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): Links = + Links(checkRequired("app", app), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Links && app == other.app && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(app, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = "Links{app=$app, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CommitRetrieveResponse && id == other.id && commit == other.commit && dateArchived == other.dateArchived && dateCreated == other.dateCreated && failingGoalCount == other.failingGoalCount && mlModelId == other.mlModelId && passingGoalCount == other.passingGoalCount && projectId == other.projectId && status == other.status && statusMessage == other.statusMessage && storageUri == other.storageUri && totalGoalCount == other.totalGoalCount && trainingDatasetId == other.trainingDatasetId && validationDatasetId == other.validationDatasetId && archived == other.archived && deploymentStatus == other.deploymentStatus && links == other.links && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, commit, dateArchived, dateCreated, failingGoalCount, mlModelId, passingGoalCount, projectId, status, statusMessage, storageUri, totalGoalCount, trainingDatasetId, validationDatasetId, archived, deploymentStatus, links, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CommitRetrieveResponse{id=$id, commit=$commit, dateArchived=$dateArchived, dateCreated=$dateCreated, failingGoalCount=$failingGoalCount, mlModelId=$mlModelId, passingGoalCount=$passingGoalCount, projectId=$projectId, status=$status, statusMessage=$statusMessage, storageUri=$storageUri, totalGoalCount=$totalGoalCount, trainingDatasetId=$trainingDatasetId, validationDatasetId=$validationDatasetId, archived=$archived, deploymentStatus=$deploymentStatus, links=$links, additionalProperties=$additionalProperties}" +} diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsync.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsync.kt index 2fbb5b68..f7973ee0 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsync.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsync.kt @@ -1,10 +1,23 @@ // File generated from our OpenAPI spec by Stainless. +@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102 + package com.openlayer.api.services.async +import com.openlayer.api.core.RequestOptions +import com.openlayer.api.models.CommitRetrieveParams +import com.openlayer.api.models.CommitRetrieveResponse import com.openlayer.api.services.async.commits.TestResultServiceAsync +import java.util.concurrent.CompletableFuture interface CommitServiceAsync { fun testResults(): TestResultServiceAsync + + /** Retrieve a project version (commit) by its id. */ + @JvmOverloads + fun retrieve( + params: CommitRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsyncImpl.kt index e2da7f51..edaf826d 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/CommitServiceAsyncImpl.kt @@ -3,15 +3,56 @@ package com.openlayer.api.services.async import com.openlayer.api.core.ClientOptions +import com.openlayer.api.core.RequestOptions +import com.openlayer.api.core.handlers.errorHandler +import com.openlayer.api.core.handlers.jsonHandler +import com.openlayer.api.core.handlers.withErrorHandler +import com.openlayer.api.core.http.HttpMethod +import com.openlayer.api.core.http.HttpRequest +import com.openlayer.api.core.http.HttpResponse.Handler +import com.openlayer.api.core.prepareAsync +import com.openlayer.api.errors.OpenlayerError +import com.openlayer.api.models.CommitRetrieveParams +import com.openlayer.api.models.CommitRetrieveResponse import com.openlayer.api.services.async.commits.TestResultServiceAsync import com.openlayer.api.services.async.commits.TestResultServiceAsyncImpl +import java.util.concurrent.CompletableFuture class CommitServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : CommitServiceAsync { + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val testResults: TestResultServiceAsync by lazy { TestResultServiceAsyncImpl(clientOptions) } override fun testResults(): TestResultServiceAsync = testResults + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + + /** Retrieve a project version (commit) by its id. */ + override fun retrieve( + params: CommitRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .addPathSegments("versions", params.getPathParam(0)) + .build() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } + } + } + } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitService.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitService.kt index 6c803869..c026c86b 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitService.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitService.kt @@ -1,10 +1,22 @@ // File generated from our OpenAPI spec by Stainless. +@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102 + package com.openlayer.api.services.blocking +import com.openlayer.api.core.RequestOptions +import com.openlayer.api.models.CommitRetrieveParams +import com.openlayer.api.models.CommitRetrieveResponse import com.openlayer.api.services.blocking.commits.TestResultService interface CommitService { fun testResults(): TestResultService + + /** Retrieve a project version (commit) by its id. */ + @JvmOverloads + fun retrieve( + params: CommitRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CommitRetrieveResponse } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitServiceImpl.kt index 4c9d1b3b..2c944d89 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/CommitServiceImpl.kt @@ -3,13 +3,50 @@ package com.openlayer.api.services.blocking import com.openlayer.api.core.ClientOptions +import com.openlayer.api.core.RequestOptions +import com.openlayer.api.core.handlers.errorHandler +import com.openlayer.api.core.handlers.jsonHandler +import com.openlayer.api.core.handlers.withErrorHandler +import com.openlayer.api.core.http.HttpMethod +import com.openlayer.api.core.http.HttpRequest +import com.openlayer.api.core.http.HttpResponse.Handler +import com.openlayer.api.core.prepare +import com.openlayer.api.errors.OpenlayerError +import com.openlayer.api.models.CommitRetrieveParams +import com.openlayer.api.models.CommitRetrieveResponse import com.openlayer.api.services.blocking.commits.TestResultService import com.openlayer.api.services.blocking.commits.TestResultServiceImpl class CommitServiceImpl internal constructor(private val clientOptions: ClientOptions) : CommitService { + private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val testResults: TestResultService by lazy { TestResultServiceImpl(clientOptions) } override fun testResults(): TestResultService = testResults + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + + /** Retrieve a project version (commit) by its id. */ + override fun retrieve( + params: CommitRetrieveParams, + requestOptions: RequestOptions, + ): CommitRetrieveResponse { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .addPathSegments("versions", params.getPathParam(0)) + .build() + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } + } + } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveParamsTest.kt new file mode 100644 index 00000000..6ec60cd9 --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveParamsTest.kt @@ -0,0 +1,29 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class CommitRetrieveParamsTest { + + @Test + fun create() { + CommitRetrieveParams.builder() + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + } + + @Test + fun getPathParam() { + val params = + CommitRetrieveParams.builder() + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + assertThat(params).isNotNull + // path param "projectVersionId" + assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params.getPathParam(1)).isEqualTo("") + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveResponseTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveResponseTest.kt new file mode 100644 index 00000000..581ef8da --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitRetrieveResponseTest.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.models + +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class CommitRetrieveResponseTest { + + @Test + fun createCommitRetrieveResponse() { + val commitRetrieveResponse = + CommitRetrieveResponse.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .commit( + CommitRetrieveResponse.Commit.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .authorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .fileSize(1024L) + .message("Updated the prompt.") + .mlModelId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .storageUri("s3://...") + .trainingDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .validationDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .gitCommitRef("main") + .gitCommitSha(0L) + .gitCommitUrl("gitCommitUrl") + .build() + ) + .dateArchived(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .failingGoalCount(1L) + .mlModelId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .passingGoalCount(5L) + .projectId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .status(CommitRetrieveResponse.Status.QUEUED) + .statusMessage("Commit successfully processed.") + .totalGoalCount(6L) + .trainingDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .validationDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .archived(false) + .deploymentStatus("Deployed") + .links( + CommitRetrieveResponse.Links.builder() + .app( + "https://app.openlayer.com/myWorkspace/3fa85f64-5717-4562-b3fc-2c963f66afa6" + ) + .build() + ) + .build() + assertThat(commitRetrieveResponse).isNotNull + assertThat(commitRetrieveResponse.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") + assertThat(commitRetrieveResponse.commit()) + .isEqualTo( + CommitRetrieveResponse.Commit.builder() + .id("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .authorId("589ece63-49a2-41b4-98e1-10547761d4b0") + .fileSize(1024L) + .message("Updated the prompt.") + .mlModelId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .storageUri("s3://...") + .trainingDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .validationDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6") + .dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + .gitCommitRef("main") + .gitCommitSha(0L) + .gitCommitUrl("gitCommitUrl") + .build() + ) + assertThat(commitRetrieveResponse.dateArchived()) + .contains(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + assertThat(commitRetrieveResponse.dateCreated()) + .isEqualTo(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) + assertThat(commitRetrieveResponse.failingGoalCount()).isEqualTo(1L) + assertThat(commitRetrieveResponse.mlModelId()) + .contains("3fa85f64-5717-4562-b3fc-2c963f66afa6") + assertThat(commitRetrieveResponse.passingGoalCount()).isEqualTo(5L) + assertThat(commitRetrieveResponse.projectId()) + .isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") + assertThat(commitRetrieveResponse.status()).isEqualTo(CommitRetrieveResponse.Status.QUEUED) + assertThat(commitRetrieveResponse.statusMessage()) + .contains("Commit successfully processed.") + assertThat(commitRetrieveResponse.totalGoalCount()).isEqualTo(6L) + assertThat(commitRetrieveResponse.trainingDatasetId()) + .contains("3fa85f64-5717-4562-b3fc-2c963f66afa6") + assertThat(commitRetrieveResponse.validationDatasetId()) + .contains("3fa85f64-5717-4562-b3fc-2c963f66afa6") + assertThat(commitRetrieveResponse.archived()).contains(false) + assertThat(commitRetrieveResponse.deploymentStatus()).contains("Deployed") + assertThat(commitRetrieveResponse.links()) + .contains( + CommitRetrieveResponse.Links.builder() + .app( + "https://app.openlayer.com/myWorkspace/3fa85f64-5717-4562-b3fc-2c963f66afa6" + ) + .build() + ) + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/CommitServiceAsyncTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/CommitServiceAsyncTest.kt new file mode 100644 index 00000000..c2e20b61 --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/async/CommitServiceAsyncTest.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.services.async + +import com.openlayer.api.TestServerExtension +import com.openlayer.api.client.okhttp.OpenlayerOkHttpClientAsync +import com.openlayer.api.models.CommitRetrieveParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +class CommitServiceAsyncTest { + + @Test + fun retrieve() { + val client = + OpenlayerOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val commitServiceAsync = client.commits() + + val commitFuture = + commitServiceAsync.retrieve( + CommitRetrieveParams.builder() + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + val commit = commitFuture.get() + commit.validate() + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/CommitServiceTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/CommitServiceTest.kt new file mode 100644 index 00000000..ed876dd9 --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/CommitServiceTest.kt @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openlayer.api.services.blocking + +import com.openlayer.api.TestServerExtension +import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient +import com.openlayer.api.models.CommitRetrieveParams +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +class CommitServiceTest { + + @Test + fun retrieve() { + val client = + OpenlayerOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val commitService = client.commits() + + val commit = + commitService.retrieve( + CommitRetrieveParams.builder() + .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + + commit.validate() + } +}