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

HCMPRE:1708 - Enable search on Village Accessibility Details and security questions in Plan Service #1323

Open
wants to merge 18 commits into
base: microplanning-v0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
067d1d3
Enable search on Village Accessibility Details in Plan Service
tanishi-egov Jan 6, 2025
8d60a42
Merge branch 'microplanning-v0.2' of https://github.com/egovernments/…
tanishi-egov Jan 7, 2025
1c2ab26
enabling search on security questions
tanishi-egov Jan 7, 2025
eb7282c
Merge branch 'HCMPRE-1768-new' of https://github.com/egovernments/hea…
tanishi-egov Jan 7, 2025
56e44cc
Merge branch 'microplanning-v0.2' of https://github.com/egovernments/…
tanishi-egov Jan 7, 2025
e4a9894
Merge branch 'HCMPRE-1768-new' of https://github.com/egovernments/hea…
tanishi-egov Jan 7, 2025
e3849c2
Updating preparePartialJsonStringFromFilterMap function
tanishi-egov Jan 7, 2025
be041ea
Modifying filter logic
tanishi-egov Jan 9, 2025
804ae7d
pull from microplanning-v0.2
tanishi-egov Jan 9, 2025
30c99f0
Merge branch 'microplanning-v0.2' of https://github.com/egovernments/…
tanishi-egov Jan 10, 2025
ef0352f
Merge branch 'microplanning-v0.2' of https://github.com/egovernments/…
tanishi-egov Jan 10, 2025
48ff551
Merge branch 'microplanning-v0.2' of https://github.com/egovernments/…
tanishi-egov Jan 13, 2025
ed5e90d
Merge branch 'HCMPRE-1708-new' of https://github.com/egovernments/hea…
tanishi-egov Jan 13, 2025
40d989d
Adding accessibility details in plan additional details
tanishi-egov Jan 16, 2025
1c8f26a
Adding accessibility details in plan additional details
tanishi-egov Jan 16, 2025
5eb30a6
Merge remote-tracking branch 'origin/HCMPRE-1708-new' into HCMPRE-170…
tanishi-egov Jan 16, 2025
2ff8b2c
Adding accessibility details in plan additional details
tanishi-egov Jan 16, 2025
eb52289
Merge remote-tracking branch 'origin/HCMPRE-1708-new' into HCMPRE-170…
tanishi-egov Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ public class ServiceConstants {

public static final String FACILITY_TYPE_SEARCH_PARAMETER_KEY = "facilityType";

public static final String TERRAIN_CONDITION_SEARCH_PARAMETER_KEY = "accessibilityDetails.terrain.code";

public static final String ROAD_CONDITION_SEARCH_PARAMETER_KEY = "accessibilityDetails.roadCondition.code";

public static final String SECURITY_Q1_SEARCH_PARAMETER_KEY = "securityDetails.1.code";

public static final String SECURITY_Q2_SEARCH_PARAMETER_KEY = "securityDetails.2.code";

public static final String COMMA_DELIMITER = ",";

public static final String SERVING_POPULATION_CODE = "servingPopulation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.util.*;

import static digit.config.ServiceConstants.FACILITY_ID_SEARCH_PARAMETER_KEY;
import static digit.config.ServiceConstants.*;

@Component
public class PlanEnricher {
Expand Down Expand Up @@ -257,6 +257,26 @@ public void enrichSearchRequest(PlanSearchRequest planSearchRequest) {
filtersMap.put(FACILITY_ID_SEARCH_PARAMETER_KEY, planSearchCriteria.getFacilityId());
}

// Add terrain as a filter if present in search criteria
if (!ObjectUtils.isEmpty(planSearchCriteria.getTerrain())) {
filtersMap.put(TERRAIN_CONDITION_SEARCH_PARAMETER_KEY, planSearchCriteria.getTerrain());
}

// Add onRoadCondition as a filter if present in search criteria
if (!ObjectUtils.isEmpty(planSearchCriteria.getOnRoadCondition())) {
filtersMap.put(ROAD_CONDITION_SEARCH_PARAMETER_KEY, planSearchCriteria.getOnRoadCondition());
}

// Add securityQ1 as a filter if present in search criteria
if (!ObjectUtils.isEmpty(planSearchCriteria.getSecurityQ1())) {
filtersMap.put(SECURITY_Q1_SEARCH_PARAMETER_KEY, planSearchCriteria.getSecurityQ1());
}

// Add securityQ2 as a filter if present in search criteria
if (!ObjectUtils.isEmpty(planSearchCriteria.getSecurityQ2())) {
filtersMap.put(SECURITY_Q2_SEARCH_PARAMETER_KEY, planSearchCriteria.getSecurityQ2());
}

if(!CollectionUtils.isEmpty(filtersMap))
planSearchCriteria.setFiltersMap(filtersMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,21 @@ public String preparePartialJsonStringFromFilterMap(Map<String, String> filterMa
if (key.contains(DOT_SEPARATOR)) {
String[] keyArray = key.split(DOT_REGEX);
Map<String, Object> nestedQueryMap = new HashMap<>();

// Recursively build the nested structure based on the key hierarchy.
prepareNestedQueryMap(0, keyArray, nestedQueryMap, filterMap.get(key));
queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0]));

// Merge the newly created nested structure into the main query map.
queryMap.merge(keyArray[0], nestedQueryMap.get(keyArray[0]), (existing, newValue) -> {
// If both existing and new values are maps, merge them to prevent overwriting.
if (existing instanceof Map && newValue instanceof Map) {
mergeMaps((Map<String, Object>) existing, (Map<String, Object>) newValue);
return existing;
}
return newValue;
});
} else {
// If no nesting, directly put the key-value pair into the query map.
queryMap.put(key, filterMap.get(key));
}
});
Expand Down Expand Up @@ -170,6 +182,31 @@ public String getPaginatedQuery(String query, List<Object> preparedStmtList) {
return paginatedQuery.toString();
}

/**
* Recursively merges two maps, combining their nested structures while preserving existing values.
*
* @param existing The final map that will contain the merged result.
* @param newMap The source map whose contents will be merged into the existing map.
*
* Example:
* existing = {"a": {"b": "value1"}}
* newMap = {"a": {"c": "value2"}}
* Result: {"a": {"b": "value1", "c": "value2"}}
*/
private void mergeMaps(Map<String, Object> existing, Map<String, Object> newMap) {
newMap.forEach((key, value) -> {
existing.merge(key, value, (oldValue, newValue) -> {
// If both values are maps, recursively merge them
if (oldValue instanceof Map && newValue instanceof Map) {
mergeMaps((Map<String, Object>) oldValue, (Map<String, Object>) newValue);
return oldValue;
}
// If either value is not a map, use the new value
return newValue;
});
});
}

/**
* This method is used to extract and parse JSON data into a JsonNode object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public class PlanSearchCriteria {
@JsonProperty("facilityId")
private String facilityId = null;

@JsonProperty("onRoadCondition")
private String onRoadCondition = null;

@JsonProperty("terrain")
private String terrain = null;

@JsonProperty("securityQ1")
private String securityQ1 = null;

@JsonProperty("securityQ2")
private String securityQ2 = null;

@JsonProperty("status")
private String status = null;

Expand Down
Loading