From 6a805d709f8fdee54273e8f4f207661e55716abb Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2026 20:43:00 +0000 Subject: [PATCH 1/7] SDK regeneration Unable to analyze changes with AI, incrementing PATCH version. --- build.gradle | 4 +- changelog.md | 4 + reference.md | 77 ++++++ sample-app/src/main/java/sample/App.java | 2 +- .../java/com/phenoml/api/AsyncClient.java | 38 --- ...ncPhenoML.java => AsyncPhenomlClient.java} | 8 +- ...er.java => AsyncPhenomlClientBuilder.java} | 51 ++-- src/main/java/com/phenoml/api/Client.java | 38 --- .../api/{PhenoML.java => PhenomlClient.java} | 8 +- ...Builder.java => PhenomlClientBuilder.java} | 51 ++-- .../com/phenoml/api/core/ClientOptions.java | 4 +- .../phenoml/api/core/OAuthTokenSupplier.java | 54 ++++ ...on.java => PhenomlClientApiException.java} | 10 +- ...ption.java => PhenomlClientException.java} | 6 +- ...se.java => PhenomlClientHttpResponse.java} | 4 +- .../com/phenoml/api/core/RequestOptions.java | 16 +- .../resources/agent/AsyncRawAgentClient.java | 141 +++++----- .../api/resources/agent/RawAgentClient.java | 105 ++++---- .../agent/errors/BadRequestError.java | 4 +- .../agent/errors/ForbiddenError.java | 4 +- .../agent/errors/InternalServerError.java | 4 +- .../resources/agent/errors/NotFoundError.java | 4 +- .../agent/errors/UnauthorizedError.java | 4 +- .../agent/prompts/AsyncRawPromptsClient.java | 114 ++++---- .../agent/prompts/RawPromptsClient.java | 84 +++--- .../authtoken/auth/AsyncAuthClient.java | 32 +++ .../authtoken/auth/AsyncRawAuthClient.java | 142 ++++++++-- .../resources/authtoken/auth/AuthClient.java | 32 +++ .../authtoken/auth/RawAuthClient.java | 118 ++++++-- .../requests/ClientCredentialsRequest.java | 163 +++++++++++ .../authtoken/errors/BadRequestError.java | 4 +- .../authtoken/errors/InternalServerError.java | 32 +++ .../authtoken/errors/UnauthorizedError.java | 4 +- .../resources/authtoken/types/OAuthError.java | 254 ++++++++++++++++++ .../authtoken/types/TokenResponse.java | 182 +++++++++++++ .../cohort/AsyncRawCohortClient.java | 22 +- .../api/resources/cohort/RawCohortClient.java | 18 +- .../cohort/errors/BadRequestError.java | 4 +- .../cohort/errors/InternalServerError.java | 4 +- .../cohort/errors/UnauthorizedError.java | 4 +- .../construe/AsyncRawConstrueClient.java | 181 +++++++------ .../resources/construe/RawConstrueClient.java | 133 ++++----- .../construe/errors/BadRequestError.java | 4 +- .../construe/errors/ConflictError.java | 4 +- .../errors/FailedDependencyError.java | 4 +- .../construe/errors/ForbiddenError.java | 4 +- .../construe/errors/GatewayTimeoutError.java | 4 +- .../construe/errors/InternalServerError.java | 4 +- .../construe/errors/NotFoundError.java | 4 +- .../construe/errors/NotImplementedError.java | 4 +- .../errors/ServiceUnavailableError.java | 4 +- .../construe/errors/UnauthorizedError.java | 4 +- .../resources/fhir/AsyncRawFhirClient.java | 96 +++---- .../api/resources/fhir/RawFhirClient.java | 74 ++--- .../fhir/errors/BadGatewayError.java | 4 +- .../fhir/errors/BadRequestError.java | 4 +- .../fhir/errors/InternalServerError.java | 4 +- .../resources/fhir/errors/NotFoundError.java | 4 +- .../fhir/errors/UnauthorizedError.java | 4 +- .../AsyncRawFhirProviderClient.java | 114 ++++---- .../fhirprovider/RawFhirProviderClient.java | 84 +++--- .../fhirprovider/errors/BadRequestError.java | 4 +- .../fhirprovider/errors/ForbiddenError.java | 4 +- .../errors/InternalServerError.java | 4 +- .../fhirprovider/errors/NotFoundError.java | 4 +- .../errors/UnauthorizedError.java | 4 +- .../lang2fhir/AsyncRawLang2FhirClient.java | 102 +++---- .../lang2fhir/RawLang2FhirClient.java | 79 +++--- .../lang2fhir/errors/BadRequestError.java | 4 +- .../errors/FailedDependencyError.java | 4 +- .../lang2fhir/errors/ForbiddenError.java | 4 +- .../lang2fhir/errors/InternalServerError.java | 4 +- .../lang2fhir/errors/UnauthorizedError.java | 4 +- .../errors/UnprocessableEntityError.java | 4 +- .../summary/AsyncRawSummaryClient.java | 96 +++---- .../resources/summary/RawSummaryClient.java | 74 ++--- .../summary/errors/BadRequestError.java | 4 +- .../summary/errors/ForbiddenError.java | 4 +- .../summary/errors/InternalServerError.java | 4 +- .../summary/errors/NotFoundError.java | 4 +- .../summary/errors/UnauthorizedError.java | 4 +- .../resources/tools/AsyncRawToolsClient.java | 63 ++--- .../api/resources/tools/RawToolsClient.java | 48 ++-- .../tools/errors/BadRequestError.java | 4 +- .../tools/errors/FailedDependencyError.java | 4 +- .../tools/errors/ForbiddenError.java | 4 +- .../tools/errors/InternalServerError.java | 4 +- .../tools/errors/UnauthorizedError.java | 4 +- .../mcpserver/AsyncRawMcpServerClient.java | 64 ++--- .../tools/mcpserver/RawMcpServerClient.java | 48 ++-- .../mcpserver/tools/AsyncRawToolsClient.java | 64 ++--- .../tools/mcpserver/tools/RawToolsClient.java | 49 ++-- .../workflows/AsyncRawWorkflowsClient.java | 97 +++---- .../workflows/RawWorkflowsClient.java | 72 ++--- .../workflows/errors/BadRequestError.java | 4 +- .../workflows/errors/ForbiddenError.java | 4 +- .../workflows/errors/InternalServerError.java | 4 +- .../workflows/errors/NotFoundError.java | 4 +- .../workflows/errors/UnauthorizedError.java | 4 +- .../api/wrapper/AsyncPhenoMLClient.java | 119 -------- .../phenoml/api/wrapper/PhenoMLClient.java | 89 ------ 101 files changed, 2272 insertions(+), 1492 deletions(-) delete mode 100644 src/main/java/com/phenoml/api/AsyncClient.java rename src/main/java/com/phenoml/api/{AsyncPhenoML.java => AsyncPhenomlClient.java} (94%) rename src/main/java/com/phenoml/api/{PhenoMLBuilder.java => AsyncPhenomlClientBuilder.java} (77%) delete mode 100644 src/main/java/com/phenoml/api/Client.java rename src/main/java/com/phenoml/api/{PhenoML.java => PhenomlClient.java} (94%) rename src/main/java/com/phenoml/api/{AsyncPhenoMLBuilder.java => PhenomlClientBuilder.java} (78%) create mode 100644 src/main/java/com/phenoml/api/core/OAuthTokenSupplier.java rename src/main/java/com/phenoml/api/core/{PhenoMLApiException.java => PhenomlClientApiException.java} (78%) rename src/main/java/com/phenoml/api/core/{PhenoMLException.java => PhenomlClientException.java} (57%) rename src/main/java/com/phenoml/api/core/{PhenoMLHttpResponse.java => PhenomlClientHttpResponse.java} (87%) create mode 100644 src/main/java/com/phenoml/api/resources/authtoken/auth/requests/ClientCredentialsRequest.java create mode 100644 src/main/java/com/phenoml/api/resources/authtoken/errors/InternalServerError.java create mode 100644 src/main/java/com/phenoml/api/resources/authtoken/types/OAuthError.java create mode 100644 src/main/java/com/phenoml/api/resources/authtoken/types/TokenResponse.java delete mode 100644 src/main/java/com/phenoml/api/wrapper/AsyncPhenoMLClient.java delete mode 100644 src/main/java/com/phenoml/api/wrapper/PhenoMLClient.java diff --git a/build.gradle b/build.gradle index 8a2cc7d..491bbb6 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ java { group = 'com.phenoml.maven' -version = '8.3.0' +version = '8.3.1' jar { dependsOn(":generatePomFileForMavenPublication") @@ -78,7 +78,7 @@ publishing { maven(MavenPublication) { groupId = 'com.phenoml.maven' artifactId = 'phenoml-java-sdk' - version = '8.3.0' + version = '8.3.1' from components.java pom { name = 'phenoml' diff --git a/changelog.md b/changelog.md index 78e9267..03372f5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +## 8.3.1 - 2026-03-04 +* SDK regeneration +* Unable to analyze changes with AI, incrementing PATCH version. + ## 8.3.0 - 2026-03-03 * feat: add document multi-resource extraction endpoint * Add a new endpoint for extracting multiple FHIR resources from documents (PDF/images). diff --git a/reference.md b/reference.md index ed64d80..844429b 100644 --- a/reference.md +++ b/reference.md @@ -1252,6 +1252,83 @@ client.authtoken().auth().generateToken( + + + + +
client.authtoken.auth.getToken(request) -> TokenResponse +
+
+ +#### ๐Ÿ“ Description + +
+
+ +
+
+ +OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). +Accepts client_id and client_secret in the request body (JSON or +form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and +returns an access token with expiration information. +
+
+
+
+ +#### ๐Ÿ”Œ Usage + +
+
+ +
+
+ +```java +client.authtoken().auth().getToken( + ClientCredentialsRequest + .builder() + .build() +); +``` +
+
+
+
+ +#### โš™๏ธ Parameters + +
+
+ +
+
+ +**grantType:** `Optional` โ€” Must be "client_credentials" if provided + +
+
+ +
+
+ +**clientId:** `Optional` โ€” The client ID (credential username) + +
+
+ +
+
+ +**clientSecret:** `Optional` โ€” The client secret (credential password) + +
+
+
+
+ +
diff --git a/sample-app/src/main/java/sample/App.java b/sample-app/src/main/java/sample/App.java index 9f6d674..c5ad4d0 100644 --- a/sample-app/src/main/java/sample/App.java +++ b/sample-app/src/main/java/sample/App.java @@ -8,6 +8,6 @@ public final class App { public static void main(String[] args) { - // import com.phenoml.api.AsyncPhenoML + // import com.phenoml.api.AsyncPhenomlClient } } diff --git a/src/main/java/com/phenoml/api/AsyncClient.java b/src/main/java/com/phenoml/api/AsyncClient.java deleted file mode 100644 index a98cae6..0000000 --- a/src/main/java/com/phenoml/api/AsyncClient.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.phenoml.api; - -import com.phenoml.api.wrapper.AsyncPhenoMLClient; - -/** - * Simple convenience class for the PhenoML async wrapper client. - * - * Usage: - *
{@code
- * // With username/password
- * AsyncClient client = AsyncClient.withCredentials("user", "pass", "https://api.example.com");
- *
- * // With token
- * AsyncClient client = AsyncClient.withToken("your-token", "https://api.example.com");
- * }
- */ -public class AsyncClient extends AsyncPhenoMLClient { - - private AsyncClient(com.phenoml.api.core.ClientOptions clientOptions) { - super(clientOptions); - } - - /** - * Create an async client with username/password authentication. - */ - public static AsyncClient withCredentials(String username, String password, String baseUrl) { - AsyncPhenoMLClient client = AsyncPhenoMLClient.withCredentials(username, password, baseUrl); - return new AsyncClient(client.clientOptions); - } - - /** - * Create an async client with direct token authentication. - */ - public static AsyncClient withToken(String token, String baseUrl) { - AsyncPhenoMLClient client = AsyncPhenoMLClient.withToken(token, baseUrl); - return new AsyncClient(client.clientOptions); - } -} diff --git a/src/main/java/com/phenoml/api/AsyncPhenoML.java b/src/main/java/com/phenoml/api/AsyncPhenomlClient.java similarity index 94% rename from src/main/java/com/phenoml/api/AsyncPhenoML.java rename to src/main/java/com/phenoml/api/AsyncPhenomlClient.java index c45c781..69faace 100644 --- a/src/main/java/com/phenoml/api/AsyncPhenoML.java +++ b/src/main/java/com/phenoml/api/AsyncPhenomlClient.java @@ -17,7 +17,7 @@ import com.phenoml.api.resources.workflows.AsyncWorkflowsClient; import java.util.function.Supplier; -public class AsyncPhenoML { +public class AsyncPhenomlClient { protected final ClientOptions clientOptions; protected final Supplier agentClient; @@ -40,7 +40,7 @@ public class AsyncPhenoML { protected final Supplier workflowsClient; - public AsyncPhenoML(ClientOptions clientOptions) { + public AsyncPhenomlClient(ClientOptions clientOptions) { this.clientOptions = clientOptions; this.agentClient = Suppliers.memoize(() -> new AsyncAgentClient(clientOptions)); this.authtokenClient = Suppliers.memoize(() -> new AsyncAuthtokenClient(clientOptions)); @@ -94,7 +94,7 @@ public AsyncWorkflowsClient workflows() { return this.workflowsClient.get(); } - public static AsyncPhenoMLBuilder builder() { - return new AsyncPhenoMLBuilder(); + public static AsyncPhenomlClientBuilder builder() { + return new AsyncPhenomlClientBuilder(); } } diff --git a/src/main/java/com/phenoml/api/PhenoMLBuilder.java b/src/main/java/com/phenoml/api/AsyncPhenomlClientBuilder.java similarity index 77% rename from src/main/java/com/phenoml/api/PhenoMLBuilder.java rename to src/main/java/com/phenoml/api/AsyncPhenomlClientBuilder.java index 7b73974..9beceb0 100644 --- a/src/main/java/com/phenoml/api/PhenoMLBuilder.java +++ b/src/main/java/com/phenoml/api/AsyncPhenomlClientBuilder.java @@ -5,38 +5,52 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.Environment; +import com.phenoml.api.core.OAuthTokenSupplier; +import com.phenoml.api.resources.authtoken.auth.AuthClient; import java.util.HashMap; import java.util.Map; import java.util.Optional; import okhttp3.OkHttpClient; -public class PhenoMLBuilder { +public class AsyncPhenomlClientBuilder { private Optional timeout = Optional.empty(); private Optional maxRetries = Optional.empty(); private final Map customHeaders = new HashMap<>(); - private String token = null; + private String clientId = System.getenv("PHENOML_CLIENT_ID"); + + private String clientSecret = System.getenv("PHENOML_CLIENT_SECRET"); private Environment environment = Environment.DEFAULT; private OkHttpClient httpClient; /** - * Sets token + * Sets clientId. + * Defaults to the PHENOML_CLIENT_ID environment variable. */ - public PhenoMLBuilder token(String token) { - this.token = token; + public AsyncPhenomlClientBuilder clientId(String clientId) { + this.clientId = clientId; return this; } - public PhenoMLBuilder environment(Environment environment) { + /** + * Sets clientSecret. + * Defaults to the PHENOML_CLIENT_SECRET environment variable. + */ + public AsyncPhenomlClientBuilder clientSecret(String clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public AsyncPhenomlClientBuilder environment(Environment environment) { this.environment = environment; return this; } - public PhenoMLBuilder url(String url) { + public AsyncPhenomlClientBuilder url(String url) { this.environment = Environment.custom(url); return this; } @@ -44,7 +58,7 @@ public PhenoMLBuilder url(String url) { /** * Sets the timeout (in seconds) for the client. Defaults to 60 seconds. */ - public PhenoMLBuilder timeout(int timeout) { + public AsyncPhenomlClientBuilder timeout(int timeout) { this.timeout = Optional.of(timeout); return this; } @@ -52,7 +66,7 @@ public PhenoMLBuilder timeout(int timeout) { /** * Sets the maximum number of retries for the client. Defaults to 2 retries. */ - public PhenoMLBuilder maxRetries(int maxRetries) { + public AsyncPhenomlClientBuilder maxRetries(int maxRetries) { this.maxRetries = Optional.of(maxRetries); return this; } @@ -60,7 +74,7 @@ public PhenoMLBuilder maxRetries(int maxRetries) { /** * Sets the underlying OkHttp client */ - public PhenoMLBuilder httpClient(OkHttpClient httpClient) { + public AsyncPhenomlClientBuilder httpClient(OkHttpClient httpClient) { this.httpClient = httpClient; return this; } @@ -73,7 +87,7 @@ public PhenoMLBuilder httpClient(OkHttpClient httpClient) { * @param value The header value * @return This builder for method chaining */ - public PhenoMLBuilder addHeader(String name, String value) { + public AsyncPhenomlClientBuilder addHeader(String name, String value) { this.customHeaders.put(name, value); return this; } @@ -118,8 +132,12 @@ protected void setEnvironment(ClientOptions.Builder builder) { * } */ protected void setAuthentication(ClientOptions.Builder builder) { - if (this.token != null) { - builder.addHeader("Authorization", "Bearer " + this.token); + if (this.clientId != null && this.clientSecret != null) { + AuthClient authClient = new AuthClient( + ClientOptions.builder().environment(this.environment).build()); + OAuthTokenSupplier oAuthTokenSupplier = + new OAuthTokenSupplier(this.clientId, this.clientSecret, authClient); + builder.addHeader("Authorization", oAuthTokenSupplier); } } @@ -195,11 +213,8 @@ protected void setAdditional(ClientOptions.Builder builder) {} */ protected void validateConfiguration() {} - public PhenoML build() { - if (token == null) { - throw new RuntimeException("Please provide token"); - } + public AsyncPhenomlClient build() { validateConfiguration(); - return new PhenoML(buildClientOptions()); + return new AsyncPhenomlClient(buildClientOptions()); } } diff --git a/src/main/java/com/phenoml/api/Client.java b/src/main/java/com/phenoml/api/Client.java deleted file mode 100644 index 40d962c..0000000 --- a/src/main/java/com/phenoml/api/Client.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.phenoml.api; - -import com.phenoml.api.wrapper.PhenoMLClient; - -/** - * Simple convenience class for the PhenoML wrapper client. - * - * Usage: - *
{@code
- * // With username/password
- * Client client = Client.withCredentials("user", "pass", "https://api.example.com");
- *
- * // With token
- * Client client = Client.withToken("your-token", "https://api.example.com");
- * }
- */ -public class Client extends PhenoMLClient { - - private Client(com.phenoml.api.core.ClientOptions clientOptions) { - super(clientOptions); - } - - /** - * Create a client with username/password authentication. - */ - public static Client withCredentials(String username, String password, String baseUrl) { - PhenoMLClient client = PhenoMLClient.withCredentials(username, password, baseUrl); - return new Client(client.clientOptions); - } - - /** - * Create a client with direct token authentication. - */ - public static Client withToken(String token, String baseUrl) { - PhenoMLClient client = PhenoMLClient.withToken(token, baseUrl); - return new Client(client.clientOptions); - } -} diff --git a/src/main/java/com/phenoml/api/PhenoML.java b/src/main/java/com/phenoml/api/PhenomlClient.java similarity index 94% rename from src/main/java/com/phenoml/api/PhenoML.java rename to src/main/java/com/phenoml/api/PhenomlClient.java index a882f6b..1b6ae23 100644 --- a/src/main/java/com/phenoml/api/PhenoML.java +++ b/src/main/java/com/phenoml/api/PhenomlClient.java @@ -17,7 +17,7 @@ import com.phenoml.api.resources.workflows.WorkflowsClient; import java.util.function.Supplier; -public class PhenoML { +public class PhenomlClient { protected final ClientOptions clientOptions; protected final Supplier agentClient; @@ -40,7 +40,7 @@ public class PhenoML { protected final Supplier workflowsClient; - public PhenoML(ClientOptions clientOptions) { + public PhenomlClient(ClientOptions clientOptions) { this.clientOptions = clientOptions; this.agentClient = Suppliers.memoize(() -> new AgentClient(clientOptions)); this.authtokenClient = Suppliers.memoize(() -> new AuthtokenClient(clientOptions)); @@ -94,7 +94,7 @@ public WorkflowsClient workflows() { return this.workflowsClient.get(); } - public static PhenoMLBuilder builder() { - return new PhenoMLBuilder(); + public static PhenomlClientBuilder builder() { + return new PhenomlClientBuilder(); } } diff --git a/src/main/java/com/phenoml/api/AsyncPhenoMLBuilder.java b/src/main/java/com/phenoml/api/PhenomlClientBuilder.java similarity index 78% rename from src/main/java/com/phenoml/api/AsyncPhenoMLBuilder.java rename to src/main/java/com/phenoml/api/PhenomlClientBuilder.java index 9d31754..147d7b5 100644 --- a/src/main/java/com/phenoml/api/AsyncPhenoMLBuilder.java +++ b/src/main/java/com/phenoml/api/PhenomlClientBuilder.java @@ -5,38 +5,52 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.Environment; +import com.phenoml.api.core.OAuthTokenSupplier; +import com.phenoml.api.resources.authtoken.auth.AuthClient; import java.util.HashMap; import java.util.Map; import java.util.Optional; import okhttp3.OkHttpClient; -public class AsyncPhenoMLBuilder { +public class PhenomlClientBuilder { private Optional timeout = Optional.empty(); private Optional maxRetries = Optional.empty(); private final Map customHeaders = new HashMap<>(); - private String token = null; + private String clientId = System.getenv("PHENOML_CLIENT_ID"); + + private String clientSecret = System.getenv("PHENOML_CLIENT_SECRET"); private Environment environment = Environment.DEFAULT; private OkHttpClient httpClient; /** - * Sets token + * Sets clientId. + * Defaults to the PHENOML_CLIENT_ID environment variable. */ - public AsyncPhenoMLBuilder token(String token) { - this.token = token; + public PhenomlClientBuilder clientId(String clientId) { + this.clientId = clientId; return this; } - public AsyncPhenoMLBuilder environment(Environment environment) { + /** + * Sets clientSecret. + * Defaults to the PHENOML_CLIENT_SECRET environment variable. + */ + public PhenomlClientBuilder clientSecret(String clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public PhenomlClientBuilder environment(Environment environment) { this.environment = environment; return this; } - public AsyncPhenoMLBuilder url(String url) { + public PhenomlClientBuilder url(String url) { this.environment = Environment.custom(url); return this; } @@ -44,7 +58,7 @@ public AsyncPhenoMLBuilder url(String url) { /** * Sets the timeout (in seconds) for the client. Defaults to 60 seconds. */ - public AsyncPhenoMLBuilder timeout(int timeout) { + public PhenomlClientBuilder timeout(int timeout) { this.timeout = Optional.of(timeout); return this; } @@ -52,7 +66,7 @@ public AsyncPhenoMLBuilder timeout(int timeout) { /** * Sets the maximum number of retries for the client. Defaults to 2 retries. */ - public AsyncPhenoMLBuilder maxRetries(int maxRetries) { + public PhenomlClientBuilder maxRetries(int maxRetries) { this.maxRetries = Optional.of(maxRetries); return this; } @@ -60,7 +74,7 @@ public AsyncPhenoMLBuilder maxRetries(int maxRetries) { /** * Sets the underlying OkHttp client */ - public AsyncPhenoMLBuilder httpClient(OkHttpClient httpClient) { + public PhenomlClientBuilder httpClient(OkHttpClient httpClient) { this.httpClient = httpClient; return this; } @@ -73,7 +87,7 @@ public AsyncPhenoMLBuilder httpClient(OkHttpClient httpClient) { * @param value The header value * @return This builder for method chaining */ - public AsyncPhenoMLBuilder addHeader(String name, String value) { + public PhenomlClientBuilder addHeader(String name, String value) { this.customHeaders.put(name, value); return this; } @@ -118,8 +132,12 @@ protected void setEnvironment(ClientOptions.Builder builder) { * } */ protected void setAuthentication(ClientOptions.Builder builder) { - if (this.token != null) { - builder.addHeader("Authorization", "Bearer " + this.token); + if (this.clientId != null && this.clientSecret != null) { + AuthClient authClient = new AuthClient( + ClientOptions.builder().environment(this.environment).build()); + OAuthTokenSupplier oAuthTokenSupplier = + new OAuthTokenSupplier(this.clientId, this.clientSecret, authClient); + builder.addHeader("Authorization", oAuthTokenSupplier); } } @@ -195,11 +213,8 @@ protected void setAdditional(ClientOptions.Builder builder) {} */ protected void validateConfiguration() {} - public AsyncPhenoML build() { - if (token == null) { - throw new RuntimeException("Please provide token"); - } + public PhenomlClient build() { validateConfiguration(); - return new AsyncPhenoML(buildClientOptions()); + return new PhenomlClient(buildClientOptions()); } } diff --git a/src/main/java/com/phenoml/api/core/ClientOptions.java b/src/main/java/com/phenoml/api/core/ClientOptions.java index b4167d8..9a81db2 100644 --- a/src/main/java/com/phenoml/api/core/ClientOptions.java +++ b/src/main/java/com/phenoml/api/core/ClientOptions.java @@ -32,10 +32,10 @@ private ClientOptions( this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.phenoml.maven:phenoml-java-sdk/8.3.0"); + put("User-Agent", "com.phenoml.maven:phenoml-java-sdk/8.3.1"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.phenoml.fern:api-sdk"); - put("X-Fern-SDK-Version", "8.3.0"); + put("X-Fern-SDK-Version", "8.3.1"); } }); this.headerSuppliers = headerSuppliers; diff --git a/src/main/java/com/phenoml/api/core/OAuthTokenSupplier.java b/src/main/java/com/phenoml/api/core/OAuthTokenSupplier.java new file mode 100644 index 0000000..1895140 --- /dev/null +++ b/src/main/java/com/phenoml/api/core/OAuthTokenSupplier.java @@ -0,0 +1,54 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.phenoml.api.core; + +import com.phenoml.api.resources.authtoken.auth.AuthClient; +import com.phenoml.api.resources.authtoken.auth.requests.ClientCredentialsRequest; +import com.phenoml.api.resources.authtoken.types.TokenResponse; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.function.Supplier; + +public final class OAuthTokenSupplier implements Supplier { + private static final long BUFFER_IN_MINUTES = 2; + + private final String clientId; + + private final String clientSecret; + + private final AuthClient authClient; + + private String accessToken; + + private Instant expiresAt; + + public OAuthTokenSupplier(String clientId, String clientSecret, AuthClient authClient) { + this.clientId = clientId; + this.clientSecret = clientSecret; + this.authClient = authClient; + this.expiresAt = Instant.now(); + } + + public TokenResponse fetchToken() { + ClientCredentialsRequest getTokenRequest = ClientCredentialsRequest.builder() + .clientId(clientId) + .clientSecret(clientSecret) + .build(); + return authClient.getToken(getTokenRequest); + } + + @java.lang.Override + public String get() { + if (accessToken == null || expiresAt.isBefore(Instant.now())) { + TokenResponse authResponse = fetchToken(); + this.accessToken = authResponse.getAccessToken(); + this.expiresAt = getExpiresAt(authResponse.getExpiresIn()); + } + return "Bearer " + accessToken; + } + + private Instant getExpiresAt(long expiresInSeconds) { + return Instant.now().plus(expiresInSeconds, ChronoUnit.SECONDS).minus(BUFFER_IN_MINUTES, ChronoUnit.MINUTES); + } +} diff --git a/src/main/java/com/phenoml/api/core/PhenoMLApiException.java b/src/main/java/com/phenoml/api/core/PhenomlClientApiException.java similarity index 78% rename from src/main/java/com/phenoml/api/core/PhenoMLApiException.java rename to src/main/java/com/phenoml/api/core/PhenomlClientApiException.java index 84e5c0d..7ceb3e3 100644 --- a/src/main/java/com/phenoml/api/core/PhenoMLApiException.java +++ b/src/main/java/com/phenoml/api/core/PhenomlClientApiException.java @@ -12,7 +12,7 @@ /** * This exception type will be thrown for any non-2XX API responses. */ -public class PhenoMLApiException extends PhenoMLException { +public class PhenomlClientApiException extends PhenomlClientException { /** * The error code of the response that triggered the exception. */ @@ -25,14 +25,14 @@ public class PhenoMLApiException extends PhenoMLException { private final Map> headers; - public PhenoMLApiException(String message, int statusCode, Object body) { + public PhenomlClientApiException(String message, int statusCode, Object body) { super(message); this.statusCode = statusCode; this.body = body; this.headers = new HashMap<>(); } - public PhenoMLApiException(String message, int statusCode, Object body, Response rawResponse) { + public PhenomlClientApiException(String message, int statusCode, Object body, Response rawResponse) { super(message); this.statusCode = statusCode; this.body = body; @@ -67,7 +67,7 @@ public Map> headers() { @java.lang.Override public String toString() { - return "PhenoMLApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: " + body - + "}"; + return "PhenomlClientApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: " + + body + "}"; } } diff --git a/src/main/java/com/phenoml/api/core/PhenoMLException.java b/src/main/java/com/phenoml/api/core/PhenomlClientException.java similarity index 57% rename from src/main/java/com/phenoml/api/core/PhenoMLException.java rename to src/main/java/com/phenoml/api/core/PhenomlClientException.java index 63658fc..c50b75a 100644 --- a/src/main/java/com/phenoml/api/core/PhenoMLException.java +++ b/src/main/java/com/phenoml/api/core/PhenomlClientException.java @@ -6,12 +6,12 @@ /** * This class serves as the base exception for all errors in the SDK. */ -public class PhenoMLException extends RuntimeException { - public PhenoMLException(String message) { +public class PhenomlClientException extends RuntimeException { + public PhenomlClientException(String message) { super(message); } - public PhenoMLException(String message, Exception e) { + public PhenomlClientException(String message, Exception e) { super(message, e); } } diff --git a/src/main/java/com/phenoml/api/core/PhenoMLHttpResponse.java b/src/main/java/com/phenoml/api/core/PhenomlClientHttpResponse.java similarity index 87% rename from src/main/java/com/phenoml/api/core/PhenoMLHttpResponse.java rename to src/main/java/com/phenoml/api/core/PhenomlClientHttpResponse.java index 1ae28a9..5f3d3d4 100644 --- a/src/main/java/com/phenoml/api/core/PhenoMLHttpResponse.java +++ b/src/main/java/com/phenoml/api/core/PhenomlClientHttpResponse.java @@ -9,13 +9,13 @@ import java.util.Map; import okhttp3.Response; -public final class PhenoMLHttpResponse { +public final class PhenomlClientHttpResponse { private final T body; private final Map> headers; - public PhenoMLHttpResponse(T body, Response rawResponse) { + public PhenomlClientHttpResponse(T body, Response rawResponse) { this.body = body; Map> headers = new HashMap<>(); diff --git a/src/main/java/com/phenoml/api/core/RequestOptions.java b/src/main/java/com/phenoml/api/core/RequestOptions.java index 712f469..c0b50d3 100644 --- a/src/main/java/com/phenoml/api/core/RequestOptions.java +++ b/src/main/java/com/phenoml/api/core/RequestOptions.java @@ -10,8 +10,6 @@ import java.util.function.Supplier; public final class RequestOptions { - private final String token; - private final Optional timeout; private final TimeUnit timeoutTimeUnit; @@ -21,12 +19,10 @@ public final class RequestOptions { private final Map> headerSuppliers; private RequestOptions( - String token, Optional timeout, TimeUnit timeoutTimeUnit, Map headers, Map> headerSuppliers) { - this.token = token; this.timeout = timeout; this.timeoutTimeUnit = timeoutTimeUnit; this.headers = headers; @@ -43,9 +39,6 @@ public TimeUnit getTimeoutTimeUnit() { public Map getHeaders() { Map headers = new HashMap<>(); - if (this.token != null) { - headers.put("Authorization", "Bearer " + this.token); - } headers.putAll(this.headers); this.headerSuppliers.forEach((key, supplier) -> { headers.put(key, supplier.get()); @@ -58,8 +51,6 @@ public static Builder builder() { } public static class Builder { - private String token = null; - private Optional timeout = Optional.empty(); private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; @@ -68,11 +59,6 @@ public static class Builder { private final Map> headerSuppliers = new HashMap<>(); - public Builder token(String token) { - this.token = token; - return this; - } - public Builder timeout(Integer timeout) { this.timeout = Optional.of(timeout); return this; @@ -95,7 +81,7 @@ public Builder addHeader(String key, Supplier value) { } public RequestOptions build() { - return new RequestOptions(token, timeout, timeoutTimeUnit, headers, headerSuppliers); + return new RequestOptions(timeout, timeoutTimeUnit, headers, headerSuppliers); } } } diff --git a/src/main/java/com/phenoml/api/resources/agent/AsyncRawAgentClient.java b/src/main/java/com/phenoml/api/resources/agent/AsyncRawAgentClient.java index f847b85..7065a18 100644 --- a/src/main/java/com/phenoml/api/resources/agent/AsyncRawAgentClient.java +++ b/src/main/java/com/phenoml/api/resources/agent/AsyncRawAgentClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.core.ResponseBodyReader; @@ -58,14 +58,14 @@ public AsyncRawAgentClient(ClientOptions clientOptions) { /** * Creates a new PhenoAgent with specified configuration */ - public CompletableFuture> create(AgentCreateRequest request) { + public CompletableFuture> create(AgentCreateRequest request) { return create(request, null); } /** * Creates a new PhenoAgent with specified configuration */ - public CompletableFuture> create( + public CompletableFuture> create( AgentCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -76,7 +76,7 @@ public CompletableFuture> create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -89,13 +89,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response)); return; @@ -127,20 +127,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -149,21 +149,21 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a list of PhenoAgents belonging to the authenticated user */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(AgentListRequest.builder().build()); } /** * Retrieves a list of PhenoAgents belonging to the authenticated user */ - public CompletableFuture> list(AgentListRequest request) { + public CompletableFuture> list(AgentListRequest request) { return list(request, null); } /** * Retrieves a list of PhenoAgents belonging to the authenticated user */ - public CompletableFuture> list( + public CompletableFuture> list( AgentListRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -182,13 +182,13 @@ public CompletableFuture> list( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentListResponse.class), response)); return; @@ -215,20 +215,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -237,14 +237,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a specific agent by its ID */ - public CompletableFuture> get(String id) { + public CompletableFuture> get(String id) { return get(id, null); } /** * Retrieves a specific agent by its ID */ - public CompletableFuture> get(String id, RequestOptions requestOptions) { + public CompletableFuture> get(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent") @@ -260,13 +260,13 @@ public CompletableFuture> get(String id, Requ if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response)); return; @@ -298,20 +298,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -320,14 +320,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Updates an existing agent's configuration */ - public CompletableFuture> update(String id, AgentCreateRequest request) { + public CompletableFuture> update(String id, AgentCreateRequest request) { return update(id, request, null); } /** * Updates an existing agent's configuration */ - public CompletableFuture> update( + public CompletableFuture> update( String id, AgentCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -339,7 +339,7 @@ public CompletableFuture> update( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -352,13 +352,13 @@ public CompletableFuture> update( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response)); return; @@ -395,20 +395,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -417,14 +417,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Deletes an existing agent */ - public CompletableFuture> delete(String id) { + public CompletableFuture> delete(String id) { return delete(id, null); } /** * Deletes an existing agent */ - public CompletableFuture> delete( + public CompletableFuture> delete( String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -441,13 +441,13 @@ public CompletableFuture> delete( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentDeleteResponse.class), response)); return; @@ -479,20 +479,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -501,14 +501,15 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Patches an existing agent's configuration */ - public CompletableFuture> patch(String id, List request) { + public CompletableFuture> patch( + String id, List request) { return patch(id, request, null); } /** * Patches an existing agent's configuration */ - public CompletableFuture> patch( + public CompletableFuture> patch( String id, List request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -520,7 +521,7 @@ public CompletableFuture> patch( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaType.parse("application/json+patch")); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -533,13 +534,13 @@ public CompletableFuture> patch( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response)); return; @@ -576,20 +577,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -598,14 +599,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Send a message to an agent and receive a JSON response. */ - public CompletableFuture> chat(AgentChatRequest request) { + public CompletableFuture> chat(AgentChatRequest request) { return chat(request, null); } /** * Send a message to an agent and receive a JSON response. */ - public CompletableFuture> chat( + public CompletableFuture> chat( AgentChatRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -649,13 +650,13 @@ public CompletableFuture> chat( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentChatResponse.class), response)); return; @@ -687,20 +688,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -711,7 +712,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * (SSE) stream. Events include message_start, content_delta, tool_use, * tool_result, message_end, and error. */ - public CompletableFuture>> streamChat( + public CompletableFuture>> streamChat( AgentStreamChatRequest request) { return streamChat(request, null); } @@ -721,7 +722,7 @@ public CompletableFuture>> st * (SSE) stream. Events include message_start, content_delta, tool_use, * tool_result, message_end, and error. */ - public CompletableFuture>> streamChat( + public CompletableFuture>> streamChat( AgentStreamChatRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -765,14 +766,14 @@ public CompletableFuture>> st if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture>> future = new CompletableFuture<>(); + CompletableFuture>> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( Stream.fromSse(AgentChatStreamEvent.class, new ResponseBodyReader(response)), response)); return; @@ -804,20 +805,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -826,7 +827,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a list of chat messages for a given chat session */ - public CompletableFuture> getChatMessages( + public CompletableFuture> getChatMessages( AgentGetChatMessagesRequest request) { return getChatMessages(request, null); } @@ -834,7 +835,7 @@ public CompletableFuture> getC /** * Retrieves a list of chat messages for a given chat session */ - public CompletableFuture> getChatMessages( + public CompletableFuture> getChatMessages( AgentGetChatMessagesRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -862,13 +863,13 @@ public CompletableFuture> getC if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), AgentGetChatMessagesResponse.class), response)); @@ -896,20 +897,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/agent/RawAgentClient.java b/src/main/java/com/phenoml/api/resources/agent/RawAgentClient.java index e5fc851..22a8af5 100644 --- a/src/main/java/com/phenoml/api/resources/agent/RawAgentClient.java +++ b/src/main/java/com/phenoml/api/resources/agent/RawAgentClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.core.ResponseBodyReader; @@ -54,14 +54,14 @@ public RawAgentClient(ClientOptions clientOptions) { /** * Creates a new PhenoAgent with specified configuration */ - public PhenoMLHttpResponse create(AgentCreateRequest request) { + public PhenomlClientHttpResponse create(AgentCreateRequest request) { return create(request, null); } /** * Creates a new PhenoAgent with specified configuration */ - public PhenoMLHttpResponse create(AgentCreateRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse create(AgentCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/create") @@ -71,7 +71,7 @@ public PhenoMLHttpResponse create(AgentCreateRequest request, Req body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -87,7 +87,7 @@ public PhenoMLHttpResponse create(AgentCreateRequest request, Req try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -109,34 +109,34 @@ public PhenoMLHttpResponse create(AgentCreateRequest request, Req } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a list of PhenoAgents belonging to the authenticated user */ - public PhenoMLHttpResponse list() { + public PhenomlClientHttpResponse list() { return list(AgentListRequest.builder().build()); } /** * Retrieves a list of PhenoAgents belonging to the authenticated user */ - public PhenoMLHttpResponse list(AgentListRequest request) { + public PhenomlClientHttpResponse list(AgentListRequest request) { return list(request, null); } /** * Retrieves a list of PhenoAgents belonging to the authenticated user */ - public PhenoMLHttpResponse list(AgentListRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse list(AgentListRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/list"); @@ -157,7 +157,7 @@ public PhenoMLHttpResponse list(AgentListRequest request, Req try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentListResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -176,27 +176,27 @@ public PhenoMLHttpResponse list(AgentListRequest request, Req } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a specific agent by its ID */ - public PhenoMLHttpResponse get(String id) { + public PhenomlClientHttpResponse get(String id) { return get(id, null); } /** * Retrieves a specific agent by its ID */ - public PhenoMLHttpResponse get(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse get(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent") @@ -215,7 +215,7 @@ public PhenoMLHttpResponse get(String id, RequestOptions requestO try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -237,27 +237,27 @@ public PhenoMLHttpResponse get(String id, RequestOptions requestO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Updates an existing agent's configuration */ - public PhenoMLHttpResponse update(String id, AgentCreateRequest request) { + public PhenomlClientHttpResponse update(String id, AgentCreateRequest request) { return update(id, request, null); } /** * Updates an existing agent's configuration */ - public PhenoMLHttpResponse update( + public PhenomlClientHttpResponse update( String id, AgentCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -269,7 +269,7 @@ public PhenoMLHttpResponse update( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -285,7 +285,7 @@ public PhenoMLHttpResponse update( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -310,27 +310,27 @@ public PhenoMLHttpResponse update( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Deletes an existing agent */ - public PhenoMLHttpResponse delete(String id) { + public PhenomlClientHttpResponse delete(String id) { return delete(id, null); } /** * Deletes an existing agent */ - public PhenoMLHttpResponse delete(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse delete(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent") @@ -349,7 +349,7 @@ public PhenoMLHttpResponse delete(String id, RequestOptions try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentDeleteResponse.class), response); } @@ -372,27 +372,27 @@ public PhenoMLHttpResponse delete(String id, RequestOptions } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Patches an existing agent's configuration */ - public PhenoMLHttpResponse patch(String id, List request) { + public PhenomlClientHttpResponse patch(String id, List request) { return patch(id, request, null); } /** * Patches an existing agent's configuration */ - public PhenoMLHttpResponse patch( + public PhenomlClientHttpResponse patch( String id, List request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -404,7 +404,7 @@ public PhenoMLHttpResponse patch( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaType.parse("application/json+patch")); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -420,7 +420,7 @@ public PhenoMLHttpResponse patch( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -445,27 +445,27 @@ public PhenoMLHttpResponse patch( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Send a message to an agent and receive a JSON response. */ - public PhenoMLHttpResponse chat(AgentChatRequest request) { + public PhenomlClientHttpResponse chat(AgentChatRequest request) { return chat(request, null); } /** * Send a message to an agent and receive a JSON response. */ - public PhenoMLHttpResponse chat(AgentChatRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse chat(AgentChatRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/chat") @@ -511,7 +511,7 @@ public PhenoMLHttpResponse chat(AgentChatRequest request, Req try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentChatResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -533,13 +533,13 @@ public PhenoMLHttpResponse chat(AgentChatRequest request, Req } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -548,7 +548,7 @@ public PhenoMLHttpResponse chat(AgentChatRequest request, Req * (SSE) stream. Events include message_start, content_delta, tool_use, * tool_result, message_end, and error. */ - public PhenoMLHttpResponse> streamChat(AgentStreamChatRequest request) { + public PhenomlClientHttpResponse> streamChat(AgentStreamChatRequest request) { return streamChat(request, null); } @@ -557,7 +557,7 @@ public PhenoMLHttpResponse> streamChat(AgentStrea * (SSE) stream. Events include message_start, content_delta, tool_use, * tool_result, message_end, and error. */ - public PhenoMLHttpResponse> streamChat( + public PhenomlClientHttpResponse> streamChat( AgentStreamChatRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -605,7 +605,7 @@ public PhenoMLHttpResponse> streamChat( Response response = client.newCall(okhttpRequest).execute(); ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( Stream.fromSse(AgentChatStreamEvent.class, new ResponseBodyReader(response)), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -627,27 +627,28 @@ public PhenoMLHttpResponse> streamChat( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a list of chat messages for a given chat session */ - public PhenoMLHttpResponse getChatMessages(AgentGetChatMessagesRequest request) { + public PhenomlClientHttpResponse getChatMessages( + AgentGetChatMessagesRequest request) { return getChatMessages(request, null); } /** * Retrieves a list of chat messages for a given chat session */ - public PhenoMLHttpResponse getChatMessages( + public PhenomlClientHttpResponse getChatMessages( AgentGetChatMessagesRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -678,7 +679,7 @@ public PhenoMLHttpResponse getChatMessages( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentGetChatMessagesResponse.class), response); } @@ -698,13 +699,13 @@ public PhenoMLHttpResponse getChatMessages( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/agent/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/agent/errors/BadRequestError.java index 44f8bf1..54352d6 100644 --- a/src/main/java/com/phenoml/api/resources/agent/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/agent/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.agent.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/agent/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/agent/errors/ForbiddenError.java index ff1368d..26aaba7 100644 --- a/src/main/java/com/phenoml/api/resources/agent/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/agent/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.agent.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/agent/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/agent/errors/InternalServerError.java index 4056eca..253a810 100644 --- a/src/main/java/com/phenoml/api/resources/agent/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/agent/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.agent.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/agent/errors/NotFoundError.java b/src/main/java/com/phenoml/api/resources/agent/errors/NotFoundError.java index e0ba0d1..4602a5c 100644 --- a/src/main/java/com/phenoml/api/resources/agent/errors/NotFoundError.java +++ b/src/main/java/com/phenoml/api/resources/agent/errors/NotFoundError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.agent.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotFoundError extends PhenoMLApiException { +public final class NotFoundError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/agent/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/agent/errors/UnauthorizedError.java index 1e48856..52459ba 100644 --- a/src/main/java/com/phenoml/api/resources/agent/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/agent/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.agent.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/agent/prompts/AsyncRawPromptsClient.java b/src/main/java/com/phenoml/api/resources/agent/prompts/AsyncRawPromptsClient.java index 6f64419..641af94 100644 --- a/src/main/java/com/phenoml/api/resources/agent/prompts/AsyncRawPromptsClient.java +++ b/src/main/java/com/phenoml/api/resources/agent/prompts/AsyncRawPromptsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.agent.errors.BadRequestError; import com.phenoml.api.resources.agent.errors.ForbiddenError; @@ -48,14 +48,15 @@ public AsyncRawPromptsClient(ClientOptions clientOptions) { /** * Creates a new agent prompt */ - public CompletableFuture> create(AgentPromptsCreateRequest request) { + public CompletableFuture> create( + AgentPromptsCreateRequest request) { return create(request, null); } /** * Creates a new agent prompt */ - public CompletableFuture> create( + public CompletableFuture> create( AgentPromptsCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -66,7 +67,7 @@ public CompletableFuture> create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -79,13 +80,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response)); return; @@ -117,20 +118,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -139,14 +140,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a list of agent prompts belonging to the authenticated user */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(null); } /** * Retrieves a list of agent prompts belonging to the authenticated user */ - public CompletableFuture> list(RequestOptions requestOptions) { + public CompletableFuture> list(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts/list") @@ -161,13 +162,13 @@ public CompletableFuture> list(RequestO if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PromptsListResponse.class), response)); return; @@ -194,20 +195,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -216,14 +217,15 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a specific prompt by its ID */ - public CompletableFuture> get(String id) { + public CompletableFuture> get(String id) { return get(id, null); } /** * Retrieves a specific prompt by its ID */ - public CompletableFuture> get(String id, RequestOptions requestOptions) { + public CompletableFuture> get( + String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts") @@ -239,13 +241,13 @@ public CompletableFuture> get(String i if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response)); return; @@ -277,20 +279,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -299,14 +301,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Updates an existing prompt */ - public CompletableFuture> update(String id) { + public CompletableFuture> update(String id) { return update(id, AgentPromptsUpdateRequest.builder().build()); } /** * Updates an existing prompt */ - public CompletableFuture> update( + public CompletableFuture> update( String id, AgentPromptsUpdateRequest request) { return update(id, request, null); } @@ -314,7 +316,7 @@ public CompletableFuture> update( /** * Updates an existing prompt */ - public CompletableFuture> update( + public CompletableFuture> update( String id, AgentPromptsUpdateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -326,7 +328,7 @@ public CompletableFuture> update( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -339,13 +341,13 @@ public CompletableFuture> update( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response)); return; @@ -382,20 +384,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -404,14 +406,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Deletes a prompt */ - public CompletableFuture> delete(String id) { + public CompletableFuture> delete(String id) { return delete(id, null); } /** * Deletes a prompt */ - public CompletableFuture> delete( + public CompletableFuture> delete( String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -428,13 +430,13 @@ public CompletableFuture> delete( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PromptsDeleteResponse.class), response)); return; @@ -466,20 +468,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -488,7 +490,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Patches an existing prompt */ - public CompletableFuture> patch( + public CompletableFuture> patch( String id, List request) { return patch(id, request, null); } @@ -496,7 +498,7 @@ public CompletableFuture> patch( /** * Patches an existing prompt */ - public CompletableFuture> patch( + public CompletableFuture> patch( String id, List request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -508,7 +510,7 @@ public CompletableFuture> patch( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaType.parse("application/json+patch")); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -521,13 +523,13 @@ public CompletableFuture> patch( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response)); return; @@ -564,20 +566,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -586,14 +588,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Loads default agent prompts for the authenticated user */ - public CompletableFuture> loadDefaults() { + public CompletableFuture> loadDefaults() { return loadDefaults(null); } /** * Loads default agent prompts for the authenticated user */ - public CompletableFuture> loadDefaults(RequestOptions requestOptions) { + public CompletableFuture> loadDefaults(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts/load-defaults") @@ -608,13 +610,13 @@ public CompletableFuture> loadDefaults(Requ if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SuccessResponse.class), response)); return; @@ -641,20 +643,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/agent/prompts/RawPromptsClient.java b/src/main/java/com/phenoml/api/resources/agent/prompts/RawPromptsClient.java index 9d1bb7f..429912b 100644 --- a/src/main/java/com/phenoml/api/resources/agent/prompts/RawPromptsClient.java +++ b/src/main/java/com/phenoml/api/resources/agent/prompts/RawPromptsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.agent.errors.BadRequestError; import com.phenoml.api.resources.agent.errors.ForbiddenError; @@ -44,14 +44,14 @@ public RawPromptsClient(ClientOptions clientOptions) { /** * Creates a new agent prompt */ - public PhenoMLHttpResponse create(AgentPromptsCreateRequest request) { + public PhenomlClientHttpResponse create(AgentPromptsCreateRequest request) { return create(request, null); } /** * Creates a new agent prompt */ - public PhenoMLHttpResponse create( + public PhenomlClientHttpResponse create( AgentPromptsCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -62,7 +62,7 @@ public PhenoMLHttpResponse create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -78,7 +78,7 @@ public PhenoMLHttpResponse create( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response); } @@ -101,27 +101,27 @@ public PhenoMLHttpResponse create( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a list of agent prompts belonging to the authenticated user */ - public PhenoMLHttpResponse list() { + public PhenomlClientHttpResponse list() { return list(null); } /** * Retrieves a list of agent prompts belonging to the authenticated user */ - public PhenoMLHttpResponse list(RequestOptions requestOptions) { + public PhenomlClientHttpResponse list(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts/list") @@ -139,7 +139,7 @@ public PhenoMLHttpResponse list(RequestOptions requestOptio try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PromptsListResponse.class), response); } @@ -159,27 +159,27 @@ public PhenoMLHttpResponse list(RequestOptions requestOptio } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a specific prompt by its ID */ - public PhenoMLHttpResponse get(String id) { + public PhenomlClientHttpResponse get(String id) { return get(id, null); } /** * Retrieves a specific prompt by its ID */ - public PhenoMLHttpResponse get(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse get(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts") @@ -198,7 +198,7 @@ public PhenoMLHttpResponse get(String id, RequestOptions r try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response); } @@ -221,34 +221,34 @@ public PhenoMLHttpResponse get(String id, RequestOptions r } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Updates an existing prompt */ - public PhenoMLHttpResponse update(String id) { + public PhenomlClientHttpResponse update(String id) { return update(id, AgentPromptsUpdateRequest.builder().build()); } /** * Updates an existing prompt */ - public PhenoMLHttpResponse update(String id, AgentPromptsUpdateRequest request) { + public PhenomlClientHttpResponse update(String id, AgentPromptsUpdateRequest request) { return update(id, request, null); } /** * Updates an existing prompt */ - public PhenoMLHttpResponse update( + public PhenomlClientHttpResponse update( String id, AgentPromptsUpdateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -260,7 +260,7 @@ public PhenoMLHttpResponse update( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -276,7 +276,7 @@ public PhenoMLHttpResponse update( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response); } @@ -302,27 +302,27 @@ public PhenoMLHttpResponse update( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Deletes a prompt */ - public PhenoMLHttpResponse delete(String id) { + public PhenomlClientHttpResponse delete(String id) { return delete(id, null); } /** * Deletes a prompt */ - public PhenoMLHttpResponse delete(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse delete(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts") @@ -341,7 +341,7 @@ public PhenoMLHttpResponse delete(String id, RequestOptio try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), PromptsDeleteResponse.class), response); } @@ -364,27 +364,27 @@ public PhenoMLHttpResponse delete(String id, RequestOptio } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Patches an existing prompt */ - public PhenoMLHttpResponse patch(String id, List request) { + public PhenomlClientHttpResponse patch(String id, List request) { return patch(id, request, null); } /** * Patches an existing prompt */ - public PhenoMLHttpResponse patch( + public PhenomlClientHttpResponse patch( String id, List request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -396,7 +396,7 @@ public PhenoMLHttpResponse patch( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaType.parse("application/json+patch")); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -412,7 +412,7 @@ public PhenoMLHttpResponse patch( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AgentPromptsResponse.class), response); } @@ -438,27 +438,27 @@ public PhenoMLHttpResponse patch( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Loads default agent prompts for the authenticated user */ - public PhenoMLHttpResponse loadDefaults() { + public PhenomlClientHttpResponse loadDefaults() { return loadDefaults(null); } /** * Loads default agent prompts for the authenticated user */ - public PhenoMLHttpResponse loadDefaults(RequestOptions requestOptions) { + public PhenomlClientHttpResponse loadDefaults(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("agent/prompts/load-defaults") @@ -476,7 +476,7 @@ public PhenoMLHttpResponse loadDefaults(RequestOptions requestO try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SuccessResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -495,13 +495,13 @@ public PhenoMLHttpResponse loadDefaults(RequestOptions requestO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncAuthClient.java b/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncAuthClient.java index 5233e64..13c0f2a 100644 --- a/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncAuthClient.java +++ b/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncAuthClient.java @@ -6,7 +6,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.authtoken.auth.requests.AuthGenerateTokenRequest; +import com.phenoml.api.resources.authtoken.auth.requests.ClientCredentialsRequest; import com.phenoml.api.resources.authtoken.auth.types.AuthGenerateTokenResponse; +import com.phenoml.api.resources.authtoken.types.TokenResponse; import java.util.concurrent.CompletableFuture; public class AsyncAuthClient { @@ -40,4 +42,34 @@ public CompletableFuture generateToken( AuthGenerateTokenRequest request, RequestOptions requestOptions) { return this.rawClient.generateToken(request, requestOptions).thenApply(response -> response.body()); } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public CompletableFuture getToken() { + return this.rawClient.getToken().thenApply(response -> response.body()); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public CompletableFuture getToken(ClientCredentialsRequest request) { + return this.rawClient.getToken(request).thenApply(response -> response.body()); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public CompletableFuture getToken(ClientCredentialsRequest request, RequestOptions requestOptions) { + return this.rawClient.getToken(request, requestOptions).thenApply(response -> response.body()); + } } diff --git a/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncRawAuthClient.java b/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncRawAuthClient.java index 3b36ec1..db61af4 100644 --- a/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncRawAuthClient.java +++ b/src/main/java/com/phenoml/api/resources/authtoken/auth/AsyncRawAuthClient.java @@ -5,17 +5,20 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.phenoml.api.core.ClientOptions; +import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.authtoken.auth.requests.AuthGenerateTokenRequest; +import com.phenoml.api.resources.authtoken.auth.requests.ClientCredentialsRequest; import com.phenoml.api.resources.authtoken.auth.types.AuthGenerateTokenResponse; import com.phenoml.api.resources.authtoken.errors.BadRequestError; +import com.phenoml.api.resources.authtoken.errors.InternalServerError; import com.phenoml.api.resources.authtoken.errors.UnauthorizedError; +import com.phenoml.api.resources.authtoken.types.TokenResponse; import java.io.IOException; -import java.util.Base64; import java.util.concurrent.CompletableFuture; import okhttp3.Call; import okhttp3.Callback; @@ -38,7 +41,7 @@ public AsyncRawAuthClient(ClientOptions clientOptions) { /** * Obtain an access token using client credentials */ - public CompletableFuture> generateToken( + public CompletableFuture> generateToken( AuthGenerateTokenRequest request) { return generateToken(request, null); } @@ -46,22 +49,23 @@ public CompletableFuture> generat /** * Obtain an access token using client credentials */ - public CompletableFuture> generateToken( + public CompletableFuture> generateToken( AuthGenerateTokenRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("auth/token") .build(); - - // Create Basic Auth header - String credentials = request.getUsername() + ":" + request.getPassword(); - String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); - + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new PhenomlClientException("Failed to serialize request", e); + } Request okhttpRequest = new Request.Builder() .url(httpUrl) - .method("POST", RequestBody.create(new byte[0])) // Empty body + .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Authorization", "Basic " + encodedCredentials) .addHeader("Content-Type", "application/json") .addHeader("Accept", "application/json") .build(); @@ -69,13 +73,13 @@ public CompletableFuture> generat if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), AuthGenerateTokenResponse.class), response)); @@ -98,20 +102,122 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } catch (IOException e) { + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); + } + }); + return future; + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public CompletableFuture> getToken() { + return getToken(ClientCredentialsRequest.builder().build()); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public CompletableFuture> getToken(ClientCredentialsRequest request) { + return getToken(request, null); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public CompletableFuture> getToken( + ClientCredentialsRequest request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/auth/token") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new PhenomlClientException("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", body) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .addHeader("Accept", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + CompletableFuture> future = new CompletableFuture<>(); + client.newCall(okhttpRequest).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + try (ResponseBody responseBody = response.body()) { + if (response.isSuccessful()) { + future.complete(new PhenomlClientHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), TokenResponse.class), + response)); + return; + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + future.completeExceptionally(new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 401: + future.completeExceptionally(new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + case 500: + future.completeExceptionally(new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response)); + return; + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/authtoken/auth/AuthClient.java b/src/main/java/com/phenoml/api/resources/authtoken/auth/AuthClient.java index 54fa3a9..e96bec5 100644 --- a/src/main/java/com/phenoml/api/resources/authtoken/auth/AuthClient.java +++ b/src/main/java/com/phenoml/api/resources/authtoken/auth/AuthClient.java @@ -6,7 +6,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.authtoken.auth.requests.AuthGenerateTokenRequest; +import com.phenoml.api.resources.authtoken.auth.requests.ClientCredentialsRequest; import com.phenoml.api.resources.authtoken.auth.types.AuthGenerateTokenResponse; +import com.phenoml.api.resources.authtoken.types.TokenResponse; public class AuthClient { protected final ClientOptions clientOptions; @@ -38,4 +40,34 @@ public AuthGenerateTokenResponse generateToken(AuthGenerateTokenRequest request) public AuthGenerateTokenResponse generateToken(AuthGenerateTokenRequest request, RequestOptions requestOptions) { return this.rawClient.generateToken(request, requestOptions).body(); } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public TokenResponse getToken() { + return this.rawClient.getToken().body(); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public TokenResponse getToken(ClientCredentialsRequest request) { + return this.rawClient.getToken(request).body(); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public TokenResponse getToken(ClientCredentialsRequest request, RequestOptions requestOptions) { + return this.rawClient.getToken(request, requestOptions).body(); + } } diff --git a/src/main/java/com/phenoml/api/resources/authtoken/auth/RawAuthClient.java b/src/main/java/com/phenoml/api/resources/authtoken/auth/RawAuthClient.java index f07d761..c4b8e60 100644 --- a/src/main/java/com/phenoml/api/resources/authtoken/auth/RawAuthClient.java +++ b/src/main/java/com/phenoml/api/resources/authtoken/auth/RawAuthClient.java @@ -5,17 +5,20 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.phenoml.api.core.ClientOptions; +import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.authtoken.auth.requests.AuthGenerateTokenRequest; +import com.phenoml.api.resources.authtoken.auth.requests.ClientCredentialsRequest; import com.phenoml.api.resources.authtoken.auth.types.AuthGenerateTokenResponse; import com.phenoml.api.resources.authtoken.errors.BadRequestError; +import com.phenoml.api.resources.authtoken.errors.InternalServerError; import com.phenoml.api.resources.authtoken.errors.UnauthorizedError; +import com.phenoml.api.resources.authtoken.types.TokenResponse; import java.io.IOException; -import java.util.Base64; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; @@ -34,29 +37,30 @@ public RawAuthClient(ClientOptions clientOptions) { /** * Obtain an access token using client credentials */ - public PhenoMLHttpResponse generateToken(AuthGenerateTokenRequest request) { + public PhenomlClientHttpResponse generateToken(AuthGenerateTokenRequest request) { return generateToken(request, null); } /** * Obtain an access token using client credentials */ - public PhenoMLHttpResponse generateToken( + public PhenomlClientHttpResponse generateToken( AuthGenerateTokenRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("auth/token") .build(); - - // Create Basic Auth header - String credentials = request.getUsername() + ":" + request.getPassword(); - String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); - + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new PhenomlClientException("Failed to serialize request", e); + } Request okhttpRequest = new Request.Builder() .url(httpUrl) - .method("POST", RequestBody.create(new byte[0])) // Empty body + .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Authorization", "Basic " + encodedCredentials) .addHeader("Content-Type", "application/json") .addHeader("Accept", "application/json") .build(); @@ -67,7 +71,7 @@ public PhenoMLHttpResponse generateToken( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AuthGenerateTokenResponse.class), response); } @@ -84,13 +88,95 @@ public PhenoMLHttpResponse generateToken( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), + response); + } catch (IOException e) { + throw new PhenomlClientException("Network error executing HTTP request", e); + } + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public PhenomlClientHttpResponse getToken() { + return getToken(ClientCredentialsRequest.builder().build()); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public PhenomlClientHttpResponse getToken(ClientCredentialsRequest request) { + return getToken(request, null); + } + + /** + * OAuth 2.0 client credentials token endpoint (RFC 6749 ยง4.4). + * Accepts client_id and client_secret in the request body (JSON or + * form-encoded) or via Basic Auth header (RFC 6749 ยง2.3.1), and + * returns an access token with expiration information. + */ + public PhenomlClientHttpResponse getToken( + ClientCredentialsRequest request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/auth/token") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new PhenomlClientException("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", body) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .addHeader("Accept", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new PhenomlClientHttpResponse<>( + ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), TokenResponse.class), response); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new BadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 401: + throw new UnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + case 500: + throw new InternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/authtoken/auth/requests/ClientCredentialsRequest.java b/src/main/java/com/phenoml/api/resources/authtoken/auth/requests/ClientCredentialsRequest.java new file mode 100644 index 0000000..e044998 --- /dev/null +++ b/src/main/java/com/phenoml/api/resources/authtoken/auth/requests/ClientCredentialsRequest.java @@ -0,0 +1,163 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.phenoml.api.resources.authtoken.auth.requests; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.phenoml.api.core.ObjectMappers; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = ClientCredentialsRequest.Builder.class) +public final class ClientCredentialsRequest { + private final Optional grantType; + + private final Optional clientId; + + private final Optional clientSecret; + + private final Map additionalProperties; + + private ClientCredentialsRequest( + Optional grantType, + Optional clientId, + Optional clientSecret, + Map additionalProperties) { + this.grantType = grantType; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.additionalProperties = additionalProperties; + } + + /** + * @return Must be "client_credentials" if provided + */ + @JsonProperty("grant_type") + public Optional getGrantType() { + return grantType; + } + + /** + * @return The client ID (credential username) + */ + @JsonProperty("client_id") + public Optional getClientId() { + return clientId; + } + + /** + * @return The client secret (credential password) + */ + @JsonProperty("client_secret") + public Optional getClientSecret() { + return clientSecret; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ClientCredentialsRequest && equalTo((ClientCredentialsRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ClientCredentialsRequest other) { + return grantType.equals(other.grantType) + && clientId.equals(other.clientId) + && clientSecret.equals(other.clientSecret); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.grantType, this.clientId, this.clientSecret); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder { + private Optional grantType = Optional.empty(); + + private Optional clientId = Optional.empty(); + + private Optional clientSecret = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ClientCredentialsRequest other) { + grantType(other.getGrantType()); + clientId(other.getClientId()); + clientSecret(other.getClientSecret()); + return this; + } + + /** + *

Must be "client_credentials" if provided

+ */ + @JsonSetter(value = "grant_type", nulls = Nulls.SKIP) + public Builder grantType(Optional grantType) { + this.grantType = grantType; + return this; + } + + public Builder grantType(String grantType) { + this.grantType = Optional.ofNullable(grantType); + return this; + } + + /** + *

The client ID (credential username)

+ */ + @JsonSetter(value = "client_id", nulls = Nulls.SKIP) + public Builder clientId(Optional clientId) { + this.clientId = clientId; + return this; + } + + public Builder clientId(String clientId) { + this.clientId = Optional.ofNullable(clientId); + return this; + } + + /** + *

The client secret (credential password)

+ */ + @JsonSetter(value = "client_secret", nulls = Nulls.SKIP) + public Builder clientSecret(Optional clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public Builder clientSecret(String clientSecret) { + this.clientSecret = Optional.ofNullable(clientSecret); + return this; + } + + public ClientCredentialsRequest build() { + return new ClientCredentialsRequest(grantType, clientId, clientSecret, additionalProperties); + } + } +} diff --git a/src/main/java/com/phenoml/api/resources/authtoken/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/authtoken/errors/BadRequestError.java index 7547bca..cb8df33 100644 --- a/src/main/java/com/phenoml/api/resources/authtoken/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/authtoken/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.authtoken.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/authtoken/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/authtoken/errors/InternalServerError.java new file mode 100644 index 0000000..c70b56d --- /dev/null +++ b/src/main/java/com/phenoml/api/resources/authtoken/errors/InternalServerError.java @@ -0,0 +1,32 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.phenoml.api.resources.authtoken.errors; + +import com.phenoml.api.core.PhenomlClientApiException; +import okhttp3.Response; + +public final class InternalServerError extends PhenomlClientApiException { + /** + * The body of the response that triggered the exception. + */ + private final Object body; + + public InternalServerError(Object body) { + super("InternalServerError", 500, body); + this.body = body; + } + + public InternalServerError(Object body, Response rawResponse) { + super("InternalServerError", 500, body, rawResponse); + this.body = body; + } + + /** + * @return the body + */ + @java.lang.Override + public Object body() { + return this.body; + } +} diff --git a/src/main/java/com/phenoml/api/resources/authtoken/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/authtoken/errors/UnauthorizedError.java index 226c8db..1c4cc3e 100644 --- a/src/main/java/com/phenoml/api/resources/authtoken/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/authtoken/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.authtoken.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/authtoken/types/OAuthError.java b/src/main/java/com/phenoml/api/resources/authtoken/types/OAuthError.java new file mode 100644 index 0000000..eca63a6 --- /dev/null +++ b/src/main/java/com/phenoml/api/resources/authtoken/types/OAuthError.java @@ -0,0 +1,254 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.phenoml.api.resources.authtoken.types; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.phenoml.api.core.ObjectMappers; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = OAuthError.Builder.class) +public final class OAuthError { + private final Error error; + + private final Optional errorDescription; + + private final Map additionalProperties; + + private OAuthError(Error error, Optional errorDescription, Map additionalProperties) { + this.error = error; + this.errorDescription = errorDescription; + this.additionalProperties = additionalProperties; + } + + /** + * @return Error code + */ + @JsonProperty("error") + public Error getError() { + return error; + } + + /** + * @return Human-readable error description + */ + @JsonProperty("error_description") + public Optional getErrorDescription() { + return errorDescription; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof OAuthError && equalTo((OAuthError) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(OAuthError other) { + return error.equals(other.error) && errorDescription.equals(other.errorDescription); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.error, this.errorDescription); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ErrorStage builder() { + return new Builder(); + } + + public interface ErrorStage { + /** + *

Error code

+ */ + _FinalStage error(@NotNull Error error); + + Builder from(OAuthError other); + } + + public interface _FinalStage { + OAuthError build(); + + /** + *

Human-readable error description

+ */ + _FinalStage errorDescription(Optional errorDescription); + + _FinalStage errorDescription(String errorDescription); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ErrorStage, _FinalStage { + private Error error; + + private Optional errorDescription = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(OAuthError other) { + error(other.getError()); + errorDescription(other.getErrorDescription()); + return this; + } + + /** + *

Error code

+ *

Error code

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("error") + public _FinalStage error(@NotNull Error error) { + this.error = Objects.requireNonNull(error, "error must not be null"); + return this; + } + + /** + *

Human-readable error description

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage errorDescription(String errorDescription) { + this.errorDescription = Optional.ofNullable(errorDescription); + return this; + } + + /** + *

Human-readable error description

+ */ + @java.lang.Override + @JsonSetter(value = "error_description", nulls = Nulls.SKIP) + public _FinalStage errorDescription(Optional errorDescription) { + this.errorDescription = errorDescription; + return this; + } + + @java.lang.Override + public OAuthError build() { + return new OAuthError(error, errorDescription, additionalProperties); + } + } + + public static final class Error { + public static final Error INVALID_REQUEST = new Error(Value.INVALID_REQUEST, "invalid_request"); + + public static final Error SERVER_ERROR = new Error(Value.SERVER_ERROR, "server_error"); + + public static final Error INVALID_CLIENT = new Error(Value.INVALID_CLIENT, "invalid_client"); + + public static final Error UNSUPPORTED_GRANT_TYPE = + new Error(Value.UNSUPPORTED_GRANT_TYPE, "unsupported_grant_type"); + + private final Value value; + + private final String string; + + Error(Value value, String string) { + this.value = value; + this.string = string; + } + + public Value getEnumValue() { + return value; + } + + @java.lang.Override + @JsonValue + public String toString() { + return this.string; + } + + @java.lang.Override + public boolean equals(Object other) { + return (this == other) || (other instanceof Error && this.string.equals(((Error) other).string)); + } + + @java.lang.Override + public int hashCode() { + return this.string.hashCode(); + } + + public T visit(Visitor visitor) { + switch (value) { + case INVALID_REQUEST: + return visitor.visitInvalidRequest(); + case SERVER_ERROR: + return visitor.visitServerError(); + case INVALID_CLIENT: + return visitor.visitInvalidClient(); + case UNSUPPORTED_GRANT_TYPE: + return visitor.visitUnsupportedGrantType(); + case UNKNOWN: + default: + return visitor.visitUnknown(string); + } + } + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + public static Error valueOf(String value) { + switch (value) { + case "invalid_request": + return INVALID_REQUEST; + case "server_error": + return SERVER_ERROR; + case "invalid_client": + return INVALID_CLIENT; + case "unsupported_grant_type": + return UNSUPPORTED_GRANT_TYPE; + default: + return new Error(Value.UNKNOWN, value); + } + } + + public enum Value { + INVALID_REQUEST, + + INVALID_CLIENT, + + UNSUPPORTED_GRANT_TYPE, + + SERVER_ERROR, + + UNKNOWN + } + + public interface Visitor { + T visitInvalidRequest(); + + T visitInvalidClient(); + + T visitUnsupportedGrantType(); + + T visitServerError(); + + T visitUnknown(String unknownType); + } + } +} diff --git a/src/main/java/com/phenoml/api/resources/authtoken/types/TokenResponse.java b/src/main/java/com/phenoml/api/resources/authtoken/types/TokenResponse.java new file mode 100644 index 0000000..1cc79a4 --- /dev/null +++ b/src/main/java/com/phenoml/api/resources/authtoken/types/TokenResponse.java @@ -0,0 +1,182 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.phenoml.api.resources.authtoken.types; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.phenoml.api.core.ObjectMappers; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = TokenResponse.Builder.class) +public final class TokenResponse { + private final String accessToken; + + private final String tokenType; + + private final int expiresIn; + + private final Map additionalProperties; + + private TokenResponse( + String accessToken, String tokenType, int expiresIn, Map additionalProperties) { + this.accessToken = accessToken; + this.tokenType = tokenType; + this.expiresIn = expiresIn; + this.additionalProperties = additionalProperties; + } + + /** + * @return JWT access token for subsequent authenticated requests + */ + @JsonProperty("access_token") + public String getAccessToken() { + return accessToken; + } + + /** + * @return Token type (always "Bearer") + */ + @JsonProperty("token_type") + public String getTokenType() { + return tokenType; + } + + /** + * @return Token lifetime in seconds + */ + @JsonProperty("expires_in") + public int getExpiresIn() { + return expiresIn; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TokenResponse && equalTo((TokenResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(TokenResponse other) { + return accessToken.equals(other.accessToken) + && tokenType.equals(other.tokenType) + && expiresIn == other.expiresIn; + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.accessToken, this.tokenType, this.expiresIn); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static AccessTokenStage builder() { + return new Builder(); + } + + public interface AccessTokenStage { + /** + *

JWT access token for subsequent authenticated requests

+ */ + TokenTypeStage accessToken(@NotNull String accessToken); + + Builder from(TokenResponse other); + } + + public interface TokenTypeStage { + /** + *

Token type (always "Bearer")

+ */ + ExpiresInStage tokenType(@NotNull String tokenType); + } + + public interface ExpiresInStage { + /** + *

Token lifetime in seconds

+ */ + _FinalStage expiresIn(int expiresIn); + } + + public interface _FinalStage { + TokenResponse build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements AccessTokenStage, TokenTypeStage, ExpiresInStage, _FinalStage { + private String accessToken; + + private String tokenType; + + private int expiresIn; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(TokenResponse other) { + accessToken(other.getAccessToken()); + tokenType(other.getTokenType()); + expiresIn(other.getExpiresIn()); + return this; + } + + /** + *

JWT access token for subsequent authenticated requests

+ *

JWT access token for subsequent authenticated requests

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("access_token") + public TokenTypeStage accessToken(@NotNull String accessToken) { + this.accessToken = Objects.requireNonNull(accessToken, "accessToken must not be null"); + return this; + } + + /** + *

Token type (always "Bearer")

+ *

Token type (always "Bearer")

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("token_type") + public ExpiresInStage tokenType(@NotNull String tokenType) { + this.tokenType = Objects.requireNonNull(tokenType, "tokenType must not be null"); + return this; + } + + /** + *

Token lifetime in seconds

+ *

Token lifetime in seconds

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("expires_in") + public _FinalStage expiresIn(int expiresIn) { + this.expiresIn = expiresIn; + return this; + } + + @java.lang.Override + public TokenResponse build() { + return new TokenResponse(accessToken, tokenType, expiresIn, additionalProperties); + } + } +} diff --git a/src/main/java/com/phenoml/api/resources/cohort/AsyncRawCohortClient.java b/src/main/java/com/phenoml/api/resources/cohort/AsyncRawCohortClient.java index c28efe3..dfee623 100644 --- a/src/main/java/com/phenoml/api/resources/cohort/AsyncRawCohortClient.java +++ b/src/main/java/com/phenoml/api/resources/cohort/AsyncRawCohortClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.cohort.errors.BadRequestError; import com.phenoml.api.resources.cohort.errors.InternalServerError; @@ -39,14 +39,14 @@ public AsyncRawCohortClient(ClientOptions clientOptions) { /** * Converts natural language text into structured FHIR search queries for patient cohort analysis */ - public CompletableFuture> analyze(CohortRequest request) { + public CompletableFuture> analyze(CohortRequest request) { return analyze(request, null); } /** * Converts natural language text into structured FHIR search queries for patient cohort analysis */ - public CompletableFuture> analyze( + public CompletableFuture> analyze( CohortRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -57,7 +57,7 @@ public CompletableFuture> analyze( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -70,13 +70,13 @@ public CompletableFuture> analyze( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CohortResponse.class), response)); return; @@ -103,20 +103,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/cohort/RawCohortClient.java b/src/main/java/com/phenoml/api/resources/cohort/RawCohortClient.java index 32bdefa..8d056a6 100644 --- a/src/main/java/com/phenoml/api/resources/cohort/RawCohortClient.java +++ b/src/main/java/com/phenoml/api/resources/cohort/RawCohortClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.cohort.errors.BadRequestError; import com.phenoml.api.resources.cohort.errors.InternalServerError; @@ -35,14 +35,14 @@ public RawCohortClient(ClientOptions clientOptions) { /** * Converts natural language text into structured FHIR search queries for patient cohort analysis */ - public PhenoMLHttpResponse analyze(CohortRequest request) { + public PhenomlClientHttpResponse analyze(CohortRequest request) { return analyze(request, null); } /** * Converts natural language text into structured FHIR search queries for patient cohort analysis */ - public PhenoMLHttpResponse analyze(CohortRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse analyze(CohortRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("cohort") @@ -52,7 +52,7 @@ public PhenoMLHttpResponse analyze(CohortRequest request, Reques body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -68,7 +68,7 @@ public PhenoMLHttpResponse analyze(CohortRequest request, Reques try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CohortResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -87,13 +87,13 @@ public PhenoMLHttpResponse analyze(CohortRequest request, Reques } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/cohort/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/cohort/errors/BadRequestError.java index deac09f..7f4376f 100644 --- a/src/main/java/com/phenoml/api/resources/cohort/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/cohort/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.cohort.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/cohort/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/cohort/errors/InternalServerError.java index ef2ad32..e909258 100644 --- a/src/main/java/com/phenoml/api/resources/cohort/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/cohort/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.cohort.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/cohort/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/cohort/errors/UnauthorizedError.java index e6f73c6..92f5247 100644 --- a/src/main/java/com/phenoml/api/resources/cohort/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/cohort/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.cohort.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/AsyncRawConstrueClient.java b/src/main/java/com/phenoml/api/resources/construe/AsyncRawConstrueClient.java index e819eee..f991ea4 100644 --- a/src/main/java/com/phenoml/api/resources/construe/AsyncRawConstrueClient.java +++ b/src/main/java/com/phenoml/api/resources/construe/AsyncRawConstrueClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.construe.errors.BadRequestError; @@ -69,7 +69,7 @@ public AsyncRawConstrueClient(ClientOptions clientOptions) { * GET /construe/codes/systems/{codesystem}?version={version} to check when status * transitions from "processing" to "ready" or "failed". */ - public CompletableFuture> uploadCodeSystem( + public CompletableFuture> uploadCodeSystem( UploadRequest request) { return uploadCodeSystem(request, null); } @@ -80,7 +80,7 @@ public CompletableFuture> * GET /construe/codes/systems/{codesystem}?version={version} to check when status * transitions from "processing" to "ready" or "failed". */ - public CompletableFuture> uploadCodeSystem( + public CompletableFuture> uploadCodeSystem( UploadRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -91,7 +91,7 @@ public CompletableFuture> body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -104,13 +104,14 @@ public CompletableFuture> if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = + new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), ConstrueUploadCodeSystemResponse.class), response)); @@ -153,20 +154,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -176,7 +177,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Converts natural language text into structured medical codes. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> extractCodes(ExtractRequest request) { + public CompletableFuture> extractCodes(ExtractRequest request) { return extractCodes(request, null); } @@ -184,7 +185,7 @@ public CompletableFuture> extractCodes(E * Converts natural language text into structured medical codes. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> extractCodes( + public CompletableFuture> extractCodes( ExtractRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -195,7 +196,7 @@ public CompletableFuture> extractCodes( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -208,13 +209,13 @@ public CompletableFuture> extractCodes( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ExtractCodesResult.class), response)); return; @@ -256,20 +257,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -278,14 +279,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Returns the terminology server's catalog of available code systems, including both built-in standard terminologies and custom uploaded systems. */ - public CompletableFuture> listAvailableCodeSystems() { + public CompletableFuture> listAvailableCodeSystems() { return listAvailableCodeSystems(null); } /** * Returns the terminology server's catalog of available code systems, including both built-in standard terminologies and custom uploaded systems. */ - public CompletableFuture> listAvailableCodeSystems( + public CompletableFuture> listAvailableCodeSystems( RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -301,13 +302,13 @@ public CompletableFuture> listAvail if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), ListCodeSystemsResponse.class), response)); @@ -330,20 +331,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -352,7 +353,8 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Returns full metadata for a single code system, including timestamps and builtin status. */ - public CompletableFuture> getCodeSystemDetail(String codesystem) { + public CompletableFuture> getCodeSystemDetail( + String codesystem) { return getCodeSystemDetail( codesystem, GetConstrueCodesSystemsCodesystemRequest.builder().build()); } @@ -360,7 +362,7 @@ public CompletableFuture> getCo /** * Returns full metadata for a single code system, including timestamps and builtin status. */ - public CompletableFuture> getCodeSystemDetail( + public CompletableFuture> getCodeSystemDetail( String codesystem, GetConstrueCodesSystemsCodesystemRequest request) { return getCodeSystemDetail(codesystem, request, null); } @@ -368,7 +370,7 @@ public CompletableFuture> getCo /** * Returns full metadata for a single code system, including timestamps and builtin status. */ - public CompletableFuture> getCodeSystemDetail( + public CompletableFuture> getCodeSystemDetail( String codesystem, GetConstrueCodesSystemsCodesystemRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -388,13 +390,13 @@ public CompletableFuture> getCo if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), GetCodeSystemDetailResponse.class), response)); @@ -427,20 +429,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -450,7 +452,8 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Deletes a custom (non-builtin) code system and all its codes. Builtin systems cannot be deleted. * Only available on dedicated instances. Large systems may take up to a minute to delete. */ - public CompletableFuture> deleteCustomCodeSystem(String codesystem) { + public CompletableFuture> deleteCustomCodeSystem( + String codesystem) { return deleteCustomCodeSystem( codesystem, DeleteConstrueCodesSystemsCodesystemRequest.builder().build()); @@ -460,7 +463,7 @@ public CompletableFuture> deleteCu * Deletes a custom (non-builtin) code system and all its codes. Builtin systems cannot be deleted. * Only available on dedicated instances. Large systems may take up to a minute to delete. */ - public CompletableFuture> deleteCustomCodeSystem( + public CompletableFuture> deleteCustomCodeSystem( String codesystem, DeleteConstrueCodesSystemsCodesystemRequest request) { return deleteCustomCodeSystem(codesystem, request, null); } @@ -469,7 +472,7 @@ public CompletableFuture> deleteCu * Deletes a custom (non-builtin) code system and all its codes. Builtin systems cannot be deleted. * Only available on dedicated instances. Large systems may take up to a minute to delete. */ - public CompletableFuture> deleteCustomCodeSystem( + public CompletableFuture> deleteCustomCodeSystem( String codesystem, DeleteConstrueCodesSystemsCodesystemRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -489,13 +492,13 @@ public CompletableFuture> deleteCu if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), DeleteCodeSystemResponse.class), response)); @@ -533,20 +536,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -557,7 +560,8 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * The exported file can be re-uploaded directly via POST /construe/upload with format "json". * Only available on dedicated instances. Builtin systems cannot be exported. */ - public CompletableFuture> exportCustomCodeSystem(String codesystem) { + public CompletableFuture> exportCustomCodeSystem( + String codesystem) { return exportCustomCodeSystem( codesystem, GetConstrueCodesSystemsCodesystemExportRequest.builder().build()); @@ -568,7 +572,7 @@ public CompletableFuture> exportCu * The exported file can be re-uploaded directly via POST /construe/upload with format "json". * Only available on dedicated instances. Builtin systems cannot be exported. */ - public CompletableFuture> exportCustomCodeSystem( + public CompletableFuture> exportCustomCodeSystem( String codesystem, GetConstrueCodesSystemsCodesystemExportRequest request) { return exportCustomCodeSystem(codesystem, request, null); } @@ -578,7 +582,7 @@ public CompletableFuture> exportCu * The exported file can be re-uploaded directly via POST /construe/upload with format "json". * Only available on dedicated instances. Builtin systems cannot be exported. */ - public CompletableFuture> exportCustomCodeSystem( + public CompletableFuture> exportCustomCodeSystem( String codesystem, GetConstrueCodesSystemsCodesystemExportRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -599,13 +603,13 @@ public CompletableFuture> exportCu if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), ExportCodeSystemResponse.class), response)); @@ -653,20 +657,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -676,7 +680,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Returns a paginated list of all codes in the specified code system from the terminology server. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> listCodesInACodeSystem(String codesystem) { + public CompletableFuture> listCodesInACodeSystem(String codesystem) { return listCodesInACodeSystem( codesystem, GetConstrueCodesCodesystemRequest.builder().build()); } @@ -685,7 +689,7 @@ public CompletableFuture> listCodesInACod * Returns a paginated list of all codes in the specified code system from the terminology server. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> listCodesInACodeSystem( + public CompletableFuture> listCodesInACodeSystem( String codesystem, GetConstrueCodesCodesystemRequest request) { return listCodesInACodeSystem(codesystem, request, null); } @@ -694,7 +698,7 @@ public CompletableFuture> listCodesInACod * Returns a paginated list of all codes in the specified code system from the terminology server. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> listCodesInACodeSystem( + public CompletableFuture> listCodesInACodeSystem( String codesystem, GetConstrueCodesCodesystemRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -722,13 +726,13 @@ public CompletableFuture> listCodesInACod if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCodesResponse.class), response)); return; @@ -760,20 +764,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -783,7 +787,8 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Looks up a specific code in the terminology server and returns its details. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> getASpecificCode(String codesystem, String codeId) { + public CompletableFuture> getASpecificCode( + String codesystem, String codeId) { return getASpecificCode( codesystem, codeId, @@ -794,7 +799,7 @@ public CompletableFuture> getASpecificCode( * Looks up a specific code in the terminology server and returns its details. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> getASpecificCode( + public CompletableFuture> getASpecificCode( String codesystem, String codeId, GetConstrueCodesCodesystemCodeIdRequest request) { return getASpecificCode(codesystem, codeId, request, null); } @@ -803,7 +808,7 @@ public CompletableFuture> getASpecificCode( * Looks up a specific code in the terminology server and returns its details. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> getASpecificCode( + public CompletableFuture> getASpecificCode( String codesystem, String codeId, GetConstrueCodesCodesystemCodeIdRequest request, @@ -827,13 +832,13 @@ public CompletableFuture> getASpecificCode( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCodeResponse.class), response)); return; @@ -865,20 +870,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -901,7 +906,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *

See also: /search/text for faster keyword-based lookup with typo tolerance.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> semanticSearchEmbeddingBased( + public CompletableFuture> semanticSearchEmbeddingBased( String codesystem, GetConstrueCodesCodesystemSearchSemanticRequest request) { return semanticSearchEmbeddingBased(codesystem, request, null); } @@ -923,7 +928,7 @@ public CompletableFuture> semanticSe *

See also: /search/text for faster keyword-based lookup with typo tolerance.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> semanticSearchEmbeddingBased( + public CompletableFuture> semanticSearchEmbeddingBased( String codesystem, GetConstrueCodesCodesystemSearchSemanticRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -949,13 +954,13 @@ public CompletableFuture> semanticSe if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), SemanticSearchResponse.class), response)); @@ -988,20 +993,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -1011,7 +1016,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Submits user feedback on results from the Construe extraction endpoint. * Feedback includes the full extraction result received and the result the user expected. */ - public CompletableFuture> submitFeedbackOnExtractionResults( + public CompletableFuture> submitFeedbackOnExtractionResults( FeedbackRequest request) { return submitFeedbackOnExtractionResults(request, null); } @@ -1020,7 +1025,7 @@ public CompletableFuture> submitFeedbackOn * Submits user feedback on results from the Construe extraction endpoint. * Feedback includes the full extraction result received and the result the user expected. */ - public CompletableFuture> submitFeedbackOnExtractionResults( + public CompletableFuture> submitFeedbackOnExtractionResults( FeedbackRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -1031,7 +1036,7 @@ public CompletableFuture> submitFeedbackOn body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -1044,13 +1049,13 @@ public CompletableFuture> submitFeedbackOn if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FeedbackResponse.class), response)); return; @@ -1082,20 +1087,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -1124,7 +1129,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *

See also: /search/semantic for finding conceptually similar codes.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> terminologyServerTextSearch( + public CompletableFuture> terminologyServerTextSearch( String codesystem, GetConstrueCodesCodesystemSearchTextRequest request) { return terminologyServerTextSearch(codesystem, request, null); } @@ -1152,7 +1157,7 @@ public CompletableFuture> terminologySer *

See also: /search/semantic for finding conceptually similar codes.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public CompletableFuture> terminologyServerTextSearch( + public CompletableFuture> terminologyServerTextSearch( String codesystem, GetConstrueCodesCodesystemSearchTextRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -1178,13 +1183,13 @@ public CompletableFuture> terminologySer if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), TextSearchResponse.class), response)); return; @@ -1221,20 +1226,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/construe/RawConstrueClient.java b/src/main/java/com/phenoml/api/resources/construe/RawConstrueClient.java index df5667e..6364176 100644 --- a/src/main/java/com/phenoml/api/resources/construe/RawConstrueClient.java +++ b/src/main/java/com/phenoml/api/resources/construe/RawConstrueClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.construe.errors.BadRequestError; @@ -65,7 +65,7 @@ public RawConstrueClient(ClientOptions clientOptions) { * GET /construe/codes/systems/{codesystem}?version={version} to check when status * transitions from "processing" to "ready" or "failed". */ - public PhenoMLHttpResponse uploadCodeSystem(UploadRequest request) { + public PhenomlClientHttpResponse uploadCodeSystem(UploadRequest request) { return uploadCodeSystem(request, null); } @@ -75,7 +75,7 @@ public PhenoMLHttpResponse uploadCodeSystem(Up * GET /construe/codes/systems/{codesystem}?version={version} to check when status * transitions from "processing" to "ready" or "failed". */ - public PhenoMLHttpResponse uploadCodeSystem( + public PhenomlClientHttpResponse uploadCodeSystem( UploadRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -86,7 +86,7 @@ public PhenoMLHttpResponse uploadCodeSystem( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -102,7 +102,7 @@ public PhenoMLHttpResponse uploadCodeSystem( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), ConstrueUploadCodeSystemResponse.class), response); @@ -132,13 +132,13 @@ public PhenoMLHttpResponse uploadCodeSystem( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -146,7 +146,7 @@ public PhenoMLHttpResponse uploadCodeSystem( * Converts natural language text into structured medical codes. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse extractCodes(ExtractRequest request) { + public PhenomlClientHttpResponse extractCodes(ExtractRequest request) { return extractCodes(request, null); } @@ -154,7 +154,8 @@ public PhenoMLHttpResponse extractCodes(ExtractRequest reque * Converts natural language text into structured medical codes. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse extractCodes(ExtractRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse extractCodes( + ExtractRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("construe/extract") @@ -164,7 +165,7 @@ public PhenoMLHttpResponse extractCodes(ExtractRequest reque body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -180,7 +181,7 @@ public PhenoMLHttpResponse extractCodes(ExtractRequest reque try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ExtractCodesResult.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -208,27 +209,27 @@ public PhenoMLHttpResponse extractCodes(ExtractRequest reque } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Returns the terminology server's catalog of available code systems, including both built-in standard terminologies and custom uploaded systems. */ - public PhenoMLHttpResponse listAvailableCodeSystems() { + public PhenomlClientHttpResponse listAvailableCodeSystems() { return listAvailableCodeSystems(null); } /** * Returns the terminology server's catalog of available code systems, including both built-in standard terminologies and custom uploaded systems. */ - public PhenoMLHttpResponse listAvailableCodeSystems(RequestOptions requestOptions) { + public PhenomlClientHttpResponse listAvailableCodeSystems(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("construe/codes/systems") @@ -246,7 +247,7 @@ public PhenoMLHttpResponse listAvailableCodeSystems(Req try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCodeSystemsResponse.class), response); } @@ -263,20 +264,20 @@ public PhenoMLHttpResponse listAvailableCodeSystems(Req } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Returns full metadata for a single code system, including timestamps and builtin status. */ - public PhenoMLHttpResponse getCodeSystemDetail(String codesystem) { + public PhenomlClientHttpResponse getCodeSystemDetail(String codesystem) { return getCodeSystemDetail( codesystem, GetConstrueCodesSystemsCodesystemRequest.builder().build()); } @@ -284,7 +285,7 @@ public PhenoMLHttpResponse getCodeSystemDetail(Stri /** * Returns full metadata for a single code system, including timestamps and builtin status. */ - public PhenoMLHttpResponse getCodeSystemDetail( + public PhenomlClientHttpResponse getCodeSystemDetail( String codesystem, GetConstrueCodesSystemsCodesystemRequest request) { return getCodeSystemDetail(codesystem, request, null); } @@ -292,7 +293,7 @@ public PhenoMLHttpResponse getCodeSystemDetail( /** * Returns full metadata for a single code system, including timestamps and builtin status. */ - public PhenoMLHttpResponse getCodeSystemDetail( + public PhenomlClientHttpResponse getCodeSystemDetail( String codesystem, GetConstrueCodesSystemsCodesystemRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -315,7 +316,7 @@ public PhenoMLHttpResponse getCodeSystemDetail( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCodeSystemDetailResponse.class), response); } @@ -338,13 +339,13 @@ public PhenoMLHttpResponse getCodeSystemDetail( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -352,7 +353,7 @@ public PhenoMLHttpResponse getCodeSystemDetail( * Deletes a custom (non-builtin) code system and all its codes. Builtin systems cannot be deleted. * Only available on dedicated instances. Large systems may take up to a minute to delete. */ - public PhenoMLHttpResponse deleteCustomCodeSystem(String codesystem) { + public PhenomlClientHttpResponse deleteCustomCodeSystem(String codesystem) { return deleteCustomCodeSystem( codesystem, DeleteConstrueCodesSystemsCodesystemRequest.builder().build()); @@ -362,7 +363,7 @@ public PhenoMLHttpResponse deleteCustomCodeSystem(Stri * Deletes a custom (non-builtin) code system and all its codes. Builtin systems cannot be deleted. * Only available on dedicated instances. Large systems may take up to a minute to delete. */ - public PhenoMLHttpResponse deleteCustomCodeSystem( + public PhenomlClientHttpResponse deleteCustomCodeSystem( String codesystem, DeleteConstrueCodesSystemsCodesystemRequest request) { return deleteCustomCodeSystem(codesystem, request, null); } @@ -371,7 +372,7 @@ public PhenoMLHttpResponse deleteCustomCodeSystem( * Deletes a custom (non-builtin) code system and all its codes. Builtin systems cannot be deleted. * Only available on dedicated instances. Large systems may take up to a minute to delete. */ - public PhenoMLHttpResponse deleteCustomCodeSystem( + public PhenomlClientHttpResponse deleteCustomCodeSystem( String codesystem, DeleteConstrueCodesSystemsCodesystemRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -394,7 +395,7 @@ public PhenoMLHttpResponse deleteCustomCodeSystem( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteCodeSystemResponse.class), response); } @@ -420,13 +421,13 @@ public PhenoMLHttpResponse deleteCustomCodeSystem( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -435,7 +436,7 @@ public PhenoMLHttpResponse deleteCustomCodeSystem( * The exported file can be re-uploaded directly via POST /construe/upload with format "json". * Only available on dedicated instances. Builtin systems cannot be exported. */ - public PhenoMLHttpResponse exportCustomCodeSystem(String codesystem) { + public PhenomlClientHttpResponse exportCustomCodeSystem(String codesystem) { return exportCustomCodeSystem( codesystem, GetConstrueCodesSystemsCodesystemExportRequest.builder().build()); @@ -446,7 +447,7 @@ public PhenoMLHttpResponse exportCustomCodeSystem(Stri * The exported file can be re-uploaded directly via POST /construe/upload with format "json". * Only available on dedicated instances. Builtin systems cannot be exported. */ - public PhenoMLHttpResponse exportCustomCodeSystem( + public PhenomlClientHttpResponse exportCustomCodeSystem( String codesystem, GetConstrueCodesSystemsCodesystemExportRequest request) { return exportCustomCodeSystem(codesystem, request, null); } @@ -456,7 +457,7 @@ public PhenoMLHttpResponse exportCustomCodeSystem( * The exported file can be re-uploaded directly via POST /construe/upload with format "json". * Only available on dedicated instances. Builtin systems cannot be exported. */ - public PhenoMLHttpResponse exportCustomCodeSystem( + public PhenomlClientHttpResponse exportCustomCodeSystem( String codesystem, GetConstrueCodesSystemsCodesystemExportRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -480,7 +481,7 @@ public PhenoMLHttpResponse exportCustomCodeSystem( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ExportCodeSystemResponse.class), response); } @@ -512,13 +513,13 @@ public PhenoMLHttpResponse exportCustomCodeSystem( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -526,7 +527,7 @@ public PhenoMLHttpResponse exportCustomCodeSystem( * Returns a paginated list of all codes in the specified code system from the terminology server. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse listCodesInACodeSystem(String codesystem) { + public PhenomlClientHttpResponse listCodesInACodeSystem(String codesystem) { return listCodesInACodeSystem( codesystem, GetConstrueCodesCodesystemRequest.builder().build()); } @@ -535,7 +536,7 @@ public PhenoMLHttpResponse listCodesInACodeSystem(String code * Returns a paginated list of all codes in the specified code system from the terminology server. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse listCodesInACodeSystem( + public PhenomlClientHttpResponse listCodesInACodeSystem( String codesystem, GetConstrueCodesCodesystemRequest request) { return listCodesInACodeSystem(codesystem, request, null); } @@ -544,7 +545,7 @@ public PhenoMLHttpResponse listCodesInACodeSystem( * Returns a paginated list of all codes in the specified code system from the terminology server. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse listCodesInACodeSystem( + public PhenomlClientHttpResponse listCodesInACodeSystem( String codesystem, GetConstrueCodesCodesystemRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -575,7 +576,7 @@ public PhenoMLHttpResponse listCodesInACodeSystem( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListCodesResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -597,13 +598,13 @@ public PhenoMLHttpResponse listCodesInACodeSystem( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -611,7 +612,7 @@ public PhenoMLHttpResponse listCodesInACodeSystem( * Looks up a specific code in the terminology server and returns its details. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse getASpecificCode(String codesystem, String codeId) { + public PhenomlClientHttpResponse getASpecificCode(String codesystem, String codeId) { return getASpecificCode( codesystem, codeId, @@ -622,7 +623,7 @@ public PhenoMLHttpResponse getASpecificCode(String codesystem, * Looks up a specific code in the terminology server and returns its details. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse getASpecificCode( + public PhenomlClientHttpResponse getASpecificCode( String codesystem, String codeId, GetConstrueCodesCodesystemCodeIdRequest request) { return getASpecificCode(codesystem, codeId, request, null); } @@ -631,7 +632,7 @@ public PhenoMLHttpResponse getASpecificCode( * Looks up a specific code in the terminology server and returns its details. *

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse getASpecificCode( + public PhenomlClientHttpResponse getASpecificCode( String codesystem, String codeId, GetConstrueCodesCodesystemCodeIdRequest request, @@ -658,7 +659,7 @@ public PhenoMLHttpResponse getASpecificCode( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetCodeResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -680,13 +681,13 @@ public PhenoMLHttpResponse getASpecificCode( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -707,7 +708,7 @@ public PhenoMLHttpResponse getASpecificCode( *

See also: /search/text for faster keyword-based lookup with typo tolerance.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse semanticSearchEmbeddingBased( + public PhenomlClientHttpResponse semanticSearchEmbeddingBased( String codesystem, GetConstrueCodesCodesystemSearchSemanticRequest request) { return semanticSearchEmbeddingBased(codesystem, request, null); } @@ -729,7 +730,7 @@ public PhenoMLHttpResponse semanticSearchEmbeddingBased( *

See also: /search/text for faster keyword-based lookup with typo tolerance.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse semanticSearchEmbeddingBased( + public PhenomlClientHttpResponse semanticSearchEmbeddingBased( String codesystem, GetConstrueCodesCodesystemSearchSemanticRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -758,7 +759,7 @@ public PhenoMLHttpResponse semanticSearchEmbeddingBased( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SemanticSearchResponse.class), response); } @@ -781,13 +782,13 @@ public PhenoMLHttpResponse semanticSearchEmbeddingBased( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -795,7 +796,7 @@ public PhenoMLHttpResponse semanticSearchEmbeddingBased( * Submits user feedback on results from the Construe extraction endpoint. * Feedback includes the full extraction result received and the result the user expected. */ - public PhenoMLHttpResponse submitFeedbackOnExtractionResults(FeedbackRequest request) { + public PhenomlClientHttpResponse submitFeedbackOnExtractionResults(FeedbackRequest request) { return submitFeedbackOnExtractionResults(request, null); } @@ -803,7 +804,7 @@ public PhenoMLHttpResponse submitFeedbackOnExtractionResults(F * Submits user feedback on results from the Construe extraction endpoint. * Feedback includes the full extraction result received and the result the user expected. */ - public PhenoMLHttpResponse submitFeedbackOnExtractionResults( + public PhenomlClientHttpResponse submitFeedbackOnExtractionResults( FeedbackRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -814,7 +815,7 @@ public PhenoMLHttpResponse submitFeedbackOnExtractionResults( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -830,7 +831,7 @@ public PhenoMLHttpResponse submitFeedbackOnExtractionResults( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FeedbackResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -852,13 +853,13 @@ public PhenoMLHttpResponse submitFeedbackOnExtractionResults( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -885,7 +886,7 @@ public PhenoMLHttpResponse submitFeedbackOnExtractionResults( *

See also: /search/semantic for finding conceptually similar codes.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse terminologyServerTextSearch( + public PhenomlClientHttpResponse terminologyServerTextSearch( String codesystem, GetConstrueCodesCodesystemSearchTextRequest request) { return terminologyServerTextSearch(codesystem, request, null); } @@ -913,7 +914,7 @@ public PhenoMLHttpResponse terminologyServerTextSearch( *

See also: /search/semantic for finding conceptually similar codes.

*

Usage of CPT is subject to AMA requirements: see PhenoML Terms of Service.

*/ - public PhenoMLHttpResponse terminologyServerTextSearch( + public PhenomlClientHttpResponse terminologyServerTextSearch( String codesystem, GetConstrueCodesCodesystemSearchTextRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -942,7 +943,7 @@ public PhenoMLHttpResponse terminologyServerTextSearch( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), TextSearchResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -967,13 +968,13 @@ public PhenoMLHttpResponse terminologyServerTextSearch( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/construe/errors/BadRequestError.java index 8a29a12..b530d71 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/ConflictError.java b/src/main/java/com/phenoml/api/resources/construe/errors/ConflictError.java index 5f5f75a..73be2ae 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/ConflictError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/ConflictError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ConflictError extends PhenoMLApiException { +public final class ConflictError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/FailedDependencyError.java b/src/main/java/com/phenoml/api/resources/construe/errors/FailedDependencyError.java index 92956eb..caa2220 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/FailedDependencyError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/FailedDependencyError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class FailedDependencyError extends PhenoMLApiException { +public final class FailedDependencyError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/construe/errors/ForbiddenError.java index 5eafc17..c9809cf 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/GatewayTimeoutError.java b/src/main/java/com/phenoml/api/resources/construe/errors/GatewayTimeoutError.java index c18558c..7a24d2c 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/GatewayTimeoutError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/GatewayTimeoutError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class GatewayTimeoutError extends PhenoMLApiException { +public final class GatewayTimeoutError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/construe/errors/InternalServerError.java index 9f69a1b..3d76a49 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/NotFoundError.java b/src/main/java/com/phenoml/api/resources/construe/errors/NotFoundError.java index d74a01e..4566c51 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/NotFoundError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/NotFoundError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotFoundError extends PhenoMLApiException { +public final class NotFoundError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/NotImplementedError.java b/src/main/java/com/phenoml/api/resources/construe/errors/NotImplementedError.java index a4d3e37..60bbc3a 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/NotImplementedError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/NotImplementedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotImplementedError extends PhenoMLApiException { +public final class NotImplementedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/ServiceUnavailableError.java b/src/main/java/com/phenoml/api/resources/construe/errors/ServiceUnavailableError.java index fd7ff1e..acdea6d 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/ServiceUnavailableError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/ServiceUnavailableError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ServiceUnavailableError extends PhenoMLApiException { +public final class ServiceUnavailableError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/construe/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/construe/errors/UnauthorizedError.java index 0ac0ee0..7ff3c28 100644 --- a/src/main/java/com/phenoml/api/resources/construe/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/construe/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.construe.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhir/AsyncRawFhirClient.java b/src/main/java/com/phenoml/api/resources/fhir/AsyncRawFhirClient.java index da3fe62..bd71ab2 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/AsyncRawFhirClient.java +++ b/src/main/java/com/phenoml/api/resources/fhir/AsyncRawFhirClient.java @@ -7,9 +7,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.fhir.errors.BadGatewayError; @@ -53,7 +53,8 @@ public AsyncRawFhirClient(ClientOptions clientOptions) { * Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> search(String fhirProviderId, String fhirPath) { + public CompletableFuture> search( + String fhirProviderId, String fhirPath) { return search(fhirProviderId, fhirPath, FhirSearchRequest.builder().build()); } @@ -61,7 +62,7 @@ public CompletableFuture> search(String * Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> search( + public CompletableFuture> search( String fhirProviderId, String fhirPath, FhirSearchRequest request) { return search(fhirProviderId, fhirPath, request, null); } @@ -70,7 +71,7 @@ public CompletableFuture> search( * Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> search( + public CompletableFuture> search( String fhirProviderId, String fhirPath, FhirSearchRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -100,13 +101,13 @@ public CompletableFuture> search( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirSearchResponse.class), response)); return; @@ -143,20 +144,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -166,7 +167,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Creates a new FHIR resource on the specified provider. The request body should contain a valid FHIR resource in JSON format. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> create( + public CompletableFuture> create( String fhirProviderId, String fhirPath, FhirCreateRequest request) { return create(fhirProviderId, fhirPath, request, null); } @@ -175,7 +176,7 @@ public CompletableFuture> create( * Creates a new FHIR resource on the specified provider. The request body should contain a valid FHIR resource in JSON format. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> create( + public CompletableFuture> create( String fhirProviderId, String fhirPath, FhirCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -211,13 +212,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirResource.class), response)); return; @@ -249,20 +250,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -272,7 +273,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Creates or updates a FHIR resource on the specified provider. If the resource exists, it will be updated; otherwise, it will be created. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> upsert( + public CompletableFuture> upsert( String fhirProviderId, String fhirPath, FhirUpsertRequest request) { return upsert(fhirProviderId, fhirPath, request, null); } @@ -281,7 +282,7 @@ public CompletableFuture> upsert( * Creates or updates a FHIR resource on the specified provider. If the resource exists, it will be updated; otherwise, it will be created. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> upsert( + public CompletableFuture> upsert( String fhirProviderId, String fhirPath, FhirUpsertRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -317,13 +318,13 @@ public CompletableFuture> upsert( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirResource.class), response)); return; @@ -355,20 +356,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -378,7 +379,8 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Deletes a FHIR resource from the specified provider. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture>> delete(String fhirProviderId, String fhirPath) { + public CompletableFuture>> delete( + String fhirProviderId, String fhirPath) { return delete(fhirProviderId, fhirPath, FhirDeleteRequest.builder().build()); } @@ -386,7 +388,7 @@ public CompletableFuture>> delete(String * Deletes a FHIR resource from the specified provider. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture>> delete( + public CompletableFuture>> delete( String fhirProviderId, String fhirPath, FhirDeleteRequest request) { return delete(fhirProviderId, fhirPath, request, null); } @@ -395,7 +397,7 @@ public CompletableFuture>> delete( * Deletes a FHIR resource from the specified provider. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture>> delete( + public CompletableFuture>> delete( String fhirProviderId, String fhirPath, FhirDeleteRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -422,13 +424,13 @@ public CompletableFuture>> delete( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture>> future = new CompletableFuture<>(); + CompletableFuture>> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), new TypeReference>() {}), response)); @@ -466,20 +468,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -495,7 +497,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> patch( + public CompletableFuture> patch( String fhirProviderId, String fhirPath, FhirPatchRequest request) { return patch(fhirProviderId, fhirPath, request, null); } @@ -510,7 +512,7 @@ public CompletableFuture> patch( * *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> patch( + public CompletableFuture> patch( String fhirProviderId, String fhirPath, FhirPatchRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -546,13 +548,13 @@ public CompletableFuture> patch( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirResource.class), response)); return; @@ -589,20 +591,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -613,7 +615,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *

The request body should contain a valid FHIR Bundle resource with transaction or batch type.

*

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> executeBundle( + public CompletableFuture> executeBundle( String fhirProviderId, FhirExecuteBundleRequest request) { return executeBundle(fhirProviderId, request, null); } @@ -623,7 +625,7 @@ public CompletableFuture> executeBundle( *

The request body should contain a valid FHIR Bundle resource with transaction or batch type.

*

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public CompletableFuture> executeBundle( + public CompletableFuture> executeBundle( String fhirProviderId, FhirExecuteBundleRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -658,13 +660,13 @@ public CompletableFuture> executeBundle( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirBundle.class), response)); return; @@ -696,20 +698,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/fhir/RawFhirClient.java b/src/main/java/com/phenoml/api/resources/fhir/RawFhirClient.java index 312e107..fec50f9 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/RawFhirClient.java +++ b/src/main/java/com/phenoml/api/resources/fhir/RawFhirClient.java @@ -7,9 +7,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.fhir.errors.BadGatewayError; @@ -49,7 +49,7 @@ public RawFhirClient(ClientOptions clientOptions) { * Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse search(String fhirProviderId, String fhirPath) { + public PhenomlClientHttpResponse search(String fhirProviderId, String fhirPath) { return search(fhirProviderId, fhirPath, FhirSearchRequest.builder().build()); } @@ -57,7 +57,7 @@ public PhenoMLHttpResponse search(String fhirProviderId, Str * Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse search( + public PhenomlClientHttpResponse search( String fhirProviderId, String fhirPath, FhirSearchRequest request) { return search(fhirProviderId, fhirPath, request, null); } @@ -66,7 +66,7 @@ public PhenoMLHttpResponse search( * Retrieves FHIR resources from the specified provider. Supports both individual resource retrieval and search operations based on the FHIR path and query parameters. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse search( + public PhenomlClientHttpResponse search( String fhirProviderId, String fhirPath, FhirSearchRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -99,7 +99,7 @@ public PhenoMLHttpResponse search( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirSearchResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -124,13 +124,13 @@ public PhenoMLHttpResponse search( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -138,7 +138,8 @@ public PhenoMLHttpResponse search( * Creates a new FHIR resource on the specified provider. The request body should contain a valid FHIR resource in JSON format. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse create(String fhirProviderId, String fhirPath, FhirCreateRequest request) { + public PhenomlClientHttpResponse create( + String fhirProviderId, String fhirPath, FhirCreateRequest request) { return create(fhirProviderId, fhirPath, request, null); } @@ -146,7 +147,7 @@ public PhenoMLHttpResponse create(String fhirProviderId, String fh * Creates a new FHIR resource on the specified provider. The request body should contain a valid FHIR resource in JSON format. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse create( + public PhenomlClientHttpResponse create( String fhirProviderId, String fhirPath, FhirCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -185,7 +186,7 @@ public PhenoMLHttpResponse create( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirResource.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -207,13 +208,13 @@ public PhenoMLHttpResponse create( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -221,7 +222,8 @@ public PhenoMLHttpResponse create( * Creates or updates a FHIR resource on the specified provider. If the resource exists, it will be updated; otherwise, it will be created. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse upsert(String fhirProviderId, String fhirPath, FhirUpsertRequest request) { + public PhenomlClientHttpResponse upsert( + String fhirProviderId, String fhirPath, FhirUpsertRequest request) { return upsert(fhirProviderId, fhirPath, request, null); } @@ -229,7 +231,7 @@ public PhenoMLHttpResponse upsert(String fhirProviderId, String fh * Creates or updates a FHIR resource on the specified provider. If the resource exists, it will be updated; otherwise, it will be created. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse upsert( + public PhenomlClientHttpResponse upsert( String fhirProviderId, String fhirPath, FhirUpsertRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -268,7 +270,7 @@ public PhenoMLHttpResponse upsert( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirResource.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -290,13 +292,13 @@ public PhenoMLHttpResponse upsert( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -304,7 +306,7 @@ public PhenoMLHttpResponse upsert( * Deletes a FHIR resource from the specified provider. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse> delete(String fhirProviderId, String fhirPath) { + public PhenomlClientHttpResponse> delete(String fhirProviderId, String fhirPath) { return delete(fhirProviderId, fhirPath, FhirDeleteRequest.builder().build()); } @@ -312,7 +314,7 @@ public PhenoMLHttpResponse> delete(String fhirProviderId, St * Deletes a FHIR resource from the specified provider. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse> delete( + public PhenomlClientHttpResponse> delete( String fhirProviderId, String fhirPath, FhirDeleteRequest request) { return delete(fhirProviderId, fhirPath, request, null); } @@ -321,7 +323,7 @@ public PhenoMLHttpResponse> delete( * Deletes a FHIR resource from the specified provider. *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse> delete( + public PhenomlClientHttpResponse> delete( String fhirProviderId, String fhirPath, FhirDeleteRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -351,7 +353,7 @@ public PhenoMLHttpResponse> delete( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), new TypeReference>() {}), response); @@ -378,13 +380,13 @@ public PhenoMLHttpResponse> delete( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -398,7 +400,8 @@ public PhenoMLHttpResponse> delete( * *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse patch(String fhirProviderId, String fhirPath, FhirPatchRequest request) { + public PhenomlClientHttpResponse patch( + String fhirProviderId, String fhirPath, FhirPatchRequest request) { return patch(fhirProviderId, fhirPath, request, null); } @@ -412,7 +415,7 @@ public PhenoMLHttpResponse patch(String fhirProviderId, String fhi * *

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse patch( + public PhenomlClientHttpResponse patch( String fhirProviderId, String fhirPath, FhirPatchRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -451,7 +454,7 @@ public PhenoMLHttpResponse patch( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirResource.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -476,13 +479,13 @@ public PhenoMLHttpResponse patch( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -491,7 +494,8 @@ public PhenoMLHttpResponse patch( *

The request body should contain a valid FHIR Bundle resource with transaction or batch type.

*

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse executeBundle(String fhirProviderId, FhirExecuteBundleRequest request) { + public PhenomlClientHttpResponse executeBundle( + String fhirProviderId, FhirExecuteBundleRequest request) { return executeBundle(fhirProviderId, request, null); } @@ -500,7 +504,7 @@ public PhenoMLHttpResponse executeBundle(String fhirProviderId, Fhir *

The request body should contain a valid FHIR Bundle resource with transaction or batch type.

*

The request is proxied to the configured FHIR server with appropriate authentication headers.

*/ - public PhenoMLHttpResponse executeBundle( + public PhenomlClientHttpResponse executeBundle( String fhirProviderId, FhirExecuteBundleRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -538,7 +542,7 @@ public PhenoMLHttpResponse executeBundle( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirBundle.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -560,13 +564,13 @@ public PhenoMLHttpResponse executeBundle( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/fhir/errors/BadGatewayError.java b/src/main/java/com/phenoml/api/resources/fhir/errors/BadGatewayError.java index ccaa439..5644331 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/errors/BadGatewayError.java +++ b/src/main/java/com/phenoml/api/resources/fhir/errors/BadGatewayError.java @@ -3,11 +3,11 @@ */ package com.phenoml.api.resources.fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import com.phenoml.api.resources.fhir.types.ErrorResponse; import okhttp3.Response; -public final class BadGatewayError extends PhenoMLApiException { +public final class BadGatewayError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhir/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/fhir/errors/BadRequestError.java index 4fb60b0..136d8b0 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/fhir/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhir/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/fhir/errors/InternalServerError.java index cbe3fc3..059565a 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/fhir/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhir/errors/NotFoundError.java b/src/main/java/com/phenoml/api/resources/fhir/errors/NotFoundError.java index 7181435..84ec745 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/errors/NotFoundError.java +++ b/src/main/java/com/phenoml/api/resources/fhir/errors/NotFoundError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotFoundError extends PhenoMLApiException { +public final class NotFoundError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhir/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/fhir/errors/UnauthorizedError.java index 76cb548..29fc093 100644 --- a/src/main/java/com/phenoml/api/resources/fhir/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/fhir/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/AsyncRawFhirProviderClient.java b/src/main/java/com/phenoml/api/resources/fhirprovider/AsyncRawFhirProviderClient.java index be7fa0d..3ce174e 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/AsyncRawFhirProviderClient.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/AsyncRawFhirProviderClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.fhirprovider.errors.BadRequestError; import com.phenoml.api.resources.fhirprovider.errors.ForbiddenError; @@ -48,7 +48,8 @@ public AsyncRawFhirProviderClient(ClientOptions clientOptions) { * Creates a new FHIR provider configuration with authentication credentials. *

Note: The "sandbox" provider type cannot be created via this API - it is managed internally.

*/ - public CompletableFuture> create(FhirProviderCreateRequest request) { + public CompletableFuture> create( + FhirProviderCreateRequest request) { return create(request, null); } @@ -56,7 +57,7 @@ public CompletableFuture> create(FhirP * Creates a new FHIR provider configuration with authentication credentials. *

Note: The "sandbox" provider type cannot be created via this API - it is managed internally.

*/ - public CompletableFuture> create( + public CompletableFuture> create( FhirProviderCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -67,7 +68,7 @@ public CompletableFuture> create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -80,13 +81,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response)); return; @@ -118,20 +119,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -142,7 +143,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *

On shared instances, only sandbox providers are returned. * Sandbox providers return FhirProviderSandboxInfo.

*/ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(null); } @@ -151,7 +152,7 @@ public CompletableFuture> list() { *

On shared instances, only sandbox providers are returned. * Sandbox providers return FhirProviderSandboxInfo.

*/ - public CompletableFuture> list(RequestOptions requestOptions) { + public CompletableFuture> list(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("fhir-provider/list") @@ -166,13 +167,13 @@ public CompletableFuture> list(Req if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), FhirProviderListResponse.class), response)); @@ -195,20 +196,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -219,7 +220,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *

Sandbox providers return FhirProviderSandboxInfo. * On shared instances, only sandbox providers can be accessed.

*/ - public CompletableFuture> get(String fhirProviderId) { + public CompletableFuture> get(String fhirProviderId) { return get(fhirProviderId, null); } @@ -228,7 +229,7 @@ public CompletableFuture> get(String f *

Sandbox providers return FhirProviderSandboxInfo. * On shared instances, only sandbox providers can be accessed.

*/ - public CompletableFuture> get( + public CompletableFuture> get( String fhirProviderId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -245,13 +246,13 @@ public CompletableFuture> get( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response)); return; @@ -278,20 +279,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -301,7 +302,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Deletes a FHIR provider. *

Note: Sandbox providers cannot be deleted.

*/ - public CompletableFuture> delete(String fhirProviderId) { + public CompletableFuture> delete(String fhirProviderId) { return delete(fhirProviderId, null); } @@ -309,7 +310,7 @@ public CompletableFuture> delete * Deletes a FHIR provider. *

Note: Sandbox providers cannot be deleted.

*/ - public CompletableFuture> delete( + public CompletableFuture> delete( String fhirProviderId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -326,13 +327,13 @@ public CompletableFuture> delete if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), FhirProviderDeleteResponse.class), response)); @@ -365,20 +366,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -389,7 +390,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * This enables key rotation and multiple auth configurations per provider. *

Note: Sandbox providers cannot be modified.

*/ - public CompletableFuture> addAuthConfig( + public CompletableFuture> addAuthConfig( String fhirProviderId, FhirProviderAddAuthConfigRequest request) { return addAuthConfig(fhirProviderId, request, null); } @@ -399,7 +400,7 @@ public CompletableFuture> addAuthConfi * This enables key rotation and multiple auth configurations per provider. *

Note: Sandbox providers cannot be modified.

*/ - public CompletableFuture> addAuthConfig( + public CompletableFuture> addAuthConfig( String fhirProviderId, FhirProviderAddAuthConfigRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -412,7 +413,7 @@ public CompletableFuture> addAuthConfi body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -425,13 +426,13 @@ public CompletableFuture> addAuthConfi if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response)); return; @@ -468,20 +469,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -494,7 +495,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * making any changes and returns a message indicating the config is already active.

*

Note: Sandbox providers cannot be modified.

*/ - public CompletableFuture> setActiveAuthConfig( + public CompletableFuture> setActiveAuthConfig( String fhirProviderId, FhirProviderSetActiveAuthConfigRequest request) { return setActiveAuthConfig(fhirProviderId, request, null); } @@ -506,7 +507,7 @@ public CompletableFuture> setActiveAut * making any changes and returns a message indicating the config is already active.

*

Note: Sandbox providers cannot be modified.

*/ - public CompletableFuture> setActiveAuthConfig( + public CompletableFuture> setActiveAuthConfig( String fhirProviderId, FhirProviderSetActiveAuthConfigRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -519,7 +520,7 @@ public CompletableFuture> setActiveAut body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -532,13 +533,13 @@ public CompletableFuture> setActiveAut if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response)); return; @@ -575,20 +576,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -599,7 +600,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Cannot remove the currently active auth configuration. *

Note: Sandbox providers cannot be modified.

*/ - public CompletableFuture> removeAuthConfig( + public CompletableFuture> removeAuthConfig( String fhirProviderId, FhirProviderRemoveAuthConfigRequest request) { return removeAuthConfig(fhirProviderId, request, null); } @@ -609,7 +610,7 @@ public CompletableFutureNote: Sandbox providers cannot be modified.

*/ - public CompletableFuture> removeAuthConfig( + public CompletableFuture> removeAuthConfig( String fhirProviderId, FhirProviderRemoveAuthConfigRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -622,7 +623,7 @@ public CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = + new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), FhirProviderRemoveAuthConfigResponse.class), response)); @@ -679,20 +681,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/RawFhirProviderClient.java b/src/main/java/com/phenoml/api/resources/fhirprovider/RawFhirProviderClient.java index ed4628d..faaced7 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/RawFhirProviderClient.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/RawFhirProviderClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.fhirprovider.errors.BadRequestError; import com.phenoml.api.resources.fhirprovider.errors.ForbiddenError; @@ -44,7 +44,7 @@ public RawFhirProviderClient(ClientOptions clientOptions) { * Creates a new FHIR provider configuration with authentication credentials. *

Note: The "sandbox" provider type cannot be created via this API - it is managed internally.

*/ - public PhenoMLHttpResponse create(FhirProviderCreateRequest request) { + public PhenomlClientHttpResponse create(FhirProviderCreateRequest request) { return create(request, null); } @@ -52,7 +52,7 @@ public PhenoMLHttpResponse create(FhirProviderCreateReques * Creates a new FHIR provider configuration with authentication credentials. *

Note: The "sandbox" provider type cannot be created via this API - it is managed internally.

*/ - public PhenoMLHttpResponse create( + public PhenomlClientHttpResponse create( FhirProviderCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -63,7 +63,7 @@ public PhenoMLHttpResponse create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -79,7 +79,7 @@ public PhenoMLHttpResponse create( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response); } @@ -102,13 +102,13 @@ public PhenoMLHttpResponse create( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -117,7 +117,7 @@ public PhenoMLHttpResponse create( *

On shared instances, only sandbox providers are returned. * Sandbox providers return FhirProviderSandboxInfo.

*/ - public PhenoMLHttpResponse list() { + public PhenomlClientHttpResponse list() { return list(null); } @@ -126,7 +126,7 @@ public PhenoMLHttpResponse list() { *

On shared instances, only sandbox providers are returned. * Sandbox providers return FhirProviderSandboxInfo.

*/ - public PhenoMLHttpResponse list(RequestOptions requestOptions) { + public PhenomlClientHttpResponse list(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("fhir-provider/list") @@ -144,7 +144,7 @@ public PhenoMLHttpResponse list(RequestOptions request try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderListResponse.class), response); } @@ -161,13 +161,13 @@ public PhenoMLHttpResponse list(RequestOptions request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -176,7 +176,7 @@ public PhenoMLHttpResponse list(RequestOptions request *

Sandbox providers return FhirProviderSandboxInfo. * On shared instances, only sandbox providers can be accessed.

*/ - public PhenoMLHttpResponse get(String fhirProviderId) { + public PhenomlClientHttpResponse get(String fhirProviderId) { return get(fhirProviderId, null); } @@ -185,7 +185,7 @@ public PhenoMLHttpResponse get(String fhirProviderId) { *

Sandbox providers return FhirProviderSandboxInfo. * On shared instances, only sandbox providers can be accessed.

*/ - public PhenoMLHttpResponse get(String fhirProviderId, RequestOptions requestOptions) { + public PhenomlClientHttpResponse get(String fhirProviderId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("fhir-provider") @@ -204,7 +204,7 @@ public PhenoMLHttpResponse get(String fhirProviderId, Requ try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response); } @@ -224,13 +224,13 @@ public PhenoMLHttpResponse get(String fhirProviderId, Requ } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -238,7 +238,7 @@ public PhenoMLHttpResponse get(String fhirProviderId, Requ * Deletes a FHIR provider. *

Note: Sandbox providers cannot be deleted.

*/ - public PhenoMLHttpResponse delete(String fhirProviderId) { + public PhenomlClientHttpResponse delete(String fhirProviderId) { return delete(fhirProviderId, null); } @@ -246,7 +246,7 @@ public PhenoMLHttpResponse delete(String fhirProvide * Deletes a FHIR provider. *

Note: Sandbox providers cannot be deleted.

*/ - public PhenoMLHttpResponse delete( + public PhenomlClientHttpResponse delete( String fhirProviderId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -266,7 +266,7 @@ public PhenoMLHttpResponse delete( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderDeleteResponse.class), response); } @@ -289,13 +289,13 @@ public PhenoMLHttpResponse delete( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -304,7 +304,7 @@ public PhenoMLHttpResponse delete( * This enables key rotation and multiple auth configurations per provider. *

Note: Sandbox providers cannot be modified.

*/ - public PhenoMLHttpResponse addAuthConfig( + public PhenomlClientHttpResponse addAuthConfig( String fhirProviderId, FhirProviderAddAuthConfigRequest request) { return addAuthConfig(fhirProviderId, request, null); } @@ -314,7 +314,7 @@ public PhenoMLHttpResponse addAuthConfig( * This enables key rotation and multiple auth configurations per provider. *

Note: Sandbox providers cannot be modified.

*/ - public PhenoMLHttpResponse addAuthConfig( + public PhenomlClientHttpResponse addAuthConfig( String fhirProviderId, FhirProviderAddAuthConfigRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -327,7 +327,7 @@ public PhenoMLHttpResponse addAuthConfig( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -343,7 +343,7 @@ public PhenoMLHttpResponse addAuthConfig( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response); } @@ -369,13 +369,13 @@ public PhenoMLHttpResponse addAuthConfig( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -386,7 +386,7 @@ public PhenoMLHttpResponse addAuthConfig( * making any changes and returns a message indicating the config is already active.

*

Note: Sandbox providers cannot be modified.

*/ - public PhenoMLHttpResponse setActiveAuthConfig( + public PhenomlClientHttpResponse setActiveAuthConfig( String fhirProviderId, FhirProviderSetActiveAuthConfigRequest request) { return setActiveAuthConfig(fhirProviderId, request, null); } @@ -398,7 +398,7 @@ public PhenoMLHttpResponse setActiveAuthConfig( * making any changes and returns a message indicating the config is already active.

*

Note: Sandbox providers cannot be modified.

*/ - public PhenoMLHttpResponse setActiveAuthConfig( + public PhenomlClientHttpResponse setActiveAuthConfig( String fhirProviderId, FhirProviderSetActiveAuthConfigRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -411,7 +411,7 @@ public PhenoMLHttpResponse setActiveAuthConfig( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -427,7 +427,7 @@ public PhenoMLHttpResponse setActiveAuthConfig( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FhirProviderResponse.class), response); } @@ -453,13 +453,13 @@ public PhenoMLHttpResponse setActiveAuthConfig( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -468,7 +468,7 @@ public PhenoMLHttpResponse setActiveAuthConfig( * Cannot remove the currently active auth configuration. *

Note: Sandbox providers cannot be modified.

*/ - public PhenoMLHttpResponse removeAuthConfig( + public PhenomlClientHttpResponse removeAuthConfig( String fhirProviderId, FhirProviderRemoveAuthConfigRequest request) { return removeAuthConfig(fhirProviderId, request, null); } @@ -478,7 +478,7 @@ public PhenoMLHttpResponse removeAuthConfi * Cannot remove the currently active auth configuration. *

Note: Sandbox providers cannot be modified.

*/ - public PhenoMLHttpResponse removeAuthConfig( + public PhenomlClientHttpResponse removeAuthConfig( String fhirProviderId, FhirProviderRemoveAuthConfigRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -491,7 +491,7 @@ public PhenoMLHttpResponse removeAuthConfi body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -507,7 +507,7 @@ public PhenoMLHttpResponse removeAuthConfi try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), FhirProviderRemoveAuthConfigResponse.class), response); @@ -534,13 +534,13 @@ public PhenoMLHttpResponse removeAuthConfi } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/BadRequestError.java index 3da5fde..36bfb1b 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhirprovider.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/ForbiddenError.java index ce01b9e..baa8b54 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhirprovider.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/InternalServerError.java index 14a6cc2..89d6200 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhirprovider.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/NotFoundError.java b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/NotFoundError.java index 677ccdc..5ff12ca 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/NotFoundError.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/NotFoundError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhirprovider.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotFoundError extends PhenoMLApiException { +public final class NotFoundError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/UnauthorizedError.java index 973efd1..1960c78 100644 --- a/src/main/java/com/phenoml/api/resources/fhirprovider/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/fhirprovider/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.fhirprovider.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/AsyncRawLang2FhirClient.java b/src/main/java/com/phenoml/api/resources/lang2fhir/AsyncRawLang2FhirClient.java index 3f50532..1179693 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/AsyncRawLang2FhirClient.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/AsyncRawLang2FhirClient.java @@ -8,9 +8,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.lang2fhir.errors.BadRequestError; import com.phenoml.api.resources.lang2fhir.errors.FailedDependencyError; @@ -51,14 +51,14 @@ public AsyncRawLang2FhirClient(ClientOptions clientOptions) { /** * Converts natural language text into a structured FHIR resource */ - public CompletableFuture>> create(CreateRequest request) { + public CompletableFuture>> create(CreateRequest request) { return create(request, null); } /** * Converts natural language text into a structured FHIR resource */ - public CompletableFuture>> create( + public CompletableFuture>> create( CreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -69,7 +69,7 @@ public CompletableFuture>> create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -82,13 +82,13 @@ public CompletableFuture>> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture>> future = new CompletableFuture<>(); + CompletableFuture>> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), new TypeReference>() {}), response)); @@ -116,20 +116,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -140,7 +140,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types from the text. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public CompletableFuture> createMulti(CreateMultiRequest request) { + public CompletableFuture> createMulti(CreateMultiRequest request) { return createMulti(request, null); } @@ -149,7 +149,7 @@ public CompletableFuture> createMulti(C * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types from the text. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public CompletableFuture> createMulti( + public CompletableFuture> createMulti( CreateMultiRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -160,7 +160,7 @@ public CompletableFuture> createMulti( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -173,13 +173,13 @@ public CompletableFuture> createMulti( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateMultiResponse.class), response)); return; @@ -206,20 +206,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -234,7 +234,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * PractitionerRole, Procedure, Provenance, Questionnaire, QuestionnaireResponse, RelatedPerson, * Schedule, ServiceRequest, Slot, and Specimen.

*/ - public CompletableFuture> search(SearchRequest request) { + public CompletableFuture> search(SearchRequest request) { return search(request, null); } @@ -247,7 +247,7 @@ public CompletableFuture> search(SearchReque * PractitionerRole, Procedure, Provenance, Questionnaire, QuestionnaireResponse, RelatedPerson, * Schedule, ServiceRequest, Slot, and Specimen.

*/ - public CompletableFuture> search( + public CompletableFuture> search( SearchRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -258,7 +258,7 @@ public CompletableFuture> search( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -271,13 +271,13 @@ public CompletableFuture> search( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchResponse.class), response)); return; @@ -309,20 +309,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -340,7 +340,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *
  • A custom profile with the same url has already been uploaded
  • * */ - public CompletableFuture> uploadProfile( + public CompletableFuture> uploadProfile( ProfileUploadRequest request) { return uploadProfile(request, null); } @@ -357,7 +357,7 @@ public CompletableFuture> up *
  • A custom profile with the same url has already been uploaded
  • * */ - public CompletableFuture> uploadProfile( + public CompletableFuture> uploadProfile( ProfileUploadRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -368,7 +368,7 @@ public CompletableFuture> up body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -381,13 +381,13 @@ public CompletableFuture> up if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), Lang2FhirUploadProfileResponse.class), response)); @@ -420,20 +420,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -442,14 +442,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Extracts text from a document (PDF or image) and converts it into a structured FHIR resource */ - public CompletableFuture>> document(DocumentRequest request) { + public CompletableFuture>> document(DocumentRequest request) { return document(request, null); } /** * Extracts text from a document (PDF or image) and converts it into a structured FHIR resource */ - public CompletableFuture>> document( + public CompletableFuture>> document( DocumentRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -460,7 +460,7 @@ public CompletableFuture>> document( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -473,13 +473,13 @@ public CompletableFuture>> document( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture>> future = new CompletableFuture<>(); + CompletableFuture>> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), new TypeReference>() {}), response)); @@ -507,20 +507,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -532,7 +532,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public CompletableFuture> extractMultipleFhirResourcesFromADocument( + public CompletableFuture> extractMultipleFhirResourcesFromADocument( DocumentMultiRequest request) { return extractMultipleFhirResourcesFromADocument(request, null); } @@ -543,7 +543,7 @@ public CompletableFuture> extractMultip * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public CompletableFuture> extractMultipleFhirResourcesFromADocument( + public CompletableFuture> extractMultipleFhirResourcesFromADocument( DocumentMultiRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -554,7 +554,7 @@ public CompletableFuture> extractMultip body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -567,13 +567,13 @@ public CompletableFuture> extractMultip if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateMultiResponse.class), response)); return; @@ -605,20 +605,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/RawLang2FhirClient.java b/src/main/java/com/phenoml/api/resources/lang2fhir/RawLang2FhirClient.java index c6dd6f9..8dee63a 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/RawLang2FhirClient.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/RawLang2FhirClient.java @@ -8,9 +8,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.lang2fhir.errors.BadRequestError; import com.phenoml.api.resources.lang2fhir.errors.FailedDependencyError; @@ -47,14 +47,14 @@ public RawLang2FhirClient(ClientOptions clientOptions) { /** * Converts natural language text into a structured FHIR resource */ - public PhenoMLHttpResponse> create(CreateRequest request) { + public PhenomlClientHttpResponse> create(CreateRequest request) { return create(request, null); } /** * Converts natural language text into a structured FHIR resource */ - public PhenoMLHttpResponse> create(CreateRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse> create(CreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("lang2fhir/create") @@ -64,7 +64,7 @@ public PhenoMLHttpResponse> create(CreateRequest request, Re body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -80,7 +80,7 @@ public PhenoMLHttpResponse> create(CreateRequest request, Re try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), new TypeReference>() {}), response); @@ -101,13 +101,13 @@ public PhenoMLHttpResponse> create(CreateRequest request, Re } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -116,7 +116,7 @@ public PhenoMLHttpResponse> create(CreateRequest request, Re * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types from the text. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public PhenoMLHttpResponse createMulti(CreateMultiRequest request) { + public PhenomlClientHttpResponse createMulti(CreateMultiRequest request) { return createMulti(request, null); } @@ -125,7 +125,7 @@ public PhenoMLHttpResponse createMulti(CreateMultiRequest r * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types from the text. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public PhenoMLHttpResponse createMulti( + public PhenomlClientHttpResponse createMulti( CreateMultiRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -136,7 +136,7 @@ public PhenoMLHttpResponse createMulti( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -152,7 +152,7 @@ public PhenoMLHttpResponse createMulti( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateMultiResponse.class), response); } @@ -172,13 +172,13 @@ public PhenoMLHttpResponse createMulti( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -191,7 +191,7 @@ public PhenoMLHttpResponse createMulti( * PractitionerRole, Procedure, Provenance, Questionnaire, QuestionnaireResponse, RelatedPerson, * Schedule, ServiceRequest, Slot, and Specimen.

    */ - public PhenoMLHttpResponse search(SearchRequest request) { + public PhenomlClientHttpResponse search(SearchRequest request) { return search(request, null); } @@ -204,7 +204,7 @@ public PhenoMLHttpResponse search(SearchRequest request) { * PractitionerRole, Procedure, Provenance, Questionnaire, QuestionnaireResponse, RelatedPerson, * Schedule, ServiceRequest, Slot, and Specimen.

    */ - public PhenoMLHttpResponse search(SearchRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse search(SearchRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("lang2fhir/search") @@ -214,7 +214,7 @@ public PhenoMLHttpResponse search(SearchRequest request, Request body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -230,7 +230,7 @@ public PhenoMLHttpResponse search(SearchRequest request, Request try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SearchResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -252,13 +252,13 @@ public PhenoMLHttpResponse search(SearchRequest request, Request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -274,7 +274,7 @@ public PhenoMLHttpResponse search(SearchRequest request, Request *
  • A custom profile with the same url has already been uploaded
  • * */ - public PhenoMLHttpResponse uploadProfile(ProfileUploadRequest request) { + public PhenomlClientHttpResponse uploadProfile(ProfileUploadRequest request) { return uploadProfile(request, null); } @@ -290,7 +290,7 @@ public PhenoMLHttpResponse uploadProfile(Profile *
  • A custom profile with the same url has already been uploaded
  • * */ - public PhenoMLHttpResponse uploadProfile( + public PhenomlClientHttpResponse uploadProfile( ProfileUploadRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -301,7 +301,7 @@ public PhenoMLHttpResponse uploadProfile( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -317,7 +317,7 @@ public PhenoMLHttpResponse uploadProfile( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), Lang2FhirUploadProfileResponse.class), response); @@ -341,27 +341,28 @@ public PhenoMLHttpResponse uploadProfile( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Extracts text from a document (PDF or image) and converts it into a structured FHIR resource */ - public PhenoMLHttpResponse> document(DocumentRequest request) { + public PhenomlClientHttpResponse> document(DocumentRequest request) { return document(request, null); } /** * Extracts text from a document (PDF or image) and converts it into a structured FHIR resource */ - public PhenoMLHttpResponse> document(DocumentRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse> document( + DocumentRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("lang2fhir/document") @@ -371,7 +372,7 @@ public PhenoMLHttpResponse> document(DocumentRequest request body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -387,7 +388,7 @@ public PhenoMLHttpResponse> document(DocumentRequest request try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), new TypeReference>() {}), response); @@ -408,13 +409,13 @@ public PhenoMLHttpResponse> document(DocumentRequest request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -424,7 +425,7 @@ public PhenoMLHttpResponse> document(DocumentRequest request * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public PhenoMLHttpResponse extractMultipleFhirResourcesFromADocument( + public PhenomlClientHttpResponse extractMultipleFhirResourcesFromADocument( DocumentMultiRequest request) { return extractMultipleFhirResourcesFromADocument(request, null); } @@ -435,7 +436,7 @@ public PhenoMLHttpResponse extractMultipleFhirResourcesFrom * Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types. * Resources are linked with proper references (e.g., Conditions reference the Patient). */ - public PhenoMLHttpResponse extractMultipleFhirResourcesFromADocument( + public PhenomlClientHttpResponse extractMultipleFhirResourcesFromADocument( DocumentMultiRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -446,7 +447,7 @@ public PhenoMLHttpResponse extractMultipleFhirResourcesFrom body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -462,7 +463,7 @@ public PhenoMLHttpResponse extractMultipleFhirResourcesFrom try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateMultiResponse.class), response); } @@ -485,13 +486,13 @@ public PhenoMLHttpResponse extractMultipleFhirResourcesFrom } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/BadRequestError.java index b0b8df8..003bc5a 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.lang2fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/FailedDependencyError.java b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/FailedDependencyError.java index 883f762..af64961 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/FailedDependencyError.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/FailedDependencyError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.lang2fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class FailedDependencyError extends PhenoMLApiException { +public final class FailedDependencyError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/ForbiddenError.java index 0b088ca..d8b95b3 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.lang2fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/InternalServerError.java index 9a51e83..4b85eee 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.lang2fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnauthorizedError.java index 88731e5..0963a4e 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.lang2fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnprocessableEntityError.java b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnprocessableEntityError.java index eb19cb5..d176e33 100644 --- a/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnprocessableEntityError.java +++ b/src/main/java/com/phenoml/api/resources/lang2fhir/errors/UnprocessableEntityError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.lang2fhir.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnprocessableEntityError extends PhenoMLApiException { +public final class UnprocessableEntityError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/summary/AsyncRawSummaryClient.java b/src/main/java/com/phenoml/api/resources/summary/AsyncRawSummaryClient.java index acfa5f9..478d8b7 100644 --- a/src/main/java/com/phenoml/api/resources/summary/AsyncRawSummaryClient.java +++ b/src/main/java/com/phenoml/api/resources/summary/AsyncRawSummaryClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.summary.errors.BadRequestError; import com.phenoml.api.resources.summary.errors.ForbiddenError; @@ -48,14 +48,14 @@ public AsyncRawSummaryClient(ClientOptions clientOptions) { /** * Retrieves all summary templates for the authenticated user */ - public CompletableFuture> listTemplates() { + public CompletableFuture> listTemplates() { return listTemplates(null); } /** * Retrieves all summary templates for the authenticated user */ - public CompletableFuture> listTemplates( + public CompletableFuture> listTemplates( RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -71,13 +71,13 @@ public CompletableFuture> list if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), SummaryListTemplatesResponse.class), response)); @@ -100,20 +100,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -122,7 +122,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Creates a summary template from an example using LLM function calling */ - public CompletableFuture> createTemplate( + public CompletableFuture> createTemplate( CreateSummaryTemplateRequest request) { return createTemplate(request, null); } @@ -130,7 +130,7 @@ public CompletableFuture> cre /** * Creates a summary template from an example using LLM function calling */ - public CompletableFuture> createTemplate( + public CompletableFuture> createTemplate( CreateSummaryTemplateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -141,7 +141,7 @@ public CompletableFuture> cre body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -154,13 +154,13 @@ public CompletableFuture> cre if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), CreateSummaryTemplateResponse.class), response)); @@ -188,20 +188,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -210,14 +210,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a specific summary template */ - public CompletableFuture> getTemplate(String id) { + public CompletableFuture> getTemplate(String id) { return getTemplate(id, null); } /** * Retrieves a specific summary template */ - public CompletableFuture> getTemplate( + public CompletableFuture> getTemplate( String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -234,13 +234,13 @@ public CompletableFuture> getTem if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), SummaryGetTemplateResponse.class), response)); @@ -273,20 +273,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -295,7 +295,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Updates an existing summary template */ - public CompletableFuture> updateTemplate( + public CompletableFuture> updateTemplate( String id, UpdateSummaryTemplateRequest request) { return updateTemplate(id, request, null); } @@ -303,7 +303,7 @@ public CompletableFuture> upd /** * Updates an existing summary template */ - public CompletableFuture> updateTemplate( + public CompletableFuture> updateTemplate( String id, UpdateSummaryTemplateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -315,7 +315,7 @@ public CompletableFuture> upd body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -328,13 +328,13 @@ public CompletableFuture> upd if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), SummaryUpdateTemplateResponse.class), response)); @@ -372,20 +372,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -394,14 +394,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Deletes a summary template */ - public CompletableFuture> deleteTemplate(String id) { + public CompletableFuture> deleteTemplate(String id) { return deleteTemplate(id, null); } /** * Deletes a summary template */ - public CompletableFuture> deleteTemplate( + public CompletableFuture> deleteTemplate( String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -418,13 +418,13 @@ public CompletableFuture> del if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), SummaryDeleteTemplateResponse.class), response)); @@ -457,20 +457,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -484,7 +484,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { *
  • ips: Generates an International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG. Requires a Bundle with exactly one Patient resource (returns 400 error if no Patient or multiple Patients are present). Automatically filters resources to those referencing the patient and generates sections for allergies, medications, problems, immunizations, procedures, and vital signs.
  • * */ - public CompletableFuture> create(CreateSummaryRequest request) { + public CompletableFuture> create(CreateSummaryRequest request) { return create(request, null); } @@ -496,7 +496,7 @@ public CompletableFuture> create(Crea *
  • ips: Generates an International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG. Requires a Bundle with exactly one Patient resource (returns 400 error if no Patient or multiple Patients are present). Automatically filters resources to those referencing the patient and generates sections for allergies, medications, problems, immunizations, procedures, and vital signs.
  • * */ - public CompletableFuture> create( + public CompletableFuture> create( CreateSummaryRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -507,7 +507,7 @@ public CompletableFuture> create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -520,13 +520,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateSummaryResponse.class), response)); return; @@ -563,20 +563,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/summary/RawSummaryClient.java b/src/main/java/com/phenoml/api/resources/summary/RawSummaryClient.java index e86c89c..a8d1ee7 100644 --- a/src/main/java/com/phenoml/api/resources/summary/RawSummaryClient.java +++ b/src/main/java/com/phenoml/api/resources/summary/RawSummaryClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.summary.errors.BadRequestError; import com.phenoml.api.resources.summary.errors.ForbiddenError; @@ -44,14 +44,14 @@ public RawSummaryClient(ClientOptions clientOptions) { /** * Retrieves all summary templates for the authenticated user */ - public PhenoMLHttpResponse listTemplates() { + public PhenomlClientHttpResponse listTemplates() { return listTemplates(null); } /** * Retrieves all summary templates for the authenticated user */ - public PhenoMLHttpResponse listTemplates(RequestOptions requestOptions) { + public PhenomlClientHttpResponse listTemplates(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("fhir2summary/templates") @@ -69,7 +69,7 @@ public PhenoMLHttpResponse listTemplates(RequestOp try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SummaryListTemplatesResponse.class), response); } @@ -86,27 +86,28 @@ public PhenoMLHttpResponse listTemplates(RequestOp } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Creates a summary template from an example using LLM function calling */ - public PhenoMLHttpResponse createTemplate(CreateSummaryTemplateRequest request) { + public PhenomlClientHttpResponse createTemplate( + CreateSummaryTemplateRequest request) { return createTemplate(request, null); } /** * Creates a summary template from an example using LLM function calling */ - public PhenoMLHttpResponse createTemplate( + public PhenomlClientHttpResponse createTemplate( CreateSummaryTemplateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -117,7 +118,7 @@ public PhenoMLHttpResponse createTemplate( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -133,7 +134,7 @@ public PhenoMLHttpResponse createTemplate( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateSummaryTemplateResponse.class), response); } @@ -153,27 +154,27 @@ public PhenoMLHttpResponse createTemplate( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a specific summary template */ - public PhenoMLHttpResponse getTemplate(String id) { + public PhenomlClientHttpResponse getTemplate(String id) { return getTemplate(id, null); } /** * Retrieves a specific summary template */ - public PhenoMLHttpResponse getTemplate(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse getTemplate(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("fhir2summary/template") @@ -192,7 +193,7 @@ public PhenoMLHttpResponse getTemplate(String id, Re try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SummaryGetTemplateResponse.class), response); } @@ -215,20 +216,20 @@ public PhenoMLHttpResponse getTemplate(String id, Re } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Updates an existing summary template */ - public PhenoMLHttpResponse updateTemplate( + public PhenomlClientHttpResponse updateTemplate( String id, UpdateSummaryTemplateRequest request) { return updateTemplate(id, request, null); } @@ -236,7 +237,7 @@ public PhenoMLHttpResponse updateTemplate( /** * Updates an existing summary template */ - public PhenoMLHttpResponse updateTemplate( + public PhenomlClientHttpResponse updateTemplate( String id, UpdateSummaryTemplateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -248,7 +249,7 @@ public PhenoMLHttpResponse updateTemplate( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -264,7 +265,7 @@ public PhenoMLHttpResponse updateTemplate( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SummaryUpdateTemplateResponse.class), response); } @@ -290,27 +291,28 @@ public PhenoMLHttpResponse updateTemplate( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Deletes a summary template */ - public PhenoMLHttpResponse deleteTemplate(String id) { + public PhenomlClientHttpResponse deleteTemplate(String id) { return deleteTemplate(id, null); } /** * Deletes a summary template */ - public PhenoMLHttpResponse deleteTemplate(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse deleteTemplate( + String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("fhir2summary/template") @@ -329,7 +331,7 @@ public PhenoMLHttpResponse deleteTemplate(String try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SummaryDeleteTemplateResponse.class), response); } @@ -352,13 +354,13 @@ public PhenoMLHttpResponse deleteTemplate(String } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -370,7 +372,7 @@ public PhenoMLHttpResponse deleteTemplate(String *
  • ips: Generates an International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG. Requires a Bundle with exactly one Patient resource (returns 400 error if no Patient or multiple Patients are present). Automatically filters resources to those referencing the patient and generates sections for allergies, medications, problems, immunizations, procedures, and vital signs.
  • * */ - public PhenoMLHttpResponse create(CreateSummaryRequest request) { + public PhenomlClientHttpResponse create(CreateSummaryRequest request) { return create(request, null); } @@ -382,7 +384,7 @@ public PhenoMLHttpResponse create(CreateSummaryRequest re *
  • ips: Generates an International Patient Summary (IPS) narrative per ISO 27269/HL7 FHIR IPS IG. Requires a Bundle with exactly one Patient resource (returns 400 error if no Patient or multiple Patients are present). Automatically filters resources to those referencing the patient and generates sections for allergies, medications, problems, immunizations, procedures, and vital signs.
  • * */ - public PhenoMLHttpResponse create( + public PhenomlClientHttpResponse create( CreateSummaryRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -393,7 +395,7 @@ public PhenoMLHttpResponse create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -409,7 +411,7 @@ public PhenoMLHttpResponse create( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateSummaryResponse.class), response); } @@ -435,13 +437,13 @@ public PhenoMLHttpResponse create( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/summary/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/summary/errors/BadRequestError.java index aa720bb..a3525a1 100644 --- a/src/main/java/com/phenoml/api/resources/summary/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/summary/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.summary.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/summary/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/summary/errors/ForbiddenError.java index 17e650d..1ed9766 100644 --- a/src/main/java/com/phenoml/api/resources/summary/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/summary/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.summary.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/summary/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/summary/errors/InternalServerError.java index 3e5a4fb..e7394e0 100644 --- a/src/main/java/com/phenoml/api/resources/summary/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/summary/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.summary.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/summary/errors/NotFoundError.java b/src/main/java/com/phenoml/api/resources/summary/errors/NotFoundError.java index a9065c3..02b9e0b 100644 --- a/src/main/java/com/phenoml/api/resources/summary/errors/NotFoundError.java +++ b/src/main/java/com/phenoml/api/resources/summary/errors/NotFoundError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.summary.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotFoundError extends PhenoMLApiException { +public final class NotFoundError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/summary/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/summary/errors/UnauthorizedError.java index f90607e..ffb0f5f 100644 --- a/src/main/java/com/phenoml/api/resources/summary/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/summary/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.summary.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/tools/AsyncRawToolsClient.java b/src/main/java/com/phenoml/api/resources/tools/AsyncRawToolsClient.java index 43bd4c5..3928ded 100644 --- a/src/main/java/com/phenoml/api/resources/tools/AsyncRawToolsClient.java +++ b/src/main/java/com/phenoml/api/resources/tools/AsyncRawToolsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.tools.errors.BadRequestError; import com.phenoml.api.resources.tools.errors.FailedDependencyError; @@ -49,7 +49,7 @@ public AsyncRawToolsClient(ClientOptions clientOptions) { /** * Converts natural language to FHIR resource and optionally stores it in a FHIR server */ - public CompletableFuture> createFhirResource( + public CompletableFuture> createFhirResource( Lang2FhirAndCreateRequest request) { return createFhirResource(request, null); } @@ -57,7 +57,7 @@ public CompletableFuture> create /** * Converts natural language to FHIR resource and optionally stores it in a FHIR server */ - public CompletableFuture> createFhirResource( + public CompletableFuture> createFhirResource( Lang2FhirAndCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -95,13 +95,13 @@ public CompletableFuture> create if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), Lang2FhirAndCreateResponse.class), response)); @@ -139,20 +139,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -165,7 +165,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { * For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically * resolve them via PUT requests after the initial bundle creation. */ - public CompletableFuture> createFhirResourcesMulti( + public CompletableFuture> createFhirResourcesMulti( Lang2FhirAndCreateMultiRequest request) { return createFhirResourcesMulti(request, null); } @@ -177,7 +177,7 @@ public CompletableFuture> c * For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically * resolve them via PUT requests after the initial bundle creation. */ - public CompletableFuture> createFhirResourcesMulti( + public CompletableFuture> createFhirResourcesMulti( Lang2FhirAndCreateMultiRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -215,13 +215,14 @@ public CompletableFuture> c if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = + new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), Lang2FhirAndCreateMultiResponse.class), response)); @@ -259,20 +260,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -281,7 +282,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Converts natural language to FHIR search parameters and executes search in FHIR server */ - public CompletableFuture> searchFhirResources( + public CompletableFuture> searchFhirResources( Lang2FhirAndSearchRequest request) { return searchFhirResources(request, null); } @@ -289,7 +290,7 @@ public CompletableFuture> search /** * Converts natural language to FHIR search parameters and executes search in FHIR server */ - public CompletableFuture> searchFhirResources( + public CompletableFuture> searchFhirResources( Lang2FhirAndSearchRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -335,13 +336,13 @@ public CompletableFuture> search if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), Lang2FhirAndSearchResponse.class), response)); @@ -379,20 +380,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -401,14 +402,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Uses LLM to extract search concepts from natural language and builds patient cohorts with inclusion/exclusion criteria */ - public CompletableFuture> analyzeCohort(CohortRequest request) { + public CompletableFuture> analyzeCohort(CohortRequest request) { return analyzeCohort(request, null); } /** * Uses LLM to extract search concepts from natural language and builds patient cohorts with inclusion/exclusion criteria */ - public CompletableFuture> analyzeCohort( + public CompletableFuture> analyzeCohort( CohortRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -443,13 +444,13 @@ public CompletableFuture> analyzeCohort( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CohortResponse.class), response)); return; @@ -481,20 +482,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/tools/RawToolsClient.java b/src/main/java/com/phenoml/api/resources/tools/RawToolsClient.java index f4414a7..b8cda17 100644 --- a/src/main/java/com/phenoml/api/resources/tools/RawToolsClient.java +++ b/src/main/java/com/phenoml/api/resources/tools/RawToolsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.tools.errors.BadRequestError; import com.phenoml.api.resources.tools.errors.FailedDependencyError; @@ -45,14 +45,14 @@ public RawToolsClient(ClientOptions clientOptions) { /** * Converts natural language to FHIR resource and optionally stores it in a FHIR server */ - public PhenoMLHttpResponse createFhirResource(Lang2FhirAndCreateRequest request) { + public PhenomlClientHttpResponse createFhirResource(Lang2FhirAndCreateRequest request) { return createFhirResource(request, null); } /** * Converts natural language to FHIR resource and optionally stores it in a FHIR server */ - public PhenoMLHttpResponse createFhirResource( + public PhenomlClientHttpResponse createFhirResource( Lang2FhirAndCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -93,7 +93,7 @@ public PhenoMLHttpResponse createFhirResource( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Lang2FhirAndCreateResponse.class), response); } @@ -119,13 +119,13 @@ public PhenoMLHttpResponse createFhirResource( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } @@ -136,7 +136,7 @@ public PhenoMLHttpResponse createFhirResource( * For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically * resolve them via PUT requests after the initial bundle creation. */ - public PhenoMLHttpResponse createFhirResourcesMulti( + public PhenomlClientHttpResponse createFhirResourcesMulti( Lang2FhirAndCreateMultiRequest request) { return createFhirResourcesMulti(request, null); } @@ -148,7 +148,7 @@ public PhenoMLHttpResponse createFhirResourcesM * For FHIR servers that don't auto-resolve urn:uuid references, this endpoint will automatically * resolve them via PUT requests after the initial bundle creation. */ - public PhenoMLHttpResponse createFhirResourcesMulti( + public PhenomlClientHttpResponse createFhirResourcesMulti( Lang2FhirAndCreateMultiRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -189,7 +189,7 @@ public PhenoMLHttpResponse createFhirResourcesM try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), Lang2FhirAndCreateMultiResponse.class), response); @@ -216,27 +216,28 @@ public PhenoMLHttpResponse createFhirResourcesM } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Converts natural language to FHIR search parameters and executes search in FHIR server */ - public PhenoMLHttpResponse searchFhirResources(Lang2FhirAndSearchRequest request) { + public PhenomlClientHttpResponse searchFhirResources( + Lang2FhirAndSearchRequest request) { return searchFhirResources(request, null); } /** * Converts natural language to FHIR search parameters and executes search in FHIR server */ - public PhenoMLHttpResponse searchFhirResources( + public PhenomlClientHttpResponse searchFhirResources( Lang2FhirAndSearchRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -285,7 +286,7 @@ public PhenoMLHttpResponse searchFhirResources( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Lang2FhirAndSearchResponse.class), response); } @@ -311,27 +312,28 @@ public PhenoMLHttpResponse searchFhirResources( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Uses LLM to extract search concepts from natural language and builds patient cohorts with inclusion/exclusion criteria */ - public PhenoMLHttpResponse analyzeCohort(CohortRequest request) { + public PhenomlClientHttpResponse analyzeCohort(CohortRequest request) { return analyzeCohort(request, null); } /** * Uses LLM to extract search concepts from natural language and builds patient cohorts with inclusion/exclusion criteria */ - public PhenoMLHttpResponse analyzeCohort(CohortRequest request, RequestOptions requestOptions) { + public PhenomlClientHttpResponse analyzeCohort( + CohortRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/cohort") @@ -368,7 +370,7 @@ public PhenoMLHttpResponse analyzeCohort(CohortRequest request, try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CohortResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -390,13 +392,13 @@ public PhenoMLHttpResponse analyzeCohort(CohortRequest request, } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/tools/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/tools/errors/BadRequestError.java index 178e80b..965ca32 100644 --- a/src/main/java/com/phenoml/api/resources/tools/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/tools/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.tools.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/tools/errors/FailedDependencyError.java b/src/main/java/com/phenoml/api/resources/tools/errors/FailedDependencyError.java index 6653be3..ff085dc 100644 --- a/src/main/java/com/phenoml/api/resources/tools/errors/FailedDependencyError.java +++ b/src/main/java/com/phenoml/api/resources/tools/errors/FailedDependencyError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.tools.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class FailedDependencyError extends PhenoMLApiException { +public final class FailedDependencyError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/tools/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/tools/errors/ForbiddenError.java index 911c59e..dd97b2a 100644 --- a/src/main/java/com/phenoml/api/resources/tools/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/tools/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.tools.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/tools/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/tools/errors/InternalServerError.java index 7386c4c..55c6829 100644 --- a/src/main/java/com/phenoml/api/resources/tools/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/tools/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.tools.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/tools/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/tools/errors/UnauthorizedError.java index 0c6e02c..821b381 100644 --- a/src/main/java/com/phenoml/api/resources/tools/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/tools/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.tools.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/tools/mcpserver/AsyncRawMcpServerClient.java b/src/main/java/com/phenoml/api/resources/tools/mcpserver/AsyncRawMcpServerClient.java index 7d2df16..94f300f 100644 --- a/src/main/java/com/phenoml/api/resources/tools/mcpserver/AsyncRawMcpServerClient.java +++ b/src/main/java/com/phenoml/api/resources/tools/mcpserver/AsyncRawMcpServerClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.tools.errors.BadRequestError; import com.phenoml.api.resources.tools.errors.ForbiddenError; @@ -40,14 +40,14 @@ public AsyncRawMcpServerClient(ClientOptions clientOptions) { /** * Creates a new MCP server */ - public CompletableFuture> create(McpServerCreateRequest request) { + public CompletableFuture> create(McpServerCreateRequest request) { return create(request, null); } /** * Creates a new MCP server */ - public CompletableFuture> create( + public CompletableFuture> create( McpServerCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -58,7 +58,7 @@ public CompletableFuture> create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -71,13 +71,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response)); return; @@ -109,20 +109,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -131,14 +131,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Lists all MCP servers for a specific user */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(null); } /** * Lists all MCP servers for a specific user */ - public CompletableFuture> list(RequestOptions requestOptions) { + public CompletableFuture> list(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server/list") @@ -153,13 +153,13 @@ public CompletableFuture> list(RequestOpt if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response)); return; @@ -186,20 +186,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -208,14 +208,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Gets a MCP server by ID */ - public CompletableFuture> get(String mcpServerId) { + public CompletableFuture> get(String mcpServerId) { return get(mcpServerId, null); } /** * Gets a MCP server by ID */ - public CompletableFuture> get( + public CompletableFuture> get( String mcpServerId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -232,13 +232,13 @@ public CompletableFuture> get( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response)); return; @@ -265,20 +265,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -287,14 +287,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Deletes a MCP server by ID */ - public CompletableFuture> delete(String mcpServerId) { + public CompletableFuture> delete(String mcpServerId) { return delete(mcpServerId, null); } /** * Deletes a MCP server by ID */ - public CompletableFuture> delete( + public CompletableFuture> delete( String mcpServerId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -311,13 +311,13 @@ public CompletableFuture> delete( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response)); return; @@ -344,20 +344,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/tools/mcpserver/RawMcpServerClient.java b/src/main/java/com/phenoml/api/resources/tools/mcpserver/RawMcpServerClient.java index 34caa92..a7770a2 100644 --- a/src/main/java/com/phenoml/api/resources/tools/mcpserver/RawMcpServerClient.java +++ b/src/main/java/com/phenoml/api/resources/tools/mcpserver/RawMcpServerClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.tools.errors.BadRequestError; import com.phenoml.api.resources.tools.errors.ForbiddenError; @@ -36,14 +36,14 @@ public RawMcpServerClient(ClientOptions clientOptions) { /** * Creates a new MCP server */ - public PhenoMLHttpResponse create(McpServerCreateRequest request) { + public PhenomlClientHttpResponse create(McpServerCreateRequest request) { return create(request, null); } /** * Creates a new MCP server */ - public PhenoMLHttpResponse create( + public PhenomlClientHttpResponse create( McpServerCreateRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -54,7 +54,7 @@ public PhenoMLHttpResponse create( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -70,7 +70,7 @@ public PhenoMLHttpResponse create( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -92,27 +92,27 @@ public PhenoMLHttpResponse create( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Lists all MCP servers for a specific user */ - public PhenoMLHttpResponse list() { + public PhenomlClientHttpResponse list() { return list(null); } /** * Lists all MCP servers for a specific user */ - public PhenoMLHttpResponse list(RequestOptions requestOptions) { + public PhenomlClientHttpResponse list(RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server/list") @@ -130,7 +130,7 @@ public PhenoMLHttpResponse list(RequestOptions requestOptions try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -149,27 +149,27 @@ public PhenoMLHttpResponse list(RequestOptions requestOptions } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Gets a MCP server by ID */ - public PhenoMLHttpResponse get(String mcpServerId) { + public PhenomlClientHttpResponse get(String mcpServerId) { return get(mcpServerId, null); } /** * Gets a MCP server by ID */ - public PhenoMLHttpResponse get(String mcpServerId, RequestOptions requestOptions) { + public PhenomlClientHttpResponse get(String mcpServerId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server") @@ -188,7 +188,7 @@ public PhenoMLHttpResponse get(String mcpServerId, RequestOpt try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -207,27 +207,27 @@ public PhenoMLHttpResponse get(String mcpServerId, RequestOpt } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Deletes a MCP server by ID */ - public PhenoMLHttpResponse delete(String mcpServerId) { + public PhenomlClientHttpResponse delete(String mcpServerId) { return delete(mcpServerId, null); } /** * Deletes a MCP server by ID */ - public PhenoMLHttpResponse delete(String mcpServerId, RequestOptions requestOptions) { + public PhenomlClientHttpResponse delete(String mcpServerId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server") @@ -246,7 +246,7 @@ public PhenoMLHttpResponse delete(String mcpServerId, Request try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerResponse.class), response); } String responseBodyString = responseBody != null ? responseBody.string() : "{}"; @@ -265,13 +265,13 @@ public PhenoMLHttpResponse delete(String mcpServerId, Request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/AsyncRawToolsClient.java b/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/AsyncRawToolsClient.java index 7603d29..e442d09 100644 --- a/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/AsyncRawToolsClient.java +++ b/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/AsyncRawToolsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.tools.errors.BadRequestError; import com.phenoml.api.resources.tools.errors.ForbiddenError; @@ -41,14 +41,14 @@ public AsyncRawToolsClient(ClientOptions clientOptions) { /** * Lists all MCP server tools for a specific MCP server */ - public CompletableFuture> list(String mcpServerId) { + public CompletableFuture> list(String mcpServerId) { return list(mcpServerId, null); } /** * Lists all MCP server tools for a specific MCP server */ - public CompletableFuture> list( + public CompletableFuture> list( String mcpServerId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -66,13 +66,13 @@ public CompletableFuture> list( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolResponse.class), response)); return; @@ -99,20 +99,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -121,14 +121,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Gets a MCP server tool by ID */ - public CompletableFuture> get(String mcpServerToolId) { + public CompletableFuture> get(String mcpServerToolId) { return get(mcpServerToolId, null); } /** * Gets a MCP server tool by ID */ - public CompletableFuture> get( + public CompletableFuture> get( String mcpServerToolId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -145,13 +145,13 @@ public CompletableFuture> get( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolResponse.class), response)); return; @@ -178,20 +178,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -200,14 +200,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Deletes a MCP server tool by ID */ - public CompletableFuture> delete(String mcpServerToolId) { + public CompletableFuture> delete(String mcpServerToolId) { return delete(mcpServerToolId, null); } /** * Deletes a MCP server tool by ID */ - public CompletableFuture> delete( + public CompletableFuture> delete( String mcpServerToolId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -224,13 +224,13 @@ public CompletableFuture> delete( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolResponse.class), response)); return; @@ -257,20 +257,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -279,7 +279,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Calls a MCP server tool */ - public CompletableFuture> call( + public CompletableFuture> call( String mcpServerToolId, McpServerToolCallRequest request) { return call(mcpServerToolId, request, null); } @@ -287,7 +287,7 @@ public CompletableFuture> call( /** * Calls a MCP server tool */ - public CompletableFuture> call( + public CompletableFuture> call( String mcpServerToolId, McpServerToolCallRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -300,7 +300,7 @@ public CompletableFuture> call( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -313,13 +313,13 @@ public CompletableFuture> call( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), McpServerToolCallResponse.class), response)); @@ -352,20 +352,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/RawToolsClient.java b/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/RawToolsClient.java index 1a0df7a..f6a4d1a 100644 --- a/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/RawToolsClient.java +++ b/src/main/java/com/phenoml/api/resources/tools/mcpserver/tools/RawToolsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.tools.errors.BadRequestError; import com.phenoml.api.resources.tools.errors.ForbiddenError; @@ -37,14 +37,14 @@ public RawToolsClient(ClientOptions clientOptions) { /** * Lists all MCP server tools for a specific MCP server */ - public PhenoMLHttpResponse list(String mcpServerId) { + public PhenomlClientHttpResponse list(String mcpServerId) { return list(mcpServerId, null); } /** * Lists all MCP server tools for a specific MCP server */ - public PhenoMLHttpResponse list(String mcpServerId, RequestOptions requestOptions) { + public PhenomlClientHttpResponse list(String mcpServerId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server") @@ -64,7 +64,7 @@ public PhenoMLHttpResponse list(String mcpServerId, Reque try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolResponse.class), response); } @@ -84,27 +84,27 @@ public PhenoMLHttpResponse list(String mcpServerId, Reque } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Gets a MCP server tool by ID */ - public PhenoMLHttpResponse get(String mcpServerToolId) { + public PhenomlClientHttpResponse get(String mcpServerToolId) { return get(mcpServerToolId, null); } /** * Gets a MCP server tool by ID */ - public PhenoMLHttpResponse get(String mcpServerToolId, RequestOptions requestOptions) { + public PhenomlClientHttpResponse get(String mcpServerToolId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server/tool") @@ -123,7 +123,7 @@ public PhenoMLHttpResponse get(String mcpServerToolId, Re try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolResponse.class), response); } @@ -143,27 +143,28 @@ public PhenoMLHttpResponse get(String mcpServerToolId, Re } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Deletes a MCP server tool by ID */ - public PhenoMLHttpResponse delete(String mcpServerToolId) { + public PhenomlClientHttpResponse delete(String mcpServerToolId) { return delete(mcpServerToolId, null); } /** * Deletes a MCP server tool by ID */ - public PhenoMLHttpResponse delete(String mcpServerToolId, RequestOptions requestOptions) { + public PhenomlClientHttpResponse delete( + String mcpServerToolId, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("tools/mcp-server/tool") @@ -182,7 +183,7 @@ public PhenoMLHttpResponse delete(String mcpServerToolId, try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolResponse.class), response); } @@ -202,20 +203,20 @@ public PhenoMLHttpResponse delete(String mcpServerToolId, } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Calls a MCP server tool */ - public PhenoMLHttpResponse call( + public PhenomlClientHttpResponse call( String mcpServerToolId, McpServerToolCallRequest request) { return call(mcpServerToolId, request, null); } @@ -223,7 +224,7 @@ public PhenoMLHttpResponse call( /** * Calls a MCP server tool */ - public PhenoMLHttpResponse call( + public PhenomlClientHttpResponse call( String mcpServerToolId, McpServerToolCallRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -236,7 +237,7 @@ public PhenoMLHttpResponse call( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -252,7 +253,7 @@ public PhenoMLHttpResponse call( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), McpServerToolCallResponse.class), response); } @@ -275,13 +276,13 @@ public PhenoMLHttpResponse call( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/workflows/AsyncRawWorkflowsClient.java b/src/main/java/com/phenoml/api/resources/workflows/AsyncRawWorkflowsClient.java index c98c0cb..920cc56 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/AsyncRawWorkflowsClient.java +++ b/src/main/java/com/phenoml/api/resources/workflows/AsyncRawWorkflowsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.workflows.errors.BadRequestError; @@ -53,21 +53,21 @@ public AsyncRawWorkflowsClient(ClientOptions clientOptions) { /** * Retrieves all workflow definitions for the authenticated user */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(WorkflowsListRequest.builder().build()); } /** * Retrieves all workflow definitions for the authenticated user */ - public CompletableFuture> list(WorkflowsListRequest request) { + public CompletableFuture> list(WorkflowsListRequest request) { return list(request, null); } /** * Retrieves all workflow definitions for the authenticated user */ - public CompletableFuture> list( + public CompletableFuture> list( WorkflowsListRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -86,13 +86,13 @@ public CompletableFuture> list( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListWorkflowsResponse.class), response)); return; @@ -119,20 +119,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -141,14 +141,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Creates a new workflow definition with graph generation from workflow instructions */ - public CompletableFuture> create(CreateWorkflowRequest request) { + public CompletableFuture> create(CreateWorkflowRequest request) { return create(request, null); } /** * Creates a new workflow definition with graph generation from workflow instructions */ - public CompletableFuture> create( + public CompletableFuture> create( CreateWorkflowRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -183,13 +183,13 @@ public CompletableFuture> create( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), CreateWorkflowResponse.class), response)); @@ -222,20 +222,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -244,21 +244,22 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Retrieves a workflow definition by its ID */ - public CompletableFuture> get(String id) { + public CompletableFuture> get(String id) { return get(id, WorkflowsGetRequest.builder().build()); } /** * Retrieves a workflow definition by its ID */ - public CompletableFuture> get(String id, WorkflowsGetRequest request) { + public CompletableFuture> get( + String id, WorkflowsGetRequest request) { return get(id, request, null); } /** * Retrieves a workflow definition by its ID */ - public CompletableFuture> get( + public CompletableFuture> get( String id, WorkflowsGetRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -278,13 +279,13 @@ public CompletableFuture> get( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), WorkflowsGetResponse.class), response)); return; @@ -316,20 +317,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -338,7 +339,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Updates an existing workflow definition */ - public CompletableFuture> update( + public CompletableFuture> update( String id, UpdateWorkflowRequest request) { return update(id, request, null); } @@ -346,7 +347,7 @@ public CompletableFuture> update( /** * Updates an existing workflow definition */ - public CompletableFuture> update( + public CompletableFuture> update( String id, UpdateWorkflowRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -382,13 +383,13 @@ public CompletableFuture> update( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), WorkflowsUpdateResponse.class), response)); @@ -426,20 +427,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -448,14 +449,14 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Deletes a workflow definition by its ID */ - public CompletableFuture> delete(String id) { + public CompletableFuture> delete(String id) { return delete(id, null); } /** * Deletes a workflow definition by its ID */ - public CompletableFuture> delete( + public CompletableFuture> delete( String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -472,13 +473,13 @@ public CompletableFuture> delete( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), WorkflowsDeleteResponse.class), response)); @@ -511,20 +512,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; @@ -533,7 +534,7 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { /** * Executes a workflow with provided input data and returns results */ - public CompletableFuture> execute( + public CompletableFuture> execute( String id, ExecuteWorkflowRequest request) { return execute(id, request, null); } @@ -541,7 +542,7 @@ public CompletableFuture> execute( /** * Executes a workflow with provided input data and returns results */ - public CompletableFuture> execute( + public CompletableFuture> execute( String id, ExecuteWorkflowRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -554,7 +555,7 @@ public CompletableFuture> execute( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -567,13 +568,13 @@ public CompletableFuture> execute( if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); } - CompletableFuture> future = new CompletableFuture<>(); + CompletableFuture> future = new CompletableFuture<>(); client.newCall(okhttpRequest).enqueue(new Callback() { @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { if (response.isSuccessful()) { - future.complete(new PhenoMLHttpResponse<>( + future.complete(new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( responseBody.string(), ExecuteWorkflowResponse.class), response)); @@ -611,20 +612,20 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - future.completeExceptionally(new PhenoMLApiException( + future.completeExceptionally(new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response)); return; } catch (IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } } @Override public void onFailure(@NotNull Call call, @NotNull IOException e) { - future.completeExceptionally(new PhenoMLException("Network error executing HTTP request", e)); + future.completeExceptionally(new PhenomlClientException("Network error executing HTTP request", e)); } }); return future; diff --git a/src/main/java/com/phenoml/api/resources/workflows/RawWorkflowsClient.java b/src/main/java/com/phenoml/api/resources/workflows/RawWorkflowsClient.java index d442662..40f09ec 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/RawWorkflowsClient.java +++ b/src/main/java/com/phenoml/api/resources/workflows/RawWorkflowsClient.java @@ -7,9 +7,9 @@ import com.phenoml.api.core.ClientOptions; import com.phenoml.api.core.MediaTypes; import com.phenoml.api.core.ObjectMappers; -import com.phenoml.api.core.PhenoMLApiException; -import com.phenoml.api.core.PhenoMLException; -import com.phenoml.api.core.PhenoMLHttpResponse; +import com.phenoml.api.core.PhenomlClientApiException; +import com.phenoml.api.core.PhenomlClientException; +import com.phenoml.api.core.PhenomlClientHttpResponse; import com.phenoml.api.core.QueryStringMapper; import com.phenoml.api.core.RequestOptions; import com.phenoml.api.resources.workflows.errors.BadRequestError; @@ -49,21 +49,21 @@ public RawWorkflowsClient(ClientOptions clientOptions) { /** * Retrieves all workflow definitions for the authenticated user */ - public PhenoMLHttpResponse list() { + public PhenomlClientHttpResponse list() { return list(WorkflowsListRequest.builder().build()); } /** * Retrieves all workflow definitions for the authenticated user */ - public PhenoMLHttpResponse list(WorkflowsListRequest request) { + public PhenomlClientHttpResponse list(WorkflowsListRequest request) { return list(request, null); } /** * Retrieves all workflow definitions for the authenticated user */ - public PhenoMLHttpResponse list( + public PhenomlClientHttpResponse list( WorkflowsListRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -85,7 +85,7 @@ public PhenoMLHttpResponse list( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListWorkflowsResponse.class), response); } @@ -105,27 +105,27 @@ public PhenoMLHttpResponse list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Creates a new workflow definition with graph generation from workflow instructions */ - public PhenoMLHttpResponse create(CreateWorkflowRequest request) { + public PhenomlClientHttpResponse create(CreateWorkflowRequest request) { return create(request, null); } /** * Creates a new workflow definition with graph generation from workflow instructions */ - public PhenoMLHttpResponse create( + public PhenomlClientHttpResponse create( CreateWorkflowRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -163,7 +163,7 @@ public PhenoMLHttpResponse create( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateWorkflowResponse.class), response); } @@ -186,34 +186,34 @@ public PhenoMLHttpResponse create( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Retrieves a workflow definition by its ID */ - public PhenoMLHttpResponse get(String id) { + public PhenomlClientHttpResponse get(String id) { return get(id, WorkflowsGetRequest.builder().build()); } /** * Retrieves a workflow definition by its ID */ - public PhenoMLHttpResponse get(String id, WorkflowsGetRequest request) { + public PhenomlClientHttpResponse get(String id, WorkflowsGetRequest request) { return get(id, request, null); } /** * Retrieves a workflow definition by its ID */ - public PhenoMLHttpResponse get( + public PhenomlClientHttpResponse get( String id, WorkflowsGetRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -236,7 +236,7 @@ public PhenoMLHttpResponse get( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), WorkflowsGetResponse.class), response); } @@ -259,27 +259,27 @@ public PhenoMLHttpResponse get( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Updates an existing workflow definition */ - public PhenoMLHttpResponse update(String id, UpdateWorkflowRequest request) { + public PhenomlClientHttpResponse update(String id, UpdateWorkflowRequest request) { return update(id, request, null); } /** * Updates an existing workflow definition */ - public PhenoMLHttpResponse update( + public PhenomlClientHttpResponse update( String id, UpdateWorkflowRequest request, RequestOptions requestOptions) { HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -318,7 +318,7 @@ public PhenoMLHttpResponse update( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), WorkflowsUpdateResponse.class), response); } @@ -344,27 +344,27 @@ public PhenoMLHttpResponse update( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Deletes a workflow definition by its ID */ - public PhenoMLHttpResponse delete(String id) { + public PhenomlClientHttpResponse delete(String id) { return delete(id, null); } /** * Deletes a workflow definition by its ID */ - public PhenoMLHttpResponse delete(String id, RequestOptions requestOptions) { + public PhenomlClientHttpResponse delete(String id, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("workflows") @@ -383,7 +383,7 @@ public PhenoMLHttpResponse delete(String id, RequestOpt try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), WorkflowsDeleteResponse.class), response); } @@ -406,27 +406,27 @@ public PhenoMLHttpResponse delete(String id, RequestOpt } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } /** * Executes a workflow with provided input data and returns results */ - public PhenoMLHttpResponse execute(String id, ExecuteWorkflowRequest request) { + public PhenomlClientHttpResponse execute(String id, ExecuteWorkflowRequest request) { return execute(id, request, null); } /** * Executes a workflow with provided input data and returns results */ - public PhenoMLHttpResponse execute( + public PhenomlClientHttpResponse execute( String id, ExecuteWorkflowRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() @@ -439,7 +439,7 @@ public PhenoMLHttpResponse execute( body = RequestBody.create( ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); } catch (JsonProcessingException e) { - throw new PhenoMLException("Failed to serialize request", e); + throw new PhenomlClientException("Failed to serialize request", e); } Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -455,7 +455,7 @@ public PhenoMLHttpResponse execute( try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); if (response.isSuccessful()) { - return new PhenoMLHttpResponse<>( + return new PhenomlClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ExecuteWorkflowResponse.class), response); } @@ -481,13 +481,13 @@ public PhenoMLHttpResponse execute( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } - throw new PhenoMLApiException( + throw new PhenomlClientApiException( "Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), response); } catch (IOException e) { - throw new PhenoMLException("Network error executing HTTP request", e); + throw new PhenomlClientException("Network error executing HTTP request", e); } } } diff --git a/src/main/java/com/phenoml/api/resources/workflows/errors/BadRequestError.java b/src/main/java/com/phenoml/api/resources/workflows/errors/BadRequestError.java index 0002878..8bb790a 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/errors/BadRequestError.java +++ b/src/main/java/com/phenoml/api/resources/workflows/errors/BadRequestError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.workflows.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class BadRequestError extends PhenoMLApiException { +public final class BadRequestError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/workflows/errors/ForbiddenError.java b/src/main/java/com/phenoml/api/resources/workflows/errors/ForbiddenError.java index e13dcd2..d03c93b 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/errors/ForbiddenError.java +++ b/src/main/java/com/phenoml/api/resources/workflows/errors/ForbiddenError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.workflows.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class ForbiddenError extends PhenoMLApiException { +public final class ForbiddenError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/workflows/errors/InternalServerError.java b/src/main/java/com/phenoml/api/resources/workflows/errors/InternalServerError.java index 01b587f..33514a7 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/errors/InternalServerError.java +++ b/src/main/java/com/phenoml/api/resources/workflows/errors/InternalServerError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.workflows.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class InternalServerError extends PhenoMLApiException { +public final class InternalServerError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/workflows/errors/NotFoundError.java b/src/main/java/com/phenoml/api/resources/workflows/errors/NotFoundError.java index fdf9db0..98592d1 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/errors/NotFoundError.java +++ b/src/main/java/com/phenoml/api/resources/workflows/errors/NotFoundError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.workflows.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class NotFoundError extends PhenoMLApiException { +public final class NotFoundError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/resources/workflows/errors/UnauthorizedError.java b/src/main/java/com/phenoml/api/resources/workflows/errors/UnauthorizedError.java index 759d67b..4a9ab88 100644 --- a/src/main/java/com/phenoml/api/resources/workflows/errors/UnauthorizedError.java +++ b/src/main/java/com/phenoml/api/resources/workflows/errors/UnauthorizedError.java @@ -3,10 +3,10 @@ */ package com.phenoml.api.resources.workflows.errors; -import com.phenoml.api.core.PhenoMLApiException; +import com.phenoml.api.core.PhenomlClientApiException; import okhttp3.Response; -public final class UnauthorizedError extends PhenoMLApiException { +public final class UnauthorizedError extends PhenomlClientApiException { /** * The body of the response that triggered the exception. */ diff --git a/src/main/java/com/phenoml/api/wrapper/AsyncPhenoMLClient.java b/src/main/java/com/phenoml/api/wrapper/AsyncPhenoMLClient.java deleted file mode 100644 index 7806a7e..0000000 --- a/src/main/java/com/phenoml/api/wrapper/AsyncPhenoMLClient.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.phenoml.api.wrapper; - -import com.phenoml.api.AsyncPhenoML; -import com.phenoml.api.core.ClientOptions; -import com.phenoml.api.core.Environment; -import com.phenoml.api.resources.authtoken.AsyncAuthtokenClient; -import com.phenoml.api.resources.authtoken.auth.AsyncAuthClient; -import com.phenoml.api.resources.authtoken.auth.requests.AuthGenerateTokenRequest; -import com.phenoml.api.resources.authtoken.auth.types.AuthGenerateTokenResponse; -import java.util.concurrent.CompletableFuture; - -/** - * Simple async wrapper that extends the base AsyncPhenoML client with automatic token generation. - * Allows users to either pass a token directly or provide username+password. - */ -public class AsyncPhenoMLClient extends AsyncPhenoML { - - public AsyncPhenoMLClient(ClientOptions clientOptions) { - super(clientOptions); - } - - /** - * Create an async client with username/password authentication. - * Automatically generates a token using the auth endpoint. - */ - public static AsyncPhenoMLClient withCredentials(String username, String password, String baseUrl) { - if (username == null || password == null || baseUrl == null) { - throw new IllegalArgumentException("username, password, and baseUrl are required"); - } - - // Generate token immediately (like sync client) - String token = generateTokenSync(username, password, baseUrl); - - // Create client with generated token - ClientOptions options = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .addHeader("Authorization", "Bearer " + token) - .build(); - - return new AsyncPhenoMLClient(options); - } - - /** - * Create an async client with direct token authentication. - */ - public static AsyncPhenoMLClient withToken(String token, String baseUrl) { - if (token == null || baseUrl == null) { - throw new IllegalArgumentException("token and baseUrl are required"); - } - - ClientOptions options = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .addHeader("Authorization", "Bearer " + token) - .build(); - - return new AsyncPhenoMLClient(options); - } - - /** - * Initialize the client. Override this for custom initialization. - */ - public CompletableFuture initialize() { - return CompletableFuture.completedFuture(null); - } - - private static CompletableFuture generateTokenAsync(String username, String password, String baseUrl) { - return CompletableFuture.supplyAsync(() -> { - try { - ClientOptions tempOptions = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .build(); - - AsyncAuthtokenClient authClient = new AsyncAuthtokenClient(tempOptions); - AsyncAuthClient auth = authClient.auth(); - - AuthGenerateTokenRequest request = AuthGenerateTokenRequest.builder() - .username(username) - .password(password) - .build(); - - AuthGenerateTokenResponse response = auth.generateToken(request).join(); - return response.getToken(); - - } catch (Exception e) { - throw new RuntimeException("Failed to generate token: " + e.getMessage(), e); - } - }); - } - - private static String generateTokenSync(String username, String password, String baseUrl) { - try { - System.out.println("๐Ÿ” Generating async token for " + username + " at " + baseUrl); - - ClientOptions tempOptions = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .build(); - - AsyncAuthtokenClient authClient = new AsyncAuthtokenClient(tempOptions); - AsyncAuthClient auth = authClient.auth(); - - AuthGenerateTokenRequest request = AuthGenerateTokenRequest.builder() - .username(username) - .password(password) - .build(); - - System.out.println("๐Ÿ“ค Async Auth Request: " + request.toString()); - AuthGenerateTokenResponse response = auth.generateToken(request).join(); - System.out.println("๐Ÿ“ฅ Async Auth Response: " + response.toString()); - - String token = response.getToken(); - System.out.println("โœ… Async token generated successfully (length: " + token.length() + ")"); - return token; - - } catch (Exception e) { - System.out.println("โŒ Failed to generate async token: " + e.getMessage()); - throw new RuntimeException("Failed to generate token: " + e.getMessage(), e); - } - } -} diff --git a/src/main/java/com/phenoml/api/wrapper/PhenoMLClient.java b/src/main/java/com/phenoml/api/wrapper/PhenoMLClient.java deleted file mode 100644 index 0c74da4..0000000 --- a/src/main/java/com/phenoml/api/wrapper/PhenoMLClient.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.phenoml.api.wrapper; - -import com.phenoml.api.PhenoML; -import com.phenoml.api.core.ClientOptions; -import com.phenoml.api.core.Environment; -import com.phenoml.api.resources.authtoken.AuthtokenClient; -import com.phenoml.api.resources.authtoken.auth.AuthClient; -import com.phenoml.api.resources.authtoken.auth.requests.AuthGenerateTokenRequest; -import com.phenoml.api.resources.authtoken.auth.types.AuthGenerateTokenResponse; - -/** - * Simple wrapper that extends the base PhenoML client with automatic token generation. - * Allows users to either pass a token directly or provide username+password. - */ -public class PhenoMLClient extends PhenoML { - - public PhenoMLClient(ClientOptions clientOptions) { - super(clientOptions); - } - - /** - * Create a client with username/password authentication. - * Automatically generates a token using the auth endpoint. - */ - public static PhenoMLClient withCredentials(String username, String password, String baseUrl) { - // Validate inputs - if (username == null || password == null || baseUrl == null) { - throw new IllegalArgumentException("username, password, and baseUrl are required"); - } - - // Generate token - String token = generateToken(username, password, baseUrl); - - // Create client with generated token - ClientOptions options = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .addHeader("Authorization", "Bearer " + token) - .build(); - - return new PhenoMLClient(options); - } - - /** - * Create a client with direct token authentication. - */ - public static PhenoMLClient withToken(String token, String baseUrl) { - if (token == null || baseUrl == null) { - throw new IllegalArgumentException("token and baseUrl are required"); - } - - ClientOptions options = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .addHeader("Authorization", "Bearer " + token) - .build(); - - return new PhenoMLClient(options); - } - - private static String generateToken(String username, String password, String baseUrl) { - try { - System.out.println("๐Ÿ” Generating token for " + username + " at " + baseUrl); - - // Create temporary client for auth request - ClientOptions tempOptions = ClientOptions.builder() - .environment(Environment.custom(baseUrl)) - .build(); - - AuthtokenClient authClient = new AuthtokenClient(tempOptions); - AuthClient auth = authClient.auth(); - - AuthGenerateTokenRequest request = AuthGenerateTokenRequest.builder() - .username(username) - .password(password) - .build(); - - System.out.println("๐Ÿ“ค Auth Request: " + request.toString()); - AuthGenerateTokenResponse response = auth.generateToken(request); - System.out.println("๐Ÿ“ฅ Auth Response: " + response.toString()); - - String token = response.getToken(); - System.out.println("โœ… Token generated successfully (length: " + token.length() + ")"); - return token; - - } catch (Exception e) { - System.out.println("โŒ Failed to generate token: " + e.getMessage()); - throw new RuntimeException("Failed to generate token: " + e.getMessage(), e); - } - } -} From 47fe1ba2edee584bb04f4b4da165ff3a00a8b675 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 4 Mar 2026 15:49:21 -0500 Subject: [PATCH 2/7] chore: bump version to 9.0.0 and update changelog for major release Update version from 8.3.1 to 9.0.0 across build.gradle, ClientOptions.java, and changelog.md to reflect the breaking changes in this release (OAuth 2.0 auth migration and client class renames). Co-Authored-By: Claude Opus 4.6 --- build.gradle | 4 ++-- changelog.md | 22 ++++++++++++++++--- .../com/phenoml/api/core/ClientOptions.java | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 491bbb6..b37d0b1 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ java { group = 'com.phenoml.maven' -version = '8.3.1' +version = '9.0.0' jar { dependsOn(":generatePomFileForMavenPublication") @@ -78,7 +78,7 @@ publishing { maven(MavenPublication) { groupId = 'com.phenoml.maven' artifactId = 'phenoml-java-sdk' - version = '8.3.1' + version = '9.0.0' from components.java pom { name = 'phenoml' diff --git a/changelog.md b/changelog.md index 03372f5..226f350 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,22 @@ -## 8.3.1 - 2026-03-04 -* SDK regeneration -* Unable to analyze changes with AI, incrementing PATCH version. +## 9.0.0 - 2026-03-04 + +### Breaking Changes + +- **Authentication**: Migrated from token-based auth to OAuth 2.0 client credentials flow. Builders now accept `clientId()` and `clientSecret()` (defaulting to `PHENOML_CLIENT_ID` and `PHENOML_CLIENT_SECRET` environment variables) instead of `token()`. Tokens are automatically obtained and refreshed via the `/v2/auth/token` endpoint. +- **Client renamed**: `PhenoML` โ†’ `PhenomlClient`, `AsyncPhenoML` โ†’ `AsyncPhenomlClient`. +- **Builder renamed**: `PhenoMLBuilder` โ†’ `PhenomlClientBuilder`, `AsyncPhenoMLBuilder` โ†’ `AsyncPhenomlClientBuilder`. +- **Wrapper clients removed**: `Client.java` and `AsyncClient.java` convenience wrappers have been removed. Use `PhenomlClient` / `AsyncPhenomlClient` directly. + +### Added + +- New `/v2/auth/token` OAuth 2.0 client credentials endpoint with `ClientCredentialsRequest`, `TokenResponse`, and `OAuthError` types. +- `OAuthTokenSupplier` for automatic token acquisition and caching. +- `InternalServerError` error type for authtoken module. + +### Internal + +- Upgraded Fern Java SDK generator and CLI. +- Error classes now include structured response bodies. ## 8.3.0 - 2026-03-03 * feat: add document multi-resource extraction endpoint diff --git a/src/main/java/com/phenoml/api/core/ClientOptions.java b/src/main/java/com/phenoml/api/core/ClientOptions.java index 9a81db2..d290518 100644 --- a/src/main/java/com/phenoml/api/core/ClientOptions.java +++ b/src/main/java/com/phenoml/api/core/ClientOptions.java @@ -32,10 +32,10 @@ private ClientOptions( this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.phenoml.maven:phenoml-java-sdk/8.3.1"); + put("User-Agent", "com.phenoml.maven:phenoml-java-sdk/9.0.0"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.phenoml.fern:api-sdk"); - put("X-Fern-SDK-Version", "8.3.1"); + put("X-Fern-SDK-Version", "9.0.0"); } }); this.headerSuppliers = headerSuppliers; From 817a942a1ce6de7ecd08905cb1eb41e518413f21 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 4 Mar 2026 15:53:27 -0500 Subject: [PATCH 3/7] Add migration guide to 9.0.0 changelog entry Add a Migration Guide section to the 9.0.0 changelog with code examples showing how to update authentication and imports from the old PhenoMLClient to the new PhenomlClient with OAuth 2.0 client credentials. Co-Authored-By: Claude Opus 4.6 --- changelog.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/changelog.md b/changelog.md index 226f350..7ff24ac 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,38 @@ - **Builder renamed**: `PhenoMLBuilder` โ†’ `PhenomlClientBuilder`, `AsyncPhenoMLBuilder` โ†’ `AsyncPhenomlClientBuilder`. - **Wrapper clients removed**: `Client.java` and `AsyncClient.java` convenience wrappers have been removed. Use `PhenomlClient` / `AsyncPhenomlClient` directly. +### Migration Guide + +**Authentication** โ€” replace token-based auth with client credentials: + +```java +// Before +PhenoMLClient client = PhenoMLClient.withCredentials("user", "pass", "https://api.phenoml.com"); +// or +PhenoMLClient client = PhenoMLClient.withToken("YOUR_TOKEN", "https://api.phenoml.com"); + +// After (option 1: env vars PHENOML_CLIENT_ID and PHENOML_CLIENT_SECRET) +PhenomlClient client = PhenomlClient.builder().build(); + +// After (option 2: explicit credentials) +PhenomlClient client = PhenomlClient.builder() + .clientId("YOUR_CLIENT_ID") + .clientSecret("YOUR_CLIENT_SECRET") + .build(); +``` + +**Import updates:** + +```java +// Before +import com.phenoml.api.Client; +// or +import com.phenoml.api.wrapper.PhenoMLClient; + +// After +import com.phenoml.api.PhenomlClient; +``` + ### Added - New `/v2/auth/token` OAuth 2.0 client credentials endpoint with `ClientCredentialsRequest`, `TokenResponse`, and `OAuthError` types. From 8a0050c802e7df5364d04a1f26d79a1df0ad3511 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 4 Mar 2026 15:57:37 -0500 Subject: [PATCH 4/7] Update changelog authentication wording to reference username/password Co-Authored-By: Claude Opus 4.6 --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 7ff24ac..0370b66 100644 --- a/changelog.md +++ b/changelog.md @@ -2,14 +2,14 @@ ### Breaking Changes -- **Authentication**: Migrated from token-based auth to OAuth 2.0 client credentials flow. Builders now accept `clientId()` and `clientSecret()` (defaulting to `PHENOML_CLIENT_ID` and `PHENOML_CLIENT_SECRET` environment variables) instead of `token()`. Tokens are automatically obtained and refreshed via the `/v2/auth/token` endpoint. +- **Authentication**: Replaced username/password authentication with OAuth 2.0 client credentials. Builders now accept `clientId()` and `clientSecret()` (defaulting to `PHENOML_CLIENT_ID` and `PHENOML_CLIENT_SECRET` environment variables). Tokens are automatically obtained and refreshed via the `/v2/auth/token` endpoint. - **Client renamed**: `PhenoML` โ†’ `PhenomlClient`, `AsyncPhenoML` โ†’ `AsyncPhenomlClient`. - **Builder renamed**: `PhenoMLBuilder` โ†’ `PhenomlClientBuilder`, `AsyncPhenoMLBuilder` โ†’ `AsyncPhenomlClientBuilder`. - **Wrapper clients removed**: `Client.java` and `AsyncClient.java` convenience wrappers have been removed. Use `PhenomlClient` / `AsyncPhenomlClient` directly. ### Migration Guide -**Authentication** โ€” replace token-based auth with client credentials: +**Authentication** โ€” replace username/password with client credentials: ```java // Before From 9ab69c3f7f39be757461fe2bda728ebd1c289170 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 4 Mar 2026 16:00:13 -0500 Subject: [PATCH 5/7] Remove Internal section from 9.0.0 changelog entry Co-Authored-By: Claude Opus 4.6 --- changelog.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/changelog.md b/changelog.md index 0370b66..e464443 100644 --- a/changelog.md +++ b/changelog.md @@ -45,11 +45,6 @@ import com.phenoml.api.PhenomlClient; - `OAuthTokenSupplier` for automatic token acquisition and caching. - `InternalServerError` error type for authtoken module. -### Internal - -- Upgraded Fern Java SDK generator and CLI. -- Error classes now include structured response bodies. - ## 8.3.0 - 2026-03-03 * feat: add document multi-resource extraction endpoint * Add a new endpoint for extracting multiple FHIR resources from documents (PDF/images). From 39990c7fb93e5027d04eeb0df583a3fa9a1c821c Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 4 Mar 2026 16:01:27 -0500 Subject: [PATCH 6/7] Update API endpoint references in changelog.md --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index e464443..495b831 100644 --- a/changelog.md +++ b/changelog.md @@ -13,9 +13,9 @@ ```java // Before -PhenoMLClient client = PhenoMLClient.withCredentials("user", "pass", "https://api.phenoml.com"); +PhenoMLClient client = PhenoMLClient.withCredentials("user", "pass", "https://yourinstance.app.pheno.ml"); // or -PhenoMLClient client = PhenoMLClient.withToken("YOUR_TOKEN", "https://api.phenoml.com"); +PhenoMLClient client = PhenoMLClient.withToken("YOUR_TOKEN", "https://yourinstance.app.pheno.ml"); // After (option 1: env vars PHENOML_CLIENT_ID and PHENOML_CLIENT_SECRET) PhenomlClient client = PhenomlClient.builder().build(); From 26936104f3b4923d55bc7dbf1eb2c547170b3fc2 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 4 Mar 2026 16:09:10 -0500 Subject: [PATCH 7/7] Update migration guide with .url() builder calls and simplified examples Co-Authored-By: Claude Opus 4.6 --- changelog.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 495b831..69a9752 100644 --- a/changelog.md +++ b/changelog.md @@ -13,17 +13,19 @@ ```java // Before -PhenoMLClient client = PhenoMLClient.withCredentials("user", "pass", "https://yourinstance.app.pheno.ml"); -// or -PhenoMLClient client = PhenoMLClient.withToken("YOUR_TOKEN", "https://yourinstance.app.pheno.ml"); +PhenoMLClient client = PhenoMLClient.withCredentials( + "user", "pass", "https://yourinstance.app.pheno.ml"); // After (option 1: env vars PHENOML_CLIENT_ID and PHENOML_CLIENT_SECRET) -PhenomlClient client = PhenomlClient.builder().build(); +PhenomlClient client = PhenomlClient.builder() + .url("https://yourinstance.app.pheno.ml") + .build(); // After (option 2: explicit credentials) PhenomlClient client = PhenomlClient.builder() .clientId("YOUR_CLIENT_ID") .clientSecret("YOUR_CLIENT_SECRET") + .url("https://yourinstance.app.pheno.ml") .build(); ```