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

Merged
merged 24 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
cf7d2a4
Resolving code rabbit comments
tanishi-egov Jan 17, 2025
ceeee9e
Merge remote-tracking branch 'origin/HCMPRE-1708-new' into HCMPRE-170…
tanishi-egov Jan 17, 2025
5f52303
Adding accessibility details in plan additional details
tanishi-egov Jan 20, 2025
87dac50
Adding pipe regex
tanishi-egov Jan 20, 2025
8b04d1b
changes in planUtil
tanishi-egov Jan 20, 2025
86ffaf4
resolving review comments
tanishi-egov Jan 20, 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 @@ -258,6 +258,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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public class Census {
private String boundaryCode = null;

@JsonProperty("assignee")
@Size(max = 64)
private String assignee = null;
private List<String> assignee = null;

@JsonProperty("status")
@Size(max = 64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public class ServiceConstants {
//Census additional field constants
public static final String UPLOADED_KEY = "UPLOADED_";
public static final String CONFIRMED_KEY = "CONFIRMED_";
public static final String CODE = "code";

//Excel header row styling constants
public static final String HEX_BACKGROUND_COLOR = "93C47D"; // Constant background color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.egov.tracer.model.CustomException;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.*;
Expand Down Expand Up @@ -49,6 +50,7 @@ public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration
* @param feature The feature JSON node.
* @param resultMap The result map.
* @param mappedValues The mapped values.
* @param boundaryCodeToCensusAdditionalDetails A Map of boundary code to censusAdditionalDetails for that boundary code.
*/
public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode feature,
Map<String, BigDecimal> resultMap, Map<String, String> mappedValues, Map<String, Object> boundaryCodeToCensusAdditionalDetails) {
Expand All @@ -63,11 +65,12 @@ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode f
/**
* Builds a PlanRequest object using the provided plan configuration request, feature JSON node,
* result map, mapped values, and assumption value map.
*
*
* @param planConfigurationRequest The plan configuration request.
* @param feature The feature JSON node.
* @param resultMap The result map.
* @param mappedValues The mapped values.
* @param boundaryCodeToCensusAdditionalDetails A Map of boundary code to censusAdditionalDetails for that boundary code.
* @return The constructed PlanRequest object.
*/
private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationRequest, JsonNode feature,
Expand All @@ -93,7 +96,7 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR
.targets(new ArrayList())
.workflow(Workflow.builder().action(WORKFLOW_ACTION_INITIATE).build())
.isRequestFromResourceEstimationConsumer(true)
.additionalDetails(enrichAdditionalDetials(boundaryCodeToCensusAdditionalDetails, boundaryCodeValue))
.additionalDetails(enrichAdditionalDetails(boundaryCodeToCensusAdditionalDetails, boundaryCodeValue))
.build())
.build();
}
Expand All @@ -106,33 +109,63 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR
* @param boundaryCodeValue The boundary code for which additional details need to be enriched.
* @return An updated object containing extracted and enriched additional details, or null if no details were found or added.
*/
private Object enrichAdditionalDetials(Map<String, Object> boundaryCodeToCensusAdditionalDetails, String boundaryCodeValue) {
private Object enrichAdditionalDetails(Map<String, Object> boundaryCodeToCensusAdditionalDetails, String boundaryCodeValue) {
if(!CollectionUtils.isEmpty(boundaryCodeToCensusAdditionalDetails)) {

Object censusAdditionalDetails = boundaryCodeToCensusAdditionalDetails.get(boundaryCodeValue);

// Return null value if censusAdditionalDetails is null
if(ObjectUtils.isEmpty(censusAdditionalDetails))
return null;

// Extract required details from census additional details object.
String facilityId = (String) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, FACILITY_ID);
Object accessibilityDetails = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, ACCESSIBILITY_DETAILS);
Object securityDetials = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, SECURITY_DETAILS);
Object securityDetails = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, SECURITY_DETAILS);

// Creating a map of fields to be added in plan additional details with their key.
Map<String, Object> fieldsToBeUpdated = new HashMap<>();
if(facilityId != null && !facilityId.isEmpty())
if(!ObjectUtils.isEmpty(facilityId))
fieldsToBeUpdated.put(FACILITY_ID, facilityId);

if(accessibilityDetails != null)
fieldsToBeUpdated.put(ACCESSIBILITY_DETAILS, accessibilityDetails);
// Add fields from accessibilityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails.
if(!ObjectUtils.isEmpty(accessibilityDetails)) {
extractNestedFields((Map<String, Object>) accessibilityDetails, ACCESSIBILITY_DETAILS, fieldsToBeUpdated);
}

if(securityDetials != null)
fieldsToBeUpdated.put(SECURITY_DETAILS, securityDetials);
// Add fields from securityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails.
if(!ObjectUtils.isEmpty(securityDetails)) {
extractNestedFields((Map<String, Object>) securityDetails, SECURITY_DETAILS, fieldsToBeUpdated);
}

if(!CollectionUtils.isEmpty(fieldsToBeUpdated))
return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated);
}
return null;
}


/**
* Extracts nested fields from the given additionalDetails map and adds them to fieldsToBeUpdated in a structured format.
* If a nested map contains CODE, its value is stored with the key formatted as "prefix|key|CODE".
*
* @param details The map containing nested key-value pairs to be processed.
* @param prefix The prefix to be used for constructing the final key in fieldsToBeUpdated.
* @param fieldsToBeUpdated The map where extracted values will be stored with formatted keys.
*/
private void extractNestedFields(Map<String, Object> details, String prefix, Map<String, Object> fieldsToBeUpdated) {
for (Map.Entry<String, Object> entry : details.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

if (value instanceof Map) {
Map<String, Object> nestedMap = (Map<String, Object>) value;
if (nestedMap.containsKey(CODE)) {
fieldsToBeUpdated.put(prefix + "|" + key + "|" + CODE, nestedMap.get(CODE));
}
}
}
}

/**
* Retrieves the boundary code value from the feature JSON node using the mapped value for the given input.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public class Census {
private String boundaryCode = null;

@JsonProperty("assignee")
@Size(max = 64)
private String assignee = null;
private List<String> assignee = null;

@JsonProperty("status")
@Size(max = 64)
Expand Down
Loading