-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: master
Are you sure you want to change the base?
Changes from all commits
08bc1d3
79f8bd3
fcf4825
cdce56b
e8baea9
df4aab8
55ba287
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -53,7 +53,21 @@ public enum TaskStatus { | |||||||||||||||||||||
* This status signifies that the task has not been processed or | ||||||||||||||||||||||
* handled yet. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
NOT_ADMINISTERED("NOT_ADMINISTERED"); | ||||||||||||||||||||||
NOT_ADMINISTERED("NOT_ADMINISTERED"), | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* Indicates that the beneficiary is ineligible. | ||||||||||||||||||||||
* This status means that the individual or entity for whom the task | ||||||||||||||||||||||
* was intended is ineligible | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
BENEFICIARY_INELIGIBLE("BENEFICIARY_INELIGIBLE"), | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* 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 | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
Comment on lines
+65
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix copy-paste error in JavaDoc comment The JavaDoc comment for 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
Suggested change
|
||||||||||||||||||||||
BENEFICIARY_REFERRED("BENEFICIARY_REFERRED"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// The string value associated with the task status. | ||||||||||||||||||||||
private String value; | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -69,7 +69,7 @@ public ProjectRepository(Producer producer, NamedParameterJdbcTemplate namedPara | |||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
public List<Project> getProjects(ProjectRequest project, Integer limit, Integer offset, String tenantId, Long lastChangedSince, Boolean includeDeleted, Boolean includeAncestors, Boolean includeDescendants, Long createdFrom, Long createdTo) { | ||||||||||||||||||||||||||||||||||||||||||
public List<Project> getProjects(ProjectRequest project, Integer limit, Integer offset, String tenantId, Long lastChangedSince, Boolean includeDeleted, Boolean includeAncestors, Boolean includeDescendants, Boolean includeImmediateChildren ,Long createdFrom, Long createdTo) { | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
//Fetch Projects based on search criteria | ||||||||||||||||||||||||||||||||||||||||||
List<Project> projects = getProjectsBasedOnSearchCriteria(project.getProjects(), limit, offset, tenantId, lastChangedSince, includeDeleted, createdFrom, createdTo); | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -86,14 +86,13 @@ public List<Project> getProjects(ProjectRequest project, Integer limit, Integer | |||||||||||||||||||||||||||||||||||||||||
projectIds.addAll(ancestorProjectIds); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
//Get Project descendants if includeDescendants flag is true | ||||||||||||||||||||||||||||||||||||||||||
if (includeDescendants) { | ||||||||||||||||||||||||||||||||||||||||||
if (includeImmediateChildren) { | ||||||||||||||||||||||||||||||||||||||||||
descendants = getProjectImmediateDescendants(projects); | ||||||||||||||||||||||||||||||||||||||||||
} else if (includeDescendants) { | ||||||||||||||||||||||||||||||||||||||||||
descendants = getProjectDescendants(projects); | ||||||||||||||||||||||||||||||||||||||||||
if (descendants != null && !descendants.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||
List<String> descendantsProjectIds = descendants.stream().map(Project :: getId).collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||||
projectIds.addAll(descendantsProjectIds); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
List<String> descendantsProjectIds = descendants == null || descendants.isEmpty() ? new ArrayList<>() : descendants.stream().map(Project::getId).collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||||
projectIds.addAll(descendantsProjectIds); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
//Fetch targets based on Project Ids | ||||||||||||||||||||||||||||||||||||||||||
List<Target> targets = getTargetsBasedOnProjectIds(projectIds); | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -176,6 +175,14 @@ private List<Project> getProjectsDescendantsBasedOnProjectIds(List<String> proje | |||||||||||||||||||||||||||||||||||||||||
return projects; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
/* 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; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+178
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
/* Fetch targets based on Project Ids */ | ||||||||||||||||||||||||||||||||||||||||||
private List<Target> getTargetsBasedOnProjectIds(Set<String> projectIds) { | ||||||||||||||||||||||||||||||||||||||||||
List<Object> preparedStmtListTarget = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -226,6 +233,16 @@ private List<Project> getProjectDescendants(List<Project> projects) { | |||||||||||||||||||||||||||||||||||||||||
return getProjectsDescendantsBasedOnProjectIds(projectIds, 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"); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return getProjectsImmediateDescendantsBasedOnProjectIds(requestProjectIds, preparedStmtListDescendants); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+236
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
/* Constructs Project Objects with fetched projects, targets and documents using Project id and return list of Projects */ | ||||||||||||||||||||||||||||||||||||||||||
private List<Project> buildProjectSearchResult(List<Project> projects, List<Target> targets, List<Document> documents, List<Project> ancestors, List<Project> descendants) { | ||||||||||||||||||||||||||||||||||||||||||
for (Project project: projects) { | ||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -365,6 +365,18 @@ public String getProjectDescendantsSearchQueryBasedOnIds(List<String> projectIds | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return queryBuilder.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* 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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+370
to
+376
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return queryBuilder.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+369
to
+379
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* Returns query to get total projects count based on project search params */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public String getSearchCountQueryString(List<Project> projects, String tenantId, Long lastChangedSince, Boolean includeDeleted, Long createdFrom, Long createdTo, List<Object> preparedStatement) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ public List<Project> searchProject( | |
Boolean includeDeleted, | ||
Boolean includeAncestors, | ||
Boolean includeDescendants, | ||
Boolean includeImmediateChildren, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Add JavaDoc for the new parameter. The new 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 |
||
Long createdFrom, | ||
Long createdTo | ||
) { | ||
|
@@ -101,6 +102,7 @@ public List<Project> searchProject( | |
includeDeleted, | ||
includeAncestors, | ||
includeDescendants, | ||
includeImmediateChildren, | ||
createdFrom, | ||
createdTo | ||
); | ||
|
@@ -125,7 +127,7 @@ public ProjectRequest updateProject(ProjectRequest request) { | |
List<Project> projectsFromDB = searchProject( | ||
getSearchProjectRequest(request.getProjects(), request.getRequestInfo(), false), | ||
projectConfiguration.getMaxLimit(), projectConfiguration.getDefaultOffset(), | ||
request.getProjects().get(0).getTenantId(), null, false, false, false, null, null | ||
request.getProjects().get(0).getTenantId(), null, false, false, false, false,null, null | ||
); | ||
log.info("Fetched projects for update request"); | ||
|
||
|
@@ -279,6 +281,7 @@ private void checkAndEnrichCascadingProjectDates(ProjectRequest request, Project | |
false, | ||
true, | ||
true, | ||
false, | ||
null, | ||
null | ||
); | ||
|
@@ -301,7 +304,7 @@ private List<Project> getParentProjects(ProjectRequest projectRequest) { | |
List<Project> parentProjects = null; | ||
List<Project> projectsForSearchRequest = projectRequest.getProjects().stream().filter(p -> StringUtils.isNotBlank(p.getParent())).collect(Collectors.toList()); | ||
if (projectsForSearchRequest.size() > 0) { | ||
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); | ||
} | ||
log.info("Fetched parent projects from DB"); | ||
return parentProjects; | ||
|
There was a problem hiding this comment.
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:1.0.20-SNAPSHOT
1.0.21-impel-SNAPSHOT
version1.0.7-SNAPSHOT
, egov-hrms:1.0.12-SNAPSHOT
)This inconsistency in versions across services needs to be addressed:
1.0.21-SNAPSHOT
to maintain consistencyimpel
qualifier is necessary🔗 Analysis chain
Verify the rationale for version qualifier change
The version change from
1.0.21-SNAPSHOT
to1.0.21-impel-SNAPSHOT
seems unrelated to the PR's objective of updating code for immediate children search. Please clarify:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 51
Script:
Length of output: 1094
Script:
Length of output: 6007