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

fix: Add custom deserialiser for idPolicies projection #38127

Open
wants to merge 1 commit into
base: pg
Choose a base branch
from

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Dec 12, 2024

Description

PR to move projection methods with IdPoliciesOnly class to custom repository.

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=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new method to retrieve ID and policy mappings based on application IDs across multiple repositories.
  • Bug Fixes

    • Removed outdated methods that previously provided ID and policy mappings, streamlining repository functionalities.
  • Documentation

    • Updated import statements to include necessary dependencies for new functionalities.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request involve the transformation of the IdPoliciesOnly interface into a class, with the addition of fields and a constructor. The repository interfaces and implementations have been updated to include a new method for retrieving IdPoliciesOnly objects based on application IDs, while some methods have been removed or modified to reflect these changes. This results in a restructured approach to handling ID and policy mappings within the application.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java Transformed IdPoliciesOnly from an interface to a class; added fields id and policyMap; removed getId() method; added constructor.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ActionCollectionRepositoryCE.java Removed method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java Added method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java Added method findIdsAndPolicyMapByApplicationIdIn; updated findByApplicationId method signature.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java Added method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java Added method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java Added method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java Added method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java Removed method findIdsAndPolicyMapByApplicationIdIn.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewPageRepositoryCE.java Removed method findIdsAndPolicyMapByApplicationIdIn.

Possibly related PRs

Suggested labels

Task, Bug, skip-changelog, ok-to-test, Query & JS Pod

Suggested reviewers

  • nidhi-nair
  • AnaghHegde
  • sharat87

🎉 In code we trust, with changes so bright,
A class now stands where an interface might.
Policies mapped, with IDs in tow,
A cleaner design, watch our features grow!
So here's to the code, new paths we embrace,
In the world of Java, we find our place! 🚀


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. (Experiment)
  • @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.

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

🧹 Outside diff range and nitpick comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java (1)

11-14: Make fields final and consider builder pattern

Class structure could be improved for immutability.

 @Getter
 public class IdPoliciesOnly {
-    String id;
-    Map<String, Policy> policyMap = new HashMap<>();
+    private final String id;
+    private final Map<String, Policy> policyMap = new HashMap<>();
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java (1)

47-48: Add JavaDoc for the new repository method

Document the method's purpose, parameters, and return value.

+    /**
+     * Retrieves ID and policies for collections matching the given application IDs
+     * @param applicationIds List of application IDs to search for
+     * @return List of ID and policy mappings
+     */
     List<IdPoliciesOnly> findIdsAndPolicyMapByApplicationIdIn(List<String> applicationIds);
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java (1)

52-53: Maintain consistent documentation across repositories

Add JavaDoc similar to CustomActionCollectionRepositoryCE.

+    /**
+     * Retrieves ID and policies for pages matching the given application IDs
+     * @param applicationIds List of application IDs to search for
+     * @return List of ID and policy mappings
+     */
     List<IdPoliciesOnly> findIdsAndPolicyMapByApplicationIdIn(List<String> applicationIds);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aea0516 and 8c2f26d.

📒 Files selected for processing (10)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/projections/IdPoliciesOnly.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ActionCollectionRepositoryCE.java (0 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java (0 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewPageRepositoryCE.java (0 hunks)
💤 Files with no reviewable changes (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewActionRepositoryCE.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/NewPageRepositoryCE.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ActionCollectionRepositoryCE.java
👮 Files not reviewed due to content moderation or server errors (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomActionCollectionRepositoryCEImpl.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCEImpl.java
🔇 Additional comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewPageRepositoryCE.java (1)

52-53: Verify consistent implementation across repositories

Ensure all repositories implement the new method consistently.

✅ Verification successful

Implementation is consistent across repositories

The search results show the method findIdsAndPolicyMapByApplicationIdIn is consistently implemented in:

  • CustomNewPageRepositoryCEImpl
  • CustomNewActionRepositoryCEImpl
  • CustomActionCollectionRepositoryCEImpl

All implementations follow the same pattern using queryBuilder() with appropriate criteria. The method is also properly defined in corresponding interfaces.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all implementations of findIdsAndPolicyMapByApplicationIdIn
ast-grep --pattern 'findIdsAndPolicyMapByApplicationIdIn($$$)'

Length of output: 130877


Script:

#!/bin/bash
# Search for implementations of findIdsAndPolicyMapByApplicationIdIn in Java files
rg -t java "findIdsAndPolicyMapByApplicationIdIn" -C 3

# Search for interface definitions and implementations
ast-grep --pattern 'interface $_ { 
  $$$
  findIdsAndPolicyMapByApplicationIdIn($$$)
  $$$
}'

Length of output: 13194

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCEImpl.java (2)

10-10: LGTM!

The import is correctly placed and used by the new method.


490-495: LGTM! Clean and consistent implementation.

The method follows the repository pattern and maintains consistency with existing query patterns in the codebase.

Let's verify the interface method declaration and IdPoliciesOnly projection usage:

✅ Verification successful

Implementation verified and consistent across the codebase

The method is properly declared in the interface and follows the same pattern used in related repositories (CustomNewPageRepository, CustomActionCollectionRepository). The IdPoliciesOnly projection is a valid class with proper id and policyMap fields, and the method is actively used in ApplicationPageService and ApplicationForkingService.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the method is declared in the interface
ast-grep --pattern 'interface CustomNewActionRepositoryCE {
  $$$
  List<IdPoliciesOnly> findIdsAndPolicyMapByApplicationIdIn(List<String> $_);
  $$$
}'

# Check IdPoliciesOnly projection implementation
ast-grep --pattern 'class IdPoliciesOnly {
  $$$
}'

Length of output: 208


Script:

#!/bin/bash
# Search for interface declaration with ripgrep
rg -l "interface\s+CustomNewActionRepositoryCE" --type java

# Search for IdPoliciesOnly class or interface
rg -l "(?:class|interface)\s+IdPoliciesOnly" --type java

# If files are found, check their content
rg "(?:class|interface)\s+CustomNewActionRepositoryCE" -A 10 --type java
rg "(?:class|interface)\s+IdPoliciesOnly" -A 10 --type java

Length of output: 6994


Script:

#!/bin/bash
# Let's check if the method is declared in the interface
rg "findIdsAndPolicyMapByApplicationIdIn" app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomNewActionRepositoryCE.java -A 2

# Check for any other implementations or usages of this method
rg "findIdsAndPolicyMapByApplicationIdIn" --type java

Length of output: 2751

Comment on lines +15 to +28
// TODO Abhijeet: This is a temporary fix to convert the map of Object to map of Policy
public IdPoliciesOnly(String id, Map<String, Object> policyMap) {
this.id = id;
if (policyMap == null) {
return;
}
policyMap.forEach((key, value) -> {
if (value instanceof Policy) {
this.policyMap.put(key, (Policy) value);
} else if (value instanceof Map) {
this.policyMap.put(key, new ObjectMapper().convertValue(value, Policy.class));
}
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle ObjectMapper conversion exceptions and add parameter validation

The constructor contains potential issues:

  1. ObjectMapper conversion could throw exceptions
  2. Missing validation for id parameter
  3. TODO comment indicates temporary solution

Consider this implementation:

-    public IdPoliciesOnly(String id, Map<String, Object> policyMap) {
+    public IdPoliciesOnly(final String id, final Map<String, Object> policyMap) {
+        if (id == null || id.trim().isEmpty()) {
+            throw new IllegalArgumentException("Id cannot be null or empty");
+        }
         this.id = id;
         if (policyMap == null) {
             return;
         }
         policyMap.forEach((key, value) -> {
             if (value instanceof Policy) {
                 this.policyMap.put(key, (Policy) value);
             } else if (value instanceof Map) {
+                try {
                     this.policyMap.put(key, new ObjectMapper().convertValue(value, Policy.class));
+                } catch (IllegalArgumentException e) {
+                    throw new IllegalStateException("Failed to convert policy map value", e);
+                }
             }
         });
     }
📝 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
// TODO Abhijeet: This is a temporary fix to convert the map of Object to map of Policy
public IdPoliciesOnly(String id, Map<String, Object> policyMap) {
this.id = id;
if (policyMap == null) {
return;
}
policyMap.forEach((key, value) -> {
if (value instanceof Policy) {
this.policyMap.put(key, (Policy) value);
} else if (value instanceof Map) {
this.policyMap.put(key, new ObjectMapper().convertValue(value, Policy.class));
}
});
}
// TODO Abhijeet: This is a temporary fix to convert the map of Object to map of Policy
public IdPoliciesOnly(final String id, final Map<String, Object> policyMap) {
if (id == null || id.trim().isEmpty()) {
throw new IllegalArgumentException("Id cannot be null or empty");
}
this.id = id;
if (policyMap == null) {
return;
}
policyMap.forEach((key, value) -> {
if (value instanceof Policy) {
this.policyMap.put(key, (Policy) value);
} else if (value instanceof Map) {
try {
this.policyMap.put(key, new ObjectMapper().convertValue(value, Policy.class));
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Failed to convert policy map value", e);
}
}
});
}

Copy link

Failed server tests

  • com.appsmith.server.git.CommonGitServiceCETest#deleteBranch_staleBranchNotInDB_NotFoundError
  • com.appsmith.server.services.ce.ApplicationServiceCETest#cloneApplication_withDeletedActionInActionCollection_deletedActionIsNotCloned

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Dec 20, 2024
@abhvsn abhvsn removed the Stale label Dec 21, 2024
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Dec 28, 2024
Copy link

github-actions bot commented Jan 4, 2025

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Jan 4, 2025
@abhvsn abhvsn reopened this Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants