From cfbfc8a57626250b49f9fc8fc037b98c3085f279 Mon Sep 17 00:00:00 2001
From: Holash Chand <132540997+holashchand@users.noreply.github.com>
Date: Mon, 27 Jan 2025 12:57:18 +0530
Subject: [PATCH] Added support to search projects based on ancestor project id
(#1298)
* Added support to search projects based on ancestor ids
* changed ancestor ids to a boolean isAncestorProjectId
* minor fix
* Fixed java heap problem due to no filter in include descendants, include ancestors etc queries
* Added support to find root level project
* Added missing parameter
* Added code comments
* incremented version of project service
* added change log
---
health-services/project/CHANGELOG.md | 3 +
health-services/project/pom.xml | 2 +-
.../project/repository/ProjectRepository.java | 95 +++++++++++--------
.../ProjectAddressQueryBuilder.java | 22 ++++-
.../egov/project/service/ProjectService.java | 22 +++--
.../web/controllers/ProjectApiController.java | 8 +-
6 files changed, 94 insertions(+), 58 deletions(-)
diff --git a/health-services/project/CHANGELOG.md b/health-services/project/CHANGELOG.md
index 95369041416..c995b81daaf 100644
--- a/health-services/project/CHANGELOG.md
+++ b/health-services/project/CHANGELOG.md
@@ -1,5 +1,8 @@
All notable changes to this module will be documented in this file.
+## 1.1.6 - 2025-01-27
+- Added isAncestorProjectId param for search projects API to support search projects with ancestor project id as well
+
## 1.1.5 - 2024-08-07
- Added UserAction functionality with support for Location capture.
diff --git a/health-services/project/pom.xml b/health-services/project/pom.xml
index 32d7bd8fa3e..2f5e99a45ab 100644
--- a/health-services/project/pom.xml
+++ b/health-services/project/pom.xml
@@ -5,7 +5,7 @@
project
jar
project
- 1.1.5
+ 1.1.6
17
${java.version}
diff --git a/health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java b/health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java
index ae7b4c9994b..31bd571cb77 100644
--- a/health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java
+++ b/health-services/project/src/main/java/org/egov/project/repository/ProjectRepository.java
@@ -69,37 +69,44 @@ public ProjectRepository(Producer producer, NamedParameterJdbcTemplate namedPara
}
- public List getProjects(ProjectRequest project, Integer limit, Integer offset, String tenantId, Long lastChangedSince, Boolean includeDeleted, Boolean includeAncestors, Boolean includeDescendants, Long createdFrom, Long createdTo) {
+ /**
+ * @param isAncestorProjectId When true, treats the project IDs in the ProjectRequest as ancestor project IDs
+ */
+ public List getProjects(ProjectRequest project, Integer limit, Integer offset, String tenantId, Long lastChangedSince, Boolean includeDeleted, Boolean includeAncestors, Boolean includeDescendants, Long createdFrom, Long createdTo, boolean isAncestorProjectId) {
//Fetch Projects based on search criteria
- List projects = getProjectsBasedOnSearchCriteria(project.getProjects(), limit, offset, tenantId, lastChangedSince, includeDeleted, createdFrom, createdTo);
+ List projects = getProjectsBasedOnSearchCriteria(project.getProjects(), limit, offset, tenantId, lastChangedSince, includeDeleted, createdFrom, createdTo, isAncestorProjectId);
Set projectIds = projects.stream().map(Project :: getId).collect(Collectors.toSet());
List ancestors = null;
List descendants = null;
- //Get Project ancestors if includeAncestors flag is true
- if (includeAncestors) {
- ancestors = getProjectAncestors(projects);
- if (ancestors != null && !ancestors.isEmpty()) {
- List ancestorProjectIds = ancestors.stream().map(Project :: getId).collect(Collectors.toList());
- projectIds.addAll(ancestorProjectIds);
+ List targets = new ArrayList<>();
+ List documents = new ArrayList<>();
+ if(!projectIds.isEmpty()) {
+ //Get Project ancestors if includeAncestors flag is true
+ if (includeAncestors) {
+ ancestors = getProjectAncestors(projects);
+ if (ancestors != null && !ancestors.isEmpty()) {
+ List ancestorProjectIds = ancestors.stream().map(Project :: getId).collect(Collectors.toList());
+ projectIds.addAll(ancestorProjectIds);
+ }
}
- }
- //Get Project descendants if includeDescendants flag is true
- if (includeDescendants) {
- descendants = getProjectDescendants(projects);
- if (descendants != null && !descendants.isEmpty()) {
- List descendantsProjectIds = descendants.stream().map(Project :: getId).collect(Collectors.toList());
- projectIds.addAll(descendantsProjectIds);
+ //Get Project descendants if includeDescendants flag is true
+ if (includeDescendants) {
+ descendants = getProjectDescendants(projects);
+ if (descendants != null && !descendants.isEmpty()) {
+ List descendantsProjectIds = descendants.stream().map(Project :: getId).collect(Collectors.toList());
+ projectIds.addAll(descendantsProjectIds);
+ }
}
- }
- //Fetch targets based on Project Ids
- List targets = getTargetsBasedOnProjectIds(projectIds);
+ //Fetch targets based on Project Ids
+ targets = getTargetsBasedOnProjectIds(projectIds);
- //Fetch documents based on Project Ids
- List documents = getDocumentsBasedOnProjectIds(projectIds);
+ //Fetch documents based on Project Ids
+ documents = getDocumentsBasedOnProjectIds(projectIds);
+ }
//Construct Project Objects with fetched projects, targets and documents using Project id
return buildProjectSearchResult(projects, targets, documents, ancestors, descendants);
@@ -114,28 +121,32 @@ public List getProjects(@NotNull @Valid ProjectSearch projectSearch, @V
List ancestors = null;
List descendants = null;
- //Get Project ancestors if includeAncestors flag is true
- if (urlParams.getIncludeAncestors()) {
- ancestors = getProjectAncestors(projects);
- if (ancestors != null && !ancestors.isEmpty()) {
- List ancestorProjectIds = ancestors.stream().map(Project :: getId).collect(Collectors.toList());
- projectIds.addAll(ancestorProjectIds);
+ List targets = new ArrayList<>();
+ List documents = new ArrayList<>();
+ if(!projectIds.isEmpty()) {
+ //Get Project ancestors if includeAncestors flag is true
+ if (urlParams.getIncludeAncestors()) {
+ ancestors = getProjectAncestors(projects);
+ if (ancestors != null && !ancestors.isEmpty()) {
+ List ancestorProjectIds = ancestors.stream().map(Project :: getId).toList();
+ projectIds.addAll(ancestorProjectIds);
+ }
}
- }
- //Get Project descendants if includeDescendants flag is true
- if (urlParams.getIncludeDescendants()) {
- descendants = getProjectDescendants(projects);
- if (descendants != null && !descendants.isEmpty()) {
- List descendantsProjectIds = descendants.stream().map(Project :: getId).collect(Collectors.toList());
- projectIds.addAll(descendantsProjectIds);
+ //Get Project descendants if includeDescendants flag is true
+ if (urlParams.getIncludeDescendants()) {
+ descendants = getProjectDescendants(projects);
+ if (descendants != null && !descendants.isEmpty()) {
+ List descendantsProjectIds = descendants.stream().map(Project :: getId).toList();
+ projectIds.addAll(descendantsProjectIds);
+ }
}
- }
- //Fetch targets based on Project Ids
- List targets = getTargetsBasedOnProjectIds(projectIds);
+ //Fetch targets based on Project Ids
+ targets = getTargetsBasedOnProjectIds(projectIds);
- //Fetch documents based on Project Ids
- List documents = getDocumentsBasedOnProjectIds(projectIds);
+ //Fetch documents based on Project Ids
+ documents = getDocumentsBasedOnProjectIds(projectIds);
+ }
//Construct Project Objects with fetched projects, targets and documents using Project id
return buildProjectSearchResult(projects, targets, documents, ancestors, descendants);
@@ -151,9 +162,9 @@ private List getProjectsBasedOnV2SearchCriteria(@NotNull @Valid Project
}
/* Fetch Projects based on search criteria */
- private List getProjectsBasedOnSearchCriteria(List projectsRequest, Integer limit, Integer offset, String tenantId, Long lastChangedSince, Boolean includeDeleted, Long createdFrom, Long createdTo) {
+ private List getProjectsBasedOnSearchCriteria(List projectsRequest, Integer limit, Integer offset, String tenantId, Long lastChangedSince, Boolean includeDeleted, Long createdFrom, Long createdTo, boolean isAncestorProjectId) {
List