diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java b/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java index 904be09cb7..6e0a864c10 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java @@ -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 diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java index a8a5d4b615..0d73780d33 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java @@ -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.*; @@ -114,25 +115,51 @@ private Object enrichAdditionalDetials(Map boundaryCodeToCensusA // 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 fieldsToBeUpdated = new HashMap<>(); - if(facilityId != null && !facilityId.isEmpty()) + if(ObjectUtils.isEmpty(fieldsToBeUpdated)) fieldsToBeUpdated.put(FACILITY_ID, facilityId); - if(accessibilityDetails != null) - fieldsToBeUpdated.put(ACCESSIBILITY_DETAILS, accessibilityDetails); + // Add fields from securityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. + if (securityDetails instanceof Map && securityDetails != null) { + extractNestedFields((Map) securityDetails, SECURITY_DETAILS, fieldsToBeUpdated); + } - if(securityDetials != null) - fieldsToBeUpdated.put(SECURITY_DETAILS, securityDetials); + // Add fields from accessibilityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. + if (accessibilityDetails instanceof Map && accessibilityDetails != null) { + extractNestedFields((Map) accessibilityDetails, ACCESSIBILITY_DETAILS, fieldsToBeUpdated); + } if(!CollectionUtils.isEmpty(fieldsToBeUpdated)) return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); } return null; } - + + /** + * Extracts nested fields from the given 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 details, String prefix, Map fieldsToBeUpdated) { + for (Map.Entry entry : details.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + + if (value instanceof Map) { + Map nestedMap = (Map) 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. * diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/census/Census.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/census/Census.java index f895f6c75f..8db4e8b6ec 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/census/Census.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/census/Census.java @@ -48,8 +48,7 @@ public class Census { private String boundaryCode = null; @JsonProperty("assignee") - @Size(max = 64) - private String assignee = null; + private List assignee = null; @JsonProperty("status") @Size(max = 64)