Skip to content

chore: refactor the appsmith-ai plugin trigger#38303

Merged
nsarupr merged 4 commits intoreleasefrom
chore/refactor-appsmith-ai-plugin
Dec 23, 2024
Merged

chore: refactor the appsmith-ai plugin trigger#38303
nsarupr merged 4 commits intoreleasefrom
chore/refactor-appsmith-ai-plugin

Conversation

@nsarupr
Copy link
Contributor

@nsarupr nsarupr commented Dec 23, 2024

Description

Important

Refactor the Appsmith AI Plugin trigger method.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12462586013
Commit: 5dc9f81
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Mon, 23 Dec 2024 07:30:58 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a new service for managing file upload and listing operations.
    • Added structured handling of triggers for file-related actions.
  • Bug Fixes
    • Enhanced error management for file operations to improve logging and response handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

Warning

Rate limit exceeded

@nsarupr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 470928f and 5dc9f81.

📒 Files selected for processing (3)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java (3 hunks)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceCEImpl.java (1 hunks)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceImpl.java (1 hunks)

Walkthrough

The pull request introduces a refactor of the AppsmithAiPlugin.java file by implementing a new TriggerService to handle file-related operations. The inline logic in the trigger method of the AppsmithAiPluginExecutor class has been replaced with a call to triggerService.executeTrigger, which encapsulates the handling of UPLOAD_FILES and LIST_FILES requests. This change aims to enhance code modularity and maintainability by separating concerns related to trigger execution.

Changes

File Change Summary
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java - Added TriggerService instance
- Refactored trigger method to delegate to TriggerService for handling requests
- Removed inline logic for file handling
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerService.java - Introduced new interface TriggerService
- Defined method executeTrigger for handling trigger execution
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceCEImpl.java - Added class TriggerServiceCEImpl implementing TriggerService
- Defined methods uploadFiles, listFiles, and handleError for processing requests
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceImpl.java - Added class TriggerServiceImpl extending TriggerServiceCEImpl
- Overridden executeTrigger method to maintain existing functionality

Possibly related PRs

Suggested labels

Task, Anvil Pod

Suggested reviewers

  • sharat87
  • albinAppsmith

Poem

In the realm of code, a change so bright,
A TriggerService shines, taking flight.
With methods refined, and logic so clear,
Complexity fades, as we cheer!
🌟 Appsmith's magic, now draws near! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 23, 2024
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)
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java (2)

91-101: Add input validation for files

Consider adding validation for request.getFiles() to handle null or empty file lists gracefully.

 private Mono<TriggerResultDTO> uploadFiles(TriggerRequestDTO request) {
+    if (request.getFiles() == null || request.getFiles().isEmpty()) {
+        return handleError("No files provided for upload", 
+            new AppsmithPluginException(
+                AppsmithPluginError.PLUGIN_ERROR,
+                "Files list cannot be empty"
+            ));
+    }
     SourceDetails sourceDetails = SourceDetails.createSourceDetails(request);
     return aiServerService

103-133: Extract response transformation logic

Consider extracting the file status to dropdown option transformation logic into a separate method for better maintainability.

+    private Map<String, Object> createDropdownOption(FileStatus file) {
+        Map<String, Object> option = new HashMap<>();
+        option.put(LABEL, file.isProcessed() 
+            ? file.getName() 
+            : "(Processing...) " + file.getName());
+        option.put(VALUE, file.getId());
+        option.put(DISABLED, !file.isProcessed());
+        return option;
+    }

     private Mono<TriggerResultDTO> listFiles(
             DatasourceConfiguration datasourceConfiguration, TriggerRequestDTO request) {
         // ... existing code ...
         return aiServerService
                 .getFilesStatus(fileIds, sourceDetails)
                 .flatMap(fileStatusDTO -> {
                     List<Map<String, Object>> response = fileStatusDTO.getFiles()
                         .stream()
                         .map(this::createDropdownOption)
                         .collect(Collectors.toList());
                     TriggerResultDTO triggerResultDTO = new TriggerResultDTO();
                     triggerResultDTO.setTrigger(response);
                     return Mono.just(triggerResultDTO);
                 })
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c69d7a2 and 826c33b.

📒 Files selected for processing (1)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java (1 hunks)
🔇 Additional comments (2)
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java (2)

84-89: Clean refactor using switch expression

Good use of Java's modern switch expression syntax for better readability and maintainability.


91-133: Verify error handling consistency

Let's verify that the error handling pattern in the new methods aligns with the rest of the codebase.

✅ Verification successful

Based on the search results, I can see that the error handling pattern used in the new methods (uploadFiles and listFiles) follows the consistent pattern used throughout the codebase:

  1. Using onErrorResume to handle errors
  2. Providing meaningful error messages
  3. Transforming errors into appropriate response formats

The error handling in the new methods matches the established patterns:

  • Using handleError helper method
  • Providing descriptive error messages
  • Maintaining the reactive flow with Mono
  • Properly transforming errors into TriggerResultDTO

Error handling implementation is consistent with codebase patterns

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for error handling patterns in the codebase
rg -A 2 "onErrorResume|handleError" --type java

Length of output: 68959

@nsarupr nsarupr added the ok-to-test Required label for CI label Dec 23, 2024
@nsarupr nsarupr requested a review from trishaanand December 23, 2024 05:29
trishaanand
trishaanand previously approved these changes Dec 23, 2024
@nsarupr
Copy link
Contributor Author

nsarupr commented Dec 23, 2024

/build-deploy-preview skip-tests=true

@nsarupr nsarupr self-assigned this Dec 23, 2024
@nsarupr nsarupr removed the ok-to-test Required label for CI label Dec 23, 2024
@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12462455598.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38303.
recreate: .

@nsarupr nsarupr added the ok-to-test Required label for CI label Dec 23, 2024
@nsarupr nsarupr requested a review from trishaanand December 23, 2024 06:36
@github-actions
Copy link

Deploy-Preview-URL: https://ce-38303.dp.appsmith.com

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: 1

🧹 Nitpick comments (5)
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceCEImpl.java (4)

25-26: Consider documenting class responsibilities.
Adding a class-level Javadoc outlining the purpose and responsibilities of this service interface will improve maintainability.


41-51: Validate non-empty file list to avoid NPE.
When request.getFiles() is null or empty, the code might encounter unexpected errors. Consider a null check or an empty check to proactively return a helpful error or message.

private Mono<TriggerResultDTO> uploadFiles(TriggerRequestDTO request) {
+    if (request.getFiles() == null || request.getFiles().isEmpty()) {
+        return Mono.error(
+            new AppsmithPluginException(
+                AppsmithPluginError.PLUGIN_ERROR,
+                "No files provided to upload"
+            )
+        );
+    }
    
    SourceDetails sourceDetails = SourceDetails.createSourceDetails(request);
    ...
}

53-84: Consider scalability for large file sets.
The current approach works well for small file sets. If the number of files grows significantly, you may want to buffer or parallelize the retrieval process to improve performance.


86-92: Log full stack trace for easier debugging.
Currently, only the error message is logged. Including the stack trace can streamline troubleshooting.

log.error("{}. Error: {}", message, error.getMessage());
+log.debug("Full stack trace:", error);
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceImpl.java (1)

9-15: Extend to add custom logic or validations.
Overriding the method without changes is fine as a pass-through, but consider whether any specialized logging or pre/post-processing might benefit this layer.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 826c33b and 470928f.

📒 Files selected for processing (4)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java (3 hunks)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerService.java (1 hunks)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceCEImpl.java (1 hunks)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/AppsmithAiPlugin.java
🔇 Additional comments (1)
app/server/appsmith-plugins/appsmithAiPlugin/src/main/java/com/external/plugins/services/TriggerService.java (1)

9-12: Interface definition looks solid.
This interface is concise and well-suited to handle trigger-related logic. Documenting the contract and expected usage of the method would help future contributors.

Comment on lines +30 to +39
@Override
public Mono<TriggerResultDTO> executeTrigger(
APIConnection connection, DatasourceConfiguration datasourceConfiguration, TriggerRequestDTO request) {
String requestType = request.getRequestType();
return switch (requestType) {
case UPLOAD_FILES -> this.uploadFiles(request);
case LIST_FILES -> this.listFiles(datasourceConfiguration, request);
default -> Mono.empty();
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle unknown request types in the switch statement.
Returning Mono.empty() for unrecognized request types might silently mask errors. Consider either returning a descriptive error or logging an alert to help surface unexpected request types.

default -> {
-    return Mono.empty();
+    return Mono.error(new AppsmithPluginException(
+        AppsmithPluginError.PLUGIN_ERROR,
+        "Unknown request type: " + requestType
+    ));
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public Mono<TriggerResultDTO> executeTrigger(
APIConnection connection, DatasourceConfiguration datasourceConfiguration, TriggerRequestDTO request) {
String requestType = request.getRequestType();
return switch (requestType) {
case UPLOAD_FILES -> this.uploadFiles(request);
case LIST_FILES -> this.listFiles(datasourceConfiguration, request);
default -> Mono.empty();
};
}
@Override
public Mono<TriggerResultDTO> executeTrigger(
APIConnection connection, DatasourceConfiguration datasourceConfiguration, TriggerRequestDTO request) {
String requestType = request.getRequestType();
return switch (requestType) {
case UPLOAD_FILES -> this.uploadFiles(request);
case LIST_FILES -> this.listFiles(datasourceConfiguration, request);
default -> Mono.error(new AppsmithPluginException(
AppsmithPluginError.PLUGIN_ERROR,
"Unknown request type: " + requestType
));
};
}

@nsarupr
Copy link
Contributor Author

nsarupr commented Dec 23, 2024

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12462631006.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38303.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-38303.dp.appsmith.com

@nsarupr nsarupr merged commit 8559d29 into release Dec 23, 2024
@nsarupr nsarupr deleted the chore/refactor-appsmith-ai-plugin branch December 23, 2024 08:29
NandanAnantharamu pushed a commit that referenced this pull request Dec 27, 2024
## Description
> [!IMPORTANT]  
> Refactor the Appsmith AI Plugin trigger method.


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12462586013>
> Commit: 5dc9f81
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12462586013&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Mon, 23 Dec 2024 07:30:58 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced a new service for managing file upload and listing
operations.
	- Added structured handling of triggers for file-related actions.
- **Bug Fixes**
- Enhanced error management for file operations to improve logging and
response handling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
## Description
> [!IMPORTANT]  
> Refactor the Appsmith AI Plugin trigger method.


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12462586013>
> Commit: 5dc9f81
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12462586013&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Mon, 23 Dec 2024 07:30:58 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced a new service for managing file upload and listing
operations.
	- Added structured handling of triggers for file-related actions.
- **Bug Fixes**
- Enhanced error management for file operations to improve logging and
response handling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants