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 1dcb9bd1ae..4860036887 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 @@ -71,13 +71,16 @@ public class ServiceConstants { public static final String FILE_NAME = "output.xls"; public static final String FILE_TYPE = "boundaryWithTarget"; public static final String FILE_TEMPLATE_IDENTIFIER_POPULATION = "Population"; + public static final String FILE_TEMPLATE_IDENTIFIER_BOUNDARY = "boundaryWithTarget"; public static final String FILE_TEMPLATE_IDENTIFIER_FACILITY = "Facilities"; public static final String INPUT_IS_NOT_VALID = "File does not contain valid input for row "; - + public static final String MDMS_SCHEMA_TYPE = "type"; public static final String MDMS_SCHEMA_SECTION = "section"; + public static final String MDMS_SCHEMA_TITLE = "title"; public static final String MDMS_PLAN_MODULE_NAME = "hcm-microplanning"; public static final String MDMS_MASTER_SCHEMAS = "Schemas"; + public static final String MDMS_MASTER_ADMIN_SCHEMA = "adminSchema"; public static final String MDMS_CAMPAIGN_TYPE = "campaignType"; public static final String MDMS_SCHEMA_ADMIN_SCHEMA = "adminSchema"; public static final String MDMS_ADMIN_CONSOLE_MODULE_NAME = "HCM-ADMIN-CONSOLE"; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java b/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java index 018a2652b4..1755fa566d 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java @@ -384,8 +384,7 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest String fileStoreId, CampaignResponse campaign, PlanConfiguration planConfig, Object mdmsData) { org.egov.processor.web.models.File file = planConfig.getFiles().stream() .filter(f -> f.getFilestoreId().equalsIgnoreCase(fileStoreId)).findFirst().get(); - return mdmsUtil.filterMasterData(mdmsData.toString(), file.getInputFileType(), - file.getTemplateIdentifier(), campaign.getCampaign().get(0).getProjectType()); + return mdmsUtil.filterMasterData(mdmsData.toString(), campaign.getCampaign().get(0).getProjectType()); } @@ -783,6 +782,6 @@ public List getAllBoundaryPresentforHierarchyType(List } return boundaryList; } - + } \ No newline at end of file diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsUtil.java index e3019ded61..6163e20d50 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsUtil.java @@ -1,9 +1,5 @@ package org.egov.processor.util; -import static org.egov.processor.config.ServiceConstants.ERROR_WHILE_FETCHING_FROM_MDMS; -import static org.egov.processor.config.ServiceConstants.NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE; -import static org.egov.processor.config.ServiceConstants.NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE; - import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -31,6 +27,8 @@ import lombok.extern.slf4j.Slf4j; +import static org.egov.processor.config.ServiceConstants.*; + @Slf4j @Component public class MdmsUtil { @@ -41,11 +39,14 @@ public class MdmsUtil { private Configuration configs; - public MdmsUtil(RestTemplate restTemplate, ObjectMapper mapper, Configuration configs) { + private ParsingUtil parsingUtil; + + public MdmsUtil(RestTemplate restTemplate, ObjectMapper mapper, Configuration configs, ParsingUtil parsingUtil) { this.restTemplate = restTemplate; this.mapper = mapper; this.configs = configs; - } + this.parsingUtil = parsingUtil; + } /** * Fetches MDMS (Municipal Data Management System) data using the provided @@ -74,7 +75,7 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) { if (result == null || ObjectUtils.isEmpty(result)) { log.error(NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE + " - " + tenantId); throw new CustomException(NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE, - "no data found for the given tenantid "+tenantId + " for master name "+ServiceConstants.MDMS_MASTER_SCHEMAS); + "no data found for the given tenantid "+tenantId + " for master name "+ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA); } return result; } @@ -87,10 +88,9 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) { * @return The MDMS criteria request object. */ public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) { - - ModuleDetail moduleDetail = getPlanModuleDetail(); + ModuleDetail adminConsoleModuleDetail = getAdminConsoleModuleDetail(); List moduleDetails = new LinkedList<>(); - moduleDetails.add(moduleDetail); + moduleDetails.add(adminConsoleModuleDetail); MdmsCriteria mdmsCriteria = MdmsCriteria.builder().moduleDetails(moduleDetails).tenantId(tenantId).build(); return MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); } @@ -109,33 +109,53 @@ private ModuleDetail getPlanModuleDetail() { .moduleName(ServiceConstants.MDMS_PLAN_MODULE_NAME).build(); } + /** + * Retrieves the module details for the HCM-ADMIN-CONSOLE module. + * + * @return ModuleDetail object containing master details for the HCM-ADMIN-CONSOLE module. + */ + private ModuleDetail getAdminConsoleModuleDetail() { + List adminSchemaMasterDetails = new ArrayList<>(); + MasterDetail schemaDetails = MasterDetail.builder().name(ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA).build(); + adminSchemaMasterDetails.add(schemaDetails); + + return ModuleDetail.builder().masterDetails(adminSchemaMasterDetails) + .moduleName(ServiceConstants.MDMS_ADMIN_CONSOLE_MODULE_NAME).build(); + } + /** * Filters master data based on the provided parameters. * * @param masterDataJson The JSON string representing the master data. - * @param fileType The type of input file. - * @param templateIdentifier The template identifier. * @param campaignType The campaign type. * @return A map containing filtered properties from the master data. * @throws JsonMappingException if there's an issue mapping JSON. * @throws JsonProcessingException if there's an issue processing JSON. */ - public Map filterMasterData(String masterDataJson, File.InputFileTypeEnum fileType, - String templateIdentifier, String campaignType) { + public Map filterMasterData(String masterDataJson, String campaignType) { Map properties = new HashMap<>(); Map masterData = JsonUtils.parseJson(masterDataJson, Map.class); - Map planModule = (Map) masterData.get(ServiceConstants.MDMS_PLAN_MODULE_NAME); - List> schemas = (List>) planModule - .get(ServiceConstants.MDMS_MASTER_SCHEMAS); - log.info("masterDataJson ==>" + schemas); - for (Map schema : schemas) { - String type = (String) schema.get(ServiceConstants.MDMS_SCHEMA_TYPE); + Map adminConsoleModule = (Map) masterData.get(ServiceConstants.MDMS_ADMIN_CONSOLE_MODULE_NAME); + List> adminSchema = (List>) adminConsoleModule + .get(ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA); + log.debug("masterDataJson ==> " + adminSchema); + + for (Map schema : adminSchema) { String campaign = (String) schema.get(ServiceConstants.MDMS_CAMPAIGN_TYPE); - // String fileT = InputFileTypeEnum.valueOf(type); - if (schema.get(ServiceConstants.MDMS_SCHEMA_SECTION).equals(ServiceConstants.FILE_TEMPLATE_IDENTIFIER_POPULATION) - && campaign.equals(campaignType) && type.equals(fileType.toString())) { - Map schemaProperties = (Map) schema.get("schema"); - properties = (Map) schemaProperties.get("Properties"); + + // Check if the schema's title matches the required template identifier + // and the campaign matches the specified campaign type. + if (schema.get(ServiceConstants.MDMS_SCHEMA_TITLE).equals(ServiceConstants.FILE_TEMPLATE_IDENTIFIER_BOUNDARY) + && campaign.equals(MICROPLAN_PREFIX + campaignType)) { + Map> schemaProperties = (Map>) schema.get("properties"); + + schemaProperties.forEach((propertyType, propertyList) -> + // For each property in the property list, extract its name and add it to the map with the property. + propertyList.forEach(property -> { + String propertyName = (String) parsingUtil.extractFieldsFromJsonObject(property, "name"); + properties.put(propertyName, property); + }) + ); } }