Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Provide a new open APl to return the organization list(#5349) #102

Merged
merged 8 commits into from
Mar 30, 2025

Conversation

wjwang00
Copy link
Contributor

@wjwang00 wjwang00 commented Mar 25, 2025

What's the purpose of this PR

feat: Provide a new open APl to return the organization list(#5349)

Which issue(s) this PR fixes:

#5349

Brief changelog

After updating the project, we can use this method like this way:

       String portalUrl = "http://localhost:8070"; // portal url
        String token = "25e545146773469d1b9874339849487dc89f28e6d6e0dbd75a1664cca3bb1ada"; // 申请的token
        ApolloOpenApiClient client = ApolloOpenApiClient.newBuilder()
                .withPortalUrl(portalUrl)
                .withToken(token)
                .build();
        client.getOrganization().forEach(System.out::println);

PixPin_2025-03-25_22-07-06

Summary by CodeRabbit

  • New Features
    • Added a capability to retrieve organization information directly via the API client.
    • Introduced a service that fetches a list of organizations.
    • Implemented a standardized representation for organization details.
    • Added a new open API to return the organization list in version 2.5.0.

Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

Walkthrough

This pull request introduces a new organization service within the Apollo OpenAPI framework. A new interface is added to declare a method for retrieving organization data, and a corresponding implementation is provided to perform an HTTP GET call and parse the response into DTOs. The ApolloOpenApiClient is updated with a new member that uses the organization service and a public method to fetch the organization data. Additionally, a new DTO class is introduced to encapsulate organization information.

Changes

File(s) Change Summary
apollo-openapi/src/main/java/…/api/OrganizationOpenApiService.java Added a new interface OrganizationOpenApiService that defines the method getOrganizations().
apollo-openapi/src/main/java/…/client/ApolloOpenApiClient.java Introduced a private final field for the organization service and added a new public method getOrganizations() to retrieve organization data. Minor formatting adjustments made in the constructor.
apollo-openapi/src/main/java/…/client/service/OrganizationOpenApiService.java Added a new class OrganizationOpenApiService that implements the interface and provides the functionality to fetch organization data via an HTTP GET request.
apollo-openapi/src/main/java/…/dto/OpenOrganizationDto.java Added a new DTO class OpenOrganizationDto with fields orgId and orgName, including getters, setters, and an overridden toString() method.
CHANGES.md Added a feature entry for version 2.5.0, highlighting the new open API to return the organization list.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant A as ApolloOpenApiClient
    participant O as OrganizationOpenApiService
    participant H as HTTP Service

    C->>A: getOrganizations()
    A->>O: getOrganizations()
    O->>H: GET /organizations
    H-->>O: JSON Response
    O-->>A: List<OpenOrganizationDto>
    A-->>C: List<OpenOrganizationDto>
Loading

Poem

Hoppin' through the code with zeal,
I found a service that's very real.
Organizations now in a neat array,
HTTP calls whisk data away!
I'm a rabbit, dancing in pure delight,
Celebrating changes from morning to night!
🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 922e1df and 283f14f.

📒 Files selected for processing (3)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenOrganizationDto.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenOrganizationDto.java
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Mar 25, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (1)

89-94: Consider renaming method for consistency.

The method is named getOrganization() (singular) but returns a list of organizations and calls getOrganizations() (plural) internally. Consider renaming for consistency:

- public List<OpenOrganizationDto> getOrganization() {
+ public List<OpenOrganizationDto> getOrganizations() {
    return organizationOpenService.getOrganizations();
  }
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1)

39-50: API implementation looks good, but consider more specific error handling.

The implementation correctly builds the API path and handles the HTTP request. The error handling catches all exceptions but could be more specific.

Consider providing more specific error messages based on exception types:

  try (CloseableHttpResponse response = get(pathBuilder)) {
      return gson.fromJson(EntityUtils.toString(response.getEntity()), ORGANIZATIONS_DTO_LIST_TYPE);
-  } catch (Throwable ex) {
-      throw new RuntimeException("get organizations information failed", ex);
+  } catch (IOException ex) {
+      throw new RuntimeException("Failed to read organizations response from API", ex);
+  } catch (JsonSyntaxException ex) {
+      throw new RuntimeException("Failed to parse organizations JSON response", ex);
+  } catch (Throwable ex) {
+      throw new RuntimeException("Unexpected error when getting organizations information", ex);
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0cad99 and 6ba3426.

📒 Files selected for processing (4)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (5 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenOrganizationDto.java (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java (2)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenOrganizationDto.java (1)
  • OpenOrganizationDto (20-47)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1)
  • OrganizationOpenApiService (30-51)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (1)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1)
  • OrganizationOpenApiService (30-51)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenOrganizationDto.java (1)
  • OpenOrganizationDto (20-47)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)
🔇 Additional comments (8)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenOrganizationDto.java (1)

20-46: Looks good - well-structured DTO implementation.

The OpenOrganizationDto class follows standard Java bean conventions with proper getters, setters, and toString implementation. The fields are appropriately named and the class is focused on a single responsibility.

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java (1)

23-26: Interface design looks good.

The interface is clean, concise, and follows the single responsibility principle. It properly defines the contract for fetching organizations with an appropriately typed return value.

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (4)

25-25: Import statement looks good.

The import for the new service is correctly added.


49-49: Field declaration is appropriate.

The service field is correctly declared as private final, consistent with other service declarations in this class.


59-60: Spacing/indentation improvement.

The indentation is now more consistent with the rest of the code.


68-68: Service initialization looks good.

The organization service is properly instantiated with the same parameters as other services.

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (2)

30-35: Service implementation looks good.

The class properly extends AbstractOpenApiService and implements the OrganizationOpenApiService interface. The constructor correctly calls the super constructor with all required parameters.


36-38: Type token for deserialization is well-implemented.

The ORGANIZATIONS_DTO_LIST_TYPE constant is correctly defined using TypeToken for JSON deserialization of the list of DTOs.

@wjwang00
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@spaceluke
Copy link
Member

@nobodyiam PTAL

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

Please also update the CHANGES.md

wjwang00 and others added 5 commits March 29, 2025 11:01
…i/client/ApolloOpenApiClient.java

Co-authored-by: Jason Song <[email protected]>
…i/api/OrganizationOpenApiService.java

Co-authored-by: Jason Song <[email protected]>
…i/client/ApolloOpenApiClient.java

Co-authored-by: Jason Song <[email protected]>
…i/client/service/OrganizationOpenApiService.java

Co-authored-by: Jason Song <[email protected]>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (1)

49-49: Consider renaming for consistency with other service fields

The field name organizationOpenService doesn't follow the same naming pattern as other service fields like appService, itemService, etc. Consider renaming it to organizationService for better consistency.

-  private final OrganizationOpenApiService organizationOpenService;
+  private final OrganizationOpenApiService organizationService;

Remember to update the reference in the constructor and the getOrganizations() method as well.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ba3426 and 922e1df.

📒 Files selected for processing (4)
  • CHANGES.md (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java (1 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (4 hunks)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGES.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/OrganizationOpenApiService.java
  • apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java
🧰 Additional context used
🧬 Code Definitions (1)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (1)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/OrganizationOpenApiService.java (1)
  • OrganizationOpenApiService (30-52)
🔇 Additional comments (1)
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java (1)

89-94: LGTM! New method follows established patterns

The implementation correctly delegates to the service layer and follows the same pattern as other methods in this class.

@wjwang00
Copy link
Contributor Author

Please also update the CHANGES.md

Thank you for your review and suggestions. I have updated the CHANGES.md and applied all the Commit suggestions.

…i/client/service/OrganizationOpenApiService.java
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@nobodyiam nobodyiam merged commit 27fc0a5 into apolloconfig:main Mar 30, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants