Skip to content

cleanups#34

Merged
orpiske merged 7 commits intowanaku-ai:mainfrom
orpiske:cleanups
Dec 2, 2025
Merged

cleanups#34
orpiske merged 7 commits intowanaku-ai:mainfrom
orpiske:cleanups

Conversation

@orpiske
Copy link
Copy Markdown
Contributor

@orpiske orpiske commented Dec 2, 2025

  • Removed redundant variables
  • Use implicit types in generics
  • Throw a more appropriate exception when dealing with invalid response data
  • Use lambdas when simpler
  • Removed redundant groupId
  • Use the HTTPs address for Wanaku website
  • Use HTTPs for the license address

Summary by Sourcery

Apply code and configuration cleanups across HTTP clients, data utilities, tests, and Maven metadata.

Bug Fixes:

  • Throw domain-specific exceptions for JSON processing and I/O issues in discovery service HTTP client.

Enhancements:

  • Use Java implicit generic type inference in HTTP client responses to simplify type declarations.
  • Simplify stream and file helper methods by removing redundant local variables and returning expressions directly.
  • Use more concise lambda syntax in tests for instance data reader construction.

Build:

  • Update Maven POM metadata to use HTTPS URLs for organization and license information.

Chores:

  • Remove redundant groupId declaration from the archetypes module POM.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Dec 2, 2025

Reviewer's Guide

Refactors several client and utility classes for cleaner, more idiomatic Java usage (implicit Jackson TypeReference generics, lambdas, and direct returns), tightens exception types in the discovery HTTP client, simplifies configuration/data-file helpers, and modernizes Maven metadata URLs and coordinates.

Sequence diagram for updated error handling in updateState HTTP call

sequenceDiagram
    actor ServiceClient
    participant DiscoveryServiceHttpClient
    participant HttpClient

    ServiceClient->>DiscoveryServiceHttpClient: updateState(id, serviceState)
    DiscoveryServiceHttpClient->>DiscoveryServiceHttpClient: serialize serviceState to json

    alt JsonProcessingException
        DiscoveryServiceHttpClient-->>ServiceClient: throw InvalidResponseDataException
    else InterruptedException or IOException
        DiscoveryServiceHttpClient-->>ServiceClient: throw WanakuException
    else Success
        DiscoveryServiceHttpClient->>HttpClient: send(request)
        HttpClient-->>DiscoveryServiceHttpClient: HttpResponse
        DiscoveryServiceHttpClient-->>ServiceClient: HttpResponse
    end
Loading

Updated class diagram for DiscoveryServiceHttpClient exception behavior

classDiagram
    class DiscoveryServiceHttpClient {
        -HttpClient httpClient
        +HttpResponseString updateState(String id, ServiceState serviceState)
    }

    class WanakuException {
    }

    class InvalidResponseDataException {
    }

    DiscoveryServiceHttpClient ..> WanakuException : throws
    DiscoveryServiceHttpClient ..> InvalidResponseDataException : throws
Loading

File-Level Changes

Change Details Files
Use implicit generic type inference for Jackson TypeReference instances in the services HTTP client.
  • Replace explicit generic parameters in TypeReference instantiations with the diamond operator to rely on type inference in executePost and executeGet calls for tools, resources, forwards, namespaces, and data stores APIs.
  • Ensure the response types are still determined by the method signatures while reducing verbosity in the client code.
capabilities-services-client/src/main/java/ai/wanaku/capabilities/sdk/services/ServicesHttpClient.java
Refine exception handling in the discovery HTTP client to use domain-specific exception types.
  • Wrap JsonProcessingException in an InvalidResponseDataException to more accurately represent invalid or unserializable response content.
  • Wrap InterruptedException and IOException in a WanakuException to surface transport/runtime issues through the library’s domain exception hierarchy.
capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/DiscoveryServiceHttpClient.java
Simplify code by removing redundant temporary variables and using lambdas directly.
  • Inline the InstanceDataReader constructor call directly into assertThrows using a lambda expression in the unit test.
  • Return the collected map directly in PropertyBasedStore.getEntries(String prefix) instead of assigning to an intermediate variable.
  • Inline the File construction in DataFileHelper.newRandomizedDataFile by returning the new File directly.
capabilities-data-files/src/test/java/ai/wanaku/capabilities/sdk/data/files/InstanceDataReaderTest.java
capabilities-config-providers/capabilities-config-provider-api/src/main/java/ai/wanaku/capabilities/sdk/config/provider/api/PropertyBasedStore.java
capabilities-data-files/src/main/java/ai/wanaku/capabilities/sdk/data/files/util/DataFileHelper.java
Update Maven project metadata to remove redundant groupId and use HTTPS URLs for organization and license.
  • Remove the redundant groupId declaration from the capabilities-archetypes child POM so it inherits the parent’s groupId.
  • Switch the developer organizationUrl to use HTTPS for the Wanaku website.
  • Update the project license URL to the HTTPS Apache 2.0 license endpoint.
pom.xml
capabilities-archetypes/pom.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The repeated new TypeReference<>() {} usages in ServicesHttpClient could be extracted into reusable constants or helper methods to avoid creating many anonymous subclasses and to keep the call sites cleaner.
  • In DiscoveryServiceHttpClient.updateState, consider whether using two different exception types (InvalidResponseDataException for JSON issues vs WanakuException for IO/interrupt) is intentional, and if not, aligning them to a single domain-specific exception would simplify error handling for callers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The repeated `new TypeReference<>() {}` usages in `ServicesHttpClient` could be extracted into reusable constants or helper methods to avoid creating many anonymous subclasses and to keep the call sites cleaner.
- In `DiscoveryServiceHttpClient.updateState`, consider whether using two different exception types (`InvalidResponseDataException` for JSON issues vs `WanakuException` for IO/interrupt) is intentional, and if not, aligning them to a single domain-specific exception would simplify error handling for callers.

## Individual Comments

### Comment 1
<location> `capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/DiscoveryServiceHttpClient.java:162-164` </location>
<code_context>
             return httpClient.send(request, HttpResponse.BodyHandlers.ofString());
         } catch (JsonProcessingException e) {
-            throw new RuntimeException(e);
+            throw new InvalidResponseDataException(e);
         } catch (InterruptedException | IOException e) {
-            throw new RuntimeException(e);
+            throw new WanakuException(e);
         }
     }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** InterruptedException is wrapped without restoring the thread’s interrupted status, which may cause subtle issues for callers that rely on interruption.

Catching `InterruptedException` clears the thread’s interrupted flag. Since this code is being modified anyway, please either re-set the flag with `Thread.currentThread().interrupt()` before throwing the wrapper, or (if possible) propagate `InterruptedException` directly so callers that rely on interruption semantics can still detect it.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +162 to +164
throw new InvalidResponseDataException(e);
} catch (InterruptedException | IOException e) {
throw new RuntimeException(e);
throw new WanakuException(e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): InterruptedException is wrapped without restoring the thread’s interrupted status, which may cause subtle issues for callers that rely on interruption.

Catching InterruptedException clears the thread’s interrupted flag. Since this code is being modified anyway, please either re-set the flag with Thread.currentThread().interrupt() before throwing the wrapper, or (if possible) propagate InterruptedException directly so callers that rely on interruption semantics can still detect it.

@orpiske orpiske merged commit 7487d8a into wanaku-ai:main Dec 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant