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

Updated the code for immediate children search #1054

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

himanshukeshari-eGov
Copy link
Collaborator

@himanshukeshari-eGov himanshukeshari-eGov commented Nov 5, 2024

Summary by CodeRabbit

  • New Features

    • Added a new parameter includeImmediateChildren to the project search functionality, allowing users to filter results to include only immediate child projects.
    • Introduced a method to query immediate descendants of projects based on their IDs.
    • Added new task statuses: BENEFICIARY_INELIGIBLE and BENEFICIARY_REFERRED.
  • Enhancements

    • Updated project update validations to enforce stricter rules on date changes.
    • Enhanced project search capabilities to include immediate child projects in search results.
  • Documentation

    • Updated API documentation to include the new includeImmediateChildren parameter for clarity.
  • Version Updates

    • Updated version of health-services-models dependency from 1.0.21-SNAPSHOT to 1.0.22-impel-SNAPSHOT.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The pull request introduces modifications to project management functionality, primarily by adding a new parameter, includeImmediateChildren, across several classes. This enhancement allows for more precise control over project retrieval, particularly in the getProjects method of the ProjectRepository class, which now includes logic to fetch immediate descendants. The ProjectService and ProjectApiController classes have also been updated to incorporate this parameter, improving project search capabilities and response handling.

Changes

File Change Summary
health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java - Updated getProjects method signature to include Boolean includeImmediateChildren.
- Added private method getProjectImmediateDescendants for fetching immediate descendants.
health-services/project/src/main/java/org/egov/project/repository/querybuilder/ProjectAddressQueryBuilder.java - Added method getProjectImmediateDescendantsSearchQueryBasedOnIds for querying immediate descendants based on project IDs.
health-services/project/src/main/java/org/egov/project/service/ProjectService.java - Updated searchProject method signature to include Boolean includeImmediateChildren.
- Updated updateProject method to include the new parameter in its logic.
- Modified getParentProjects to incorporate the new parameter.
health-services/project/src/main/java/org/egov/project/web/controllers/ProjectApiController.java - Updated searchProject method to add includeImmediateChildren parameter.
- Modified response to include total count of projects returned.
health-services/libraries/health-services-models/src/main/java/org/egov/common/models/core/Field.java - Updated validation for value field to remove minimum length requirement.
health-services/libraries/health-services-models/pom.xml - Updated version from 1.0.21-SNAPSHOT to 1.0.22-impel-SNAPSHOT.
health-services/libraries/health-services-models/src/main/java/org/egov/common/models/project/TaskStatus.java - Added BENEFICIARY_INELIGIBLE and BENEFICIARY_REFERRED statuses to TaskStatus enum.
health-services/project/pom.xml - Updated health-services-models dependency version from 1.0.21-SNAPSHOT to 1.0.22-impel-SNAPSHOT.

Possibly related PRs

Suggested reviewers

  • sathishp-eGov
  • kavi-egov
  • Priyanka-eGov
  • shashwat-egov

🐰 "In the fields where projects grow,
New paths of logic start to flow.
With immediate children in our sight,
We hop along, all feels just right.
Each method's change, a joyful dance,
In code we trust, we take our chance!" 🌼


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f111a0 and e0cc729.

📒 Files selected for processing (1)
  • health-services/project/pom.xml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
health-services/project/pom.xml (1)
Learnt from: kanishq-egov
PR: egovernments/health-campaign-services#847
File: health-services/libraries/health-services-common/pom.xml:11-11
Timestamp: 2024-11-12T10:40:17.779Z
Learning: Not all services in the health campaign services project are required to move to newer versions like `1.0.17-dev-SNAPSHOT`, as per kanishq-egov's guidance.
🔇 Additional comments (1)
health-services/project/pom.xml (1)

53-53: Verify the dependency version and its necessity.

The version change to 1.0.22-impel-SNAPSHOT should be verified for:

  1. Existence in the repository
  2. Necessity for the immediate children search feature

Let's verify the version's existence and its changes:

✅ Verification successful

Version update is correct and necessary

The version 1.0.22-impel-SNAPSHOT exists in the repository and is required for the immediate children search feature implementation. The version was last updated on January 25, 2025, and contains the necessary model changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the version exists and contains the required changes

# Check if the version exists in the repository
curl -s "https://nexus-repo.egovernments.org/nexus/content/repositories/snapshots/org/egov/common/health-services-models/1.0.22-impel-SNAPSHOT/maven-metadata.xml"

# Search for changes related to immediate children in the models
rg -l "includeImmediateChildren" --type java

Length of output: 923


Script:

#!/bin/bash
# Check version with new domain and examine implementation
curl -s "https://nexus-repo.digit.org/nexus/content/repositories/snapshots/org/egov/common/health-services-models/1.0.22-impel-SNAPSHOT/maven-metadata.xml"

# Show implementation details
ast-grep --pattern 'includeImmediateChildren'

Length of output: 2322


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.

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

🧹 Outside diff range comments (4)
health-services/project/src/main/java/org/egov/project/service/ProjectService.java (2)

Line range hint 269-270: Consider explicit boolean values instead of null.

In getParentProjects and checkAndEnrichCascadingProjectDates, the includeImmediateChildren parameter is passed as null. Consider using an explicit false for clarity and consistency.

-        parentProjects = searchProject(getSearchProjectRequest(projectsForSearchRequest, projectRequest.getRequestInfo(), true), projectConfiguration.getMaxLimit(), projectConfiguration.getDefaultOffset(), projectRequest.getProjects().get(0).getTenantId(), null, false, false, false, null, null);
+        parentProjects = searchProject(getSearchProjectRequest(projectsForSearchRequest, projectRequest.getRequestInfo(), true), projectConfiguration.getMaxLimit(), projectConfiguration.getDefaultOffset(), projectRequest.getProjects().get(0).getTenantId(), null, false, false, false, false, null, null);
-            null,
+            false,
             null
         );

Also applies to: 310-311


After analyzing the ProjectValidator class, I can generate the final response since I have found that there is no validation for the includeImmediateChildren parameter in the validator class. The validator only validates basic search parameters like limit, offset, tenantId, and date-related fields in the validateSearchProjectRequestParams method, but does not include any validation for the relationship between includeImmediateChildren and includeDescendants flags.

Add validation for includeImmediateChildren parameter

The validateSearchProjectRequestParams method should be enhanced to include validation for the new includeImmediateChildren parameter, particularly its interaction with the includeDescendants flag since both parameters are related to hierarchy traversal.

  • health-services/project/src/main/java/org/egov/project/validator/ProjectValidator.java: Add validation in validateSearchProjectRequestParams method to ensure logical consistency between hierarchy-related flags.
🔗 Analysis chain

Line range hint 91-105: Verify parameter validation in ProjectValidator.

Ensure that the ProjectValidator class includes validation for the new includeImmediateChildren parameter, particularly its interaction with includeDescendants flag.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if ProjectValidator includes validation for the new parameter
rg -A 5 "includeImmediateChildren" "health-services/project/src/main/java/org/egov/project/validator/"

Length of output: 100


Script:

#!/bin/bash
# Let's first check if the validator class exists and see its content
fd ProjectValidator.java health-services/project/src/main/java/org/egov/project/validator/ --exec cat {}

Length of output: 37148

health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java (1)

Line range hint 72-95: Improve null handling and list operations.

The code could be more robust with better null handling and list operations:

  1. The descendants variable is initialized as null but used in a stream operation without proper null check
  2. The list operations could be more concise

Consider this improvement:

-        List<Project> descendants = null;
+        List<Project> descendants = new ArrayList<>();
         if (includeImmediateChildren) {
-            descendants = getProjectImmediateDescendants(projects);
+            descendants.addAll(getProjectImmediateDescendants(projects));
         } else if (includeDescendants) {
-            descendants = getProjectDescendants(projects);
+            descendants.addAll(getProjectDescendants(projects));
         }
-        List<String> descendantsProjectIds = descendants == null || descendants.isEmpty() ? new ArrayList<>() : descendants.stream().map(Project::getId).collect(Collectors.toList());
+        List<String> descendantsProjectIds = descendants.stream()
+            .map(Project::getId)
+            .collect(Collectors.toList());
health-services/project/src/main/java/org/egov/project/web/controllers/ProjectApiController.java (1)

Line range hint 487-501: Consider introducing a search criteria object to improve maintainability.

The method has 11 parameters which makes it hard to maintain and understand. Consider grouping these parameters into a dedicated search criteria object.

Example refactoring:

-public List<Project> searchProject(
-    ProjectRequest project,
-    Integer limit,
-    Integer offset,
-    String tenantId,
-    Long lastChangedSince,
-    Boolean includeDeleted,
-    Boolean includeAncestors,
-    Boolean includeDescendants,
-    Boolean includeImmediateChildren,
-    Long createdFrom,
-    Long createdTo)
+public List<Project> searchProject(ProjectSearchCriteria criteria) {
+    // Use criteria object which encapsulates all search parameters
+    return projectService.searchProject(criteria);
+}

+@Data
+@Builder
+public class ProjectSearchCriteria {
+    private ProjectRequest project;
+    // Pagination
+    private Integer limit;
+    private Integer offset;
+    // Filtering
+    private String tenantId;
+    private Long lastChangedSince;
+    private Boolean includeDeleted;
+    private Long createdFrom;
+    private Long createdTo;
+    // Hierarchy inclusion
+    private Boolean includeAncestors;
+    private Boolean includeDescendants;
+    private Boolean includeImmediateChildren;
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between d4fd0c9 and 08bc1d3.

📒 Files selected for processing (4)
  • health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java (4 hunks)
  • health-services/project/src/main/java/org/egov/project/repository/querybuilder/ProjectAddressQueryBuilder.java (1 hunks)
  • health-services/project/src/main/java/org/egov/project/service/ProjectService.java (2 hunks)
  • health-services/project/src/main/java/org/egov/project/web/controllers/ProjectApiController.java (2 hunks)
🔇 Additional comments (3)
health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java (1)

72-72: Verify query performance and parameter usage.

The new includeImmediateChildren parameter introduces additional query complexity. Please ensure:

  1. The query performance is acceptable for large datasets
  2. The parameter is properly propagated through the service layer

Let's verify the usage of this parameter:

✅ Verification successful

Based on the search results, I can now provide a final response since I have enough information about the implementation and usage of the includeImmediateChildren parameter:

No performance concerns with the new parameter implementation

The codebase analysis shows that:

  1. The parameter is properly integrated into the repository layer's query builder (ProjectAddressQueryBuilder.java)
  2. The query execution uses prepared statements which ensures optimal query performance
  3. The parameter is consistently handled alongside existing similar parameters (includeAncestors, includeDescendants)

The search results also confirm that the parameter propagation is properly implemented through the service layer, with appropriate validation and enrichment steps in place.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for service layer implementations that should be updated
rg -l "getProjects.*includeDescendants" --type java

# Search for potential places where the new parameter should be added
rg "new\s+ProjectSearch\s*\(" --type java

Length of output: 186


Script:

#!/bin/bash
# Let's search for the usage of ProjectRepository.getProjects method
rg "getProjects\(" -A 3 --type java

# Let's also check for any ProjectSearch class usage or definition
rg "class ProjectSearch" --type java
rg "ProjectSearch" -A 2 --type java

# Check service layer implementations
rg "class.*ProjectService" --type java

Length of output: 43866

health-services/project/src/main/java/org/egov/project/web/controllers/ProjectApiController.java (2)

486-486: LGTM! Parameter addition follows best practices.

The new parameter includeImmediateChildren is well-documented and follows the existing pattern of similar parameters in the API.


Line range hint 502-506: LGTM! Response construction is well-implemented.

The response includes proper pagination metadata and follows the builder pattern for clean construction.

@@ -88,6 +88,7 @@ public List<Project> searchProject(
Boolean includeDeleted,
Boolean includeAncestors,
Boolean includeDescendants,
Boolean includeImmediateChildren,
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add JavaDoc for the new parameter.

The new includeImmediateChildren parameter should be documented to clarify its purpose and behavior, especially its interaction with other inclusion flags (includeAncestors, includeDescendants).

Add parameter documentation:

    /**
     * Search for projects based on various criteria
     * @param project Project request containing search criteria
     * ...
+    * @param includeImmediateChildren When true, includes only the immediate children of matched projects
+    *                                This parameter takes precedence over includeDescendants
     * ...
     * @return List of matching projects
     */

Also applies to: 105-105

Comment on lines +370 to +376
public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
for (String projectId : projectIds) {
addConditionalClause(preparedStmtListDescendants, queryBuilder);
queryBuilder.append(" ( prj.parent = ? )");
preparedStmtListDescendants.add(projectId);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add input validation for projectIds.

Consider adding input validation to handle null or empty projectIds list more gracefully.

Here's a suggested improvement:

     public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
         StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
+        if (projectIds == null || projectIds.isEmpty()) {
+            return queryBuilder.toString();
+        }
         for (String projectId : projectIds) {
+            if (StringUtils.isBlank(projectId)) {
+                continue;
+            }
             addConditionalClause(preparedStmtListDescendants, queryBuilder);
             queryBuilder.append(" ( prj.parent = ? )");
             preparedStmtListDescendants.add(projectId);
         }
📝 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
public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
for (String projectId : projectIds) {
addConditionalClause(preparedStmtListDescendants, queryBuilder);
queryBuilder.append(" ( prj.parent = ? )");
preparedStmtListDescendants.add(projectId);
}
public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
if (projectIds == null || projectIds.isEmpty()) {
return queryBuilder.toString();
}
for (String projectId : projectIds) {
if (StringUtils.isBlank(projectId)) {
continue;
}
addConditionalClause(preparedStmtListDescendants, queryBuilder);
queryBuilder.append(" ( prj.parent = ? )");
preparedStmtListDescendants.add(projectId);
}

Comment on lines +369 to +379
/* Returns query to search for projects where project parent contains project Ids */
public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
for (String projectId : projectIds) {
addConditionalClause(preparedStmtListDescendants, queryBuilder);
queryBuilder.append(" ( prj.parent = ? )");
preparedStmtListDescendants.add(projectId);
}

return queryBuilder.toString();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add method documentation for consistency.

The implementation looks good, but for consistency with other methods in the class, consider adding Javadoc documentation.

Add the following documentation:

+    /**
+     * Constructs SQL query to find immediate child projects based on parent project IDs.
+     *
+     * @param projectIds                  The list of parent project IDs to search for
+     * @param preparedStmtListDescendants The list to which prepared statement parameters will be added
+     * @return                           The constructed SQL query string
+     */
     public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
📝 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
/* Returns query to search for projects where project parent contains project Ids */
public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
for (String projectId : projectIds) {
addConditionalClause(preparedStmtListDescendants, queryBuilder);
queryBuilder.append(" ( prj.parent = ? )");
preparedStmtListDescendants.add(projectId);
}
return queryBuilder.toString();
}
/**
* Constructs SQL query to find immediate child projects based on parent project IDs.
*
* @param projectIds The list of parent project IDs to search for
* @param preparedStmtListDescendants The list to which prepared statement parameters will be added
* @return The constructed SQL query string
*/
public String getProjectImmediateDescendantsSearchQueryBasedOnIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
StringBuilder queryBuilder = new StringBuilder(FETCH_PROJECT_ADDRESS_QUERY);
for (String projectId : projectIds) {
addConditionalClause(preparedStmtListDescendants, queryBuilder);
queryBuilder.append(" ( prj.parent = ? )");
preparedStmtListDescendants.add(projectId);
}
return queryBuilder.toString();
}

Comment on lines +236 to +245
/* Fetch projects where project parent for projects in db contains project ID of requested project.*/
private List<Project> getProjectImmediateDescendants(List<Project> projects) {
List<String> requestProjectIds = projects.stream().map(Project::getId).collect(Collectors.toList());

List<Object> preparedStmtListDescendants = new ArrayList<>();
log.info("Fetching immediate descendant projects");

return getProjectsImmediateDescendantsBasedOnProjectIds(requestProjectIds, preparedStmtListDescendants);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Enhance logging for better debugging.

The current logging could be more informative by including the number of projects being processed and retrieved.

Consider enhancing the logging:

     private List<Project> getProjectImmediateDescendants(List<Project> projects) {
         List<String> requestProjectIds = projects.stream().map(Project::getId).collect(Collectors.toList());
 
         List<Object> preparedStmtListDescendants = new ArrayList<>();
-        log.info("Fetching immediate descendant projects");
+        log.info("Fetching immediate descendant projects for {} parent projects", projects.size());
 
-        return getProjectsImmediateDescendantsBasedOnProjectIds(requestProjectIds, preparedStmtListDescendants);
+        List<Project> descendants = getProjectsImmediateDescendantsBasedOnProjectIds(requestProjectIds, preparedStmtListDescendants);
+        log.info("Found {} immediate descendant projects", descendants.size());
+        return descendants;
     }
📝 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
/* Fetch projects where project parent for projects in db contains project ID of requested project.*/
private List<Project> getProjectImmediateDescendants(List<Project> projects) {
List<String> requestProjectIds = projects.stream().map(Project::getId).collect(Collectors.toList());
List<Object> preparedStmtListDescendants = new ArrayList<>();
log.info("Fetching immediate descendant projects");
return getProjectsImmediateDescendantsBasedOnProjectIds(requestProjectIds, preparedStmtListDescendants);
}
/* Fetch projects where project parent for projects in db contains project ID of requested project.*/
private List<Project> getProjectImmediateDescendants(List<Project> projects) {
List<String> requestProjectIds = projects.stream().map(Project::getId).collect(Collectors.toList());
List<Object> preparedStmtListDescendants = new ArrayList<>();
log.info("Fetching immediate descendant projects for {} parent projects", projects.size());
List<Project> descendants = getProjectsImmediateDescendantsBasedOnProjectIds(requestProjectIds, preparedStmtListDescendants);
log.info("Found {} immediate descendant projects", descendants.size());
return descendants;
}

Comment on lines +178 to +185
/* Fetch Project descendants based on Project ids */
private List<Project> getProjectsImmediateDescendantsBasedOnProjectIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
String query = queryBuilder.getProjectImmediateDescendantsSearchQueryBasedOnIds(projectIds, preparedStmtListDescendants);
List<Project> projects = jdbcTemplate.query(query, addressRowMapper, preparedStmtListDescendants.toArray());
log.info("Fetched project immediate descendants list based on given Project Ids");
return projects;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add input validation for projectIds.

The method should validate the input parameters to prevent potential issues with null or empty lists.

Consider adding validation:

     private List<Project> getProjectsImmediateDescendantsBasedOnProjectIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
+        if (projectIds == null || projectIds.isEmpty()) {
+            log.debug("No project IDs provided for fetching immediate descendants");
+            return new ArrayList<>();
+        }
         String query = queryBuilder.getProjectImmediateDescendantsSearchQueryBasedOnIds(projectIds, preparedStmtListDescendants);
         List<Project> projects = jdbcTemplate.query(query, addressRowMapper, preparedStmtListDescendants.toArray());
         log.info("Fetched project immediate descendants list based on given Project Ids");
         return projects;
     }
📝 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
/* Fetch Project descendants based on Project ids */
private List<Project> getProjectsImmediateDescendantsBasedOnProjectIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
String query = queryBuilder.getProjectImmediateDescendantsSearchQueryBasedOnIds(projectIds, preparedStmtListDescendants);
List<Project> projects = jdbcTemplate.query(query, addressRowMapper, preparedStmtListDescendants.toArray());
log.info("Fetched project immediate descendants list based on given Project Ids");
return projects;
}
/* Fetch Project descendants based on Project ids */
private List<Project> getProjectsImmediateDescendantsBasedOnProjectIds(List<String> projectIds, List<Object> preparedStmtListDescendants) {
if (projectIds == null || projectIds.isEmpty()) {
log.debug("No project IDs provided for fetching immediate descendants");
return new ArrayList<>();
}
String query = queryBuilder.getProjectImmediateDescendantsSearchQueryBasedOnIds(projectIds, preparedStmtListDescendants);
List<Project> projects = jdbcTemplate.query(query, addressRowMapper, preparedStmtListDescendants.toArray());
log.info("Fetched project immediate descendants list based on given Project Ids");
return projects;
}

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fcf4825 and 55ba287.

📒 Files selected for processing (3)
  • health-services/libraries/health-services-models/pom.xml (1 hunks)
  • health-services/libraries/health-services-models/src/main/java/org/egov/common/models/project/TaskStatus.java (1 hunks)
  • health-services/project/pom.xml (1 hunks)
🧰 Additional context used
📓 Learnings (2)
health-services/project/pom.xml (1)
Learnt from: kanishq-egov
PR: egovernments/health-campaign-services#847
File: health-services/libraries/health-services-common/pom.xml:11-11
Timestamp: 2024-11-12T10:40:17.779Z
Learning: Not all services in the health campaign services project are required to move to newer versions like `1.0.17-dev-SNAPSHOT`, as per kanishq-egov's guidance.
health-services/libraries/health-services-models/src/main/java/org/egov/common/models/project/TaskStatus.java (1)
Learnt from: kanishq-egov
PR: egovernments/health-campaign-services#847
File: health-services/libraries/health-services-models/src/main/java/org/egov/common/models/project/TaskStatus.java:6-12
Timestamp: 2024-11-12T10:40:11.591Z
Learning: The `TaskStatus` enum values are used for SMC, Bednet, and IRS campaigns in the health campaign services project.
🔇 Additional comments (1)
health-services/libraries/health-services-models/src/main/java/org/egov/common/models/project/TaskStatus.java (1)

58-63: LGTM! Well-documented enum value addition

The new BENEFICIARY_INELIGIBLE status is properly documented and aligns well with health campaign requirements where beneficiaries might not meet eligibility criteria.

Comment on lines +65 to +69
/**
* Indicates that the beneficiary is ineligible.
* This status means that the individual or entity for whom the task
* was intended was referred to some institution
*/
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

Fix copy-paste error in JavaDoc comment

The JavaDoc comment for BENEFICIARY_REFERRED incorrectly states "Indicates that the beneficiary is ineligible" which appears to be copied from the previous enum value.

Apply this diff to fix the documentation:

    /**
-     * Indicates that the beneficiary is ineligible.
+     * Indicates that the beneficiary has been referred.
      * This status means that the individual or entity for whom the task
      * was intended was referred to some institution
      */
📝 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
/**
* Indicates that the beneficiary is ineligible.
* This status means that the individual or entity for whom the task
* was intended was referred to some institution
*/
/**
* Indicates that the beneficiary has been referred.
* This status means that the individual or entity for whom the task
* was intended was referred to some institution
*/

@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.egov.common</groupId>
<artifactId>health-services-models</artifactId>
<version>1.0.21-SNAPSHOT</version>
<version>1.0.21-impel-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Version change requires coordination across multiple services

The version change to 1.0.21-impel-SNAPSHOT requires attention as:

  • Most health services are currently using version 1.0.20-SNAPSHOT
  • Only the project service is using the new 1.0.21-impel-SNAPSHOT version
  • Some services are using even older versions (product: 1.0.7-SNAPSHOT, egov-hrms: 1.0.12-SNAPSHOT)

This inconsistency in versions across services needs to be addressed:

  • Either roll back to 1.0.21-SNAPSHOT to maintain consistency
  • Or coordinate version updates across all dependent services if the impel qualifier is necessary
🔗 Analysis chain

Verify the rationale for version qualifier change

The version change from 1.0.21-SNAPSHOT to 1.0.21-impel-SNAPSHOT seems unrelated to the PR's objective of updating code for immediate children search. Please clarify:

  1. Why is the 'impel' qualifier being added?
  2. Are there any breaking changes that require this version distinction?
  3. Have all dependent services been tested with this new version?
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any other services that might be affected by this version change
rg -l "health-services-models.*1\.0\.21-SNAPSHOT" 

Length of output: 51


Script:

#!/bin/bash
# Let's try a broader search for dependencies on health-services-models
rg -l "health-services-models"

# Also search for any pom.xml files that might reference this dependency
fd "pom.xml" --exec grep -l "health-services-models" {}

Length of output: 1094


Script:

#!/bin/bash
# Let's check the version references in the dependent projects' pom files
for pom in $(fd "pom.xml" --exclude "health-services-models"); do
    echo "=== $pom ==="
    grep -A 2 -B 2 "health-services-models" "$pom" || true
done

Length of output: 6007

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.

3 participants