From dba50acfee0c69b7c12755d315c3c0bb579fdf3b Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 3 Jan 2025 14:24:09 +0530 Subject: [PATCH 01/76] Removed readme sheet, localised estimation sheet and added facility name --- .../processor/config/ServiceConstants.java | 11 + .../egov/processor/service/ExcelParser.java | 58 ++---- .../egov/processor/util/EnrichmentUtil.java | 11 +- .../egov/processor/util/ExcelStylingUtil.java | 78 +++++++ .../util/OutputEstimationGenerationUtil.java | 196 ++++++++++++++++++ .../org/egov/processor/util/ParsingUtil.java | 73 ++++++- 6 files changed, 385 insertions(+), 42 deletions(-) create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java 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 7200f29cec..41e9144856 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 @@ -39,6 +39,9 @@ public class ServiceConstants { public static final String FILE_NOT_FOUND_CODE = "FILE_NOT_FOUND"; public static final String FILE_NOT_FOUND_MESSAGE = "No file with the specified templateIdentifier found - "; + public static final String PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_CODE = "PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT"; + public static final String PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_MESSAGE = "Key is not present in json object - "; + public static final String UNABLE_TO_CREATE_ADDITIONAL_DETAILS_CODE = "UNABLE_TO_CREATE_ADDITIONAL_DETAILS"; public static final String UNABLE_TO_CREATE_ADDITIONAL_DETAILS_MESSAGE = "Unable to create additional details for facility creation."; @@ -116,8 +119,16 @@ public class ServiceConstants { public static final String SOURCE_KEY = "source"; public static final String MICROPLAN_SOURCE_KEY = "microplan"; public static final String MICROPLAN_ID_KEY = "microplanId"; + public static final String FACILITY_NAME = "facilityName"; + public static final String HCM_MICROPLAN_SERVING_FACILITY = "HCM_MICROPLAN_SERVING_FACILITY"; //Census additional field constants public static final String UPLOADED_KEY = "UPLOADED_"; public static final String CONFIRMED_KEY = "CONFIRMED_"; + + //Excel header row styling constants + public static final String HEX_BACKGROUND_COLOR = "93C47D"; // Constant background color + public static final boolean FREEZE_CELL = true; // Constant to lock cell + public static final int COLUMN_WIDTH = 40; // Column width in characters + } 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 6f2326d628..2faa00b43f 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 @@ -13,7 +13,6 @@ import org.egov.processor.config.ServiceConstants; import org.egov.processor.util.*; import org.egov.processor.web.models.*; -import org.egov.processor.web.models.Locale; import org.egov.processor.web.models.boundary.BoundarySearchResponse; import org.egov.processor.web.models.boundary.EnrichedBoundary; import org.egov.processor.web.models.campaignManager.Boundary; @@ -31,9 +30,6 @@ import java.util.*; import java.util.stream.Collectors; -import static org.egov.processor.config.ServiceConstants.HCM_ADMIN_CONSOLE_BOUNDARY_DATA; -import static org.egov.processor.config.ServiceConstants.READ_ME_SHEET_NAME; - @Slf4j @Service public class ExcelParser implements FileParser { @@ -64,9 +60,11 @@ public class ExcelParser implements FileParser { private PlanConfigurationUtil planConfigurationUtil; + private OutputEstimationGenerationUtil outputEstimationGenerationUtil; + public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, PlanUtil planUtil, CampaignIntegrationUtil campaignIntegrationUtil, - Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil) { + Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil) { this.objectMapper = objectMapper; this.parsingUtil = parsingUtil; this.filestoreUtil = filestoreUtil; @@ -80,6 +78,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore this.censusUtil = censusUtil; this.enrichmentUtil = enrichmentUtil; this.planConfigurationUtil = planConfigurationUtil; + this.outputEstimationGenerationUtil = outputEstimationGenerationUtil; } /** @@ -128,7 +127,7 @@ private void processExcelFile(PlanConfigurationRequest planConfigurationRequest, processSheets(planConfigurationRequest, fileStoreId, campaignResponse, workbook, campaignBoundaryList, dataFormatter); uploadFileAndIntegrateCampaign(planConfigurationRequest, campaignResponse, - workbook, campaignBoundaryList, campaignResourcesList); + workbook, campaignBoundaryList, campaignResourcesList, fileStoreId); } catch (FileNotFoundException e) { log.error("File not found: {}", e.getMessage()); throw new CustomException("FileNotFound", "The specified file was not found."); @@ -153,7 +152,7 @@ private void processExcelFile(PlanConfigurationRequest planConfigurationRequest, */ private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigurationRequest, Object campaignResponse, Workbook workbook, - List campaignBoundaryList, List campaignResourcesList) { + List campaignBoundaryList, List campaignResourcesList, String filestoreId) { File fileToUpload = null; try { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); @@ -164,9 +163,21 @@ private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigu planUtil.update(planConfigurationRequest); } if (planConfig.getStatus().equals(config.getPlanConfigUpdatePlanEstimatesIntoOutputFileStatus()) && config.isIntegrateWithAdminConsole()) { + //Upload the processed output file into project factory String uploadedFileStoreId = uploadConvertedFile(fileToUpload, planConfig.getTenantId()); campaignIntegrationUtil.updateResourcesInProjectFactory(planConfigurationRequest, uploadedFileStoreId); - } + + outputEstimationGenerationUtil.processOutputFile(workbook, planConfigurationRequest); + + // Adding facility information for each boundary code + outputEstimationGenerationUtil.addAssignedFacility(workbook, planConfigurationRequest, filestoreId); + + //update processed output file into plan configuration file object + fileToUpload = convertWorkbookToXls(workbook); + uploadedFileStoreId = uploadConvertedFile(fileToUpload, planConfig.getTenantId()); + planUtil.setFileStoreIdForPopulationTemplate(planConfigurationRequest, uploadedFileStoreId); + planUtil.update(planConfigurationRequest); + } } finally { try { if (fileToUpload != null && !fileToUpload.delete()) { @@ -189,7 +200,7 @@ private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigu * @param campaignBoundaryList List of boundary objects related to the campaign. * @param dataFormatter The data formatter for formatting cell values. */ - + //TODO: processsheetforestimate and processsheetforcensus private void processSheets(PlanConfigurationRequest request, String fileStoreId, Object campaignResponse, Workbook excelWorkbook, List campaignBoundaryList, @@ -213,7 +224,7 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, LinkedHashMap::new )); excelWorkbook.forEach(excelWorkbookSheet -> { - if (isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { + if (parsingUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues); processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId, @@ -312,7 +323,6 @@ private List getBoundaryCodeList(PlanConfigurationRequest planConfigurat * @return A map of attribute names to their corresponding indices or data types. */ - //TODO: fetch from adminSchema master private Map prepareAttributeVsIndexMap(PlanConfigurationRequest planConfigurationRequest, String fileStoreId, CampaignResponse campaign, PlanConfiguration planConfig, Object mdmsData) { @@ -370,7 +380,8 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues); - + // TODO: remove after testing + parsingUtil.printRow(sheet, row); } } @@ -718,28 +729,5 @@ public List getAllBoundaryPresentforHierarchyType(List return boundaryList; } - /** - * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. - * - * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. - * @param sheetName The name of the sheet to be processed. - * @return true if the sheet is allowed to be processed, false otherwise. - * @throws JsonMappingException If there's an issue mapping JSON response to Java objects. - * @throws JsonProcessingException If there's an issue processing JSON during conversion. - */ - private boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { - Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( - planConfigurationRequest.getRequestInfo(), - planConfigurationRequest.getPlanConfiguration().getTenantId()); - - for (Locale locale : localeResponse.getMessages()) { - if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) - || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { - if (sheetName.equals(locale.getMessage())) - return false; - } - } - return true; - } } \ No newline at end of file diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 89f0a89511..e543dd062a 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -144,6 +144,9 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR } } } + //TODO: remove after testing + log.info("After updating values in sheet -> "); + parsingUtil.printRow(sheet, row); log.info("Successfully update file with approved census data."); } @@ -220,10 +223,10 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR Integer indexOfBoundaryCode = parsingUtil.getIndexOfBoundaryCode(0, parsingUtil.sortColumnByIndex(mapOfColumnNameAndIndex), mappedValues); - //Getting census records for the list of boundaryCodes + //Getting plan records for the list of boundaryCodes List planList = getPlanRecordsForEnrichment(planConfigurationRequest, boundaryCodes); - // Create a map from boundaryCode to Census for quick lookups + // Create a map from boundaryCode to Plan for quick lookups Map planMap = planList.stream() .collect(Collectors.toMap(Plan::getLocality, plan -> plan)); @@ -233,6 +236,7 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR for(Row row: sheet) { + parsingUtil.printRow(sheet, row); // Skip the header row and empty rows if (row.getRowNum() == 0 || parsingUtil.isRowEmpty(row)) { continue; @@ -265,6 +269,9 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR } } } + //TODO: remove after testing + log.info("After updating values in sheet -> "); + parsingUtil.printRow(sheet, row); log.info("Successfully update file with approved census data."); } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java new file mode 100644 index 0000000000..c8da424ea1 --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java @@ -0,0 +1,78 @@ +package org.egov.processor.util; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.*; +import org.springframework.stereotype.Component; + +import java.awt.Color; + +import static org.egov.processor.config.ServiceConstants.*; + +@Component +public class ExcelStylingUtil { + + public void styleCell(Cell cell) { + Sheet sheet = cell.getSheet(); + Workbook workbook = sheet.getWorkbook(); + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook; + + // Create a cell style + XSSFCellStyle cellStyle = (XSSFCellStyle) workbook.createCellStyle(); + + // Set background color + XSSFColor backgroundColor = hexToXSSFColor(HEX_BACKGROUND_COLOR, xssfWorkbook); + cellStyle.setFillForegroundColor(backgroundColor); + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + // Set font style (bold) + XSSFFont font = (XSSFFont) workbook.createFont(); + font.setBold(true); + cellStyle.setFont(font); + + // Set alignment and wrap text + cellStyle.setAlignment(HorizontalAlignment.LEFT); + cellStyle.setVerticalAlignment(VerticalAlignment.TOP); + cellStyle.setWrapText(true); + + // Lock the cell if FREEZE_CELL is true + if (FREEZE_CELL) { + cellStyle.setLocked(true); + } + + // Apply the style to the cell + cell.setCellStyle(cellStyle); + + // Adjust the column width + int columnIndex = cell.getColumnIndex(); + sheet.setColumnWidth(columnIndex, COLUMN_WIDTH * 256); // Width is measured in units of 1/256 of a character + } + + /** + * Converts a HEX color string to XSSFColor using the XSSFWorkbook context. + * + * @param hexColor The HEX color string (e.g., "93C47D"). + * @param xssfWorkbook The XSSFWorkbook context for styles. + * @return XSSFColor The corresponding XSSFColor object. + */ + public static XSSFColor hexToXSSFColor(String hexColor, XSSFWorkbook xssfWorkbook) { + // Convert HEX to RGB + int red = Integer.valueOf(hexColor.substring(0, 2), 16); + int green = Integer.valueOf(hexColor.substring(2, 4), 16); + int blue = Integer.valueOf(hexColor.substring(4, 6), 16); + + red = (int) (red * 1.1); // increase red component by 10% + green = (int) (green * 1.1); // increase green component by 10% + blue = (int) (blue * 1.1); // increase blue component by 10% + + // Clamp the values to be between 0 and 255 + red = Math.min(255, Math.max(0, red)); + green = Math.min(255, Math.max(0, green)); + blue = Math.min(255, Math.max(0, blue)); + + // Create IndexedColorMap from the workbook's styles source + IndexedColorMap colorMap = xssfWorkbook.getStylesSource().getIndexedColors(); + + // Create XSSFColor using the XSSFWorkbook context and colorMap + return new XSSFColor(new Color(red, green, blue), colorMap); + } +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java new file mode 100644 index 0000000000..71b3ac8b65 --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -0,0 +1,196 @@ +package org.egov.processor.util; + +import org.apache.poi.ss.usermodel.*; +import org.egov.processor.web.models.Locale; +import org.egov.processor.web.models.LocaleResponse; +import org.egov.processor.web.models.PlanConfigurationRequest; +import org.egov.processor.web.models.ResourceMapping; +import org.egov.processor.web.models.census.Census; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.egov.tracer.model.CustomException; + +import static org.egov.processor.config.ServiceConstants.FACILITY_NAME; +import static org.egov.processor.config.ServiceConstants.HCM_MICROPLAN_SERVING_FACILITY; + +@Component +public class OutputEstimationGenerationUtil { + + private LocaleUtil localeUtil; + + private ParsingUtil parsingUtil; + + private ExcelStylingUtil excelStylingUtil; + + private EnrichmentUtil enrichmentUtil; + + public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsingUtil, EnrichmentUtil enrichmentUtil, ExcelStylingUtil excelStylingUtil) { + this.localeUtil = localeUtil; + this.parsingUtil = parsingUtil; + this.excelStylingUtil = excelStylingUtil; + this.enrichmentUtil = enrichmentUtil; + } + + public void processOutputFile(Workbook workbook, PlanConfigurationRequest request) { + LocaleResponse localeResponse = localeUtil.searchLocale(request); + //removing readme sheet + for (int i = workbook.getNumberOfSheets() - 1; i >= 0; i--) { + Sheet sheet = workbook.getSheetAt(i); + if (!parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + workbook.removeSheetAt(i); + } + } + + Map localizationCodeAndMessageMap = localeResponse.getMessages().stream() + .collect(Collectors.toMap( + Locale::getCode, + Locale::getMessage, + (existingValue, newValue) -> existingValue // Keep the existing value in case of duplicates + )); + + for(Sheet sheet: workbook) { + processSheetForHeaderLocalization(sheet, localizationCodeAndMessageMap); + } + } + + public void processSheetForHeaderLocalization(Sheet sheet, Map localizationCodeAndMessageMap) { + // Fetch the header row from sheet + Row row = sheet.getRow(0); + if (parsingUtil.isRowEmpty(row)) throw new CustomException(); + + + //Iterate from the end, for every cell localize the header value + for (int i = row.getLastCellNum() - 1; i >= 0; i--) { + Cell headerColumn = row.getCell(i); + + if (headerColumn == null || headerColumn.getCellType() != CellType.STRING) { + continue; + } + String headerColumnValue = headerColumn.getStringCellValue(); + + // Exit the loop if the header column value is not in the localization map + if (!localizationCodeAndMessageMap.containsKey(headerColumnValue)) { + break; + } + + // Update the cell value with the localized message + excelStylingUtil.styleCell(headerColumn); + headerColumn.setCellValue(localizationCodeAndMessageMap.get(headerColumnValue)); + } + + } + + /** + * This is the main method responsible for adding an assigned facility name column to each sheet in the workbook. + * It iterates through all the sheets, verifies if they are eligible for processing, retrieves required mappings + * and boundary codes, and populates the new column with facility names based on these mappings. + * + * @param workbook the workbook containing the sheets to be processed. + * @param request the plan configuration request containing the resource mapping and other configurations. + * @param fileStoreId the associated file store ID used to filter resource mappings. + */ + public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { + LocaleResponse localeResponse = localeUtil.searchLocale(request); + + String assignedFacilityColHeader = localeUtil.localeSearch(localeResponse.getMessages(), HCM_MICROPLAN_SERVING_FACILITY); + assignedFacilityColHeader = assignedFacilityColHeader != null ? assignedFacilityColHeader : HCM_MICROPLAN_SERVING_FACILITY; + + // Creating a map of MappedTo and MappedFrom values from resource mapping + Map mappedValues = request.getPlanConfiguration().getResourceMapping().stream() + .filter(f -> f.getFilestoreId().equals(fileStoreId)) + .collect(Collectors.toMap( + ResourceMapping::getMappedTo, + ResourceMapping::getMappedFrom, + (existing, replacement) -> existing, + LinkedHashMap::new + )); + + // Get the map of boundary code to the facility assigned to that boundary. + Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId); + + for (int i = 0; i < workbook.getNumberOfSheets(); i++) { + Sheet sheet = workbook.getSheetAt(i); + if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); + } + } + } + + /** + * Collects boundary codes from all eligible sheets in the workbook, fetches census records for these boundaries, + * and maps each boundary code to its assigned facility name obtained from the census data. + * + * @param workbook the workbook containing the sheets. + * @param request the plan configuration request with boundary code details. + * @param fileStoreId the associated file store ID for filtering. + * @return a map of boundary codes to their assigned facility names. + */ + private Map getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { + List boundaryCodes = new ArrayList<>(); + + for (int i = 0; i < workbook.getNumberOfSheets(); i++) { + Sheet sheet = workbook.getSheetAt(i); + if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { + boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); + } + } + + List censusList = enrichmentUtil.getCensusRecordsForEnrichment(request, boundaryCodes); + return censusList.stream() + .collect(Collectors.toMap( + Census::getBoundaryCode, + census -> (String) parsingUtil.extractFieldsFromJsonObject(census.getAdditionalDetails(), FACILITY_NAME))); + } + + /** + * Processes a given sheet by adding a new column for assigned facilities and populating + * each row with the corresponding facility name based on the boundary code. + * + * @param sheet the sheet being processed. + * @param assignedFacilityColHeader the header for the new assigned facility column. + * @param boundaryCodeToFacility the mapping of boundary codes to assigned facilities. + * @param mappedValues a map of 'MappedTo' to 'MappedFrom' values. + */ + private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeader, Map boundaryCodeToFacility, Map mappedValues) { + int indexOfFacility = createAssignedFacilityColumn(sheet, assignedFacilityColHeader); + Map columnNameIndexMap = parsingUtil.getAttributeNameIndexFromExcel(sheet); + int indexOfBoundaryCode = parsingUtil.getIndexOfBoundaryCode(0, parsingUtil.sortColumnByIndex(columnNameIndexMap), mappedValues); + + for (Row row : sheet) { + if (row.getRowNum() == 0 || parsingUtil.isRowEmpty(row)) { + continue; + } + + String boundaryCode = row.getCell(indexOfBoundaryCode).getStringCellValue(); + + Cell facilityCell = row.getCell(indexOfFacility); + if (facilityCell == null) { + facilityCell = row.createCell(indexOfFacility, CellType.STRING); + } + + facilityCell.setCellValue(boundaryCodeToFacility.getOrDefault(boundaryCode, "")); + } + } + + /** + * Adds a new column for the assigned facility name in the provided sheet, styles the header cell, + * and returns the index of the newly created column. + * + * @param sheet the sheet where the column is to be added. + * @param assignedFacilityColHeader the header for the new column. + * @return the index of the newly created column. + */ + private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityColHeader) { + int indexOfFacility = (int) sheet.getRow(0).getLastCellNum(); + Cell facilityColHeader = sheet.getRow(0).createCell(indexOfFacility, CellType.STRING); + excelStylingUtil.styleCell(facilityColHeader); + facilityColHeader.setCellValue(assignedFacilityColHeader); + return indexOfFacility; + } +} + diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index ba10327e4c..756252b562 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -7,8 +7,8 @@ import org.apache.commons.io.FileUtils; import org.apache.poi.ss.usermodel.*; import org.egov.processor.config.ServiceConstants; -import org.egov.processor.web.models.PlanConfiguration; -import org.egov.processor.web.models.ResourceMapping; +import org.egov.processor.web.models.Locale; +import org.egov.processor.web.models.*; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; @@ -17,6 +17,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; @@ -24,7 +25,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.egov.processor.config.ServiceConstants.PROPERTIES; +import static org.egov.processor.config.ServiceConstants.*; @Slf4j @Component @@ -36,10 +37,16 @@ public class ParsingUtil { private CalculationUtil calculationUtil; - public ParsingUtil(PlanConfigurationUtil planConfigurationUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil) { + private MdmsUtil mdmsUtil; + + private ObjectMapper objectMapper; + + public ParsingUtil(PlanConfigurationUtil planConfigurationUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, MdmsUtil mdmsUtil, ObjectMapper objectMapper) { this.planConfigurationUtil = planConfigurationUtil; this.filestoreUtil = filestoreUtil; this.calculationUtil = calculationUtil; + this.mdmsUtil = mdmsUtil; + this.objectMapper = objectMapper; } public List fetchAttributeNamesFromJson(JsonNode jsonNode) @@ -314,7 +321,7 @@ public List extractPropertyNamesFromAdminSchema(JsonNode rootNode) { * @param row the Row to check * @return true if the row is empty, false otherwise */ - public static boolean isRowEmpty(Row row) { + public boolean isRowEmpty(Row row) { if (row == null) { return true; } @@ -392,4 +399,60 @@ public void printRow(Sheet sheet, Row row) { System.out.println(); // Move to the next line after printing the row } + /** + * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. + * + * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. + * @param sheetName The name of the sheet to be processed. + * @return true if the sheet is allowed to be processed, false otherwise. + */ + public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { + Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( + planConfigurationRequest.getRequestInfo(), + planConfigurationRequest.getPlanConfiguration().getTenantId()); + + for (Locale locale : localeResponse.getMessages()) { + if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) + || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { + if (sheetName.equals(locale.getMessage())) + return false; + } + } + return true; + + } + + /** + * Extracts provided field from the additional details object + * + * @param additionalDetails the additionalDetails object from PlanConfigurationRequest + * @param fieldToExtract the name of the field to be extracted from the additional details + * @return the value of the specified field as a string + * @throws CustomException if the field does not exist + */ + public Object extractFieldsFromJsonObject(Object additionalDetails, String fieldToExtract) { + try { + String jsonString = objectMapper.writeValueAsString(additionalDetails); + JsonNode rootNode = objectMapper.readTree(jsonString); + + JsonNode node = rootNode.get(fieldToExtract); + if (node != null && !node.isNull()) { + + // Check for different types of JSON nodes + if (node.isDouble() || node.isFloat()) { + return BigDecimal.valueOf(node.asDouble()); // Convert Double to BigDecimal + } else if (node.isLong() || node.isInt()) { + return BigDecimal.valueOf(node.asLong()); // Convert Long to BigDecimal + } else if (node.isBoolean()) { + return node.asBoolean(); + } else if (node.isTextual()) { + return node.asText(); + } + } + return null; + } catch (Exception e) { + log.error(e.getMessage() + fieldToExtract); + throw new CustomException(PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_CODE, PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_MESSAGE + fieldToExtract); + } + } } From f3893e34345e334e65d9bdf9f164ba6e93821671 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 3 Jan 2025 14:32:45 +0530 Subject: [PATCH 02/76] Adding additional field in plan --- .../repository/impl/PlanRepositoryImpl.java | 1 + .../querybuilder/PlanQueryBuilder.java | 6 ++- .../repository/rowmapper/PlanRowMapper.java | 38 +++++++++++++++++++ .../service/enrichment/PlanEnricher.java | 10 +++++ .../enrichment/PlanFacilityEnricher.java | 5 +-- .../models/{census => }/AdditionalField.java | 2 +- .../src/main/java/digit/web/models/Plan.java | 4 ++ .../main/java/digit/web/models/PlanDTO.java | 4 ++ .../java/digit/web/models/census/Census.java | 1 + ...1500__plan_additional_field_create_ddl.sql | 12 ++++++ 10 files changed, 76 insertions(+), 7 deletions(-) rename health-services/plan-service/src/main/java/digit/web/models/{census => }/AdditionalField.java (96%) create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index 99e4b9487d..90cdb199bf 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -189,6 +189,7 @@ private PlanRequestDTO convertToPlanReqDTO(PlanRequest planRequest) { .assignee(assignee) .additionalDetails(plan.getAdditionalDetails()) .jurisdictionMapping(plan.getJurisdictionMapping()) + .additionalFields(plan.getAdditionalFields()) .activities(plan.getActivities()) .resources(plan.getResources()) .targets(plan.getTargets()) diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 5c8bc91097..76530427b1 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -30,12 +30,14 @@ public PlanQueryBuilder(Configuration config, QueryUtil queryUtil) { "\t plan_activity.id as plan_activity_id, plan_activity.code as plan_activity_code, plan_activity.description as plan_activity_description, plan_activity.planned_start_date as plan_activity_planned_start_date, plan_activity.planned_end_date as plan_activity_planned_end_date, plan_activity.dependencies as plan_activity_dependencies, plan_activity.plan_id as plan_activity_plan_id, plan_activity.created_by as plan_activity_created_by, plan_activity.created_time as plan_activity_created_time, plan_activity.last_modified_by as plan_activity_last_modified_by, plan_activity.last_modified_time as plan_activity_last_modified_time,\n" + "\t plan_activity_condition.id as plan_activity_condition_id, plan_activity_condition.entity as plan_activity_condition_entity, plan_activity_condition.entity_property as plan_activity_condition_entity_property, plan_activity_condition.expression as plan_activity_condition_expression, plan_activity_condition.activity_id as plan_activity_condition_activity_id, plan_activity_condition.is_active as plan_activity_condition_is_active, plan_activity_condition.created_by as plan_activity_condition_created_by, plan_activity_condition.created_time as plan_activity_condition_created_time, plan_activity_condition.last_modified_by as plan_activity_condition_last_modified_by, plan_activity_condition.last_modified_time as plan_activity_condition_last_modified_time,\n" + "\t plan_resource.id as plan_resource_id, plan_resource.resource_type as plan_resource_resource_type, plan_resource.estimated_number as plan_resource_estimated_number, plan_resource.plan_id as plan_resource_plan_id, plan_resource.activity_code as plan_resource_activity_code, plan_resource.created_by as plan_resource_created_by, plan_resource.created_time as plan_resource_created_time, plan_resource.last_modified_by as plan_resource_last_modified_by, plan_resource.last_modified_time as plan_resource_last_modified_time,\n" + - "\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time\n" + + "\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time, \n" + + "\t paf.id as plan_additional_field_id, paf.plan_id as plan_additional_field_plan_id, paf.key as plan_additional_field_key, paf.value as plan_additional_field_value, paf.show_on_ui as plan_additional_field_show_on_ui, paf.editable as plan_additional_field_editable, paf.order as plan_additional_field_order \n" + "\t FROM plan \n" + "\t LEFT JOIN plan_activity ON plan.id = plan_activity.plan_id\n" + "\t LEFT JOIN plan_activity_condition ON plan_activity.id = plan_activity_condition.activity_id\n" + "\t LEFT JOIN plan_resource ON plan.id = plan_resource.plan_id\n" + - "\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id"; + "\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id\n" + + "\t LEFT JOIN plan_additional_field paf ON plan.id = paf.plan_id"; private static final String BULK_PLAN_UPDATE_QUERY = "UPDATE plan SET status = ?, assignee = ?, last_modified_by = ?, last_modified_time = ? WHERE id = ?"; diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java index aa00207a74..b37561fbc3 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -30,6 +30,7 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep Set conditionSet = new HashSet<>(); Set resourceSet = new HashSet<>(); Set targetSet = new HashSet<>(); + Set additionalFieldSet = new HashSet<>(); // Traverse through result set and create plan objects while (rs.next()) { @@ -43,6 +44,7 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep conditionSet.clear(); resourceSet.clear(); targetSet.clear(); + additionalFieldSet.clear(); // Prepare audit details AuditDetails auditDetails = AuditDetails.builder() @@ -72,6 +74,7 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep addActivities(rs, planEntry, activityMap, conditionSet); addResources(rs, planEntry, resourceSet); addTargets(rs, planEntry, targetSet); + addAdditionalField(rs, planEntry, additionalFieldSet); planMap.put(planId, planEntry); } @@ -234,4 +237,39 @@ private void addTargets(ResultSet rs, Plan planEntry, Set targetSet) thr targetSet.add(target.getId()); } + + /** + * Adds a AdditionalField object to the plan entry based on the result set. + * + * @param rs The ResultSet containing the data. + * @param additionalFieldSet A set to keep track of added AdditionalField objects. + * @param planEntry The Plan entry to which the AdditionalField object will be added. + * @throws SQLException If an SQL error occurs. + */ + private void addAdditionalField(ResultSet rs, Plan planEntry, Set additionalFieldSet) throws SQLException { + String additionalFieldId = rs.getString("plan_additional_field_id"); + + if (ObjectUtils.isEmpty(additionalFieldId) || additionalFieldSet.contains(additionalFieldId)) { + return; + } + + AdditionalField additionalField = new AdditionalField(); + additionalField.setId(rs.getString("plan_additional_field_id")); + additionalField.setKey(rs.getString("plan_additional_field_key")); + additionalField.setValue(rs.getBigDecimal("plan_additional_field_value")); + additionalField.setShowOnUi(rs.getBoolean("plan_additional_field_show_on_ui")); + additionalField.setEditable(rs.getBoolean("plan_additional_field_editable")); + additionalField.setOrder(rs.getInt("plan_additional_field_order")); + + if (CollectionUtils.isEmpty(planEntry.getAdditionalFields())) { + List additionalFields = new ArrayList<>(); + additionalFields.add(additionalField); + planEntry.setAdditionalFields(additionalFields); + } else { + planEntry.getAdditionalFields().add(additionalField); + } + + additionalFieldSet.add(additionalFieldId); + } + } diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java index 17364bfdb6..39586d650c 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java @@ -53,6 +53,9 @@ public void enrichPlanCreate(PlanRequest body) { // Generate id for targets body.getPlan().getTargets().forEach(target -> UUIDEnrichmentUtil.enrichRandomUuid(target, "id")); + // Generate id for additional fields + body.getPlan().getAdditionalFields().forEach(additionalField -> UUIDEnrichmentUtil.enrichRandomUuid(additionalField, "id")); + // Enrich audit details body.getPlan().setAuditDetails(AuditDetailsEnrichmentUtil .prepareAuditDetails(body.getPlan().getAuditDetails(), body.getRequestInfo(), Boolean.TRUE)); @@ -107,6 +110,13 @@ public void enrichPlanUpdate(PlanRequest body) { } }); + // Generate uuid for new additionalFields + body.getPlan().getAdditionalFields().forEach(additionalFields -> { + if(ObjectUtils.isEmpty(additionalFields.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id"); + } + }); + // Enriching last modified time for update body.getPlan().getAuditDetails().setLastModifiedTime(System.currentTimeMillis()); } diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java index a07530dbfd..fccb2de96d 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java @@ -3,10 +3,7 @@ import digit.util.BoundaryUtil; import digit.util.CensusUtil; import digit.util.CommonUtil; -import digit.web.models.PlanFacility; -import digit.web.models.PlanFacilityRequest; -import digit.web.models.PlanFacilitySearchCriteria; -import digit.web.models.PlanFacilitySearchRequest; +import digit.web.models.*; import digit.web.models.boundary.BoundarySearchResponse; import digit.web.models.boundary.EnrichedBoundary; import digit.web.models.census.*; diff --git a/health-services/plan-service/src/main/java/digit/web/models/census/AdditionalField.java b/health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java similarity index 96% rename from health-services/plan-service/src/main/java/digit/web/models/census/AdditionalField.java rename to health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java index 65ae422283..10351283cd 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/census/AdditionalField.java +++ b/health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java @@ -1,4 +1,4 @@ -package digit.web.models.census; +package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.Valid; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 3ff0e8ce87..f39dcfa676 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -74,6 +74,10 @@ public class Plan { @JsonProperty("jurisdictionMapping") private Map jurisdictionMapping; + @JsonProperty("additionalFields") + @Valid + private List additionalFields = null; + @JsonIgnore private String boundaryAncestralPath = null; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java b/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java index f56569c134..d7adb85ece 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java @@ -59,6 +59,10 @@ public class PlanDTO { @JsonProperty("jurisdictionMapping") private Map jurisdictionMapping; + @JsonProperty("additionalFields") + @Valid + private List additionalFields = null; + @JsonProperty("activities") @Valid private List activities; diff --git a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java index e8f384d1e9..2b989edb10 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java +++ b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java @@ -8,6 +8,7 @@ import java.util.List; +import digit.web.models.AdditionalField; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql new file mode 100644 index 0000000000..764ee79bb2 --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql @@ -0,0 +1,12 @@ +-- Table: plan_additional_field +CREATE TABLE plan_additional_field ( + id character varying(64) NOT NULL, + plan_id character varying(64) NOT NULL, + "key" character varying(64) NOT NULL, + "value" numeric(12,2) NOT NULL, + show_on_ui boolean DEFAULT true NOT NULL, + editable boolean DEFAULT true NOT NULL, + "order" bigint NOT NULL, + CONSTRAINT uk_plan_additional_field_id PRIMARY KEY (id), + FOREIGN KEY (plan_id) REFERENCES plan(id) +); From ffa7974b3dabc602c5b567885ce7a36d8b1ac75d Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 3 Jan 2025 15:16:15 +0530 Subject: [PATCH 03/76] Resolved code rabbit review comments --- .../org/egov/processor/config/ServiceConstants.java | 5 +++++ .../java/org/egov/processor/service/ExcelParser.java | 3 +-- .../java/org/egov/processor/util/EnrichmentUtil.java | 7 ------- .../java/org/egov/processor/util/ExcelStylingUtil.java | 10 +++++++--- .../processor/util/OutputEstimationGenerationUtil.java | 6 +++--- .../main/java/org/egov/processor/util/ParsingUtil.java | 1 + 6 files changed, 17 insertions(+), 15 deletions(-) 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 41e9144856..f13f37ceca 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 @@ -42,6 +42,9 @@ public class ServiceConstants { public static final String PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_CODE = "PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT"; public static final String PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_MESSAGE = "Key is not present in json object - "; + public static final String EMPTY_HEADER_ROW_CODE = "EMPTY_HEADER_ROW"; + public static final String EMPTY_HEADER_ROW_MESSAGE = "The header row is empty for the given sheet"; + public static final String UNABLE_TO_CREATE_ADDITIONAL_DETAILS_CODE = "UNABLE_TO_CREATE_ADDITIONAL_DETAILS"; public static final String UNABLE_TO_CREATE_ADDITIONAL_DETAILS_MESSAGE = "Unable to create additional details for facility creation."; @@ -60,6 +63,7 @@ public class ServiceConstants { public static final String ERROR_WHILE_DATA_CREATE_CALL = "Exception occurred while creating data for campaign - "; public static final String ERROR_WHILE_CALLING_MICROPLAN_API = "Unexpected error while calling fetch from Microplan API for plan config Id: "; + public static final String INVALID_HEX = "Invalid hex color specified: "; public static final String FILE_NAME = "output.xls"; public static final String FILE_TYPE = "boundaryWithTarget"; @@ -77,6 +81,7 @@ public class ServiceConstants { public static final String BOUNDARY = "boundary"; public static final String DOT_SEPARATOR = "."; public static final String MICROPLAN_PREFIX = "MP-"; + public static final Double BRIGHTEN_FACTOR = 1.1; //MDMS field Constants public static final String DATA = "data"; 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 2faa00b43f..b951270f8d 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 @@ -380,8 +380,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues); - // TODO: remove after testing - parsingUtil.printRow(sheet, row); + } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index e543dd062a..330a391484 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -144,9 +144,6 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR } } } - //TODO: remove after testing - log.info("After updating values in sheet -> "); - parsingUtil.printRow(sheet, row); log.info("Successfully update file with approved census data."); } @@ -236,7 +233,6 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR for(Row row: sheet) { - parsingUtil.printRow(sheet, row); // Skip the header row and empty rows if (row.getRowNum() == 0 || parsingUtil.isRowEmpty(row)) { continue; @@ -269,9 +265,6 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR } } } - //TODO: remove after testing - log.info("After updating values in sheet -> "); - parsingUtil.printRow(sheet, row); log.info("Successfully update file with approved census data."); } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java index c8da424ea1..39e5fd75de 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java @@ -55,14 +55,18 @@ public void styleCell(Cell cell) { * @return XSSFColor The corresponding XSSFColor object. */ public static XSSFColor hexToXSSFColor(String hexColor, XSSFWorkbook xssfWorkbook) { + + if (hexColor == null || hexColor.length() < 6) + throw new IllegalArgumentException(INVALID_HEX + hexColor); + // Convert HEX to RGB int red = Integer.valueOf(hexColor.substring(0, 2), 16); int green = Integer.valueOf(hexColor.substring(2, 4), 16); int blue = Integer.valueOf(hexColor.substring(4, 6), 16); - red = (int) (red * 1.1); // increase red component by 10% - green = (int) (green * 1.1); // increase green component by 10% - blue = (int) (blue * 1.1); // increase blue component by 10% + red = (int) (red * BRIGHTEN_FACTOR); // increase red component by 10% + green = (int) (green * BRIGHTEN_FACTOR); // increase green component by 10% + blue = (int) (blue * BRIGHTEN_FACTOR); // increase blue component by 10% // Clamp the values to be between 0 and 255 red = Math.min(255, Math.max(0, red)); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 71b3ac8b65..eb2dd82baa 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -15,8 +15,7 @@ import java.util.stream.Collectors; import org.egov.tracer.model.CustomException; -import static org.egov.processor.config.ServiceConstants.FACILITY_NAME; -import static org.egov.processor.config.ServiceConstants.HCM_MICROPLAN_SERVING_FACILITY; +import static org.egov.processor.config.ServiceConstants.*; @Component public class OutputEstimationGenerationUtil { @@ -61,7 +60,8 @@ public void processOutputFile(Workbook workbook, PlanConfigurationRequest reques public void processSheetForHeaderLocalization(Sheet sheet, Map localizationCodeAndMessageMap) { // Fetch the header row from sheet Row row = sheet.getRow(0); - if (parsingUtil.isRowEmpty(row)) throw new CustomException(); + if (parsingUtil.isRowEmpty(row)) + throw new CustomException(EMPTY_HEADER_ROW_CODE, EMPTY_HEADER_ROW_MESSAGE); //Iterate from the end, for every cell localize the header value diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index 756252b562..ec20dbd2bd 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -449,6 +449,7 @@ public Object extractFieldsFromJsonObject(Object additionalDetails, String field return node.asText(); } } + log.debug("The field to be extracted - " + fieldToExtract + " is not present in additional details."); return null; } catch (Exception e) { log.error(e.getMessage() + fieldToExtract); From 47cc3b26bb51f2576c9b19f763915db147483622 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 3 Jan 2025 16:14:20 +0530 Subject: [PATCH 04/76] Updating validation for residing boundaries in plan facility --- .../validator/PlanFacilityValidator.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java index dd7b251eaf..ef254d73ea 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java @@ -126,27 +126,43 @@ private void validateCampaignDetails(String campaignId, String rootTenantId, Pla String lowestHierarchy = hierarchyMap.get(LOWEST_HIERARCHY_FIELD_FOR_MICROPLAN); // Collect all boundary code for the campaign - Set boundaryCodes = fetchBoundaryCodes(campaignResponse.getCampaignDetails().get(0), lowestHierarchy); + Set lowestHierarchyBCodes = fetchBoundaryCodes(campaignResponse.getCampaignDetails().get(0), lowestHierarchy); + Set boundaryCode = fetchAllBoundaryCodes(campaignResponse.getCampaignDetails().get(0)); // Validate residing boundaries - validateResidingBoundaries(boundaryCodes, planFacility); + validateResidingBoundaries(boundaryCode, planFacility); // Validate service boundaries - validateServiceBoundaries(boundaryCodes, planFacility); + validateServiceBoundaries(lowestHierarchyBCodes, planFacility); //Enrich jurisdiction mapping and boundary ancestral path enrichment.enrichJurisdictionMapping(planFacilityRequest, campaignResponse.getCampaignDetails().get(0).getHierarchyType()); } /** - * This method returns boundary code for the campaign + * This method returns a set of all boundary codes for the given campaign. * - * @param campaignDetail - * @param lowestHierarchy + * @param campaignDetail the campaign details whose BCodes are required. + * @return returns a set of boundaries for the given campaign. */ - private Set fetchBoundaryCodes(CampaignDetail campaignDetail, String lowestHierarchy) { + private Set fetchAllBoundaryCodes(CampaignDetail campaignDetail) { Set boundaryCodes = campaignDetail.getBoundaries().stream() - .filter(boundary -> lowestHierarchy.equals(boundary.getType().toLowerCase())) + .map(Boundary::getCode) + .collect(Collectors.toSet()); + + return boundaryCodes; + } + + /** + * This method filters the boundaries based on given hierarchy type for the campaign and returns a set of those boundaries. + * + * @param campaignDetail the campaign details whose BCodes are required. + * @param hierarchyType hierarchy type of the required boundaries. + * @return returns a set of boundaries of the given hierarchy type. + */ + private Set fetchBoundaryCodes(CampaignDetail campaignDetail, String hierarchyType) { + Set boundaryCodes = campaignDetail.getBoundaries().stream() + .filter(boundary -> hierarchyType.equals(boundary.getType().toLowerCase())) .map(Boundary::getCode) .collect(Collectors.toSet()); From 4dd4d23e96047977be8fb10a2a7818bf47102a4e Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 6 Jan 2025 10:44:39 +0530 Subject: [PATCH 05/76] Change the mdms master to adminSchemas in resource generator --- .../processor/config/ServiceConstants.java | 6 ++ .../egov/processor/service/ExcelParser.java | 6 +- .../org/egov/processor/util/MdmsUtil.java | 70 ++++++++++++------- .../org/egov/processor/util/ParsingUtil.java | 42 ++++++++++- 4 files changed, 92 insertions(+), 32 deletions(-) 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 7200f29cec..dfd4e3f842 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 @@ -61,13 +61,19 @@ 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 PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_CODE = "PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT"; + public static final String PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_MESSAGE = "Key is not present in json object - "; 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 6f2326d628..b0b53ab98a 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 @@ -311,15 +311,11 @@ private List getBoundaryCodeList(PlanConfigurationRequest planConfigurat * @param planConfig The configuration details specific to the plan. * @return A map of attribute names to their corresponding indices or data types. */ - - - //TODO: fetch from adminSchema master private Map prepareAttributeVsIndexMap(PlanConfigurationRequest 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()); } 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..ae85cfdd7c 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.info("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); + }) + ); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index ba10327e4c..7825ac2101 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; @@ -24,7 +25,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.egov.processor.config.ServiceConstants.PROPERTIES; +import static org.egov.processor.config.ServiceConstants.*; @Slf4j @Component @@ -36,10 +37,13 @@ public class ParsingUtil { private CalculationUtil calculationUtil; - public ParsingUtil(PlanConfigurationUtil planConfigurationUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil) { + private ObjectMapper objectMapper; + + public ParsingUtil(PlanConfigurationUtil planConfigurationUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, ObjectMapper objectMapper) { this.planConfigurationUtil = planConfigurationUtil; this.filestoreUtil = filestoreUtil; this.calculationUtil = calculationUtil; + this.objectMapper = objectMapper; } public List fetchAttributeNamesFromJson(JsonNode jsonNode) @@ -392,4 +396,38 @@ public void printRow(Sheet sheet, Row row) { System.out.println(); // Move to the next line after printing the row } + /** + * Extracts provided field from the additional details object + * + * @param additionalDetails the additionalDetails object from PlanConfigurationRequest + * @param fieldToExtract the name of the field to be extracted from the additional details + * @return the value of the specified field as a string + * @throws CustomException if the field does not exist + */ + public Object extractFieldsFromJsonObject(Object additionalDetails, String fieldToExtract) { + try { + String jsonString = objectMapper.writeValueAsString(additionalDetails); + JsonNode rootNode = objectMapper.readTree(jsonString); + + JsonNode node = rootNode.get(fieldToExtract); + if (node != null && !node.isNull()) { + + // Check for different types of JSON nodes + if (node.isDouble() || node.isFloat()) { + return BigDecimal.valueOf(node.asDouble()); // Convert Double to BigDecimal + } else if (node.isLong() || node.isInt()) { + return BigDecimal.valueOf(node.asLong()); // Convert Long to BigDecimal + } else if (node.isBoolean()) { + return node.asBoolean(); + } else if (node.isTextual()) { + return node.asText(); + } + } + return null; + } catch (Exception e) { + log.error(e.getMessage() + fieldToExtract); + throw new CustomException(PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_CODE, PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_MESSAGE + fieldToExtract); + } + } + } From 27fad49d2a1966cbb2154ffe4511d46ab83a3776 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 6 Jan 2025 11:29:14 +0530 Subject: [PATCH 06/76] Add Facility Name in additional details and enable search on facility name in Plan --- .../querybuilder/PlanQueryBuilder.java | 6 ++ .../{enrichment => }/PlanEnricher.java | 27 ++++++- .../main/java/digit/service/PlanService.java | 7 +- .../{validator => }/PlanValidator.java | 4 +- .../digit/web/models/PlanSearchCriteria.java | 8 +++ .../processor/config/ServiceConstants.java | 4 ++ .../egov/processor/service/ExcelParser.java | 14 ++-- .../egov/processor/util/CalculationUtil.java | 3 +- .../egov/processor/util/EnrichmentUtil.java | 6 +- .../org/egov/processor/util/ParsingUtil.java | 72 +++++++++++++++++-- .../org/egov/processor/util/PlanUtil.java | 35 ++++++--- 11 files changed, 155 insertions(+), 31 deletions(-) rename health-services/plan-service/src/main/java/digit/service/{enrichment => }/PlanEnricher.java (91%) rename health-services/plan-service/src/main/java/digit/service/{validator => }/PlanValidator.java (99%) diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 5c8bc91097..4ae958aa9d 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -170,6 +170,12 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< queryUtil.addToPreparedStatement(preparedStmtList, planSearchCriteria.getJurisdiction()); } + if(!CollectionUtils.isEmpty(planSearchCriteria.getFiltersMap())) { + queryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" additional_details @> CAST( ? AS jsonb )"); + String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap()); + preparedStmtList.add(partialQueryJsonString); + } StringBuilder countQuery = new StringBuilder(); if (isCount) { diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java similarity index 91% rename from health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java rename to health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 17364bfdb6..9ed16aa593 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -1,7 +1,6 @@ -package digit.service.enrichment; +package digit.service; -import digit.web.models.Plan; -import digit.web.models.PlanRequest; +import digit.web.models.*; import digit.web.models.boundary.BoundaryTypeHierarchy; import digit.web.models.boundary.BoundaryTypeHierarchyDefinition; import digit.web.models.boundary.EnrichedBoundary; @@ -14,6 +13,8 @@ import java.util.*; +import static digit.config.ServiceConstants.FACILITY_NAME_SEARCH_PARAMETER_KEY; + @Component public class PlanEnricher { @@ -228,4 +229,24 @@ private List getBoundaryCodeFromAncestralPath(String boundaryAncestralPa } return Arrays.asList(boundaryAncestralPath.split("\\|")); } + + /** + * Enriches plan search request + * + * @param planSearchRequest + */ + public void enrichSearchRequest(PlanSearchRequest planSearchRequest) { + PlanSearchCriteria planSearchCriteria = planSearchRequest.getPlanSearchCriteria(); + + // Filter map for filtering plan metadata present in additional details + Map filtersMap = new LinkedHashMap<>(); + + // Add facility name as a filter if present in search criteria + if (!ObjectUtils.isEmpty(planSearchCriteria.getFacilityName())) { + filtersMap.put(FACILITY_NAME_SEARCH_PARAMETER_KEY, planSearchCriteria.getFacilityName()); + } + + if(!CollectionUtils.isEmpty(filtersMap)) + planSearchCriteria.setFiltersMap(filtersMap); + } } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index dad7e8b7d8..eff10a393c 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -1,13 +1,13 @@ package digit.service; import digit.repository.PlanRepository; -import digit.service.enrichment.PlanEnricher; -import digit.service.validator.PlanValidator; import digit.service.workflow.WorkflowService; import digit.web.models.*; +import org.egov.common.contract.response.ResponseInfo; import org.egov.common.utils.ResponseInfoUtil; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -61,6 +61,9 @@ public PlanResponse createPlan(PlanRequest body) { * @return */ public PlanResponse searchPlan(PlanSearchRequest body) { + // Enrich search request + planEnricher.enrichSearchRequest(body); + // Delegate search request to repository List planList = planRepository.search(body.getPlanSearchCriteria()); diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java similarity index 99% rename from health-services/plan-service/src/main/java/digit/service/validator/PlanValidator.java rename to health-services/plan-service/src/main/java/digit/service/PlanValidator.java index 1fd98c823b..aa1656c00b 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanValidator.java @@ -1,11 +1,9 @@ -package digit.service.validator; +package digit.service; import com.jayway.jsonpath.JsonPath; import digit.config.Configuration; import digit.repository.PlanConfigurationRepository; import digit.repository.PlanRepository; -import digit.service.PlanEmployeeService; -import digit.service.enrichment.PlanEnricher; import digit.util.BoundaryUtil; import digit.util.CampaignUtil; import digit.util.CommonUtil; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index 357b306fa8..79a67c4201 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -1,5 +1,6 @@ package digit.web.models; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -10,6 +11,7 @@ import org.springframework.validation.annotation.Validated; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -38,6 +40,9 @@ public class PlanSearchCriteria { @JsonProperty("planConfigurationId") private String planConfigurationId = null; + @JsonProperty("facilityName") + private String facilityName = null; + @JsonProperty("status") private String status = null; @@ -54,4 +59,7 @@ public class PlanSearchCriteria { @JsonProperty("limit") private Integer limit = null; + @JsonIgnore + private Map filtersMap = null; + } 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 7200f29cec..6f5f9c5a69 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 @@ -33,6 +33,9 @@ public class ServiceConstants { public static final String ERROR_WHILE_FETCHING_FROM_PLAN_SERVICE = "Exception occurred while fetching plan configuration from plan service "; + public static final String ERROR_WHILE_UPDATING_ADDITIONAL_DETAILS_CODE = "ERROR_WHILE_UPDATING_ADDITIONAL_DETAILS"; + public static final String ERROR_WHILE_UPDATING_ADDITIONAL_DETAILS_MESSAGE = "Exception occurred while updating additional details : "; + public static final String NOT_ABLE_TO_CONVERT_MULTIPARTFILE_TO_BYTESTREAM_CODE = "NOT_ABLE_TO_CONVERT_MULTIPARTFILE_TO_BYTESTREAM"; public static final String NOT_ABLE_TO_CONVERT_MULTIPARTFILE_TO_BYTESTREAM_MESSAGE = "Not able to fetch byte stream from a multipart file"; @@ -116,6 +119,7 @@ public class ServiceConstants { public static final String SOURCE_KEY = "source"; public static final String MICROPLAN_SOURCE_KEY = "microplan"; public static final String MICROPLAN_ID_KEY = "microplanId"; + public static final String FACILITY_NAME = "facilityName"; //Census additional field constants public static final String UPLOADED_KEY = "UPLOADED_"; 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 6f2326d628..e711a31c82 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 @@ -215,9 +215,11 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, excelWorkbook.forEach(excelWorkbookSheet -> { if (isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { - enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues); + Map BCodeToFacilityDetails = new HashMap<>(); + + enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToFacilityDetails); processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId, - campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList); + campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerCensusRecordsStatus())) { processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); @@ -246,9 +248,9 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, * @param boundaryCodeList List of boundary codes. * @throws IOException If an I/O error occurs. */ - private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList) { + private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); - performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList); + performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); } private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map attributeNameVsDataTypeMap, List boundaryCodeList, String hierarchyType) { @@ -339,7 +341,7 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest */ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, - PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList) { + PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { Row firstRow = null; Map mappedValues = planConfig.getResourceMapping().stream() .filter(f -> f.getFilestoreId().equals(fileStoreId)) @@ -369,7 +371,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToFacilityDetails)); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java index 551206d9b9..c0fa5b70cd 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java @@ -15,6 +15,7 @@ import java.math.RoundingMode; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import static org.egov.processor.config.ServiceConstants.PROPERTIES; @@ -78,7 +79,7 @@ public void calculateResources(JsonNode jsonNode, PlanConfigurationRequest planC resultMap.put(output, result); ((ObjectNode) feature.get("properties")).put(output, result); } - planUtil.create(planConfigurationRequest,feature,resultMap,mappedValues); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.empty()); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 89f0a89511..49f85c1f5f 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -89,7 +89,7 @@ public void enrichResourceMapping(PlanConfigurationRequest request, LocaleRespon } - public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues) { + public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues, Map BCodeToFacilityDetails) { List boundaryCodes = getBoundaryCodesFromTheSheet(sheet, planConfigurationRequest, fileStoreId); Map mapOfColumnNameAndIndex = parsingUtil.getAttributeNameIndexFromExcel(sheet); @@ -143,6 +143,10 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR } } + + String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(census.getAdditionalDetails(), FACILITY_NAME); + if(facilityName != null && !facilityName.isEmpty()) + BCodeToFacilityDetails.put(boundaryCode, facilityName); } log.info("Successfully update file with approved census data."); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index ba10327e4c..cc33356b95 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.DecimalNode; +import com.fasterxml.jackson.databind.node.NullNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.poi.ss.usermodel.*; @@ -17,6 +19,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; @@ -24,22 +27,19 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.egov.processor.config.ServiceConstants.PROPERTIES; +import static org.egov.processor.config.ServiceConstants.*; @Slf4j @Component public class ParsingUtil { - private PlanConfigurationUtil planConfigurationUtil; - private FilestoreUtil filestoreUtil; - private CalculationUtil calculationUtil; + private ObjectMapper objectMapper; - public ParsingUtil(PlanConfigurationUtil planConfigurationUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil) { - this.planConfigurationUtil = planConfigurationUtil; + public ParsingUtil(FilestoreUtil filestoreUtil, ObjectMapper objectMapper) { this.filestoreUtil = filestoreUtil; - this.calculationUtil = calculationUtil; + this.objectMapper = objectMapper; } public List fetchAttributeNamesFromJson(JsonNode jsonNode) @@ -392,4 +392,62 @@ public void printRow(Sheet sheet, Row row) { System.out.println(); // Move to the next line after printing the row } + /** + * Adds or updates the value of provided field in the additional details object. + * @param additionalDetails + * @param fieldsToBeUpdated + * @return + */ + public Map updateFieldInAdditionalDetails(Object additionalDetails, Map fieldsToBeUpdated) { + try { + + // Get or create the additionalDetails as an ObjectNode + ObjectNode objectNode = (additionalDetails == null || additionalDetails instanceof NullNode) + ? objectMapper.createObjectNode() + : objectMapper.convertValue(additionalDetails, ObjectNode.class); + + // Update or add the field in additional details object + fieldsToBeUpdated.forEach((key, value) -> objectNode.set(key, objectMapper.valueToTree(value))); + + // Convert updated ObjectNode back to a Map + return objectMapper.convertValue(objectNode, Map.class); + + } catch (Exception e) { + throw new CustomException(ERROR_WHILE_UPDATING_ADDITIONAL_DETAILS_CODE, ERROR_WHILE_UPDATING_ADDITIONAL_DETAILS_MESSAGE + e); + } + } + + /** + * Extracts provided field from the additional details object + * + * @param additionalDetails the additionalDetails object from PlanConfigurationRequest + * @param fieldToExtract the name of the field to be extracted from the additional details + * @return the value of the specified field as a string + * @throws CustomException if the field does not exist + */ + public Object extractFieldsFromJsonObject(Object additionalDetails, String fieldToExtract) { + try { + String jsonString = objectMapper.writeValueAsString(additionalDetails); + JsonNode rootNode = objectMapper.readTree(jsonString); + + JsonNode node = rootNode.get(fieldToExtract); + if (node != null && !node.isNull()) { + + // Check for different types of JSON nodes + if (node.isDouble() || node.isFloat()) { + return BigDecimal.valueOf(node.asDouble()); // Convert Double to BigDecimal + } else if (node.isLong() || node.isInt()) { + return BigDecimal.valueOf(node.asLong()); // Convert Long to BigDecimal + } else if (node.isBoolean()) { + return node.asBoolean(); + } else if (node.isTextual()) { + return node.asText(); + } + } + return null; + } catch (Exception e) { + log.error(e.getMessage() + fieldToExtract); + throw new CustomException("PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_CODE", "PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_MESSAGE " + fieldToExtract); + } + } } 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 97c9810e0c..cc990136e7 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 @@ -16,8 +16,7 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static org.egov.processor.config.ServiceConstants.*; @@ -33,11 +32,14 @@ public class PlanUtil { private ObjectMapper mapper; - public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration config, Producer producer, ObjectMapper mapper) { + private ParsingUtil parsingUtil; + + public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration config, Producer producer, ObjectMapper mapper, ParsingUtil parsingUtil) { this.serviceRequestRepository = serviceRequestRepository; this.config = config; this.producer = producer; this.mapper = mapper; + this.parsingUtil = parsingUtil; } /** @@ -49,8 +51,8 @@ public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration * @param mappedValues The mapped values. */ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues) { - PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues); + Map resultMap, Map mappedValues, Optional> BCodeToFacilityDetails) { + PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, BCodeToFacilityDetails.orElse(Collections.emptyMap())); try { producer.push(config.getResourceMicroplanCreateTopic(), planRequest); } catch (Exception e) { @@ -69,17 +71,18 @@ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode f * @return The constructed PlanRequest object. */ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues) { + Map resultMap, Map mappedValues, Map BCodeToFacilityDetails) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); + String boundaryCodeValue = getBoundaryCodeValue(ServiceConstants.BOUNDARY_CODE, feature, mappedValues); + return PlanRequest.builder() .requestInfo(planConfigurationRequest.getRequestInfo()) .plan(Plan.builder() .tenantId(planConfig.getTenantId()) .planConfigurationId(planConfig.getId()) .campaignId(planConfig.getCampaignId()) - .locality(getBoundaryCodeValue(ServiceConstants.BOUNDARY_CODE, - feature, mappedValues)) + .locality(boundaryCodeValue) .resources(resultMap.entrySet().stream().map(result -> { Resource res = new Resource(); res.setResourceType(result.getKey()); @@ -90,9 +93,25 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .targets(new ArrayList()) .workflow(Workflow.builder().action(WORKFLOW_ACTION_INITIATE).build()) .isRequestFromResourceEstimationConsumer(true) + .additionalDetails(enrichAdditionalDetials(BCodeToFacilityDetails, boundaryCodeValue)) .build()) .build(); + } + + private Object enrichAdditionalDetials(Map BCodeToFacilityDetails, String boundaryCodeValue) { + if(!CollectionUtils.isEmpty(BCodeToFacilityDetails)) { + // Iterate over each boundary and add facility details in plan additional details + String facilityName = BCodeToFacilityDetails.get(boundaryCodeValue); + + if(facilityName != null && !facilityName.isEmpty()) { + Map fieldsToBeUpdated = new HashMap<>(); + fieldsToBeUpdated.put(FACILITY_NAME, facilityName); + + return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); + } + } + return null; } /** From fee41c74ad4b1a3a88359029299d2adea0820595 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 6 Jan 2025 11:48:38 +0530 Subject: [PATCH 07/76] Resource generator - add Village accessibility details from census into plans --- .../processor/config/ServiceConstants.java | 1 + .../egov/processor/service/ExcelParser.java | 14 +++++----- .../egov/processor/util/EnrichmentUtil.java | 6 ++-- .../org/egov/processor/util/ParsingUtil.java | 2 ++ .../org/egov/processor/util/PlanUtil.java | 28 +++++++++++-------- 5 files changed, 29 insertions(+), 22 deletions(-) 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 6f5f9c5a69..c25dc64bd1 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 @@ -77,6 +77,7 @@ public class ServiceConstants { public static final String BOUNDARY = "boundary"; public static final String DOT_SEPARATOR = "."; public static final String MICROPLAN_PREFIX = "MP-"; + public static final String ACCESSIBILITY_DETAILS = "accessibilityDetails"; //MDMS field Constants public static final String DATA = "data"; 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 e711a31c82..0d8e17e19a 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 @@ -215,11 +215,11 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, excelWorkbook.forEach(excelWorkbookSheet -> { if (isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { - Map BCodeToFacilityDetails = new HashMap<>(); + Map BCodeToCensusAdditionalDetails = new HashMap<>(); - enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToFacilityDetails); + enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToCensusAdditionalDetails); processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId, - campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); + campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToCensusAdditionalDetails); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerCensusRecordsStatus())) { processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); @@ -248,9 +248,9 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, * @param boundaryCodeList List of boundary codes. * @throws IOException If an I/O error occurs. */ - private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { + private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToCensusAdditionalDetails) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); - performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); + performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToCensusAdditionalDetails); } private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map attributeNameVsDataTypeMap, List boundaryCodeList, String hierarchyType) { @@ -341,7 +341,7 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest */ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, - PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { + PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToCensusAdditionalDetails) { Row firstRow = null; Map mappedValues = planConfig.getResourceMapping().stream() .filter(f -> f.getFilestoreId().equals(fileStoreId)) @@ -371,7 +371,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToFacilityDetails)); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToCensusAdditionalDetails)); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 49f85c1f5f..09e68b5cc0 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -89,7 +89,7 @@ public void enrichResourceMapping(PlanConfigurationRequest request, LocaleRespon } - public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues, Map BCodeToFacilityDetails) { + public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues, Map BCodeToCensusAdditionalDetails) { List boundaryCodes = getBoundaryCodesFromTheSheet(sheet, planConfigurationRequest, fileStoreId); Map mapOfColumnNameAndIndex = parsingUtil.getAttributeNameIndexFromExcel(sheet); @@ -144,9 +144,7 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR } } - String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(census.getAdditionalDetails(), FACILITY_NAME); - if(facilityName != null && !facilityName.isEmpty()) - BCodeToFacilityDetails.put(boundaryCode, facilityName); + BCodeToCensusAdditionalDetails.put(boundaryCode, census.getAdditionalDetails()); } log.info("Successfully update file with approved census data."); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index cc33356b95..eaf7b673ac 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -442,6 +442,8 @@ public Object extractFieldsFromJsonObject(Object additionalDetails, String field return node.asBoolean(); } else if (node.isTextual()) { return node.asText(); + } else if (node.isObject()) { + return objectMapper.convertValue(node, Map.class); // Return the object node as a Map } } return null; 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 cc990136e7..3f73e1c9ca 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 @@ -51,8 +51,8 @@ public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration * @param mappedValues The mapped values. */ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Optional> BCodeToFacilityDetails) { - PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, BCodeToFacilityDetails.orElse(Collections.emptyMap())); + Map resultMap, Map mappedValues, Optional> BCodeToCensusAdditionalDetails) { + PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, BCodeToCensusAdditionalDetails.orElse(Collections.emptyMap())); try { producer.push(config.getResourceMicroplanCreateTopic(), planRequest); } catch (Exception e) { @@ -71,7 +71,7 @@ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode f * @return The constructed PlanRequest object. */ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Map BCodeToFacilityDetails) { + Map resultMap, Map mappedValues, Map BCodeToCensusAdditionalDetails) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); String boundaryCodeValue = getBoundaryCodeValue(ServiceConstants.BOUNDARY_CODE, feature, mappedValues); @@ -93,23 +93,29 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .targets(new ArrayList()) .workflow(Workflow.builder().action(WORKFLOW_ACTION_INITIATE).build()) .isRequestFromResourceEstimationConsumer(true) - .additionalDetails(enrichAdditionalDetials(BCodeToFacilityDetails, boundaryCodeValue)) + .additionalDetails(enrichAdditionalDetials(BCodeToCensusAdditionalDetails, boundaryCodeValue)) .build()) .build(); } - private Object enrichAdditionalDetials(Map BCodeToFacilityDetails, String boundaryCodeValue) { - if(!CollectionUtils.isEmpty(BCodeToFacilityDetails)) { + private Object enrichAdditionalDetials(Map BCodeToCensusAdditionalDetails, String boundaryCodeValue) { + if(!CollectionUtils.isEmpty(BCodeToCensusAdditionalDetails)) { - // Iterate over each boundary and add facility details in plan additional details - String facilityName = BCodeToFacilityDetails.get(boundaryCodeValue); + Object censusAdditionalDetails = BCodeToCensusAdditionalDetails.get(boundaryCodeValue); - if(facilityName != null && !facilityName.isEmpty()) { - Map fieldsToBeUpdated = new HashMap<>(); + // Extract required details from census additional details object. + String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, FACILITY_NAME); + Object accessibilityDetails = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, ACCESSIBILITY_DETAILS); + + Map fieldsToBeUpdated = new HashMap<>(); + if(facilityName != null && !facilityName.isEmpty()) fieldsToBeUpdated.put(FACILITY_NAME, facilityName); + if(accessibilityDetails != null) + fieldsToBeUpdated.put(ACCESSIBILITY_DETAILS, accessibilityDetails); + + if(!CollectionUtils.isEmpty(fieldsToBeUpdated)) return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); - } } return null; } From 067d1d35a137559b9d6b73c1a8e5ca9a5fc13801 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 6 Jan 2025 11:54:50 +0530 Subject: [PATCH 08/76] Enable search on Village Accessibility Details in Plan Service --- .../src/main/java/digit/config/ServiceConstants.java | 4 ++++ .../src/main/java/digit/service/PlanEnricher.java | 12 +++++++++++- .../java/digit/web/models/PlanSearchCriteria.java | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index a2b9696b48..0d78f925b1 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -364,6 +364,10 @@ 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 COMMA_DELIMITER = ","; public static final String SERVING_POPULATION_CODE = "servingPopulation"; diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 9ed16aa593..18c35985f4 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -13,7 +13,7 @@ import java.util.*; -import static digit.config.ServiceConstants.FACILITY_NAME_SEARCH_PARAMETER_KEY; +import static digit.config.ServiceConstants.*; @Component public class PlanEnricher { @@ -246,6 +246,16 @@ public void enrichSearchRequest(PlanSearchRequest planSearchRequest) { filtersMap.put(FACILITY_NAME_SEARCH_PARAMETER_KEY, planSearchCriteria.getFacilityName()); } + // 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()); + } + if(!CollectionUtils.isEmpty(filtersMap)) planSearchCriteria.setFiltersMap(filtersMap); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index 79a67c4201..89a11e1fc1 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -43,6 +43,12 @@ public class PlanSearchCriteria { @JsonProperty("facilityName") private String facilityName = null; + @JsonProperty("onRoadCondition") + private String onRoadCondition = null; + + @JsonProperty("terrain") + private String terrain = null; + @JsonProperty("status") private String status = null; From 62cf501a74118b11c941f24688f955849c711de1 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 6 Jan 2025 15:17:46 +0530 Subject: [PATCH 09/76] Plan-facility integration to fetch fixedPost details --- .../egov/processor/config/Configuration.java | 3 + .../processor/config/ServiceConstants.java | 7 +- .../egov/processor/service/ExcelParser.java | 46 +++++++++- .../egov/processor/util/PlanFacilityUtil.java | 55 +++++++++++ .../web/models/planFacility/PlanFacility.java | 92 +++++++++++++++++++ .../planFacility/PlanFacilityResponse.java | 33 +++++++ .../PlanFacilitySearchCriteria.java | 64 +++++++++++++ .../PlanFacilitySearchRequest.java | 34 +++++++ .../src/main/resources/application.properties | 3 + 9 files changed, 332 insertions(+), 5 deletions(-) create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java b/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java index c652337ba2..1f49dc085e 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java @@ -41,6 +41,9 @@ public class Configuration { @Value("${egov.plan.search.endpoint}") private String planSearchEndPoint; + @Value("${egov.plan.facility.search.endpoint}") + private String planFacilitySearchEndPoint; + // Filestore @Value("${egov.filestore.service.host}") 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 f13f37ceca..1dcb9bd1ae 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 @@ -54,6 +54,9 @@ public class ServiceConstants { public static final String NO_PLAN_FOUND_FOR_GIVEN_DETAILS_CODE = "NO_PLAN_FOUND_FOR_GIVEN_DETAILS"; public static final String NO_PLAN_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan records do not exists for the given details: "; + public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE = "NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS"; + public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan facilities do not exists for the given details: "; + public static final String BOUNDARY_CODE = "HCM_ADMIN_CONSOLE_BOUNDARY_CODE"; public static final String TOTAL_POPULATION = "HCM_ADMIN_CONSOLE_TOTAL_POPULATION"; @@ -91,7 +94,8 @@ public class ServiceConstants { public static final String NAME = "name"; public static final String ERROR_WHILE_UPDATING_PLAN_CONFIG = "Exception occurred while updating plan configuration."; - public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while search plans."; + public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while searching plans."; + public static final String ERROR_WHILE_SEARCHING_PLAN_FACILITY = "Exception occurred while searching plan facility."; public static final String VALIDATE_STRING_REGX = "^(?!\\d+$).+$"; public static final String VALIDATE_NUMBER_REGX = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; @@ -126,6 +130,7 @@ public class ServiceConstants { public static final String MICROPLAN_ID_KEY = "microplanId"; public static final String FACILITY_NAME = "facilityName"; public static final String HCM_MICROPLAN_SERVING_FACILITY = "HCM_MICROPLAN_SERVING_FACILITY"; + public static final String FIXED_POST = "fixedPost"; //Census additional field constants public static final String UPLOADED_KEY = "UPLOADED_"; 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 b951270f8d..14bf09b527 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 @@ -18,6 +18,10 @@ import org.egov.processor.web.models.campaignManager.Boundary; import org.egov.processor.web.models.campaignManager.CampaignResources; import org.egov.processor.web.models.campaignManager.CampaignResponse; +import org.egov.processor.web.models.planFacility.PlanFacility; +import org.egov.processor.web.models.planFacility.PlanFacilityResponse; +import org.egov.processor.web.models.planFacility.PlanFacilitySearchCriteria; +import org.egov.processor.web.models.planFacility.PlanFacilitySearchRequest; import org.egov.tracer.model.CustomException; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -30,6 +34,8 @@ import java.util.*; import java.util.stream.Collectors; +import static org.egov.processor.config.ServiceConstants.FIXED_POST; + @Slf4j @Service public class ExcelParser implements FileParser { @@ -62,9 +68,11 @@ public class ExcelParser implements FileParser { private OutputEstimationGenerationUtil outputEstimationGenerationUtil; + private PlanFacilityUtil planFacilityUtil; + public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, PlanUtil planUtil, CampaignIntegrationUtil campaignIntegrationUtil, - Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil) { + Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil, PlanFacilityUtil planFacilityUtil) { this.objectMapper = objectMapper; this.parsingUtil = parsingUtil; this.filestoreUtil = filestoreUtil; @@ -79,6 +87,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore this.enrichmentUtil = enrichmentUtil; this.planConfigurationUtil = planConfigurationUtil; this.outputEstimationGenerationUtil = outputEstimationGenerationUtil; + this.planFacilityUtil = planFacilityUtil; } /** @@ -169,9 +178,6 @@ private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigu outputEstimationGenerationUtil.processOutputFile(workbook, planConfigurationRequest); - // Adding facility information for each boundary code - outputEstimationGenerationUtil.addAssignedFacility(workbook, planConfigurationRequest, filestoreId); - //update processed output file into plan configuration file object fileToUpload = convertWorkbookToXls(workbook); uploadedFileStoreId = uploadConvertedFile(fileToUpload, planConfig.getTenantId()); @@ -233,12 +239,44 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigUpdatePlanEstimatesIntoOutputFileStatus())) { + // Adding facility information for each boundary code + outputEstimationGenerationUtil.addAssignedFacility(excelWorkbook, request, fileStoreId); + + Map facilityToFixedPost = fetchFixedPostDetails(request); enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues); } } }); } + /** + * This method makes plan facility search call and creates a map of facility name to it's fixed post details. + * + * @param request the plan configuration request. + * @return returns a map of facility name to it's fixed post details. + */ + private Map fetchFixedPostDetails(PlanConfigurationRequest request) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + + //Create plan facility search request + PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder() + .requestInfo(request.getRequestInfo()) + .planFacilitySearchCriteria(PlanFacilitySearchCriteria.builder() + .tenantId(planConfiguration.getTenantId()) + .planConfigurationId(planConfiguration.getId()) + .build()) + .build(); + + PlanFacilityResponse planFacilityResponse = planFacilityUtil.search(searchRequest); + + // Create and return a map of facility name to fixed post details + return planFacilityResponse.getPlanFacility().stream() + .collect(Collectors.toMap( + PlanFacility::getFacilityName, + planFacility -> (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST) + )); + } + /** * Processes rows of data in an Excel sheet, performs calculations, updates * campaign boundaries, and creates plans. diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java new file mode 100644 index 0000000000..1c8a09186d --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java @@ -0,0 +1,55 @@ +package org.egov.processor.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.processor.config.Configuration; +import org.egov.processor.config.ServiceConstants; +import org.egov.processor.repository.ServiceRequestRepository; +import org.egov.processor.web.models.planFacility.PlanFacilityResponse; +import org.egov.processor.web.models.planFacility.PlanFacilitySearchRequest; +import org.egov.tracer.model.CustomException; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import static org.egov.processor.config.ServiceConstants.*; + +@Slf4j +@Component +public class PlanFacilityUtil { + private Configuration config; + + private ServiceRequestRepository serviceRequestRepository; + + private ObjectMapper mapper; + + public PlanFacilityUtil(Configuration config, ServiceRequestRepository serviceRequestRepository, ObjectMapper mapper) { + this.config = config; + this.serviceRequestRepository = serviceRequestRepository; + this.mapper = mapper; + } + + public PlanFacilityResponse search(PlanFacilitySearchRequest planfacilitySearchRequest) { + + PlanFacilityResponse planFacilityResponse = null; + try { + Object response = serviceRequestRepository.fetchResult(getPlanFacilitySearchUri(), planfacilitySearchRequest); + planFacilityResponse = mapper.convertValue(response, PlanFacilityResponse.class); + } catch (Exception e) { + log.error(ServiceConstants.ERROR_WHILE_SEARCHING_PLAN_FACILITY); + } + + if (CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { + throw new CustomException(NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE, NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE); + } + + return planFacilityResponse; + } + + /** + * Creates a complete search uri for plan facility search. + * @return + */ + private StringBuilder getPlanFacilitySearchUri() { + return new StringBuilder().append(config.getPlanConfigHost()).append(config.getPlanFacilitySearchEndPoint()); + } +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java new file mode 100644 index 0000000000..e9471ac84a --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java @@ -0,0 +1,92 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.models.AuditDetails; +import org.springframework.validation.annotation.Validated; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Plan Facility + */ +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacility { + + @JsonProperty("id") + private String id = null; + + @JsonProperty("tenantId") + @NotNull + @Size(min = 2, max = 64) + private String tenantId = null; + + @JsonProperty("planConfigurationId") + @NotNull + @Size(max = 64) + private String planConfigurationId = null; + + @JsonProperty("planConfigurationName") + private String planConfigurationName = null; + + @JsonProperty("boundaryAncestralPath") + private String boundaryAncestralPath = null; + + @JsonProperty("facilityId") + @NotNull + @Size(max = 64) + private String facilityId = null; + + @JsonProperty("facilityName") + private String facilityName = null; + + @JsonProperty("residingBoundary") + @NotNull + @Size(min = 1, max = 64) + private String residingBoundary = null; + + @JsonProperty("serviceBoundaries") + @NotNull + @Valid + private List serviceBoundaries; + + @JsonIgnore + private List initiallySetServiceBoundaries; + + @JsonProperty("jurisdictionMapping") + private Map jurisdictionMapping; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + @JsonProperty("active") + @NotNull + private Boolean active = null; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + + public PlanFacility addServiceBoundariesItem(String serviceBoundariesItem) { + if (this.serviceBoundaries == null) { + this.serviceBoundaries = new ArrayList<>(); + } + this.serviceBoundaries.add(serviceBoundariesItem); + return this; + } + + + +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java new file mode 100644 index 0000000000..4b39c308b6 --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java @@ -0,0 +1,33 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; +import java.util.List; + +/** + * PlanFacilityResponse + */ +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacilityResponse { + + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo = null; + + @JsonProperty("PlanFacility") + @Valid + private List planFacility = null; + + @JsonProperty("TotalCount") + @Valid + private Integer totalCount = null; +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java new file mode 100644 index 0000000000..e36e30f97e --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java @@ -0,0 +1,64 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.validation.annotation.Validated; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacilitySearchCriteria { + + @JsonProperty("ids") + private Set ids = null; + + @JsonProperty("tenantId") + @NotNull + private String tenantId = null; + + @JsonProperty("planConfigurationId") + @NotNull + private String planConfigurationId = null; + + @JsonProperty("planConfigurationName") + private String planConfigurationName = null; + + @JsonProperty("facilityName") + private String facilityName = null; + + @JsonProperty("facilityStatus") + private String facilityStatus = null; + + @JsonProperty("facilityType") + private String facilityType = null; + + @JsonProperty("residingBoundaries") + private List residingBoundaries = null; + + @JsonProperty("jurisdiction") + private List jurisdiction = null; + + @JsonProperty("facilityId") + private String facilityId = null; + + @JsonProperty("offset") + private Integer offset = null; + + @JsonProperty("limit") + private Integer limit = null; + + @JsonIgnore + private Map filtersMap = null; + +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java new file mode 100644 index 0000000000..91fd4fa17c --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java @@ -0,0 +1,34 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotNull; + +/** + * PlanFacilitySearchRequest + */ +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacilitySearchRequest { + + @JsonProperty("RequestInfo") + @NotNull + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("PlanFacilitySearchCriteria") + @NotNull + @Valid + private PlanFacilitySearchCriteria planFacilitySearchCriteria = null; + +} diff --git a/health-services/resource-generator/src/main/resources/application.properties b/health-services/resource-generator/src/main/resources/application.properties index 45e36a74e5..643d334cea 100644 --- a/health-services/resource-generator/src/main/resources/application.properties +++ b/health-services/resource-generator/src/main/resources/application.properties @@ -68,6 +68,9 @@ plan.config.consumer.kafka.update.topic=plan-config-update-topic egov.plan.create.endpoint=/plan-service/plan/_create egov.plan.search.endpoint=/plan-service/plan/_search +#Plan Facility +egov.plan.facility.search.endpoint=/plan-service/plan/facility/_search + #Campaign Manager egov.project.factory.search.endpoint=/project-factory/v1/project-type/search egov.project.factory.update.endpoint=/project-factory/v1/project-type/update From f6f02d178ebe0c2ec142d18220cd960344a31012 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 6 Jan 2025 16:02:48 +0530 Subject: [PATCH 10/76] HCMPRE-1801 setting dynamic column width for column headers --- .../egov/processor/util/ExcelStylingUtil.java | 26 +++++++++++++++++-- .../util/OutputEstimationGenerationUtil.java | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java index 39e5fd75de..63d38d6654 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java @@ -42,9 +42,31 @@ public void styleCell(Cell cell) { // Apply the style to the cell cell.setCellStyle(cellStyle); - // Adjust the column width + } + + /** + * Adjusts the column width to fit the content of the given cell, adding padding for readability. + * + * @param cell the cell whose column width is to be adjusted; does nothing if null. + */ + public void adjustColumnWidthForCell(Cell cell) { + if (cell == null) { + return; + } + + Sheet sheet = cell.getSheet(); int columnIndex = cell.getColumnIndex(); - sheet.setColumnWidth(columnIndex, COLUMN_WIDTH * 256); // Width is measured in units of 1/256 of a character + int maxWidth = sheet.getColumnWidth(columnIndex); + + // Calculate the width needed for the current cell content + String cellValue = cell.toString(); // Convert cell content to string + int cellWidth = cellValue.length() * 256; // Approximate width (1/256th of character width) + + // Use the maximum width seen so far, including padding for readability + int padding = 512; // Adjust padding as needed + int newWidth = Math.max(maxWidth, cellWidth + padding); + + sheet.setColumnWidth(columnIndex, newWidth); } /** diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index eb2dd82baa..e687c32dc9 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -81,6 +81,7 @@ public void processSheetForHeaderLocalization(Sheet sheet, Map l // Update the cell value with the localized message excelStylingUtil.styleCell(headerColumn); headerColumn.setCellValue(localizationCodeAndMessageMap.get(headerColumnValue)); + excelStylingUtil.adjustColumnWidthForCell(headerColumn); } } @@ -190,6 +191,7 @@ private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityCol Cell facilityColHeader = sheet.getRow(0).createCell(indexOfFacility, CellType.STRING); excelStylingUtil.styleCell(facilityColHeader); facilityColHeader.setCellValue(assignedFacilityColHeader); + excelStylingUtil.adjustColumnWidthForCell(facilityColHeader); return indexOfFacility; } } From a6e93b1686f856e685e00fb9cd4fd8830b1ed0ff Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 6 Jan 2025 16:48:39 +0530 Subject: [PATCH 11/76] Enriching additionalField ID after empty check --- .../src/main/java/digit/service/enrichment/PlanEnricher.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java index 39586d650c..2b4efe8ae8 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java @@ -54,7 +54,8 @@ public void enrichPlanCreate(PlanRequest body) { body.getPlan().getTargets().forEach(target -> UUIDEnrichmentUtil.enrichRandomUuid(target, "id")); // Generate id for additional fields - body.getPlan().getAdditionalFields().forEach(additionalField -> UUIDEnrichmentUtil.enrichRandomUuid(additionalField, "id")); + if(!CollectionUtils.isEmpty(body.getPlan().getAdditionalFields())) + body.getPlan().getAdditionalFields().forEach(additionalField -> UUIDEnrichmentUtil.enrichRandomUuid(additionalField, "id")); // Enrich audit details body.getPlan().setAuditDetails(AuditDetailsEnrichmentUtil From b35e3a3b2be30e913ceae0e3c23d497a3517632a Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 7 Jan 2025 11:56:37 +0530 Subject: [PATCH 12/76] Adding comments --- .../digit/service/validator/PlanFacilityValidator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java index ef254d73ea..ec7706750b 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java @@ -127,12 +127,12 @@ private void validateCampaignDetails(String campaignId, String rootTenantId, Pla // Collect all boundary code for the campaign Set lowestHierarchyBCodes = fetchBoundaryCodes(campaignResponse.getCampaignDetails().get(0), lowestHierarchy); - Set boundaryCode = fetchAllBoundaryCodes(campaignResponse.getCampaignDetails().get(0)); + Set allBoundaryCodes = fetchAllBoundaryCodes(campaignResponse.getCampaignDetails().get(0)); - // Validate residing boundaries - validateResidingBoundaries(boundaryCode, planFacility); + // Validate residing boundaries with all the boundary codes. + validateResidingBoundaries(allBoundaryCodes, planFacility); - // Validate service boundaries + // Validate service boundaries with the lowest hierarchy boundary codes. validateServiceBoundaries(lowestHierarchyBCodes, planFacility); //Enrich jurisdiction mapping and boundary ancestral path From 1c2ab26e93bbd795e0faf90bbfd642ab74ccc128 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 7 Jan 2025 12:22:06 +0530 Subject: [PATCH 13/76] enabling search on security questions --- .../src/main/java/digit/config/ServiceConstants.java | 4 ++++ .../src/main/java/digit/service/PlanEnricher.java | 10 ++++++++++ .../main/java/digit/web/models/PlanSearchCriteria.java | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 0d78f925b1..7cf45c8441 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -368,6 +368,10 @@ public class ServiceConstants { 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"; diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index ec1757fe43..cb660701b1 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -267,6 +267,16 @@ public void enrichSearchRequest(PlanSearchRequest planSearchRequest) { 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); } diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index 89a11e1fc1..4298738d1f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -49,6 +49,12 @@ public class PlanSearchCriteria { @JsonProperty("terrain") private String terrain = null; + @JsonProperty("securityQ1") + private String securityQ1 = null; + + @JsonProperty("securityQ2") + private String securityQ2 = null; + @JsonProperty("status") private String status = null; From e5d73f84083cd79f89cb8a4c0602a265fd6fb385 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 7 Jan 2025 13:55:58 +0530 Subject: [PATCH 14/76] Adding security details in plan additional details --- .../java/org/egov/processor/config/ServiceConstants.java | 1 + .../src/main/java/org/egov/processor/util/PlanUtil.java | 5 +++++ 2 files changed, 6 insertions(+) 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 c25dc64bd1..09013ace23 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 @@ -78,6 +78,7 @@ public class ServiceConstants { public static final String DOT_SEPARATOR = "."; public static final String MICROPLAN_PREFIX = "MP-"; public static final String ACCESSIBILITY_DETAILS = "accessibilityDetails"; + public static final String SECURITY_DETAILS = "securityDetails"; //MDMS field Constants public static final String DATA = "data"; 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 3f73e1c9ca..eb4e34cdcb 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 @@ -106,7 +106,9 @@ private Object enrichAdditionalDetials(Map BCodeToCensusAddition // Extract required details from census additional details object. String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, FACILITY_NAME); Object accessibilityDetails = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, ACCESSIBILITY_DETAILS); + Object securityDetials = (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(facilityName != null && !facilityName.isEmpty()) fieldsToBeUpdated.put(FACILITY_NAME, facilityName); @@ -114,6 +116,9 @@ private Object enrichAdditionalDetials(Map BCodeToCensusAddition if(accessibilityDetails != null) fieldsToBeUpdated.put(ACCESSIBILITY_DETAILS, accessibilityDetails); + if(securityDetials != null) + fieldsToBeUpdated.put(SECURITY_DETAILS, securityDetials); + if(!CollectionUtils.isEmpty(fieldsToBeUpdated)) return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); } From 518c1cfa70f838a3228e7002af8e293bca9c9cf9 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 7 Jan 2025 15:02:42 +0530 Subject: [PATCH 15/76] Validating only active employee assignments --- .../service/validator/PlanEmployeeAssignmentValidator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanEmployeeAssignmentValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanEmployeeAssignmentValidator.java index 772ec6dd13..774ff75313 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanEmployeeAssignmentValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanEmployeeAssignmentValidator.java @@ -317,8 +317,9 @@ public void validateUpdate(PlanEmployeeAssignmentRequest request) { // Validate if Plan employee assignment exists validatePlanEmployeeAssignmentExistance(planEmployeeAssignment); - // Validate campaign id and employee jurisdiction - validateCampaignDetails(planConfigurations.get(0).getCampaignId(), rootTenantId, request); + // Validate campaign id and employee jurisdiction for active records + if(planEmployeeAssignment.getActive()) + validateCampaignDetails(planConfigurations.get(0).getCampaignId(), rootTenantId, request); } From ee76c4d05f23ca9e71484f2b58a53fb7f0320d3a Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 7 Jan 2025 16:59:26 +0530 Subject: [PATCH 16/76] Creating map of boundary code to facility fixed post details --- .../org/egov/processor/service/ExcelParser.java | 17 ++++++++++------- .../util/OutputEstimationGenerationUtil.java | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) 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 14bf09b527..3b96fdcb57 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 @@ -239,10 +239,12 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigUpdatePlanEstimatesIntoOutputFileStatus())) { + Map boundaryCodeToFacility = new HashMap<>(); + // Adding facility information for each boundary code - outputEstimationGenerationUtil.addAssignedFacility(excelWorkbook, request, fileStoreId); + outputEstimationGenerationUtil.addAssignedFacility(excelWorkbook, request, fileStoreId, boundaryCodeToFacility); - Map facilityToFixedPost = fetchFixedPostDetails(request); + Map facilityToFixedPost = fetchFixedPostDetails(request, boundaryCodeToFacility); enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues); } } @@ -250,12 +252,13 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, } /** - * This method makes plan facility search call and creates a map of facility name to it's fixed post details. + * This method makes plan facility search call and creates a map of boundary code to it's fixed post facility details. * - * @param request the plan configuration request. - * @return returns a map of facility name to it's fixed post details. + * @param request the plan configuration request. + * @param boundaryCodeToFacility map of boundary code to facility assigned. + * @return returns a map of boundary code to it's fixed post facility details. */ - private Map fetchFixedPostDetails(PlanConfigurationRequest request) { + private Map fetchFixedPostDetails(PlanConfigurationRequest request, Map boundaryCodeToFacility) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); //Create plan facility search request @@ -272,7 +275,7 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque // Create and return a map of facility name to fixed post details return planFacilityResponse.getPlanFacility().stream() .collect(Collectors.toMap( - PlanFacility::getFacilityName, + planFacility -> findByValue(boundaryCodeToFacility, planFacility.getFacilityName()), planFacility -> (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST) )); } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index eb2dd82baa..379b34acdc 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -94,7 +94,7 @@ public void processSheetForHeaderLocalization(Sheet sheet, Map l * @param request the plan configuration request containing the resource mapping and other configurations. * @param fileStoreId the associated file store ID used to filter resource mappings. */ - public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { + public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest request, String fileStoreId, Map boundaryCodeToFacility) { LocaleResponse localeResponse = localeUtil.searchLocale(request); String assignedFacilityColHeader = localeUtil.localeSearch(localeResponse.getMessages(), HCM_MICROPLAN_SERVING_FACILITY); @@ -110,8 +110,8 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ LinkedHashMap::new )); - // Get the map of boundary code to the facility assigned to that boundary. - Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId); + // Enrich the map of boundary code to the facility assigned to that boundary. + boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); From e3849c244b7cf8ecbf260740024f5c8a98d2f2e7 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 7 Jan 2025 17:28:48 +0530 Subject: [PATCH 17/76] Updating preparePartialJsonStringFromFilterMap function --- .../plan-service/src/main/java/digit/util/QueryUtil.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index 070f442a89..1aba9d3f07 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -110,7 +110,14 @@ public String preparePartialJsonStringFromFilterMap(Map filterMa String[] keyArray = key.split(DOT_REGEX); Map nestedQueryMap = new HashMap<>(); prepareNestedQueryMap(0, keyArray, nestedQueryMap, filterMap.get(key)); - queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0])); + queryMap.merge(keyArray[0], nestedQueryMap.get(keyArray[0]), (existing, newValue) -> { + if (existing instanceof Map && newValue instanceof Map) { + ((Map) existing).putAll((Map) newValue); + return existing; + } + return newValue; + }); + } else { queryMap.put(key, filterMap.get(key)); } From 308cd0b0eed85c78b1971c423492779de20df782 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 8 Jan 2025 12:20:04 +0530 Subject: [PATCH 18/76] HCMPRE-1577 Updating comments --- .../egov/processor/service/ExcelParser.java | 8 ++-- .../util/OutputEstimationGenerationUtil.java | 41 +++++++++++++++---- 2 files changed, 36 insertions(+), 13 deletions(-) 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 b951270f8d..9913ed6a83 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 @@ -167,12 +167,10 @@ private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigu String uploadedFileStoreId = uploadConvertedFile(fileToUpload, planConfig.getTenantId()); campaignIntegrationUtil.updateResourcesInProjectFactory(planConfigurationRequest, uploadedFileStoreId); - outputEstimationGenerationUtil.processOutputFile(workbook, planConfigurationRequest); + //process output file for localized header columns and addition of new columns + outputEstimationGenerationUtil.processOutputFile(workbook, planConfigurationRequest, filestoreId); - // Adding facility information for each boundary code - outputEstimationGenerationUtil.addAssignedFacility(workbook, planConfigurationRequest, filestoreId); - - //update processed output file into plan configuration file object + //upload the processed output file and update the same into plan configuration file object fileToUpload = convertWorkbookToXls(workbook); uploadedFileStoreId = uploadConvertedFile(fileToUpload, planConfig.getTenantId()); planUtil.setFileStoreIdForPopulationTemplate(planConfigurationRequest, uploadedFileStoreId); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index e687c32dc9..bb1a34c14d 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -35,9 +35,19 @@ public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsing this.enrichmentUtil = enrichmentUtil; } - public void processOutputFile(Workbook workbook, PlanConfigurationRequest request) { + /** + * Processes an output Excel workbook by removing unnecessary sheets, localizing header columns, + * and adding facility information for each boundary code. The configuration for processing + * is based on the provided PlanConfigurationRequest. + * + * @param workbook the Excel workbook to process + * @param request the PlanConfigurationRequest containing processing configuration + * @param filestoreId the identifier of the file store for additional processing requirements + */ + public void processOutputFile(Workbook workbook, PlanConfigurationRequest request, String filestoreId) { LocaleResponse localeResponse = localeUtil.searchLocale(request); - //removing readme sheet + + // 1. removing readme sheet for (int i = workbook.getNumberOfSheets() - 1; i >= 0; i--) { Sheet sheet = workbook.getSheetAt(i); if (!parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { @@ -45,6 +55,25 @@ public void processOutputFile(Workbook workbook, PlanConfigurationRequest reques } } + // 2. Stylize and localize output column headers + for(Sheet sheet: workbook) { + processSheetForHeaderLocalization(sheet, localeResponse); + } + + // 3. Adding facility information for each boundary code + addAssignedFacility(workbook, request, filestoreId); + + } + + /** + * Localizes the header row in the given sheet using the provided localization map. + * Applies styling and adjusts column widths for each localized header cell. + * + * @param sheet the Excel sheet whose header row needs localization + * @param localeResponse localization search call response + */ + public void processSheetForHeaderLocalization(Sheet sheet, LocaleResponse localeResponse) { + // create localization code and message map Map localizationCodeAndMessageMap = localeResponse.getMessages().stream() .collect(Collectors.toMap( Locale::getCode, @@ -52,12 +81,6 @@ public void processOutputFile(Workbook workbook, PlanConfigurationRequest reques (existingValue, newValue) -> existingValue // Keep the existing value in case of duplicates )); - for(Sheet sheet: workbook) { - processSheetForHeaderLocalization(sheet, localizationCodeAndMessageMap); - } - } - - public void processSheetForHeaderLocalization(Sheet sheet, Map localizationCodeAndMessageMap) { // Fetch the header row from sheet Row row = sheet.getRow(0); if (parsingUtil.isRowEmpty(row)) @@ -189,6 +212,8 @@ private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeade private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityColHeader) { int indexOfFacility = (int) sheet.getRow(0).getLastCellNum(); Cell facilityColHeader = sheet.getRow(0).createCell(indexOfFacility, CellType.STRING); + + //stylize cell and set cell value as the localized value excelStylingUtil.styleCell(facilityColHeader); facilityColHeader.setCellValue(assignedFacilityColHeader); excelStylingUtil.adjustColumnWidthForCell(facilityColHeader); From 2988c15f07eb8600876f6d2fd3bb8e662e988b2d Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 8 Jan 2025 12:22:23 +0530 Subject: [PATCH 19/76] Adding comments --- .../util/OutputEstimationGenerationUtil.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index e687c32dc9..bd6f2e899e 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -98,7 +98,10 @@ public void processSheetForHeaderLocalization(Sheet sheet, Map l public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { LocaleResponse localeResponse = localeUtil.searchLocale(request); + // Get the localized column header name for assigned facilities. String assignedFacilityColHeader = localeUtil.localeSearch(localeResponse.getMessages(), HCM_MICROPLAN_SERVING_FACILITY); + + // Default to a constant value if no localized value is found. assignedFacilityColHeader = assignedFacilityColHeader != null ? assignedFacilityColHeader : HCM_MICROPLAN_SERVING_FACILITY; // Creating a map of MappedTo and MappedFrom values from resource mapping @@ -114,9 +117,12 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ // Get the map of boundary code to the facility assigned to that boundary. Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId); + // Iterate through all sheets in the workbook. for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); + if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + // Add facility names to the sheet. addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); } } @@ -134,13 +140,16 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ private Map getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { List boundaryCodes = new ArrayList<>(); + // Iterate through all sheets in the workbook. for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { + // Extract boundary codes from the sheet. boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); } } + // Fetch census records for the extracted boundary codes. List censusList = enrichmentUtil.getCensusRecordsForEnrichment(request, boundaryCodes); return censusList.stream() .collect(Collectors.toMap( @@ -159,9 +168,14 @@ private Map getBoundaryCodeToFacilityMap(Workbook workbook, Plan */ private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeader, Map boundaryCodeToFacility, Map mappedValues) { int indexOfFacility = createAssignedFacilityColumn(sheet, assignedFacilityColHeader); + + // Get column index mappings from the sheet. Map columnNameIndexMap = parsingUtil.getAttributeNameIndexFromExcel(sheet); + + // Get the index of the boundary code column based on the provided mappings. int indexOfBoundaryCode = parsingUtil.getIndexOfBoundaryCode(0, parsingUtil.sortColumnByIndex(columnNameIndexMap), mappedValues); + // Iterate over each row in the sheet and set the facility name for each row. for (Row row : sheet) { if (row.getRowNum() == 0 || parsingUtil.isRowEmpty(row)) { continue; @@ -169,11 +183,13 @@ private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeade String boundaryCode = row.getCell(indexOfBoundaryCode).getStringCellValue(); + // Get or create the facility cell in the row. Cell facilityCell = row.getCell(indexOfFacility); if (facilityCell == null) { facilityCell = row.createCell(indexOfFacility, CellType.STRING); } + // Assign the facility name based on the boundary code. facilityCell.setCellValue(boundaryCodeToFacility.getOrDefault(boundaryCode, "")); } } @@ -188,7 +204,11 @@ private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeade */ private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityColHeader) { int indexOfFacility = (int) sheet.getRow(0).getLastCellNum(); + + // Create a new cell for the column header. Cell facilityColHeader = sheet.getRow(0).createCell(indexOfFacility, CellType.STRING); + + // Apply styling to the header cell, adjust width and set column header for facility. excelStylingUtil.styleCell(facilityColHeader); facilityColHeader.setCellValue(assignedFacilityColHeader); excelStylingUtil.adjustColumnWidthForCell(facilityColHeader); From 2670e269d745e92f1d87b3530a9e2e6bb3dd1599 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 8 Jan 2025 12:27:20 +0530 Subject: [PATCH 20/76] HCMPRE-1577 Updating comments --- .../src/main/java/org/egov/processor/service/ExcelParser.java | 1 - 1 file changed, 1 deletion(-) 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 9913ed6a83..adbed6b243 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 @@ -198,7 +198,6 @@ private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigu * @param campaignBoundaryList List of boundary objects related to the campaign. * @param dataFormatter The data formatter for formatting cell values. */ - //TODO: processsheetforestimate and processsheetforcensus private void processSheets(PlanConfigurationRequest request, String fileStoreId, Object campaignResponse, Workbook excelWorkbook, List campaignBoundaryList, From 89f4046f62ad5766b4f4179a5cba95aa8a3e10e8 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 8 Jan 2025 12:28:34 +0530 Subject: [PATCH 21/76] HCMPRE-1577 Removing todo --- .../src/main/java/org/egov/processor/service/ExcelParser.java | 1 - 1 file changed, 1 deletion(-) 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 adbed6b243..26f7735067 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 @@ -320,7 +320,6 @@ private List getBoundaryCodeList(PlanConfigurationRequest planConfigurat * @return A map of attribute names to their corresponding indices or data types. */ - //TODO: fetch from adminSchema master private Map prepareAttributeVsIndexMap(PlanConfigurationRequest planConfigurationRequest, String fileStoreId, CampaignResponse campaign, PlanConfiguration planConfig, Object mdmsData) { org.egov.processor.web.models.File file = planConfig.getFiles().stream() From 8ff81e2cfc7dd23367cd6590474cf603172821bc Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 8 Jan 2025 15:32:29 +0530 Subject: [PATCH 22/76] Resolved review comments --- .../egov/processor/service/ExcelParser.java | 43 +++++++++++++------ .../egov/processor/util/PlanFacilityUtil.java | 12 +++--- .../src/main/resources/application.properties | 11 +++-- 3 files changed, 42 insertions(+), 24 deletions(-) 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 6b45feb9fe..018a2652b4 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 @@ -25,6 +25,7 @@ import org.egov.tracer.model.CustomException; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.io.File; import java.io.FileNotFoundException; @@ -34,7 +35,7 @@ import java.util.*; import java.util.stream.Collectors; -import static org.egov.processor.config.ServiceConstants.FIXED_POST; +import static org.egov.processor.config.ServiceConstants.*; @Slf4j @Service @@ -240,9 +241,8 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigUpdatePlanEstimatesIntoOutputFileStatus())) { - // Create the map of boundary code to the facility assigned to that boundary. - Map boundaryCodeToFacility = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(excelWorkbook, request, fileStoreId); - Map facilityToFixedPost = fetchFixedPostDetails(request, boundaryCodeToFacility); + // Create a Map of Boundary Code to Facility's fixed post detail. + Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(request, excelWorkbook, fileStoreId); enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues); } @@ -253,13 +253,17 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, /** * This method makes plan facility search call and creates a map of boundary code to it's fixed post facility details. * - * @param request the plan configuration request. - * @param boundaryCodeToFacility map of boundary code to facility assigned. + * @param request the plan configuration request. + * @param excelWorkbook the Excel workbook to be processed. + * @param fileStoreId the fileStore id of the file. * @return returns a map of boundary code to it's fixed post facility details. */ - private Map fetchFixedPostDetails(PlanConfigurationRequest request, Map boundaryCodeToFacility) { + private Map fetchFixedPostDetails(PlanConfigurationRequest request, Workbook excelWorkbook, String fileStoreId) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); + // Create the map of boundary code to the facility assigned to that boundary. + Map boundaryCodeToFacilityNameMap = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(excelWorkbook, request, fileStoreId); + //Create plan facility search request PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder() .requestInfo(request.getRequestInfo()) @@ -271,12 +275,25 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque PlanFacilityResponse planFacilityResponse = planFacilityUtil.search(searchRequest); - // Create and return a map of facility name to fixed post details - return planFacilityResponse.getPlanFacility().stream() - .collect(Collectors.toMap( - planFacility -> findByValue(boundaryCodeToFacility, planFacility.getFacilityName()), - planFacility -> (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST) - )); + if (CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { + throw new CustomException(NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE, NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE); + } + + // Create a Boundary Code to Facility's fixed post detail map. + Map boundaryCodeToFixedPostMap = new HashMap<>(); + + for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { + // Find the boundary code corresponding to the facility name. + String boundaryCode = findByValue(boundaryCodeToFacilityNameMap, planFacility.getFacilityName()); + + // Extract the 'FIXED_POST' field from additional details. + String fixedPostValue = (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST); + + // Populate the map. + boundaryCodeToFixedPostMap.put(boundaryCode, fixedPostValue); + } + + return boundaryCodeToFixedPostMap; } /** diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java index 1c8a09186d..cd8bb70288 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java @@ -28,6 +28,12 @@ public PlanFacilityUtil(Configuration config, ServiceRequestRepository serviceRe this.mapper = mapper; } + /** + * Searches for plan facilities based on the provided search request. + * + * @param planfacilitySearchRequest The search request containing the search criteria. + * @return A response with a list of plan facilities that matches the search criteria. + */ public PlanFacilityResponse search(PlanFacilitySearchRequest planfacilitySearchRequest) { PlanFacilityResponse planFacilityResponse = null; @@ -38,15 +44,11 @@ public PlanFacilityResponse search(PlanFacilitySearchRequest planfacilitySearchR log.error(ServiceConstants.ERROR_WHILE_SEARCHING_PLAN_FACILITY); } - if (CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { - throw new CustomException(NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE, NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE); - } - return planFacilityResponse; } /** - * Creates a complete search uri for plan facility search. + * Creates a search uri for plan facility search. * @return */ private StringBuilder getPlanFacilitySearchUri() { diff --git a/health-services/resource-generator/src/main/resources/application.properties b/health-services/resource-generator/src/main/resources/application.properties index 643d334cea..ce74288a82 100644 --- a/health-services/resource-generator/src/main/resources/application.properties +++ b/health-services/resource-generator/src/main/resources/application.properties @@ -49,11 +49,6 @@ egov.mdms.host=https://unified-dev.digit.org egov.mdms.search.endpoint=/egov-mdms-service/v1/_search egov.mdms.search.v2.endpoint=/mdms-v2/v2/_search -#plan config -egov.plan.config.host=https://unified-dev.digit.org -#egov.plan.config.host=http://localhost:8080 -egov.plan.config.endpoint=/plan-service/config/_search - #file store #egov.filestore.host=https://unified-dev.digit.org egov.filestore.service.host=http://localhost:8084 @@ -64,7 +59,11 @@ egov.filestore.upload.endpoint=/filestore/v1/files plan.config.consumer.kafka.save.topic=plan-config-create-topic plan.config.consumer.kafka.update.topic=plan-config-update-topic -#Plan Create +#Plan Config +egov.plan.config.host=https://unified-dev.digit.org +egov.plan.config.endpoint=/plan-service/config/_search + +#Plan egov.plan.create.endpoint=/plan-service/plan/_create egov.plan.search.endpoint=/plan-service/plan/_search From c4ba102badeabe3327b0dcbe159edd2fba0106e6 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 8 Jan 2025 16:15:45 +0530 Subject: [PATCH 23/76] HCMPRE-1808 adding changes for Mixed Strategy --- .../processor/config/ServiceConstants.java | 3 + .../egov/processor/service/ExcelParser.java | 27 ++++--- .../egov/processor/util/EnrichmentUtil.java | 11 +++ .../processor/util/MixedStartegyUtil.java | 81 +++++++++++++++++++ .../org/egov/processor/util/PlanUtil.java | 1 + .../mdmsV2/MixedStrategyOperationLogic.java | 30 +++++++ 6 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java create mode 100644 health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java 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..b7dfbf5d32 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 @@ -68,6 +68,8 @@ public class ServiceConstants { "Unexpected error while calling fetch from Microplan API for plan config Id: "; public static final String INVALID_HEX = "Invalid hex color specified: "; + public static final String DISTRIBUTION_PROCESS = "DistributionProcess"; + public static final String REGISTRATION_PROCESS = "RegistrationProcess"; public static final String FILE_NAME = "output.xls"; public static final String FILE_TYPE = "boundaryWithTarget"; public static final String FILE_TEMPLATE_IDENTIFIER_POPULATION = "Population"; @@ -80,6 +82,7 @@ public class ServiceConstants { public static final String MDMS_MASTER_SCHEMAS = "Schemas"; public static final String MDMS_CAMPAIGN_TYPE = "campaignType"; public static final String MDMS_SCHEMA_ADMIN_SCHEMA = "adminSchema"; + public static final String MDMS_MASTER_MIXED_STRATEGY = "MixedStrategyOperationLogic"; public static final String MDMS_ADMIN_CONSOLE_MODULE_NAME = "HCM-ADMIN-CONSOLE"; public static final String BOUNDARY = "boundary"; public static final String DOT_SEPARATOR = "."; 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..3fbaa58ff4 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 @@ -18,6 +18,7 @@ import org.egov.processor.web.models.campaignManager.Boundary; import org.egov.processor.web.models.campaignManager.CampaignResources; import org.egov.processor.web.models.campaignManager.CampaignResponse; +import org.egov.processor.web.models.mdmsV2.MixedStrategyOperationLogic; import org.egov.processor.web.models.planFacility.PlanFacility; import org.egov.processor.web.models.planFacility.PlanFacilityResponse; import org.egov.processor.web.models.planFacility.PlanFacilitySearchCriteria; @@ -69,11 +70,13 @@ public class ExcelParser implements FileParser { private OutputEstimationGenerationUtil outputEstimationGenerationUtil; + private MixedStartegyUtil mixedStartegyUtil; + private PlanFacilityUtil planFacilityUtil; public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, PlanUtil planUtil, CampaignIntegrationUtil campaignIntegrationUtil, - Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil, PlanFacilityUtil planFacilityUtil) { + Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil, MixedStartegyUtil mixedStartegyUtil, PlanFacilityUtil planFacilityUtil) { this.objectMapper = objectMapper; this.parsingUtil = parsingUtil; this.filestoreUtil = filestoreUtil; @@ -88,6 +91,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore this.enrichmentUtil = enrichmentUtil; this.planConfigurationUtil = planConfigurationUtil; this.outputEstimationGenerationUtil = outputEstimationGenerationUtil; + this.mixedStartegyUtil = mixedStartegyUtil; this.planFacilityUtil = planFacilityUtil; } @@ -240,10 +244,6 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigUpdatePlanEstimatesIntoOutputFileStatus())) { - - // Create a Map of Boundary Code to Facility's fixed post detail. - Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(request, excelWorkbook, fileStoreId); - enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues); } } @@ -280,6 +280,7 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque } // Create a Boundary Code to Facility's fixed post detail map. + //TODO: make it Map Map boundaryCodeToFixedPostMap = new HashMap<>(); for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { @@ -315,8 +316,10 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque * @throws IOException If an I/O error occurs. */ private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList) { - PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); - performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList); + // TODO: pass sheet instead + // Create a Map of Boundary Code to Facility's fixed post detail. + Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(request, excelWorkbook, fileStoreId); + performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, boundaryCodeToFixedPostMap); } private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map attributeNameVsDataTypeMap, List boundaryCodeList, String hierarchyType) { @@ -399,14 +402,15 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest * @param dataFormatter The data formatter for formatting cell values. * @param fileStoreId The ID of the uploaded file in the file store. * @param campaignBoundaryList List of boundary objects related to the campaign. - * @param planConfig The configuration details specific to the plan. * @param attributeNameVsDataTypeMap Mapping of attribute names to their data types. * @param boundaryCodeList List of boundary codes. */ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, - PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList) { + Map attributeNameVsDataTypeMap, List boundaryCodeList, + Map boundaryCodeToFixedPostMap) { Row firstRow = null; + PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); Map mappedValues = planConfig.getResourceMapping().stream() .filter(f -> f.getFilestoreId().equals(fileStoreId)) .collect(Collectors.toMap(ResourceMapping::getMappedTo, ResourceMapping::getMappedFrom)); @@ -417,6 +421,9 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat Integer indexOfBoundaryCode = parsingUtil.getIndexOfBoundaryCode(0, parsingUtil.sortColumnByIndex(mapOfColumnNameAndIndex), mappedValues); + List mixedStrategyOperationLogicList = mixedStartegyUtil + .fetchMixedStrategyOperationLogicFromMDMS(planConfigurationRequest); + for (Row row : sheet) { if(parsingUtil.isRowEmpty(row)) continue; @@ -432,6 +439,8 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat JsonNode feature = createFeatureNodeFromRow(row, mapOfColumnNameAndIndex); performCalculationsOnOperations(sheet, planConfig, row, resultMap, mappedValues, assumptionValueMap, feature); + + mixedStartegyUtil.processResultMap(resultMap, planConfig.getOperations(), mixedStartegyUtil.getCategoriesNotAllowed(boundaryCodeToFixedPostMap.get("")), planConfig, mixedStrategyOperationLogicList)); if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 330a391484..18a5592c24 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -262,6 +262,17 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR } cell.setCellValue(estimatedValue.doubleValue()); } + } else { + // If estimatedValue is null, set the cell to empty + Integer columnIndex = mapOfColumnNameAndIndex.get(resourceType); + if (columnIndex != null) { + // Ensure the cell is empty + Cell cell = row.getCell(columnIndex); + if (cell == null) { + cell = row.createCell(columnIndex); + } + cell.setCellValue(""); // Set as empty string + } } } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java new file mode 100644 index 0000000000..d46111ceef --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java @@ -0,0 +1,81 @@ +package org.egov.processor.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.egov.processor.web.models.Operation; +import org.egov.processor.web.models.PlanConfiguration; +import org.egov.processor.web.models.PlanConfigurationRequest; +import org.egov.processor.web.models.mdmsV2.Mdms; +import org.egov.processor.web.models.mdmsV2.MixedStrategyOperationLogic; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.egov.processor.config.ServiceConstants.*; +import static org.egov.processor.config.ServiceConstants.MDMS_SCHEMA_ADMIN_SCHEMA; + +@Component +public class MixedStartegyUtil { + + private MdmsV2Util mdmsV2Util; + + private ParsingUtil parsingUtil; + + private ObjectMapper mapper; + + public MixedStartegyUtil(MdmsV2Util mdmsV2Util, ParsingUtil parsingUtil, ObjectMapper mapper) { + this.mdmsV2Util = mdmsV2Util; + this.parsingUtil = parsingUtil; + this.mapper = mapper; + } + + public List fetchMixedStrategyOperationLogicFromMDMS(PlanConfigurationRequest request) { + String rootTenantId = request.getPlanConfiguration().getTenantId().split("\\.")[0]; + List mdmsV2Data = mdmsV2Util.fetchMdmsV2Data(request.getRequestInfo(), rootTenantId, MDMS_PLAN_MODULE_NAME + DOT_SEPARATOR + MDMS_MASTER_MIXED_STRATEGY, null); + + return mdmsV2Data.stream() + .map(mdms -> mapper.convertValue(mdms.getData(), MixedStrategyOperationLogic.class)) + .collect(Collectors.toList()); + + } + + public List getCategoriesNotAllowed(boolean isFixedPost, + PlanConfiguration planConfiguration, List logicList) { + + return logicList.stream() + .filter(logic -> logic.isFixedPost() == isFixedPost && + logic.getRegistrationProcess().equalsIgnoreCase((String) parsingUtil.extractFieldsFromJsonObject(planConfiguration.getAdditionalDetails(), REGISTRATION_PROCESS)) && + logic.getDistributionProcess().equalsIgnoreCase((String) parsingUtil.extractFieldsFromJsonObject(planConfiguration.getAdditionalDetails(), DISTRIBUTION_PROCESS))) + .map(MixedStrategyOperationLogic::getCategoriesNotAllowed) + .findAny() // Returns any matching element since there is only one match + .orElse(List.of()); + + } + + public void processResultMap(Map resultMap, + List operations, + List categoriesNotAllowed) { + + // Map each category to its corresponding list of output keys + Map> categoryToOutputMap = operations.stream() + .filter(Operation::getActive) + .collect(Collectors.groupingBy( + Operation::getCategory, + Collectors.mapping(Operation::getOutput, Collectors.toList()))); + + // Iterate through categories in the categoriesNotAllowed list and set their result values to null + for (String category : categoriesNotAllowed) { + List outputKeys = categoryToOutputMap.getOrDefault(category, Collections.emptyList()); + for (String outputKey : outputKeys) { + if (resultMap.containsKey(outputKey)) { + resultMap.put(outputKey, null); + } + } + } + } + + +} 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 97c9810e0c..01b8eec8af 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 @@ -83,6 +83,7 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .resources(resultMap.entrySet().stream().map(result -> { Resource res = new Resource(); res.setResourceType(result.getKey()); + //TODO: remove null check res.setEstimatedNumber(result.getValue()); return res; }).collect(Collectors.toList())) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java new file mode 100644 index 0000000000..d48f5077a7 --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java @@ -0,0 +1,30 @@ +package org.egov.processor.web.models.mdmsV2; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class MixedStrategyOperationLogic { + + @JsonProperty("isFixedPost") + private boolean isFixedPost; + + @JsonProperty("RegistrationProcess") + private String registrationProcess; + + @JsonProperty("DistributionProcess") + private String distributionProcess; + + @JsonProperty("CategoriesNotAllowed") + private List categoriesNotAllowed; +} From d2d7f2b6490a387712cf914330688b4315791b10 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 8 Jan 2025 17:03:53 +0530 Subject: [PATCH 24/76] HCMPRE-1846 making output columns and facility name cell editable. --- .../src/main/java/org/egov/processor/service/ExcelParser.java | 2 ++ .../org/egov/processor/util/OutputEstimationGenerationUtil.java | 2 ++ 2 files changed, 4 insertions(+) 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..b49c1b2ef4 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 @@ -466,10 +466,12 @@ private void performCalculationsOnOperations(Sheet sheet, PlanConfiguration plan Cell cell = row.createCell(columnIndex++); cell.setCellValue(result.doubleValue()); + cell.getCellStyle().setLocked(false); // Ensure the new cell is editable if (row.getRowNum() == 1) { Cell headerCell = sheet.getRow(0).createCell(row.getLastCellNum() - 1); headerCell.setCellValue(output); + headerCell.getCellStyle().setLocked(true); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index cec7afccb0..395a14d36b 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -214,6 +214,8 @@ private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeade // Assign the facility name based on the boundary code. facilityCell.setCellValue(boundaryCodeToFacility.getOrDefault(boundaryCode, "")); + facilityCell.getCellStyle().setLocked(false); // Ensure the new cell is editable + } } From 1a926cf7507bf328814f7c56fbb49bde3c14fed6 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 8 Jan 2025 17:19:58 +0530 Subject: [PATCH 25/76] removing not null constraint from Resource.java --- .../plan-service/src/main/java/digit/web/models/Resource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/web/models/Resource.java b/health-services/plan-service/src/main/java/digit/web/models/Resource.java index d0d8ce2500..2a614db0ba 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Resource.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Resource.java @@ -29,7 +29,6 @@ public class Resource { private String resourceType = null; @JsonProperty("estimatedNumber") - @NotNull private BigDecimal estimatedNumber = null; @JsonProperty("activityCode") From be041ea30e8f81c1118c65553366a97b9dce1824 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 12:16:01 +0530 Subject: [PATCH 26/76] Modifying filter logic --- .../src/main/java/digit/util/QueryUtil.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index 1aba9d3f07..643f45a79e 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -109,16 +109,21 @@ public String preparePartialJsonStringFromFilterMap(Map filterMa if (key.contains(DOT_SEPARATOR)) { String[] keyArray = key.split(DOT_REGEX); Map nestedQueryMap = new HashMap<>(); + + // Recursively build the nested structure based on the key hierarchy. prepareNestedQueryMap(0, keyArray, nestedQueryMap, filterMap.get(key)); + + // 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) { - ((Map) existing).putAll((Map) newValue); + mergeMaps((Map) existing, (Map) 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)); } }); @@ -177,6 +182,31 @@ public String getPaginatedQuery(String query, List 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 existing, Map 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) oldValue, (Map) 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 * From 7e8980893bfbe1993965e41f68f733471f967b9e Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 12:55:32 +0530 Subject: [PATCH 27/76] changing filter from facilityName to facilityId --- .../src/main/java/digit/config/ServiceConstants.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 186e383846..87793bbdad 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -358,6 +358,8 @@ public class ServiceConstants { public static final String FAILED_MESSAGE = "Failed to push message to topic"; + public static final String FACILITY_NAME_SEARCH_PARAMETER_KEY = "facilityName"; + public static final String FACILITY_ID_SEARCH_PARAMETER_KEY = "facilityId"; public static final String FACILITY_STATUS_SEARCH_PARAMETER_KEY = "facilityStatus"; From ec0e93c8e8c8654f39574e76de4edb624f94d295 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 12:57:04 +0530 Subject: [PATCH 28/76] removed not null constraint from plan --- .../egov/processor/service/ExcelParser.java | 28 +++++++++++-------- .../processor/util/MixedStartegyUtil.java | 18 +++++++----- .../util/OutputEstimationGenerationUtil.java | 15 ++++------ .../org/egov/processor/util/PlanUtil.java | 1 - .../egov/processor/web/models/Resource.java | 1 - 5 files changed, 33 insertions(+), 30 deletions(-) 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 3fbaa58ff4..b46414a2cc 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 @@ -253,16 +253,16 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, /** * This method makes plan facility search call and creates a map of boundary code to it's fixed post facility details. * - * @param request the plan configuration request. - * @param excelWorkbook the Excel workbook to be processed. - * @param fileStoreId the fileStore id of the file. + * @param request the plan configuration request. + * @param sheet the Excel sheet to be processed. + * @param fileStoreId the fileStore id of the file. * @return returns a map of boundary code to it's fixed post facility details. */ - private Map fetchFixedPostDetails(PlanConfigurationRequest request, Workbook excelWorkbook, String fileStoreId) { + private Map fetchFixedPostDetails(PlanConfigurationRequest request, Sheet sheet, String fileStoreId) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); // Create the map of boundary code to the facility assigned to that boundary. - Map boundaryCodeToFacilityNameMap = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(excelWorkbook, request, fileStoreId); + Map boundaryCodeToFacilityNameMap = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(sheet, request, fileStoreId); //Create plan facility search request PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder() @@ -280,8 +280,7 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque } // Create a Boundary Code to Facility's fixed post detail map. - //TODO: make it Map - Map boundaryCodeToFixedPostMap = new HashMap<>(); + Map boundaryCodeToFixedPostMap = new HashMap<>(); for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { // Find the boundary code corresponding to the facility name. @@ -290,8 +289,11 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque // Extract the 'FIXED_POST' field from additional details. String fixedPostValue = (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST); + // Normalize the value and determine boolean equivalent. + boolean isFixedPost = fixedPostValue != null && fixedPostValue.trim().equalsIgnoreCase("yes"); + // Populate the map. - boundaryCodeToFixedPostMap.put(boundaryCode, fixedPostValue); + boundaryCodeToFixedPostMap.put(boundaryCode, isFixedPost); } return boundaryCodeToFixedPostMap; @@ -316,9 +318,9 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque * @throws IOException If an I/O error occurs. */ private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList) { - // TODO: pass sheet instead + // Create a Map of Boundary Code to Facility's fixed post detail. - Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(request, excelWorkbook, fileStoreId); + Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(planConfigurationRequest, sheet, fileStoreId); performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, boundaryCodeToFixedPostMap); } @@ -408,7 +410,7 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest private void performRowLevelCalculations(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, - Map boundaryCodeToFixedPostMap) { + Map boundaryCodeToFixedPostMap) { Row firstRow = null; PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); Map mappedValues = planConfig.getResourceMapping().stream() @@ -440,7 +442,9 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat performCalculationsOnOperations(sheet, planConfig, row, resultMap, mappedValues, assumptionValueMap, feature); - mixedStartegyUtil.processResultMap(resultMap, planConfig.getOperations(), mixedStartegyUtil.getCategoriesNotAllowed(boundaryCodeToFixedPostMap.get("")), planConfig, mixedStrategyOperationLogicList)); + // Get Boundary Code for the current row. + String boundaryCode = row.getCell(indexOfBoundaryCode).getStringCellValue(); + mixedStartegyUtil.processResultMap(resultMap, planConfig.getOperations(), mixedStartegyUtil.getCategoriesNotAllowed(boundaryCodeToFixedPostMap.get(boundaryCode), planConfig, mixedStrategyOperationLogicList)); if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java index d46111ceef..31f4faa177 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java @@ -7,6 +7,7 @@ import org.egov.processor.web.models.mdmsV2.Mdms; import org.egov.processor.web.models.mdmsV2.MixedStrategyOperationLogic; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.Collections; @@ -55,20 +56,23 @@ public List getCategoriesNotAllowed(boolean isFixedPost, } - public void processResultMap(Map resultMap, - List operations, - List categoriesNotAllowed) { + public void processResultMap(Map resultMap, List operations, List categoriesNotAllowed) { - // Map each category to its corresponding list of output keys - Map> categoryToOutputMap = operations.stream() - .filter(Operation::getActive) + // If all te categories are allowed, don't process further. + if(CollectionUtils.isEmpty(categoriesNotAllowed)) + return; + + // Map categories not allowed to its corresponding list of output keys + Map> categoryNotAllowedToOutputMap = operations.stream() + .filter(op -> op.getActive() && categoriesNotAllowed.contains(op.getCategory())) .collect(Collectors.groupingBy( Operation::getCategory, Collectors.mapping(Operation::getOutput, Collectors.toList()))); + // Iterate through categories in the categoriesNotAllowed list and set their result values to null for (String category : categoriesNotAllowed) { - List outputKeys = categoryToOutputMap.getOrDefault(category, Collections.emptyList()); + List outputKeys = categoryNotAllowedToOutputMap.getOrDefault(category, Collections.emptyList()); for (String outputKey : outputKeys) { if (resultMap.containsKey(outputKey)) { resultMap.put(outputKey, null); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index cec7afccb0..2b6149595b 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -155,21 +155,18 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ * Collects boundary codes from all eligible sheets in the workbook, fetches census records for these boundaries, * and maps each boundary code to its assigned facility name obtained from the census data. * - * @param workbook the workbook containing the sheets. + * @param sheet the sheet to be processed. * @param request the plan configuration request with boundary code details. * @param fileStoreId the associated file store ID for filtering. * @return a map of boundary codes to their assigned facility names. */ - public Map getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { + public Map getBoundaryCodeToFacilityMap(Sheet sheet, PlanConfigurationRequest request, String fileStoreId) { List boundaryCodes = new ArrayList<>(); - // Iterate through all sheets in the workbook. - for (int i = 0; i < workbook.getNumberOfSheets(); i++) { - Sheet sheet = workbook.getSheetAt(i); - if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { - // Extract boundary codes from the sheet. - boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); - } + + if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { + // Extract boundary codes from the sheet. + boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); } // Fetch census records for the extracted boundary codes. 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 01b8eec8af..97c9810e0c 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 @@ -83,7 +83,6 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .resources(resultMap.entrySet().stream().map(result -> { Resource res = new Resource(); res.setResourceType(result.getKey()); - //TODO: remove null check res.setEstimatedNumber(result.getValue()); return res; }).collect(Collectors.toList())) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/Resource.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/Resource.java index 693ba12ef3..c33fd233ec 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/Resource.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/Resource.java @@ -29,7 +29,6 @@ public class Resource { private String resourceType = null; @JsonProperty("estimatedNumber") - @NotNull private BigDecimal estimatedNumber = null; @JsonProperty("activityCode") From 0de2e9a3530d9f9750d9e26452594bd96b3e6345 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 12:59:09 +0530 Subject: [PATCH 29/76] removed not null constraint from plan --- .../util/OutputEstimationGenerationUtil.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 2b6149595b..382cbea83d 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -61,7 +61,9 @@ public void processOutputFile(Workbook workbook, PlanConfigurationRequest reques } // 3. Adding facility information for each boundary code - addAssignedFacility(workbook, request, filestoreId); + for(Sheet sheet: workbook) { + addAssignedFacility(sheet, request, filestoreId); + } } @@ -114,11 +116,11 @@ public void processSheetForHeaderLocalization(Sheet sheet, LocaleResponse locale * It iterates through all the sheets, verifies if they are eligible for processing, retrieves required mappings * and boundary codes, and populates the new column with facility names based on these mappings. * - * @param workbook the workbook containing the sheets to be processed. + * @param sheet the sheet to be processed. * @param request the plan configuration request containing the resource mapping and other configurations. * @param fileStoreId the associated file store ID used to filter resource mappings. */ - public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { + public void addAssignedFacility(Sheet sheet, PlanConfigurationRequest request, String fileStoreId) { LocaleResponse localeResponse = localeUtil.searchLocale(request); // Get the localized column header name for assigned facilities. @@ -138,16 +140,11 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ )); // Create the map of boundary code to the facility assigned to that boundary. - Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId); + Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(sheet, request, fileStoreId); - // Iterate through all sheets in the workbook. - for (int i = 0; i < workbook.getNumberOfSheets(); i++) { - Sheet sheet = workbook.getSheetAt(i); - - if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { - // Add facility names to the sheet. - addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); - } + if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + // Add facility names to the sheet. + addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); } } From 6f9da7b1378a87cc7a7de894ece61c2a5cfa8022 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 15:37:06 +0530 Subject: [PATCH 30/76] filter on facilityId --- .../java/org/egov/processor/config/ServiceConstants.java | 1 + .../src/main/java/org/egov/processor/util/PlanUtil.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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 0c53521791..b0ea2fdc00 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 @@ -134,6 +134,7 @@ public class ServiceConstants { public static final String MICROPLAN_SOURCE_KEY = "microplan"; public static final String MICROPLAN_ID_KEY = "microplanId"; public static final String FACILITY_NAME = "facilityName"; + public static final String FACILITY_ID = "facilityId"; public static final String HCM_MICROPLAN_SERVING_FACILITY = "HCM_MICROPLAN_SERVING_FACILITY"; public static final String FIXED_POST = "fixedPost"; 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 ec63f11a3d..2a3ba38942 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 @@ -104,14 +104,14 @@ private Object enrichAdditionalDetials(Map boundaryCodeToCensusA Object censusAdditionalDetails = boundaryCodeToCensusAdditionalDetails.get(boundaryCodeValue); // Extract required details from census additional details object. - String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, FACILITY_NAME); + String facilityId = (String) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, FACILITY_ID); Object accessibilityDetails = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, ACCESSIBILITY_DETAILS); Object securityDetials = (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(facilityName != null && !facilityName.isEmpty()) - fieldsToBeUpdated.put(FACILITY_NAME, facilityName); + if(facilityId != null && !facilityId.isEmpty()) + fieldsToBeUpdated.put(FACILITY_ID, facilityId); if(accessibilityDetails != null) fieldsToBeUpdated.put(ACCESSIBILITY_DETAILS, accessibilityDetails); From c270aedd4b33c17dffa7729f1bbdb34945afd7c5 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 15:46:57 +0530 Subject: [PATCH 31/76] adding facilityId in plan additional details --- .../processor/config/ServiceConstants.java | 1 + .../egov/processor/service/ExcelParser.java | 58 ++++++++++++++++--- .../egov/processor/util/EnrichmentUtil.java | 6 +- .../org/egov/processor/util/PlanUtil.java | 20 +++---- 4 files changed, 62 insertions(+), 23 deletions(-) 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 f98a0885b8..fcd82ee970 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 @@ -132,6 +132,7 @@ public class ServiceConstants { public static final String MICROPLAN_SOURCE_KEY = "microplan"; public static final String MICROPLAN_ID_KEY = "microplanId"; public static final String FACILITY_NAME = "facilityName"; + public static final String FACILITY_ID = "facilityId"; public static final String HCM_MICROPLAN_SERVING_FACILITY = "HCM_MICROPLAN_SERVING_FACILITY"; public static final String FIXED_POST = "fixedPost"; 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 ba27f92a65..097a896a2f 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 @@ -230,14 +230,16 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, (existing, replacement) -> existing, LinkedHashMap::new )); + + // Create a map of boundary code to facilityId. + Map boundaryToFacilityId = getBoundaryToFacilityIdMap(request); + excelWorkbook.forEach(excelWorkbookSheet -> { if (parsingUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { - Map BCodeToFacilityDetails = new HashMap<>(); - - enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToFacilityDetails); + enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues); processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId, - campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); + campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, boundaryToFacilityId); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerCensusRecordsStatus())) { processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); @@ -252,6 +254,46 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, }); } + /** + * Retrieves a mapping of service boundary codes to facility IDs for a given PlanConfigurationID. + * + * @param request The PlanConfigurationRequest containing plan configuration id. + * @return A Map where keys are service boundary codes and values are corresponding facility IDs. + */ + private Map getBoundaryToFacilityIdMap(PlanConfigurationRequest request) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + + //Create plan facility search request + PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder() + .requestInfo(request.getRequestInfo()) + .planFacilitySearchCriteria(PlanFacilitySearchCriteria.builder() + .tenantId(planConfiguration.getTenantId()) + .planConfigurationId(planConfiguration.getId()) + .build()) + .build(); + + PlanFacilityResponse planFacilityResponse = planFacilityUtil.search(searchRequest); + + if (CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { + throw new CustomException(NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE, NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE); + } + + // Initialize map to store serviceBoundary -> facilityId mapping + Map boundaryToFacilityMap = new HashMap<>(); + + // Populate the map + for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { + // Ensure serviceBoundaries is not empty + if (!CollectionUtils.isEmpty(planFacility.getServiceBoundaries())) { + for (String boundary : planFacility.getServiceBoundaries()) { + boundaryToFacilityMap.put(boundary, planFacility.getFacilityId()); + } + } + } + + return boundaryToFacilityMap; + } + /** * This method makes plan facility search call and creates a map of boundary code to it's fixed post facility details. * @@ -316,9 +358,9 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque * @param boundaryCodeList List of boundary codes. * @throws IOException If an I/O error occurs. */ - private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { + private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map boundaryToFacilityId) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); - performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); + performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, boundaryToFacilityId); } private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map attributeNameVsDataTypeMap, List boundaryCodeList, String hierarchyType) { @@ -407,7 +449,7 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest */ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, - PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { + PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map boundaryToFacilityId) { Row firstRow = null; Map mappedValues = planConfig.getResourceMapping().stream() .filter(f -> f.getFilestoreId().equals(fileStoreId)) @@ -437,7 +479,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToFacilityDetails)); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(boundaryToFacilityId)); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 3d44e0ee7e..330a391484 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -89,7 +89,7 @@ public void enrichResourceMapping(PlanConfigurationRequest request, LocaleRespon } - public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues, Map BCodeToFacilityDetails) { + public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues) { List boundaryCodes = getBoundaryCodesFromTheSheet(sheet, planConfigurationRequest, fileStoreId); Map mapOfColumnNameAndIndex = parsingUtil.getAttributeNameIndexFromExcel(sheet); @@ -143,10 +143,6 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR } } - - String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(census.getAdditionalDetails(), FACILITY_NAME); - if(facilityName != null && !facilityName.isEmpty()) - BCodeToFacilityDetails.put(boundaryCode, facilityName); } log.info("Successfully update file with approved census data."); 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 cc990136e7..50f0de3863 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 @@ -51,8 +51,8 @@ public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration * @param mappedValues The mapped values. */ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Optional> BCodeToFacilityDetails) { - PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, BCodeToFacilityDetails.orElse(Collections.emptyMap())); + Map resultMap, Map mappedValues, Optional> boundaryToFacilityId) { + PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, boundaryToFacilityId.orElse(Collections.emptyMap())); try { producer.push(config.getResourceMicroplanCreateTopic(), planRequest); } catch (Exception e) { @@ -71,7 +71,7 @@ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode f * @return The constructed PlanRequest object. */ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Map BCodeToFacilityDetails) { + Map resultMap, Map mappedValues, Map boundaryToFacilityId) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); String boundaryCodeValue = getBoundaryCodeValue(ServiceConstants.BOUNDARY_CODE, feature, mappedValues); @@ -93,20 +93,20 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .targets(new ArrayList()) .workflow(Workflow.builder().action(WORKFLOW_ACTION_INITIATE).build()) .isRequestFromResourceEstimationConsumer(true) - .additionalDetails(enrichAdditionalDetials(BCodeToFacilityDetails, boundaryCodeValue)) + .additionalDetails(enrichAdditionalDetials(boundaryToFacilityId, boundaryCodeValue)) .build()) .build(); } - private Object enrichAdditionalDetials(Map BCodeToFacilityDetails, String boundaryCodeValue) { - if(!CollectionUtils.isEmpty(BCodeToFacilityDetails)) { + private Object enrichAdditionalDetials(Map boundaryToFacilityId, String boundaryCodeValue) { + if(!CollectionUtils.isEmpty(boundaryToFacilityId)) { - // Iterate over each boundary and add facility details in plan additional details - String facilityName = BCodeToFacilityDetails.get(boundaryCodeValue); + // Iterate over each boundary and add facility id in plan additional details + String facilityId = boundaryToFacilityId.get(boundaryCodeValue); - if(facilityName != null && !facilityName.isEmpty()) { + if(facilityId != null && !facilityId.isEmpty()) { Map fieldsToBeUpdated = new HashMap<>(); - fieldsToBeUpdated.put(FACILITY_NAME, facilityName); + fieldsToBeUpdated.put(FACILITY_ID, facilityId); return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); } From 8b22819d7b4c4f32b16767b843c9ad1bf2caa3d2 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 16:06:03 +0530 Subject: [PATCH 32/76] removing calculationUtil from parsingUtil since unused --- .../src/main/java/org/egov/processor/util/ParsingUtil.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index 893eb50fac..50ef733d87 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -35,15 +35,12 @@ public class ParsingUtil { private FilestoreUtil filestoreUtil; - private CalculationUtil calculationUtil; - private MdmsUtil mdmsUtil; private ObjectMapper objectMapper; - public ParsingUtil(FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, MdmsUtil mdmsUtil, ObjectMapper objectMapper) { + public ParsingUtil(FilestoreUtil filestoreUtil, MdmsUtil mdmsUtil, ObjectMapper objectMapper) { this.filestoreUtil = filestoreUtil; - this.calculationUtil = calculationUtil; this.mdmsUtil = mdmsUtil; this.objectMapper = objectMapper; } From 8ef639887d33745ac45aa25002ab91c5c45c81f8 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 17:33:00 +0530 Subject: [PATCH 33/76] resolved review comments --- .../src/main/java/digit/service/PlanEnricher.java | 5 +++-- .../main/java/org/egov/processor/service/ExcelParser.java | 2 +- .../main/java/org/egov/processor/util/CalculationUtil.java | 2 +- .../src/main/java/org/egov/processor/util/PlanUtil.java | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 1a33ef4b6e..e25aee0789 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -242,9 +242,10 @@ private List getBoundaryCodeFromAncestralPath(String boundaryAncestralPa } /** - * Enriches plan search request + * Enriches the PlanSearchRequest by populating the filters map in the search criteria. + * This filterMap is populated to search the fields in plan additional detail object. * - * @param planSearchRequest + * @param planSearchRequest the planSearchRequest object whose search criteria need enrichment. */ public void enrichSearchRequest(PlanSearchRequest planSearchRequest) { PlanSearchCriteria planSearchCriteria = planSearchRequest.getPlanSearchCriteria(); 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 8a16e52b5e..629e3b8d5f 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 @@ -437,7 +437,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(boundaryCodeToCensusAdditionalDetails)); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, boundaryCodeToCensusAdditionalDetails); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java index c0fa5b70cd..237b70040c 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java @@ -79,7 +79,7 @@ public void calculateResources(JsonNode jsonNode, PlanConfigurationRequest planC resultMap.put(output, result); ((ObjectNode) feature.get("properties")).put(output, result); } - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.empty()); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, null); } } 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 2a3ba38942..b43a9560e4 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 @@ -51,8 +51,8 @@ public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration * @param mappedValues The mapped values. */ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Optional> boundaryCodeToCensusAdditionalDetails) { - PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, boundaryCodeToCensusAdditionalDetails.orElse(Collections.emptyMap())); + Map resultMap, Map mappedValues, Map boundaryCodeToCensusAdditionalDetails) { + PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, boundaryCodeToCensusAdditionalDetails); try { producer.push(config.getResourceMicroplanCreateTopic(), planRequest); } catch (Exception e) { From 2d388cc744bc95899771282a1aa0df37e3c8df1d Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 20:34:10 +0530 Subject: [PATCH 34/76] Mark formula as null --- .../egov/processor/service/ExcelParser.java | 25 +++++++------ .../org/egov/processor/util/MdmsV2Util.java | 5 +-- .../util/OutputEstimationGenerationUtil.java | 34 +++++++++++++++--- .../org/egov/processor/util/ParsingUtil.java | 35 +------------------ .../processor/web/models/census/Census.java | 3 +- 5 files changed, 47 insertions(+), 55 deletions(-) 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 8fe68badb9..caeb137161 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 @@ -235,7 +235,7 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, LinkedHashMap::new )); excelWorkbook.forEach(excelWorkbookSheet -> { - if (parsingUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { + if (outputEstimationGenerationUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues); processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId, @@ -261,9 +261,6 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, private Map fetchFixedPostDetails(PlanConfigurationRequest request, Sheet sheet, String fileStoreId) { PlanConfiguration planConfiguration = request.getPlanConfiguration(); - // Create the map of boundary code to the facility assigned to that boundary. - Map boundaryCodeToFacilityNameMap = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(sheet, request, fileStoreId); - //Create plan facility search request PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder() .requestInfo(request.getRequestInfo()) @@ -283,19 +280,21 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest requ Map boundaryCodeToFixedPostMap = new HashMap<>(); for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { - // Find the boundary code corresponding to the facility name. - String boundaryCode = findByValue(boundaryCodeToFacilityNameMap, planFacility.getFacilityName()); + // Ensure serviceBoundaries is not empty + if (!CollectionUtils.isEmpty(planFacility.getServiceBoundaries())) { - // Extract the 'FIXED_POST' field from additional details. - String fixedPostValue = (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST); + // Extract the 'FIXED_POST' field from additional details. + String fixedPostValue = (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST); - // Normalize the value and determine boolean equivalent. - boolean isFixedPost = fixedPostValue != null && fixedPostValue.trim().equalsIgnoreCase("yes"); + // Normalize the value and determine boolean equivalent. + boolean isFixedPost = fixedPostValue != null && fixedPostValue.trim().equalsIgnoreCase("yes"); - // Populate the map. - boundaryCodeToFixedPostMap.put(boundaryCode, isFixedPost); + // Populate the map with boundary code and isFixedPost. + for (String boundary : planFacility.getServiceBoundaries()) { + boundaryCodeToFixedPostMap.put(boundary, isFixedPost); + } + } } - return boundaryCodeToFixedPostMap; } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java index 85b8787265..e9d7026ef0 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java @@ -67,9 +67,10 @@ private MdmsCriteriaReqV2 getMdmsV2Request(RequestInfo requestInfo, String tenan MdmsCriteriaV2 mdmsCriteriaV2 = MdmsCriteriaV2.builder() .tenantId(tenantId) .schemaCode(schemaCode) - .uniqueIdentifiers(Collections.singletonList(uniqueIdentifier)) + .uniqueIdentifiers(uniqueIdentifier != null ? Collections.singletonList(uniqueIdentifier) : null) .limit(config.getDefaultLimit()) - .offset(config.getDefaultOffset()).build(); + .offset(config.getDefaultOffset()) + .build(); return MdmsCriteriaReqV2.builder() .requestInfo(requestInfo) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index e95cc88730..040d842670 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -28,11 +28,14 @@ public class OutputEstimationGenerationUtil { private EnrichmentUtil enrichmentUtil; - public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsingUtil, EnrichmentUtil enrichmentUtil, ExcelStylingUtil excelStylingUtil) { + private MdmsUtil mdmsUtil; + + public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsingUtil, EnrichmentUtil enrichmentUtil, ExcelStylingUtil excelStylingUtil, MdmsUtil mdmsUtil) { this.localeUtil = localeUtil; this.parsingUtil = parsingUtil; this.excelStylingUtil = excelStylingUtil; this.enrichmentUtil = enrichmentUtil; + this.mdmsUtil = mdmsUtil; } /** @@ -50,7 +53,7 @@ public void processOutputFile(Workbook workbook, PlanConfigurationRequest reques // 1. removing readme sheet for (int i = workbook.getNumberOfSheets() - 1; i >= 0; i--) { Sheet sheet = workbook.getSheetAt(i); - if (!parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { workbook.removeSheetAt(i); } } @@ -142,7 +145,7 @@ public void addAssignedFacility(Sheet sheet, PlanConfigurationRequest request, S // Create the map of boundary code to the facility assigned to that boundary. Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(sheet, request, fileStoreId); - if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { // Add facility names to the sheet. addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); } @@ -161,7 +164,7 @@ public Map getBoundaryCodeToFacilityMap(Sheet sheet, PlanConfigu List boundaryCodes = new ArrayList<>(); - if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { + if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { // Extract boundary codes from the sheet. boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); } @@ -233,5 +236,28 @@ private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityCol excelStylingUtil.adjustColumnWidthForCell(facilityColHeader); return indexOfFacility; } + + /** + * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. + * + * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. + * @param sheetName The name of the sheet to be processed. + * @return true if the sheet is allowed to be processed, false otherwise. + */ + public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { + Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( + planConfigurationRequest.getRequestInfo(), + planConfigurationRequest.getPlanConfiguration().getTenantId()); + + for (Locale locale : localeResponse.getMessages()) { + if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) + || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { + if (sheetName.equals(locale.getMessage())) + return false; + } + } + return true; + + } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index ec20dbd2bd..4e34aa871d 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -7,7 +7,6 @@ import org.apache.commons.io.FileUtils; import org.apache.poi.ss.usermodel.*; import org.egov.processor.config.ServiceConstants; -import org.egov.processor.web.models.Locale; import org.egov.processor.web.models.*; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; @@ -31,21 +30,12 @@ @Component public class ParsingUtil { - private PlanConfigurationUtil planConfigurationUtil; - private FilestoreUtil filestoreUtil; - private CalculationUtil calculationUtil; - - private MdmsUtil mdmsUtil; - private ObjectMapper objectMapper; - public ParsingUtil(PlanConfigurationUtil planConfigurationUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, MdmsUtil mdmsUtil, ObjectMapper objectMapper) { - this.planConfigurationUtil = planConfigurationUtil; + public ParsingUtil(FilestoreUtil filestoreUtil, ObjectMapper objectMapper) { this.filestoreUtil = filestoreUtil; - this.calculationUtil = calculationUtil; - this.mdmsUtil = mdmsUtil; this.objectMapper = objectMapper; } @@ -399,29 +389,6 @@ public void printRow(Sheet sheet, Row row) { System.out.println(); // Move to the next line after printing the row } - /** - * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. - * - * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. - * @param sheetName The name of the sheet to be processed. - * @return true if the sheet is allowed to be processed, false otherwise. - */ - public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { - Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( - planConfigurationRequest.getRequestInfo(), - planConfigurationRequest.getPlanConfiguration().getTenantId()); - - for (Locale locale : localeResponse.getMessages()) { - if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) - || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { - if (sheetName.equals(locale.getMessage())) - return false; - } - } - return true; - - } - /** * Extracts provided field from the additional details object * 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) From 035542f04b142c63ae5e7d7e592c03c0fc820532 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 10 Jan 2025 10:33:39 +0530 Subject: [PATCH 35/76] modified census pojo --- .../src/main/java/digit/web/models/census/Census.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java index 2b989edb10..ad052ca93c 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java +++ b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java @@ -49,8 +49,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) From 89c9a9044f4ea9ff5e22c163b461a5cc0c7dcb4a Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 10 Jan 2025 14:02:20 +0530 Subject: [PATCH 36/76] added comment --- .../plan-service/src/main/java/digit/service/PlanEnricher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index e25aee0789..af3cc14aac 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -242,7 +242,7 @@ private List getBoundaryCodeFromAncestralPath(String boundaryAncestralPa } /** - * Enriches the PlanSearchRequest by populating the filters map in the search criteria. + * Enriches the PlanSearchRequest by populating the filters map from the fields in search criteria. * This filterMap is populated to search the fields in plan additional detail object. * * @param planSearchRequest the planSearchRequest object whose search criteria need enrichment. From 44201d894fbaf9286640c01370ea8034ddb4f0d2 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 10 Jan 2025 14:13:31 +0530 Subject: [PATCH 37/76] resolved comment --- .../src/main/java/org/egov/processor/util/PlanUtil.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 b43a9560e4..a8a5d4b615 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 @@ -98,6 +98,14 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .build(); } + /** + * Creates an additional details object. Extracts the required fields from census additional details for the given boundary. + * The extracted fields are then used to update the additional details object. + * + * @param boundaryCodeToCensusAdditionalDetails A map containing boundary codes mapped to their respective census additional details. + * @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 boundaryCodeToCensusAdditionalDetails, String boundaryCodeValue) { if(!CollectionUtils.isEmpty(boundaryCodeToCensusAdditionalDetails)) { From 3db1245c25e66939a8eb40163a656869c3361678 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 10 Jan 2025 14:54:41 +0530 Subject: [PATCH 38/76] moving isSheetAllowedToProcess function --- .../egov/processor/service/ExcelParser.java | 2 +- .../util/OutputEstimationGenerationUtil.java | 34 ++++++++++++++++--- .../org/egov/processor/util/ParsingUtil.java | 29 +--------------- 3 files changed, 32 insertions(+), 33 deletions(-) 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 34bd738e70..7b5a52234b 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 @@ -232,7 +232,7 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, )); excelWorkbook.forEach(excelWorkbookSheet -> { - if (parsingUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { + if (outputEstimationGenerationUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { Map boundaryCodeToCensusAdditionalDetails = new HashMap<>(); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 395a14d36b..8ec8f595bd 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -28,11 +28,14 @@ public class OutputEstimationGenerationUtil { private EnrichmentUtil enrichmentUtil; - public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsingUtil, EnrichmentUtil enrichmentUtil, ExcelStylingUtil excelStylingUtil) { + private MdmsUtil mdmsUtil; + + public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsingUtil, EnrichmentUtil enrichmentUtil, ExcelStylingUtil excelStylingUtil, MdmsUtil mdmsUtil) { this.localeUtil = localeUtil; this.parsingUtil = parsingUtil; this.excelStylingUtil = excelStylingUtil; this.enrichmentUtil = enrichmentUtil; + this.mdmsUtil = mdmsUtil; } /** @@ -50,7 +53,7 @@ public void processOutputFile(Workbook workbook, PlanConfigurationRequest reques // 1. removing readme sheet for (int i = workbook.getNumberOfSheets() - 1; i >= 0; i--) { Sheet sheet = workbook.getSheetAt(i); - if (!parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + if (!isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { workbook.removeSheetAt(i); } } @@ -144,7 +147,7 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); - if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { // Add facility names to the sheet. addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); } @@ -166,7 +169,7 @@ public Map getBoundaryCodeToFacilityMap(Workbook workbook, PlanC // Iterate through all sheets in the workbook. for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); - if (parsingUtil.isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { + if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { // Extract boundary codes from the sheet. boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); } @@ -239,5 +242,28 @@ private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityCol excelStylingUtil.adjustColumnWidthForCell(facilityColHeader); return indexOfFacility; } + + /** + * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. + * + * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. + * @param sheetName The name of the sheet to be processed. + * @return true if the sheet is allowed to be processed, false otherwise. + */ + public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { + Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( + planConfigurationRequest.getRequestInfo(), + planConfigurationRequest.getPlanConfiguration().getTenantId()); + + for (Locale locale : localeResponse.getMessages()) { + if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) + || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { + if (sheetName.equals(locale.getMessage())) + return false; + } + } + return true; + + } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index d19b443d54..b5f20eaf36 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -9,7 +9,6 @@ import org.apache.commons.io.FileUtils; import org.apache.poi.ss.usermodel.*; import org.egov.processor.config.ServiceConstants; -import org.egov.processor.web.models.Locale; import org.egov.processor.web.models.*; import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; @@ -35,13 +34,10 @@ public class ParsingUtil { private FilestoreUtil filestoreUtil; - private MdmsUtil mdmsUtil; - private ObjectMapper objectMapper; - public ParsingUtil(FilestoreUtil filestoreUtil, MdmsUtil mdmsUtil, ObjectMapper objectMapper) { + public ParsingUtil(FilestoreUtil filestoreUtil, ObjectMapper objectMapper) { this.filestoreUtil = filestoreUtil; - this.mdmsUtil = mdmsUtil; this.objectMapper = objectMapper; } @@ -395,29 +391,6 @@ public void printRow(Sheet sheet, Row row) { System.out.println(); // Move to the next line after printing the row } - /** - * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. - * - * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. - * @param sheetName The name of the sheet to be processed. - * @return true if the sheet is allowed to be processed, false otherwise. - */ - public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { - Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( - planConfigurationRequest.getRequestInfo(), - planConfigurationRequest.getPlanConfiguration().getTenantId()); - - for (Locale locale : localeResponse.getMessages()) { - if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) - || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { - if (sheetName.equals(locale.getMessage())) - return false; - } - } - return true; - - } - /** * Extracts provided field from the additional details object * From 8c69a08d23a05db6a1f035769918cdfbe3d2f0a4 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 13 Jan 2025 17:57:56 +0530 Subject: [PATCH 39/76] handling NullPointerException --- .../util/CampaignIntegrationUtil.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java index 9bfbe7cb62..6665e411de 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java @@ -225,7 +225,7 @@ public void updateCampaignBoundary(PlanConfiguration planConfig, JsonNode featur List> sortedColumnList = parsingUtil.sortColumnByIndex(mapOfColumnNameAndIndex); indexValue = parsingUtil.getIndexOfBoundaryCode(indexValue, sortedColumnList, mappedValues); prepareBoundary(indexOfType, indexValue, sortedColumnList, feature, boundary, mappedValues); - if (isValidToAdd(boundaryList, resultMap, validToAdd, boundary)) + if (isValidToAdd(resultMap, validToAdd)) boundaryList.add(boundary); } @@ -263,22 +263,22 @@ private Integer prepareBoundary(Integer indexOfType, Integer indexValue, /** * Checks if the provided boundary is valid to add to the boundary list based on the result map. * - * @param boundaryList The list of existing boundaries. * @param resultMap The map containing result values. * @param validToAdd The flag indicating whether the boundary is valid to add. - * @param boundary The boundary to be checked for validity. * @return True if the boundary is valid to add, false otherwise. */ - private boolean isValidToAdd(List boundaryList, Map resultMap, boolean validToAdd, - Boundary boundary) { + private boolean isValidToAdd(Map resultMap, boolean validToAdd) { for (Entry entry : resultMap.entrySet()) { - if (entry.getValue().compareTo(new BigDecimal(0)) > 0) { - validToAdd = true; - } else { + BigDecimal value = entry.getValue(); + + if (value == null || value.compareTo(BigDecimal.ZERO) <= 0) { validToAdd = false; break; + } else { + validToAdd = true; } - } + } + return validToAdd; } From 40d989da53fa6e280304bd508443ea6be44e4638 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 16 Jan 2025 14:00:37 +0530 Subject: [PATCH 40/76] Adding accessibility details in plan additional details --- .../processor/config/ServiceConstants.java | 1 + .../org/egov/processor/util/PlanUtil.java | 41 +++++++++++++++---- .../processor/web/models/census/Census.java | 3 +- 3 files changed, 36 insertions(+), 9 deletions(-) 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) From 1c8f26a43bdb4b8fbc1beddf92bfdbcc651a2e05 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 16 Jan 2025 14:01:02 +0530 Subject: [PATCH 41/76] Adding accessibility details in plan additional details --- .../java/digit/config/ServiceConstants.java | 8 ++-- .../src/main/java/digit/util/QueryUtil.java | 39 +------------------ .../java/digit/web/models/census/Census.java | 3 +- 3 files changed, 6 insertions(+), 44 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 06a2bbf31e..69d0986f96 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -366,13 +366,13 @@ 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 TERRAIN_CONDITION_SEARCH_PARAMETER_KEY = "accessibilityDetails|terrain|code"; - public static final String ROAD_CONDITION_SEARCH_PARAMETER_KEY = "accessibilityDetails.roadCondition.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_Q1_SEARCH_PARAMETER_KEY = "securityDetails|1|code"; - public static final String SECURITY_Q2_SEARCH_PARAMETER_KEY = "securityDetails.2.code"; + public static final String SECURITY_Q2_SEARCH_PARAMETER_KEY = "securityDetails|2|code"; public static final String COMMA_DELIMITER = ","; diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index 643f45a79e..070f442a89 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -109,21 +109,9 @@ public String preparePartialJsonStringFromFilterMap(Map filterMa if (key.contains(DOT_SEPARATOR)) { String[] keyArray = key.split(DOT_REGEX); Map nestedQueryMap = new HashMap<>(); - - // Recursively build the nested structure based on the key hierarchy. prepareNestedQueryMap(0, keyArray, nestedQueryMap, filterMap.get(key)); - - // 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) existing, (Map) newValue); - return existing; - } - return newValue; - }); + queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0])); } else { - // If no nesting, directly put the key-value pair into the query map. queryMap.put(key, filterMap.get(key)); } }); @@ -182,31 +170,6 @@ public String getPaginatedQuery(String query, List 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 existing, Map 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) oldValue, (Map) 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 * diff --git a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java index 2b989edb10..ad052ca93c 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java +++ b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java @@ -49,8 +49,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) From 2ff8b2ce149deba3cbd3282ec3ee8b968a8bb60d Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 16 Jan 2025 14:03:28 +0530 Subject: [PATCH 42/76] Adding accessibility details in plan additional details --- .../src/main/java/org/egov/processor/util/PlanUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0d73780d33..3bdb199d3c 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 @@ -119,7 +119,7 @@ private Object enrichAdditionalDetials(Map boundaryCodeToCensusA // Creating a map of fields to be added in plan additional details with their key. Map fieldsToBeUpdated = new HashMap<>(); - if(ObjectUtils.isEmpty(fieldsToBeUpdated)) + if(ObjectUtils.isEmpty(facilityId)) fieldsToBeUpdated.put(FACILITY_ID, facilityId); // Add fields from securityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. From cf7d2a410def35b0299953f80a4947191fc6bbc5 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 17 Jan 2025 12:16:19 +0530 Subject: [PATCH 43/76] Resolving code rabbit comments --- .../org/egov/processor/util/PlanUtil.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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 0d73780d33..f2c595d257 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 @@ -50,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 resultMap, Map mappedValues, Map boundaryCodeToCensusAdditionalDetails) { @@ -64,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 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, @@ -94,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(); } @@ -107,11 +109,15 @@ 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 boundaryCodeToCensusAdditionalDetails, String boundaryCodeValue) { + private Object enrichAdditionalDetails(Map boundaryCodeToCensusAdditionalDetails, String boundaryCodeValue) { if(!CollectionUtils.isEmpty(boundaryCodeToCensusAdditionalDetails)) { Object censusAdditionalDetails = boundaryCodeToCensusAdditionalDetails.get(boundaryCodeValue); + // Return null value if censusAdditionalDetails is null + if(censusAdditionalDetails == null) + 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); From 5f523032ceddc00b840780d628bdaa167567ccee Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 11:39:34 +0530 Subject: [PATCH 44/76] Adding accessibility details in plan additional details --- .../src/main/java/org/egov/processor/util/PlanUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b0c53ecbce..bdcc403396 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 @@ -125,7 +125,7 @@ private Object enrichAdditionalDetails(Map boundaryCodeToCensusA // Creating a map of fields to be added in plan additional details with their key. Map fieldsToBeUpdated = new HashMap<>(); - if(ObjectUtils.isEmpty(facilityId)) + if(!ObjectUtils.isEmpty(facilityId)) fieldsToBeUpdated.put(FACILITY_ID, facilityId); // Add fields from securityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. From 87dac50497376f954a677fa7572e9e137d7938e8 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 11:48:41 +0530 Subject: [PATCH 45/76] Adding pipe regex --- .../processor/config/ServiceConstants.java | 1 + .../org/egov/processor/util/PlanUtil.java | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) 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 6e0a864c10..252353aa5d 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 @@ -108,6 +108,7 @@ public class ServiceConstants { public static final String VALIDATE_STRING_REGX = "^(?!\\d+$).+$"; public static final String VALIDATE_NUMBER_REGX = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; public static final String VALIDATE_BOOLEAN_REGX = "^(?i)(true|false)$"; + public static final String PIPE_REGEX = "\\|"; public static final String FILE_TEMPLATE = "Facilities"; public static final String HIERARCHYTYPE_REPLACER = "{hierarchyType}"; 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 bdcc403396..0232619707 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 @@ -66,10 +66,10 @@ 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 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. */ @@ -128,16 +128,16 @@ private Object enrichAdditionalDetails(Map boundaryCodeToCensusA if(!ObjectUtils.isEmpty(facilityId)) fieldsToBeUpdated.put(FACILITY_ID, facilityId); - // 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); - } - // Add fields from accessibilityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. - if (accessibilityDetails instanceof Map && accessibilityDetails != null) { + if(accessibilityDetails != null) { extractNestedFields((Map) accessibilityDetails, ACCESSIBILITY_DETAILS, fieldsToBeUpdated); } + // Add fields from securityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. + if(securityDetails != null) { + extractNestedFields((Map) securityDetails, SECURITY_DETAILS, fieldsToBeUpdated); + } + if(!CollectionUtils.isEmpty(fieldsToBeUpdated)) return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); } @@ -145,7 +145,7 @@ private Object enrichAdditionalDetails(Map boundaryCodeToCensusA } /** - * Extracts nested fields from the given map and adds them to fieldsToBeUpdated in a structured format. + * 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. @@ -160,7 +160,7 @@ private void extractNestedFields(Map details, String prefix, Map if (value instanceof Map) { Map nestedMap = (Map) value; if (nestedMap.containsKey(CODE)) { - fieldsToBeUpdated.put(prefix + "|" + key + "|" + CODE, nestedMap.get(CODE)); + fieldsToBeUpdated.put(prefix + PIPE_REGEX + key + PIPE_REGEX + CODE, nestedMap.get(CODE)); } } } From 8b04d1b481c7382e100cda7288476b6a7ea8cc4a Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 12:30:57 +0530 Subject: [PATCH 46/76] changes in planUtil --- .../main/java/org/egov/processor/config/ServiceConstants.java | 1 - .../src/main/java/org/egov/processor/util/PlanUtil.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 252353aa5d..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 @@ -108,7 +108,6 @@ public class ServiceConstants { public static final String VALIDATE_STRING_REGX = "^(?!\\d+$).+$"; public static final String VALIDATE_NUMBER_REGX = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; public static final String VALIDATE_BOOLEAN_REGX = "^(?i)(true|false)$"; - public static final String PIPE_REGEX = "\\|"; public static final String FILE_TEMPLATE = "Facilities"; public static final String HIERARCHYTYPE_REPLACER = "{hierarchyType}"; 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 0232619707..72c892663c 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 @@ -160,7 +160,7 @@ private void extractNestedFields(Map details, String prefix, Map if (value instanceof Map) { Map nestedMap = (Map) value; if (nestedMap.containsKey(CODE)) { - fieldsToBeUpdated.put(prefix + PIPE_REGEX + key + PIPE_REGEX + CODE, nestedMap.get(CODE)); + fieldsToBeUpdated.put(prefix + "|" + key + "|" + CODE, nestedMap.get(CODE)); } } } From 86ffaf410a910d66d188a245cc46cba0e3c45e34 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 14:10:20 +0530 Subject: [PATCH 47/76] resolving review comments --- .../src/main/java/org/egov/processor/util/PlanUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 72c892663c..fde26ae8d1 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 @@ -115,7 +115,7 @@ private Object enrichAdditionalDetails(Map boundaryCodeToCensusA Object censusAdditionalDetails = boundaryCodeToCensusAdditionalDetails.get(boundaryCodeValue); // Return null value if censusAdditionalDetails is null - if(censusAdditionalDetails == null) + if(ObjectUtils.isEmpty(censusAdditionalDetails)) return null; // Extract required details from census additional details object. @@ -129,12 +129,12 @@ private Object enrichAdditionalDetails(Map boundaryCodeToCensusA fieldsToBeUpdated.put(FACILITY_ID, facilityId); // Add fields from accessibilityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. - if(accessibilityDetails != null) { + if(!ObjectUtils.isEmpty(accessibilityDetails)) { extractNestedFields((Map) accessibilityDetails, ACCESSIBILITY_DETAILS, fieldsToBeUpdated); } // Add fields from securityDetails to fieldsToBeUpdated map if it's present in censusAdditionalDetails. - if(securityDetails != null) { + if(!ObjectUtils.isEmpty(securityDetails)) { extractNestedFields((Map) securityDetails, SECURITY_DETAILS, fieldsToBeUpdated); } From 8cc80556b185f3ee90a115f4a5e1edc23343e76f Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 15:46:12 +0530 Subject: [PATCH 48/76] Pull from microplanning-v0.2 --- .../src/main/java/org/egov/processor/service/ExcelParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 527e2f06fb..3b014de22c 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 @@ -283,7 +283,7 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest requ Map boundaryCodeToFixedPostMap = new HashMap<>(); for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { - // Ensure serviceBoundaries is not empty + // Ensure serviceBoundaries are not empty if (!CollectionUtils.isEmpty(planFacility.getServiceBoundaries())) { // Extract the 'FIXED_POST' field from additional details. From cdb1e5a5fcce90ff3a4be169c41c34f984d3b44d Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 21 Jan 2025 11:17:57 +0530 Subject: [PATCH 49/76] Code review changes --- .../java/org/egov/processor/config/ServiceConstants.java | 3 +++ .../egov/processor/util/OutputEstimationGenerationUtil.java | 5 +++++ 2 files changed, 8 insertions(+) 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..a0e6f8c25a 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 @@ -60,6 +60,9 @@ public class ServiceConstants { public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE = "NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS"; public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan facilities do not exists for the given details: "; + public static final String README_SHEET_NAME_LOCALISATION_NOT_FOUND_CODE = "README_SHEET_NAME_LOCALISATION_NOT_FOUND"; + public static final String README_SHEET_NAME_LOCALISATION_NOT_FOUND_MESSAGE = "Constant defined for error message when the README sheet name localization is not found or plan facilities do not exist for the provided details."; + public static final String BOUNDARY_CODE = "HCM_ADMIN_CONSOLE_BOUNDARY_CODE"; public static final String TOTAL_POPULATION = "HCM_ADMIN_CONSOLE_TOTAL_POPULATION"; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 8ec8f595bd..f4375ce596 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -14,6 +14,7 @@ import java.util.Map; import java.util.stream.Collectors; import org.egov.tracer.model.CustomException; +import org.springframework.util.ObjectUtils; import static org.egov.processor.config.ServiceConstants.*; @@ -255,6 +256,10 @@ public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfiguratio planConfigurationRequest.getRequestInfo(), planConfigurationRequest.getPlanConfiguration().getTenantId()); + String readMeSheetName = (String) mdmsDataConstants.get(READ_ME_SHEET_NAME); + if(ObjectUtils.isEmpty(readMeSheetName)) + throw new CustomException(README_SHEET_NAME_LOCALISATION_NOT_FOUND_CODE, README_SHEET_NAME_LOCALISATION_NOT_FOUND_MESSAGE); + for (Locale locale : localeResponse.getMessages()) { if ((locale.getCode().equalsIgnoreCase((String) mdmsDataConstants.get(READ_ME_SHEET_NAME))) || locale.getCode().equalsIgnoreCase(HCM_ADMIN_CONSOLE_BOUNDARY_DATA)) { From a7c69ba564c1598146f9174a90bc20f162590367 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 17:02:38 +0530 Subject: [PATCH 50/76] Resolving code rabbit comments --- .../java/org/egov/processor/config/ServiceConstants.java | 2 +- .../java/org/egov/processor/util/CalculationUtil.java | 1 - .../java/org/egov/processor/util/PlanFacilityUtil.java | 9 +++------ .../processor/web/models/planFacility/PlanFacility.java | 5 +---- .../models/planFacility/PlanFacilitySearchCriteria.java | 4 ++++ 5 files changed, 9 insertions(+), 12 deletions(-) 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 4a7cd1e8c1..53ec687aee 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 @@ -106,7 +106,7 @@ public class ServiceConstants { public static final String ERROR_WHILE_UPDATING_PLAN_CONFIG = "Exception occurred while updating plan configuration."; public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while searching plans."; - public static final String ERROR_WHILE_SEARCHING_PLAN_FACILITY = "Exception occurred while searching plan facility."; + public static final String ERROR_WHILE_SEARCHING_PLAN_FACILITY = "Exception occurred while searching plan facility : "; public static final String VALIDATE_STRING_REGX = "^(?!\\d+$).+$"; public static final String VALIDATE_NUMBER_REGX = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java index 237b70040c..c96169492c 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java @@ -15,7 +15,6 @@ import java.math.RoundingMode; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.stream.Collectors; import static org.egov.processor.config.ServiceConstants.PROPERTIES; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java index cd8bb70288..74a14fca3a 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java @@ -5,14 +5,10 @@ import org.egov.processor.config.Configuration; import org.egov.processor.config.ServiceConstants; import org.egov.processor.repository.ServiceRequestRepository; -import org.egov.processor.web.models.planFacility.PlanFacilityResponse; -import org.egov.processor.web.models.planFacility.PlanFacilitySearchRequest; -import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; +import org.egov.processor.web.models.planFacility.*; import org.springframework.util.CollectionUtils; -import static org.egov.processor.config.ServiceConstants.*; - @Slf4j @Component public class PlanFacilityUtil { @@ -40,8 +36,9 @@ public PlanFacilityResponse search(PlanFacilitySearchRequest planfacilitySearchR try { Object response = serviceRequestRepository.fetchResult(getPlanFacilitySearchUri(), planfacilitySearchRequest); planFacilityResponse = mapper.convertValue(response, PlanFacilityResponse.class); + } catch (Exception e) { - log.error(ServiceConstants.ERROR_WHILE_SEARCHING_PLAN_FACILITY); + log.error(ServiceConstants.ERROR_WHILE_SEARCHING_PLAN_FACILITY, e); } return planFacilityResponse; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java index e9471ac84a..7111050551 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java @@ -74,7 +74,7 @@ public class PlanFacility { @JsonProperty("active") @NotNull - private Boolean active = null; + private Boolean active = Boolean.TRUE; @JsonProperty("auditDetails") private AuditDetails auditDetails = null; @@ -86,7 +86,4 @@ public PlanFacility addServiceBoundariesItem(String serviceBoundariesItem) { this.serviceBoundaries.add(serviceBoundariesItem); return this; } - - - } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java index e36e30f97e..07b82a00e4 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java @@ -13,6 +13,10 @@ import java.util.Map; import java.util.Set; + +/** + * PlanFacilitySearchCriteria + */ @Validated @Data @AllArgsConstructor From 4c5f3b3c8702e9a671ac360c1d0200fe85e2e906 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 21 Jan 2025 15:48:26 +0530 Subject: [PATCH 51/76] Handling null pointer exception --- .../main/java/org/egov/processor/util/EnrichmentUtil.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 24db89cb8e..af945c1b5d 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -22,6 +22,7 @@ import java.math.BigDecimal; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -246,8 +247,10 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR Plan planEstimate = planMap.get(boundaryCode); if (planEstimate != null) { - Map resourceTypeToEstimatedNumberMap = planEstimate.getResources().stream() - .collect(Collectors.toMap(Resource::getResourceType, Resource::getEstimatedNumber)); + Map resourceTypeToEstimatedNumberMap = new HashMap<>(); + planEstimate.getResources().forEach(resource -> + resourceTypeToEstimatedNumberMap.put(resource.getResourceType(), resource.getEstimatedNumber())); + // Iterate over each output column to update the row cells with resource values for (String resourceType : outputColumnList) { From 4b2e60fc3a935c3dfcfb0b230acfe5d3e6746381 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 21 Jan 2025 16:33:41 +0530 Subject: [PATCH 52/76] renaming pagination variables --- .../java/org/egov/processor/config/Configuration.java | 8 ++++---- .../src/main/java/org/egov/processor/util/MdmsV2Util.java | 4 ++-- .../src/main/resources/application.properties | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java b/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java index 1f49dc085e..c0e08a02aa 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java @@ -112,11 +112,11 @@ public class Configuration { private String resourceCensusCreateTopic; //Default - @Value("${resource.default.offset}") - private Integer defaultOffset; + @Value("${default.offset.for.mdms.data}") + private Integer defaultOffsetForMdms; - @Value("${resource.default.limit}") - private Integer defaultLimit; + @Value("${default.limit.for.mdms.data}") + private Integer defaultLimitForMdms; //census additonal field configs @Value("${census.additional.field.override.keys}") diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java index e9d7026ef0..5430e0e55c 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MdmsV2Util.java @@ -68,8 +68,8 @@ private MdmsCriteriaReqV2 getMdmsV2Request(RequestInfo requestInfo, String tenan .tenantId(tenantId) .schemaCode(schemaCode) .uniqueIdentifiers(uniqueIdentifier != null ? Collections.singletonList(uniqueIdentifier) : null) - .limit(config.getDefaultLimit()) - .offset(config.getDefaultOffset()) + .limit(config.getDefaultLimitForMdms()) + .offset(config.getDefaultOffsetForMdms()) .build(); return MdmsCriteriaReqV2.builder() diff --git a/health-services/resource-generator/src/main/resources/application.properties b/health-services/resource-generator/src/main/resources/application.properties index ce74288a82..f5f8ba1c4f 100644 --- a/health-services/resource-generator/src/main/resources/application.properties +++ b/health-services/resource-generator/src/main/resources/application.properties @@ -98,8 +98,8 @@ plan.config.trigger.plan.facility.mappings.status=EXECUTION_TO_BE_DONE plan.config.update.plan.estimates.into.output.file.status=RESOURCE_ESTIMATIONS_APPROVED # Pagination config -resource.default.offset=0 -resource.default.limit=10 +default.offset.for.mdms.data=0 +default.limit.for.mdms.data=10 # Census egov.census.host=https://unified-dev.digit.org From 9faf6e304d79e09270e4f9e4579a131d49092ea3 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 21 Jan 2025 17:58:19 +0530 Subject: [PATCH 53/76] resolving code rabbit review comments --- .../validator/PlanFacilityValidator.java | 6 +- .../processor/config/ServiceConstants.java | 11 ++-- .../egov/processor/service/ExcelParser.java | 3 +- .../org/egov/processor/util/MdmsUtil.java | 66 +++++++++++-------- .../egov/processor/util/PlanFacilityUtil.java | 1 - .../planFacility/PlanFacilityResponse.java | 6 +- 6 files changed, 54 insertions(+), 39 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java index ec7706750b..d8114403d3 100644 --- a/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java @@ -129,10 +129,12 @@ private void validateCampaignDetails(String campaignId, String rootTenantId, Pla Set lowestHierarchyBCodes = fetchBoundaryCodes(campaignResponse.getCampaignDetails().get(0), lowestHierarchy); Set allBoundaryCodes = fetchAllBoundaryCodes(campaignResponse.getCampaignDetails().get(0)); - // Validate residing boundaries with all the boundary codes. + // Validate residing boundaries against boundary codes across all hierarchy levels, + // as a facility's residing boundary may correspond to any jurisdiction level. validateResidingBoundaries(allBoundaryCodes, planFacility); - // Validate service boundaries with the lowest hierarchy boundary codes. + // Validate service boundaries against the lowest hierarchy boundary codes, + // as a facility can only be mapped to boundaries at the lowest hierarchy level. validateServiceBoundaries(lowestHierarchyBCodes, planFacility); //Enrich jurisdiction mapping and boundary ancestral path 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 53ec687aee..5bc26a4bb1 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 @@ -58,7 +58,7 @@ public class ServiceConstants { public static final String NO_PLAN_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan records do not exists for the given details: "; public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE = "NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS"; - public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan facilities do not exists for the given details: "; + public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan facilities do not exists for the given details. "; public static final String README_SHEET_NAME_LOCALISATION_NOT_FOUND_CODE = "README_SHEET_NAME_LOCALISATION_NOT_FOUND"; public static final String README_SHEET_NAME_LOCALISATION_NOT_FOUND_MESSAGE = "Constant defined for error message when the README sheet name localization is not found or plan facilities do not exist for the provided details."; @@ -66,6 +66,7 @@ public class ServiceConstants { public static final String BOUNDARY_CODE = "HCM_ADMIN_CONSOLE_BOUNDARY_CODE"; public static final String TOTAL_POPULATION = "HCM_ADMIN_CONSOLE_TOTAL_POPULATION"; + public static final String ERROR_PROCESSING_DATA_FROM_MDMS = "Exception occurred while processing data from mdms "; public static final String ERROR_WHILE_FETCHING_FROM_PLAN_SERVICE_FOR_LOCALITY = "Exception occurred while fetching plan configuration from plan service for Locality "; public static final String ERROR_WHILE_PUSHING_TO_PLAN_SERVICE_FOR_LOCALITY = "Exception occurred while fetching plan configuration from plan service for Locality "; public static final String ERROR_WHILE_SEARCHING_CAMPAIGN = "Exception occurred while searching/updating campaign."; @@ -135,14 +136,14 @@ public class ServiceConstants { //Facility Create constants public static final String TYPE_FACILITY = "facility"; - public static final String ACTION_CREATE = "create"; - public static final String SOURCE_KEY = "source"; - public static final String MICROPLAN_SOURCE_KEY = "microplan"; - public static final String MICROPLAN_ID_KEY = "microplanId"; public static final String FACILITY_NAME = "facilityName"; public static final String FACILITY_ID = "facilityId"; public static final String HCM_MICROPLAN_SERVING_FACILITY = "HCM_MICROPLAN_SERVING_FACILITY"; public static final String FIXED_POST = "fixedPost"; + public static final String ACTION_CREATE = "create"; + public static final String SOURCE_KEY = "source"; + public static final String MICROPLAN_SOURCE_KEY = "microplan"; + public static final String MICROPLAN_ID_KEY = "microplanId"; //Census additional field constants public static final String UPLOADED_KEY = "UPLOADED_"; 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 7b5a52234b..e39285021f 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 @@ -26,6 +26,7 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.io.File; import java.io.FileNotFoundException; @@ -278,7 +279,7 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest reque PlanFacilityResponse planFacilityResponse = planFacilityUtil.search(searchRequest); - if (CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { + if (ObjectUtils.isEmpty(planFacilityResponse) || CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { throw new CustomException(NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE, NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE); } 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 6163e20d50..5c168f8d30 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,10 +1,6 @@ package org.egov.processor.util; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import org.egov.common.contract.request.RequestInfo; import org.egov.mdms.model.MasterDetail; @@ -18,6 +14,7 @@ import org.egov.tracer.model.CustomException; import org.flywaydb.core.internal.util.JsonUtils; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.client.RestTemplate; @@ -134,29 +131,44 @@ private ModuleDetail getAdminConsoleModuleDetail() { */ public Map filterMasterData(String masterDataJson, String campaignType) { Map properties = new HashMap<>(); - Map masterData = JsonUtils.parseJson(masterDataJson, Map.class); - 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); - - // 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); - }) - ); + try { + Map masterData = JsonUtils.parseJson(masterDataJson, Map.class); + Map adminConsoleModule = (Map) masterData.get(ServiceConstants.MDMS_ADMIN_CONSOLE_MODULE_NAME); + + //Extracting adminSchema master from the HCM-ADMIN-CONSOLE module + List> adminSchema = (List>) adminConsoleModule.get(ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA); + + log.debug("masterDataJson ==> " + adminSchema); + + //Iterating through each schema in adminSchema master + for (Map schema : adminSchema) { + String campaign = (String) schema.get(ServiceConstants.MDMS_CAMPAIGN_TYPE); + + // Skipping schema for which the required fields are missing to avoid null pointer exception + if (ObjectUtils.isEmpty(campaign) || ObjectUtils.isEmpty(schema.get(ServiceConstants.MDMS_SCHEMA_TITLE))) + continue; + + // 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"); + + // Skipping if schema properties are not present for the given campaign type. + if (CollectionUtils.isEmpty(schemaProperties)) + continue; + + 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); + }) + ); + } } + } catch (Exception e) { + log.error(ERROR_PROCESSING_DATA_FROM_MDMS, e); } return properties; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java index 74a14fca3a..8467353933 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java @@ -7,7 +7,6 @@ import org.egov.processor.repository.ServiceRequestRepository; import org.springframework.stereotype.Component; import org.egov.processor.web.models.planFacility.*; -import org.springframework.util.CollectionUtils; @Slf4j @Component diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java index 4b39c308b6..4737171d90 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java @@ -21,13 +21,13 @@ public class PlanFacilityResponse { @JsonProperty("ResponseInfo") - private ResponseInfo responseInfo = null; + private ResponseInfo responseInfo; @JsonProperty("PlanFacility") @Valid - private List planFacility = null; + private List planFacility; @JsonProperty("TotalCount") @Valid - private Integer totalCount = null; + private Integer totalCount; } From 54660efe6017c4118e344ee41e8f02d6d6204365 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 22 Jan 2025 12:24:38 +0530 Subject: [PATCH 54/76] Adding function comments --- .../processor/util/MixedStartegyUtil.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java index 31f4faa177..0bfc1c49b5 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java @@ -33,6 +33,12 @@ public MixedStartegyUtil(MdmsV2Util mdmsV2Util, ParsingUtil parsingUtil, ObjectM this.mapper = mapper; } + /** + * Fetches a list of MixedStrategyOperationLogic objects from MDMS based on the provided planConfigurationRequest. + * + * @param request The PlanConfigurationRequest containing the plan configuration and request info. + * @return A list of MixedStrategyOperationLogic objects fetched from MDMS. + */ public List fetchMixedStrategyOperationLogicFromMDMS(PlanConfigurationRequest request) { String rootTenantId = request.getPlanConfiguration().getTenantId().split("\\.")[0]; List mdmsV2Data = mdmsV2Util.fetchMdmsV2Data(request.getRequestInfo(), rootTenantId, MDMS_PLAN_MODULE_NAME + DOT_SEPARATOR + MDMS_MASTER_MIXED_STRATEGY, null); @@ -43,8 +49,16 @@ public List fetchMixedStrategyOperationLogicFromMDM } - public List getCategoriesNotAllowed(boolean isFixedPost, - PlanConfiguration planConfiguration, List logicList) { + /** + * Retrieves a list of categories that are restricted based on the provided details. + * Returns an empty list if no match is found. + * + * @param isFixedPost A boolean indicating whether the mapped facility is fixed post. + * @param planConfiguration The plan configuration containing additional details. + * @param logicList A list of MixedStrategyOperationLogic objects to filter against. + * @return A list of categories not allowed to have output value or an empty list if no matching logic is found. + */ + public List getCategoriesNotAllowed(boolean isFixedPost, PlanConfiguration planConfiguration, List logicList) { return logicList.stream() .filter(logic -> logic.isFixedPost() == isFixedPost && @@ -56,6 +70,14 @@ public List getCategoriesNotAllowed(boolean isFixedPost, } + /** + * Nullifies result values in the map for outputs belonging to the categories not allowed. + * Exits early if no restrictions are specified. + * + * @param resultMap A map containing output keys and their corresponding result values. + * @param operations A list of operations. + * @param categoriesNotAllowed A list of categories that are restricted and should not have associated outputs. + */ public void processResultMap(Map resultMap, List operations, List categoriesNotAllowed) { // If all te categories are allowed, don't process further. @@ -80,6 +102,4 @@ public void processResultMap(Map resultMap, List } } } - - } From 46cc2f3360361529ce586fa48781127814033b7c Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 22 Jan 2025 13:29:13 +0530 Subject: [PATCH 55/76] Resolving review comments --- .../java/org/egov/processor/config/ServiceConstants.java | 2 ++ .../java/org/egov/processor/service/ExcelParser.java | 9 +++++---- .../java/org/egov/processor/util/EnrichmentUtil.java | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) 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 cab79abd8f..09ba679d81 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 @@ -96,6 +96,8 @@ public class ServiceConstants { public static final Double BRIGHTEN_FACTOR = 1.1; public static final String ACCESSIBILITY_DETAILS = "accessibilityDetails"; public static final String SECURITY_DETAILS = "securityDetails"; + public static final String EMPTY_STRING = ""; + public static final String FIXED_POST_YES = "yes"; //MDMS field Constants public static final String DATA = "data"; 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 3b014de22c..3a37e0d04a 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 @@ -27,6 +27,7 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.io.File; import java.io.FileNotFoundException; @@ -290,12 +291,12 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest requ String fixedPostValue = (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST); // Normalize the value and determine boolean equivalent. - boolean isFixedPost = fixedPostValue != null && fixedPostValue.trim().equalsIgnoreCase("yes"); + Boolean isFixedPost = !ObjectUtils.isEmpty(fixedPostValue) && fixedPostValue.trim().equalsIgnoreCase(FIXED_POST_YES); // Populate the map with boundary code and isFixedPost. - for (String boundary : planFacility.getServiceBoundaries()) { - boundaryCodeToFixedPostMap.put(boundary, isFixedPost); - } + planFacility.getServiceBoundaries().forEach((String boundary) -> + boundaryCodeToFixedPostMap.put(boundary, isFixedPost) + ); } } return boundaryCodeToFixedPostMap; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index af945c1b5d..2ca5b2c5c7 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -276,7 +276,7 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR if (cell == null) { cell = row.createCell(columnIndex); } - cell.setCellValue(""); // Set as empty string + cell.setCellValue(EMPTY_STRING); // Set as empty string } } } From 4149d630e23917bc993301d366b5dbb1a437cea9 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 22 Jan 2025 14:52:02 +0530 Subject: [PATCH 56/76] Removing unused functions --- .../egov/processor/service/ExcelParser.java | 3 - .../util/CampaignIntegrationUtil.java | 188 +----------------- 2 files changed, 1 insertion(+), 190 deletions(-) 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 3a37e0d04a..f892f5a405 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 @@ -447,9 +447,6 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat // Get Boundary Code for the current row. String boundaryCode = row.getCell(indexOfBoundaryCode).getStringCellValue(); mixedStartegyUtil.processResultMap(resultMap, planConfig.getOperations(), mixedStartegyUtil.getCategoriesNotAllowed(boundaryCodeToFixedPostMap.get(boundaryCode), planConfig, mixedStrategyOperationLogicList)); - if (config.isIntegrateWithAdminConsole()) - campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, - mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, boundaryCodeToCensusAdditionalDetails); } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java index 6665e411de..aa394c5a33 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/CampaignIntegrationUtil.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.egov.processor.config.Configuration; import org.egov.processor.config.ServiceConstants; import org.egov.processor.repository.ServiceRequestRepository; @@ -14,10 +13,7 @@ import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; -import java.io.IOException; -import java.math.BigDecimal; import java.util.*; -import java.util.Map.Entry; import static org.egov.processor.config.ServiceConstants.*; @@ -28,15 +24,11 @@ public class CampaignIntegrationUtil { private ServiceRequestRepository serviceRequestRepository; private Configuration config; private ObjectMapper mapper; - private ParsingUtil parsingUtil; - - public CampaignIntegrationUtil(ServiceRequestRepository serviceRequestRepository, Configuration config, - ObjectMapper mapper, FilestoreUtil filestoreUtil, ParsingUtil parsingUtil) { + public CampaignIntegrationUtil(ServiceRequestRepository serviceRequestRepository, Configuration config, ObjectMapper mapper) { this.serviceRequestRepository = serviceRequestRepository; this.config = config; this.mapper = mapper; - this.parsingUtil= parsingUtil; } /** @@ -82,34 +74,6 @@ private MicroplanDetailsRequest buildMicroplanDetailsForUpdate(PlanConfiguration } - /** - * Updates campaign details based on the provided plan configuration request and response data. - * This method integrates the campaign details obtained from the response into the provided plan configuration request. - * It also updates the campaign boundaries and resources accordingly. - * - * @param planConfigurationRequest The plan configuration request containing the execution plan details. - * @param response The response object containing campaign details. - * @param campaignBoundaryList The list of campaign boundaries. - * @param campaignResourcesList The list of campaign resources. - */ - public void updateCampaignDetails(PlanConfigurationRequest planConfigurationRequest,Object response,List campaignBoundaryList,List campaignResourcesList) { - CampaignResponse campaignResponse = null; - try { - campaignResponse = mapper.convertValue(response, CampaignResponse.class); - campaignResponse.getCampaign().get(0).setResources(campaignResourcesList); - Boundary[] array = campaignBoundaryList.toArray(new Boundary[0]); - campaignResponse.getCampaign().get(0).setBoundaries(campaignBoundaryList.toArray(new Boundary[0])); - serviceRequestRepository.fetchResult( - new StringBuilder(config.getProjectFactoryHostEndPoint() + config.getCampaignIntegrationUpdateEndPoint()), - buildCampaignRequestForUpdate(planConfigurationRequest, campaignResponse)); - log.info("Campaign Integration successful."); - } catch (Exception e) { - log.error(ServiceConstants.ERROR_WHILE_SEARCHING_CAMPAIGN - + planConfigurationRequest.getPlanConfiguration().getCampaignId(), e); - throw new CustomException("Failed to update campaign details in CampaignIntegration class within method updateCampaignDetails.", e.toString()); - } - } - /** * Sends a data creation request to the Project Factory service using the provided * plan and campaign details. @@ -131,41 +95,6 @@ public void createProjectFactoryDataCall(PlanConfigurationRequest planConfigurat } } - /** - * Updates the campaign resources in the given campaign response based on the files specified in the plan configuration request. - * - * @param campaignResponse The campaign response object to be updated with resources. - * @param planConfigurationRequest The plan configuration request containing file information. - * @param fileStoreId The file store ID. - */ - public void updateResources(CampaignResponse campaignResponse, PlanConfigurationRequest planConfigurationRequest, - String fileStoreId) { - List campaignResourcesList = new ArrayList<>(); - List files = planConfigurationRequest.getPlanConfiguration().getFiles(); - for (File file : files) { - CampaignResources campaignResource = new CampaignResources(); - campaignResource.setFilename(ServiceConstants.FILE_NAME); - campaignResource.setFilestoreId(fileStoreId); - campaignResource.setType(ServiceConstants.FILE_TYPE); - campaignResourcesList.add(campaignResource); - } - campaignResponse.getCampaign().get(0).setResources(campaignResourcesList); - } - - /** - * Builds a campaign request object for updating campaign details based on the provided plan configuration request and campaign response. - * - * @param planConfigurationRequest The plan configuration request containing necessary information for updating the campaign. - * @param campaignResponse The campaign response containing the updated campaign details. - * @return The campaign request object built for updating campaign details. - */ - private CampaignRequest buildCampaignRequestForUpdate(PlanConfigurationRequest planConfigurationRequest, - CampaignResponse campaignResponse) { - return CampaignRequest.builder().requestInfo(planConfigurationRequest.getRequestInfo()) - .campaignDetails(campaignResponse.getCampaign().get(0)).build(); - - } - /** * Builds a {@link ResourceDetailsRequest} object for facility creation using the provided * plan configuration and campaign details. @@ -202,121 +131,6 @@ private ResourceDetailsRequest buildResourceDetailsObjectForFacilityCreate(PlanC } - /** - * Updates campaign boundary based on the provided plan configuration, feature, assumption values, mapped values, column index map, boundary list, and result map. - * - * @param planConfig The plan configuration containing relevant details. - * @param feature The JSON node representing the feature. - * @param assumptionValueMap The map containing assumption values. - * @param mappedValues The map containing mapped values. - * @param mapOfColumnNameAndIndex The map containing column names and their indices. - * @param boundaryList The list of campaign boundaries to update. - * @param resultMap The map containing result values. - * @throws IOException If an I/O error occurs. - */ - public void updateCampaignBoundary(PlanConfiguration planConfig, JsonNode feature, - Map assumptionValueMap, Map mappedValues, - Map mapOfColumnNameAndIndex, List boundaryList, - Map resultMap) { - Integer indexOfType = null; - boolean validToAdd = false; - Integer indexValue = 0; - Boundary boundary = new Boundary(); - List> sortedColumnList = parsingUtil.sortColumnByIndex(mapOfColumnNameAndIndex); - indexValue = parsingUtil.getIndexOfBoundaryCode(indexValue, sortedColumnList, mappedValues); - prepareBoundary(indexOfType, indexValue, sortedColumnList, feature, boundary, mappedValues); - if (isValidToAdd(resultMap, validToAdd)) - boundaryList.add(boundary); - } - - - /** - * Prepares a campaign boundary based on the provided index values, sorted column list, feature, and mapped values. - * - * @param indexOfType The index of the boundary type. - * @param indexValue The index value. - * @param sortedColumnList The sorted list of column names and indices. - * @param feature The JSON node representing the feature. - * @param boundary The boundary object to be prepared. - * @param mappedValues The map containing mapped values. - * @return The index of the boundary type after preparation. - */ - private Integer prepareBoundary(Integer indexOfType, Integer indexValue, - List> sortedColumnList, JsonNode feature, Boundary boundary,Map mappedValues) { - String codeValue = getBoundaryCodeValue(ServiceConstants.BOUNDARY_CODE, feature, mappedValues); - boundary.setCode(codeValue); - for (int j = 0; j < indexValue; j++) { - Map.Entry entry = sortedColumnList.get(j); - String value = String.valueOf(feature.get(PROPERTIES).get(entry.getKey())); - if (StringUtils.isNotBlank(value) && value.length() > 2) { - boundary.setType(entry.getKey()); - indexOfType = entry.getValue(); - } - } - if (indexOfType == 0) { - boundary.setRoot(true); - boundary.setIncludeAllChildren(true); - } - return indexOfType; - } - - /** - * Checks if the provided boundary is valid to add to the boundary list based on the result map. - * - * @param resultMap The map containing result values. - * @param validToAdd The flag indicating whether the boundary is valid to add. - * @return True if the boundary is valid to add, false otherwise. - */ - private boolean isValidToAdd(Map resultMap, boolean validToAdd) { - for (Entry entry : resultMap.entrySet()) { - BigDecimal value = entry.getValue(); - - if (value == null || value.compareTo(BigDecimal.ZERO) <= 0) { - validToAdd = false; - break; - } else { - validToAdd = true; - } - } - - return validToAdd; - } - - - - /** - * Retrieves the value of the boundary code from the feature JSON node based on the mapped values. - * - * @param input The input key. - * @param feature The JSON node representing the feature. - * @param mappedValues The map containing mapped values. - * @return The value of the boundary code. - * @throws CustomException If the input value is not found in the feature JSON node. - */ - private String getBoundaryCodeValue(String input, JsonNode feature, Map mappedValues) { - if (feature.get(PROPERTIES).get(mappedValues.get(input)) != null) { - String value = String.valueOf(feature.get(PROPERTIES).get(mappedValues.get(input))); - return ((value != null && value.length() > 2) ? value.substring(1, value.length() - 1) : value); - } else { - throw new CustomException("INPUT_VALUE_NOT_FOUND", "Input value not found: " + input); - } - } - - /** - * Updates campaign resources with the provided file store ID. - * - * @param fileStoreId The file store ID. - * @param campaignResourcesList The list of campaign resources to update. - */ - public void updateCampaignResources(String fileStoreId,List campaignResourcesList,String fileName) { - CampaignResources campaignResource = new CampaignResources(); - campaignResource.setFilename(fileName); - campaignResource.setFilestoreId(fileStoreId); - campaignResource.setType(ServiceConstants.FILE_TYPE); - campaignResourcesList.add(campaignResource); - - } - /** * Builds a campaign search request based on the provided plan configuration request. * From 073ea3e11573c380f38b593a193caecaaa65008d Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 22 Jan 2025 15:26:44 +0530 Subject: [PATCH 57/76] added better comments --- .../java/org/egov/processor/config/ServiceConstants.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 a0e6f8c25a..593b6bd308 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 @@ -149,8 +149,8 @@ public class ServiceConstants { public static final String CONFIRMED_KEY = "CONFIRMED_"; //Excel header row styling constants - public static final String HEX_BACKGROUND_COLOR = "93C47D"; // Constant background color - public static final boolean FREEZE_CELL = true; // Constant to lock cell - public static final int COLUMN_WIDTH = 40; // Column width in characters + public static final String HEX_BACKGROUND_COLOR = "93C47D"; // Background color in HEX format (RRGGBB) for Excel header rows + public static final boolean FREEZE_CELL = true; // Controls whether cells should be locked for editing + public static final int COLUMN_WIDTH = 40; //Default column width in characters (1-255) } From f4687157e5e6208b3c10b91b9ad3b84f95baae49 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 22 Jan 2025 15:48:32 +0530 Subject: [PATCH 58/76] Fixing typo in mixedStrategyUtil.class --- .../java/org/egov/processor/service/ExcelParser.java | 12 ++++++------ ...MixedStartegyUtil.java => MixedStrategyUtil.java} | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) rename health-services/resource-generator/src/main/java/org/egov/processor/util/{MixedStartegyUtil.java => MixedStrategyUtil.java} (96%) 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 9e6f8d0311..954f69e624 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 @@ -71,13 +71,13 @@ public class ExcelParser implements FileParser { private OutputEstimationGenerationUtil outputEstimationGenerationUtil; - private MixedStartegyUtil mixedStartegyUtil; + private MixedStrategyUtil mixedStrategyUtil; private PlanFacilityUtil planFacilityUtil; public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, FilestoreUtil filestoreUtil, - CalculationUtil calculationUtil, PlanUtil planUtil, CampaignIntegrationUtil campaignIntegrationUtil, - Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil, MixedStartegyUtil mixedStartegyUtil, PlanFacilityUtil planFacilityUtil) { + CalculationUtil calculationUtil, PlanUtil planUtil, CampaignIntegrationUtil campaignIntegrationUtil, + Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil, MixedStrategyUtil mixedStrategyUtil, PlanFacilityUtil planFacilityUtil) { this.objectMapper = objectMapper; this.parsingUtil = parsingUtil; this.filestoreUtil = filestoreUtil; @@ -92,7 +92,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore this.enrichmentUtil = enrichmentUtil; this.planConfigurationUtil = planConfigurationUtil; this.outputEstimationGenerationUtil = outputEstimationGenerationUtil; - this.mixedStartegyUtil = mixedStartegyUtil; + this.mixedStrategyUtil = mixedStrategyUtil; this.planFacilityUtil = planFacilityUtil; } @@ -425,7 +425,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat Integer indexOfBoundaryCode = parsingUtil.getIndexOfBoundaryCode(0, parsingUtil.sortColumnByIndex(mapOfColumnNameAndIndex), mappedValues); - List mixedStrategyOperationLogicList = mixedStartegyUtil + List mixedStrategyOperationLogicList = mixedStrategyUtil .fetchMixedStrategyOperationLogicFromMDMS(planConfigurationRequest); for (Row row : sheet) { @@ -446,7 +446,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat // Get Boundary Code for the current row. String boundaryCode = row.getCell(indexOfBoundaryCode).getStringCellValue(); - mixedStartegyUtil.processResultMap(resultMap, planConfig.getOperations(), mixedStartegyUtil.getCategoriesNotAllowed(boundaryCodeToFixedPostMap.get(boundaryCode), planConfig, mixedStrategyOperationLogicList)); + mixedStrategyUtil.processResultMap(resultMap, planConfig.getOperations(), mixedStrategyUtil.getCategoriesNotAllowed(boundaryCodeToFixedPostMap.get(boundaryCode), planConfig, mixedStrategyOperationLogicList)); planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, boundaryCodeToCensusAdditionalDetails); } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java similarity index 96% rename from health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java rename to health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java index 0bfc1c49b5..df8343074d 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStartegyUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java @@ -16,10 +16,9 @@ import java.util.stream.Collectors; import static org.egov.processor.config.ServiceConstants.*; -import static org.egov.processor.config.ServiceConstants.MDMS_SCHEMA_ADMIN_SCHEMA; @Component -public class MixedStartegyUtil { +public class MixedStrategyUtil { private MdmsV2Util mdmsV2Util; @@ -27,7 +26,7 @@ public class MixedStartegyUtil { private ObjectMapper mapper; - public MixedStartegyUtil(MdmsV2Util mdmsV2Util, ParsingUtil parsingUtil, ObjectMapper mapper) { + public MixedStrategyUtil(MdmsV2Util mdmsV2Util, ParsingUtil parsingUtil, ObjectMapper mapper) { this.mdmsV2Util = mdmsV2Util; this.parsingUtil = parsingUtil; this.mapper = mapper; From f7ee03f3d42b522f1fae1c1cebc66a0aedfcb9e4 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 22 Jan 2025 16:19:38 +0530 Subject: [PATCH 59/76] Adding error while fetching mdms data --- .../java/org/egov/processor/config/ServiceConstants.java | 4 ++++ .../java/org/egov/processor/util/MixedStrategyUtil.java | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 d6fc72d50f..945fa51a65 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 @@ -63,6 +63,9 @@ public class ServiceConstants { public static final String README_SHEET_NAME_LOCALISATION_NOT_FOUND_CODE = "README_SHEET_NAME_LOCALISATION_NOT_FOUND"; public static final String README_SHEET_NAME_LOCALISATION_NOT_FOUND_MESSAGE = "Constant defined for error message when the README sheet name localization is not found or plan facilities do not exist for the provided details."; + public static final String NO_MDMS_DATA_FOUND_FOR_MIXED_STRATEGY_MASTER_CODE = "NO_MDMS_DATA_FOUND_FOR_MIXED_STRATEGY_MASTER"; + public static final String NO_MDMS_DATA_FOUND_FOR_MIXED_STRATEGY_MASTER_CODE_MESSAGE = "Master data not found for Mixed Strategy master"; + public static final String BOUNDARY_CODE = "HCM_ADMIN_CONSOLE_BOUNDARY_CODE"; public static final String TOTAL_POPULATION = "HCM_ADMIN_CONSOLE_TOTAL_POPULATION"; @@ -160,4 +163,5 @@ public class ServiceConstants { public static final boolean FREEZE_CELL = true; // Controls whether cells should be locked for editing public static final int COLUMN_WIDTH = 40; //Default column width in characters (1-255) + } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java index df8343074d..f61907ae61 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java @@ -6,6 +6,7 @@ import org.egov.processor.web.models.PlanConfigurationRequest; import org.egov.processor.web.models.mdmsV2.Mdms; import org.egov.processor.web.models.mdmsV2.MixedStrategyOperationLogic; +import org.egov.tracer.model.CustomException; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -42,6 +43,10 @@ public List fetchMixedStrategyOperationLogicFromMDM String rootTenantId = request.getPlanConfiguration().getTenantId().split("\\.")[0]; List mdmsV2Data = mdmsV2Util.fetchMdmsV2Data(request.getRequestInfo(), rootTenantId, MDMS_PLAN_MODULE_NAME + DOT_SEPARATOR + MDMS_MASTER_MIXED_STRATEGY, null); + if (CollectionUtils.isEmpty(mdmsV2Data)) { + throw new CustomException(NO_MDMS_DATA_FOUND_FOR_MIXED_STRATEGY_MASTER_CODE, NO_MDMS_DATA_FOUND_FOR_MIXED_STRATEGY_MASTER_CODE_MESSAGE); + } + return mdmsV2Data.stream() .map(mdms -> mapper.convertValue(mdms.getData(), MixedStrategyOperationLogic.class)) .collect(Collectors.toList()); @@ -79,7 +84,7 @@ public List getCategoriesNotAllowed(boolean isFixedPost, PlanConfigurati */ public void processResultMap(Map resultMap, List operations, List categoriesNotAllowed) { - // If all te categories are allowed, don't process further. + // If all the categories are allowed, don't process further. if(CollectionUtils.isEmpty(categoriesNotAllowed)) return; From 66be9e6ffafa13897aefb57eb4b862c30171dd89 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 22 Jan 2025 16:27:05 +0530 Subject: [PATCH 60/76] Making getCategoriesNotAllowed function readable --- .../egov/processor/config/ServiceConstants.java | 5 +++++ .../egov/processor/util/MixedStrategyUtil.java | 16 +++++++++++++--- .../mdmsV2/MixedStrategyOperationLogic.java | 4 ++++ .../planFacility/PlanFacilitySearchCriteria.java | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) 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 d6fc72d50f..3b980026c2 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 @@ -28,6 +28,7 @@ public class ServiceConstants { public static final String MICROPLANNING_MODULE = "microplan"; + //Custom Exceptions public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE = "NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT"; public static final String NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE = "Invalid or incorrect TenantId. No mdms data found for provided Tenant."; @@ -77,6 +78,8 @@ public class ServiceConstants { public static final String DISTRIBUTION_PROCESS = "DistributionProcess"; public static final String REGISTRATION_PROCESS = "RegistrationProcess"; + + //File constants public static final String FILE_NAME = "output.xls"; public static final String FILE_TYPE = "boundaryWithTarget"; public static final String FILE_TEMPLATE_IDENTIFIER_POPULATION = "Population"; @@ -84,6 +87,7 @@ public class ServiceConstants { 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 "; + //Mdms constants and masters public static final String MDMS_SCHEMA_TYPE = "type"; public static final String MDMS_SCHEMA_SECTION = "section"; public static final String MDMS_SCHEMA_TITLE = "title"; @@ -110,6 +114,7 @@ public class ServiceConstants { public static final String STRING_PROPERTIES = "stringProperties"; public static final String NAME = "name"; + //Error messages public static final String ERROR_WHILE_UPDATING_PLAN_CONFIG = "Exception occurred while updating plan configuration."; public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while searching plans."; public static final String ERROR_WHILE_SEARCHING_PLAN_FACILITY = "Exception occurred while searching plan facility : "; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java index df8343074d..7b244f6ef3 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/MixedStrategyUtil.java @@ -8,6 +8,7 @@ import org.egov.processor.web.models.mdmsV2.MixedStrategyOperationLogic; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.math.BigDecimal; import java.util.Collections; @@ -59,10 +60,19 @@ public List fetchMixedStrategyOperationLogicFromMDM */ public List getCategoriesNotAllowed(boolean isFixedPost, PlanConfiguration planConfiguration, List logicList) { + //Extract fields from additional details + String registrationProcess = (String) parsingUtil.extractFieldsFromJsonObject(planConfiguration.getAdditionalDetails(), REGISTRATION_PROCESS); + String distributionProcess = (String) parsingUtil.extractFieldsFromJsonObject(planConfiguration.getAdditionalDetails(), DISTRIBUTION_PROCESS); + + // If any of the process detail value is null, return an empty list + if (ObjectUtils.isEmpty(registrationProcess) || ObjectUtils.isEmpty(distributionProcess)) { + return Collections.emptyList(); + } + return logicList.stream() - .filter(logic -> logic.isFixedPost() == isFixedPost && - logic.getRegistrationProcess().equalsIgnoreCase((String) parsingUtil.extractFieldsFromJsonObject(planConfiguration.getAdditionalDetails(), REGISTRATION_PROCESS)) && - logic.getDistributionProcess().equalsIgnoreCase((String) parsingUtil.extractFieldsFromJsonObject(planConfiguration.getAdditionalDetails(), DISTRIBUTION_PROCESS))) + .filter(logic -> logic.isFixedPost() == isFixedPost) + .filter(logic -> logic.getRegistrationProcess().equalsIgnoreCase(registrationProcess)) + .filter(logic -> logic.getDistributionProcess().equalsIgnoreCase(distributionProcess)) .map(MixedStrategyOperationLogic::getCategoriesNotAllowed) .findAny() // Returns any matching element since there is only one match .orElse(List.of()); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java index d48f5077a7..19f73f32e4 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/mdmsV2/MixedStrategyOperationLogic.java @@ -9,6 +9,10 @@ import java.util.List; +/** + * MixedStrategyOperationLogic: + * Represents the configuration logic for mixed strategy operations in microplanning + */ @Validated @Data @AllArgsConstructor diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java index 07b82a00e4..78b308dc12 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; @@ -57,9 +58,11 @@ public class PlanFacilitySearchCriteria { private String facilityId = null; @JsonProperty("offset") + @Min(0) private Integer offset = null; @JsonProperty("limit") + @Min(1) private Integer limit = null; @JsonIgnore From bba68fd2dc323c151992385b2985ff7fd0fea861 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 22 Jan 2025 17:13:16 +0530 Subject: [PATCH 61/76] Error handling for null pointer exceptions and replacing string literals with string constants --- .../src/main/java/digit/service/PlanEnricher.java | 12 +++++++----- .../org/egov/processor/config/ServiceConstants.java | 4 ++-- .../org/egov/processor/util/EnrichmentUtil.java | 11 ++++++----- .../org/egov/processor/util/ExcelStylingUtil.java | 13 +++++++++++-- .../util/OutputEstimationGenerationUtil.java | 2 +- .../main/java/org/egov/processor/util/PlanUtil.java | 1 + 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 9cde70548e..1cff13076d 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -113,11 +113,13 @@ public void enrichPlanUpdate(PlanRequest body) { }); // Generate uuid for new additionalFields - body.getPlan().getAdditionalFields().forEach(additionalFields -> { - if(ObjectUtils.isEmpty(additionalFields.getId())) { - UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id"); - } - }); + if(!CollectionUtils.isEmpty(body.getPlan().getAdditionalFields())) { + body.getPlan().getAdditionalFields().forEach(additionalFields -> { + if(ObjectUtils.isEmpty(additionalFields.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id"); + } + }); + } // Enriching last modified time for update body.getPlan().getAuditDetails().setLastModifiedTime(System.currentTimeMillis()); 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 0e0b2dab95..7026bf7e80 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 @@ -121,6 +121,7 @@ public class ServiceConstants { public static final String ERROR_WHILE_UPDATING_PLAN_CONFIG = "Exception occurred while updating plan configuration."; public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while searching plans."; public static final String ERROR_WHILE_SEARCHING_PLAN_FACILITY = "Exception occurred while searching plan facility : "; + public static final String ERROR_WHILE_CREATING_CELL_STYLE = "Failed to create cell style : "; public static final String VALIDATE_STRING_REGX = "^(?!\\d+$).+$"; public static final String VALIDATE_NUMBER_REGX = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; @@ -167,6 +168,5 @@ public class ServiceConstants { public static final String HEX_BACKGROUND_COLOR = "93C47D"; // Background color in HEX format (RRGGBB) for Excel header rows public static final boolean FREEZE_CELL = true; // Controls whether cells should be locked for editing public static final int COLUMN_WIDTH = 40; //Default column width in characters (1-255) - - + public static final int COLUMN_PADDING = 512; } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 2ca5b2c5c7..ce2b8c740f 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -18,6 +18,7 @@ import org.egov.processor.web.models.mdmsV2.Mdms; 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; @@ -44,12 +45,10 @@ public class EnrichmentUtil { private PlanUtil planUtil; private Configuration config; -// private MultiStateInstanceUtil centralInstanceUtil; public EnrichmentUtil(MdmsV2Util mdmsV2Util, LocaleUtil localeUtil, ParsingUtil parsingUtil, CensusUtil censusUtil, PlanUtil planUtil, Configuration config) { this.mdmsV2Util = mdmsV2Util; this.localeUtil = localeUtil; -// this.centralInstanceUtil = centralInstanceUtil; this.parsingUtil = parsingUtil; this.censusUtil = censusUtil; this.planUtil = planUtil; @@ -66,7 +65,6 @@ public EnrichmentUtil(MdmsV2Util mdmsV2Util, LocaleUtil localeUtil, ParsingUtil */ public void enrichResourceMapping(PlanConfigurationRequest request, LocaleResponse localeResponse, String campaignType, String fileStoreId) { -// String rootTenantId = centralInstanceUtil.getStateLevelTenant(request.getPlanConfiguration().getTenantId()); String rootTenantId = request.getPlanConfiguration().getTenantId().split("\\.")[0]; String uniqueIndentifier = BOUNDARY + DOT_SEPARATOR + MICROPLAN_PREFIX + campaignType; List mdmsV2Data = mdmsV2Util.fetchMdmsV2Data(request.getRequestInfo(), rootTenantId, MDMS_ADMIN_CONSOLE_MODULE_NAME + DOT_SEPARATOR + MDMS_SCHEMA_ADMIN_SCHEMA, uniqueIndentifier); @@ -248,8 +246,11 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR if (planEstimate != null) { Map resourceTypeToEstimatedNumberMap = new HashMap<>(); - planEstimate.getResources().forEach(resource -> - resourceTypeToEstimatedNumberMap.put(resource.getResourceType(), resource.getEstimatedNumber())); + + // If resources are not empty, iterate over each resource and map resourceType with it's estimatedValue. + if(!CollectionUtils.isEmpty(planEstimate.getResources())) + planEstimate.getResources().forEach(resource -> + resourceTypeToEstimatedNumberMap.put(resource.getResourceType(), resource.getEstimatedNumber())); // Iterate over each output column to update the row cells with resource values diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java index 63d38d6654..bdd1b7bea0 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java @@ -12,12 +12,20 @@ public class ExcelStylingUtil { public void styleCell(Cell cell) { + if(cell == null) + return; + Sheet sheet = cell.getSheet(); Workbook workbook = sheet.getWorkbook(); XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook; // Create a cell style - XSSFCellStyle cellStyle = (XSSFCellStyle) workbook.createCellStyle(); + XSSFCellStyle cellStyle; + try { + cellStyle = (XSSFCellStyle) workbook.createCellStyle(); + } catch (Exception e) { + throw new IllegalStateException(ERROR_WHILE_CREATING_CELL_STYLE, e); + } // Set background color XSSFColor backgroundColor = hexToXSSFColor(HEX_BACKGROUND_COLOR, xssfWorkbook); @@ -63,7 +71,7 @@ public void adjustColumnWidthForCell(Cell cell) { int cellWidth = cellValue.length() * 256; // Approximate width (1/256th of character width) // Use the maximum width seen so far, including padding for readability - int padding = 512; // Adjust padding as needed + int padding = COLUMN_PADDING; // Adjust padding as needed int newWidth = Math.max(maxWidth, cellWidth + padding); sheet.setColumnWidth(columnIndex, newWidth); @@ -75,6 +83,7 @@ public void adjustColumnWidthForCell(Cell cell) { * @param hexColor The HEX color string (e.g., "93C47D"). * @param xssfWorkbook The XSSFWorkbook context for styles. * @return XSSFColor The corresponding XSSFColor object. + * @throws IllegalArgumentException if the hex color is null, empty, or in invalid format */ public static XSSFColor hexToXSSFColor(String hexColor, XSSFWorkbook xssfWorkbook) { diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 68198704b4..9becc2486f 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -211,7 +211,7 @@ private void addFacilityNameToSheet(Sheet sheet, String assignedFacilityColHeade } // Assign the facility name based on the boundary code. - facilityCell.setCellValue(boundaryCodeToFacility.getOrDefault(boundaryCode, "")); + facilityCell.setCellValue(boundaryCodeToFacility.getOrDefault(boundaryCode, EMPTY_STRING)); facilityCell.getCellStyle().setLocked(false); // Ensure the new cell is editable } 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 fde26ae8d1..1a6ee1e7cd 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 @@ -138,6 +138,7 @@ private Object enrichAdditionalDetails(Map boundaryCodeToCensusA extractNestedFields((Map) securityDetails, SECURITY_DETAILS, fieldsToBeUpdated); } + // If the fieldsToBeUpdated map is not empty, pass a new empty object to serve as the additional details object. if(!CollectionUtils.isEmpty(fieldsToBeUpdated)) return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); } From d67bd4d759d96900e5dcd793b35b007ba619908a Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 23 Jan 2025 11:06:30 +0530 Subject: [PATCH 62/76] moving mdms data search call outside the isSheetAllowedToProcess function for optimization --- .../egov/processor/service/ExcelParser.java | 11 ++++++-- .../util/OutputEstimationGenerationUtil.java | 28 ++++++++----------- 2 files changed, 21 insertions(+), 18 deletions(-) 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 954f69e624..d6c0ec35a2 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 @@ -236,8 +236,13 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, LinkedHashMap::new )); + // Fetch mdms data for common constants + Map mdmsDataForCommonConstants = mdmsUtil.fetchMdmsDataForCommonConstants( + request.getRequestInfo(), + request.getPlanConfiguration().getTenantId()); + excelWorkbook.forEach(excelWorkbookSheet -> { - if (outputEstimationGenerationUtil.isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { + if (outputEstimationGenerationUtil.isSheetAllowedToProcess(excelWorkbookSheet.getSheetName(), localeResponse, mdmsDataForCommonConstants)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { Map boundaryCodeToCensusAdditionalDetails = new HashMap<>(); @@ -320,7 +325,9 @@ private Map fetchFixedPostDetails(PlanConfigurationRequest requ * @param boundaryCodeList List of boundary codes. * @throws IOException If an I/O error occurs. */ - private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map boundaryCodeToCensusAdditionalDetails) { + private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, + String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, + List boundaryCodeList, Map boundaryCodeToCensusAdditionalDetails) { // Create a Map of Boundary Code to Facility's fixed post detail. Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(planConfigurationRequest, sheet, fileStoreId); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 9becc2486f..b6417c4572 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -50,11 +50,14 @@ public OutputEstimationGenerationUtil(LocaleUtil localeUtil, ParsingUtil parsing */ public void processOutputFile(Workbook workbook, PlanConfigurationRequest request, String filestoreId) { LocaleResponse localeResponse = localeUtil.searchLocale(request); + Map mdmsDataForCommonConstants = mdmsUtil.fetchMdmsDataForCommonConstants( + request.getRequestInfo(), + request.getPlanConfiguration().getTenantId()); // 1. removing readme sheet for (int i = workbook.getNumberOfSheets() - 1; i >= 0; i--) { Sheet sheet = workbook.getSheetAt(i); - if (!isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { + if (!isSheetAllowedToProcess(sheet.getSheetName(), localeResponse, mdmsDataForCommonConstants)) { workbook.removeSheetAt(i); } } @@ -146,10 +149,8 @@ public void addAssignedFacility(Sheet sheet, PlanConfigurationRequest request, S // Create the map of boundary code to the facility assigned to that boundary. Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(sheet, request, fileStoreId); - if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeResponse)) { - // Add facility names to the sheet. - addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); - } + // Add facility names to the sheet. + addFacilityNameToSheet(sheet, assignedFacilityColHeader, boundaryCodeToFacility, mappedValues); } /** @@ -164,11 +165,8 @@ public void addAssignedFacility(Sheet sheet, PlanConfigurationRequest request, S public Map getBoundaryCodeToFacilityMap(Sheet sheet, PlanConfigurationRequest request, String fileStoreId) { List boundaryCodes = new ArrayList<>(); - - if (isSheetAllowedToProcess(request, sheet.getSheetName(), localeUtil.searchLocale(request))) { - // Extract boundary codes from the sheet. - boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); - } + // Extract boundary codes from the sheet. + boundaryCodes.addAll(enrichmentUtil.getBoundaryCodesFromTheSheet(sheet, request, fileStoreId)); // Fetch census records for the extracted boundary codes. List censusList = enrichmentUtil.getCensusRecordsForEnrichment(request, boundaryCodes); @@ -241,14 +239,12 @@ private int createAssignedFacilityColumn(Sheet sheet, String assignedFacilityCol /** * Checks if a sheet is allowed to be processed based on MDMS constants and locale-specific configuration. * - * @param planConfigurationRequest The request containing configuration details including request info and tenant ID. - * @param sheetName The name of the sheet to be processed. + * @param sheetName The name of the sheet to be processed. + * @param localeResponse Localisation response for the given tenant id. + * @param mdmsDataConstants Mdms data for common constants. * @return true if the sheet is allowed to be processed, false otherwise. */ - public boolean isSheetAllowedToProcess(PlanConfigurationRequest planConfigurationRequest, String sheetName, LocaleResponse localeResponse) { - Map mdmsDataConstants = mdmsUtil.fetchMdmsDataForCommonConstants( - planConfigurationRequest.getRequestInfo(), - planConfigurationRequest.getPlanConfiguration().getTenantId()); + public boolean isSheetAllowedToProcess(String sheetName, LocaleResponse localeResponse, Map mdmsDataConstants) { String readMeSheetName = (String) mdmsDataConstants.get(READ_ME_SHEET_NAME); if(ObjectUtils.isEmpty(readMeSheetName)) From 33e4b5499ea57fa7196220b9737ec0c95cdec5ad Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 23 Jan 2025 11:12:51 +0530 Subject: [PATCH 63/76] Removing unused parameters --- .../org/egov/processor/service/ExcelParser.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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 d6c0ec35a2..56a4e6de9c 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 @@ -137,12 +137,10 @@ private void processExcelFile(PlanConfigurationRequest planConfigurationRequest, Object campaignResponse) { try (Workbook workbook = new XSSFWorkbook(file)) { List campaignBoundaryList = new ArrayList<>(); - List campaignResourcesList = new ArrayList<>(); DataFormatter dataFormatter = new DataFormatter(); processSheets(planConfigurationRequest, fileStoreId, campaignResponse, workbook, campaignBoundaryList, dataFormatter); - uploadFileAndIntegrateCampaign(planConfigurationRequest, campaignResponse, - workbook, campaignBoundaryList, campaignResourcesList, fileStoreId); + uploadFileAndIntegrateCampaign(planConfigurationRequest, workbook, fileStoreId); } catch (FileNotFoundException e) { log.error("File not found: {}", e.getMessage()); throw new CustomException("FileNotFound", "The specified file was not found."); @@ -158,16 +156,12 @@ private void processExcelFile(PlanConfigurationRequest planConfigurationRequest, /** * Uploads a converted file and integrates campaign details if configured to do so. - * + * * @param planConfigurationRequest The request containing configuration details including tenant ID. - * @param campaignResponse The response object containing campaign details. - * @param workbook The workbook containing data to be uploaded and integrated. - * @param campaignBoundaryList List of boundary objects related to the campaign. - * @param campaignResourcesList List of campaign resources to be integrated. + * @param workbook The workbook containing data to be uploaded and integrated. + * @param filestoreId The ID of the file in the file store. */ - private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigurationRequest, - Object campaignResponse, Workbook workbook, - List campaignBoundaryList, List campaignResourcesList, String filestoreId) { + private void uploadFileAndIntegrateCampaign(PlanConfigurationRequest planConfigurationRequest, Workbook workbook, String filestoreId) { File fileToUpload = null; try { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); From 4a842e11f1e0b36981bc93db1d49f3bc9596d174 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 23 Jan 2025 11:24:12 +0530 Subject: [PATCH 64/76] Setting cellValue as N/A for restricted categories --- .../main/java/org/egov/processor/config/ServiceConstants.java | 1 + .../src/main/java/org/egov/processor/util/EnrichmentUtil.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 7026bf7e80..ae2e04160d 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 @@ -108,6 +108,7 @@ public class ServiceConstants { public static final String ACCESSIBILITY_DETAILS = "accessibilityDetails"; public static final String SECURITY_DETAILS = "securityDetails"; public static final String EMPTY_STRING = ""; + public static final String NOT_APPLICABLE = "N/A"; public static final String FIXED_POST_YES = "yes"; //MDMS field Constants diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index ce2b8c740f..2041438247 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -277,7 +277,7 @@ public void enrichsheetWithApprovedPlanEstimates(Sheet sheet, PlanConfigurationR if (cell == null) { cell = row.createCell(columnIndex); } - cell.setCellValue(EMPTY_STRING); // Set as empty string + cell.setCellValue(NOT_APPLICABLE); // Set as not applicable } } } From 464b4878755f85295cc0a9a0587e8c6070532450 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Fri, 24 Jan 2025 15:08:45 +0530 Subject: [PATCH 65/76] Changing facility_name constraint from VARCHAR(64) to VARCHAR(2000) --- ...2201141000__alter_plan_facility_linkage_facility_name_ddl.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 health-services/plan-service/src/main/resources/db/migration/main/V20242201141000__alter_plan_facility_linkage_facility_name_ddl.sql diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20242201141000__alter_plan_facility_linkage_facility_name_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20242201141000__alter_plan_facility_linkage_facility_name_ddl.sql new file mode 100644 index 0000000000..649a80d10f --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20242201141000__alter_plan_facility_linkage_facility_name_ddl.sql @@ -0,0 +1 @@ +ALTER TABLE plan_facility_linkage ALTER COLUMN facility_name TYPE character varying(2000); From 1e2505b3a6b9ed17bb06a51ef16642d4613dc095 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 27 Jan 2025 18:10:37 +0530 Subject: [PATCH 66/76] HCMPRE-2212 making facilityId in plan search a set for multiple drop down search, changes filterMap signature. --- .../src/main/java/digit/service/PlanEnricher.java | 14 +++++++------- .../java/digit/web/models/PlanSearchCriteria.java | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java index 1cff13076d..7ab443a6f3 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java @@ -253,31 +253,31 @@ public void enrichSearchRequest(PlanSearchRequest planSearchRequest) { PlanSearchCriteria planSearchCriteria = planSearchRequest.getPlanSearchCriteria(); // Filter map for filtering plan metadata present in additional details - Map filtersMap = new LinkedHashMap<>(); + Map> filtersMap = new LinkedHashMap<>(); // Add facility id as a filter if present in search criteria - if (!ObjectUtils.isEmpty(planSearchCriteria.getFacilityId())) { - filtersMap.put(FACILITY_ID_SEARCH_PARAMETER_KEY, planSearchCriteria.getFacilityId()); + if (!ObjectUtils.isEmpty(planSearchCriteria.getFacilityIds())) { + filtersMap.put(FACILITY_ID_SEARCH_PARAMETER_KEY, planSearchCriteria.getFacilityIds()); } // Add terrain as a filter if present in search criteria if (!ObjectUtils.isEmpty(planSearchCriteria.getTerrain())) { - filtersMap.put(TERRAIN_CONDITION_SEARCH_PARAMETER_KEY, planSearchCriteria.getTerrain()); + filtersMap.put(TERRAIN_CONDITION_SEARCH_PARAMETER_KEY, Collections.singleton(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()); + filtersMap.put(ROAD_CONDITION_SEARCH_PARAMETER_KEY, Collections.singleton(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()); + filtersMap.put(SECURITY_Q1_SEARCH_PARAMETER_KEY, Collections.singleton(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()); + filtersMap.put(SECURITY_Q2_SEARCH_PARAMETER_KEY, Collections.singleton(planSearchCriteria.getSecurityQ2())); } if(!CollectionUtils.isEmpty(filtersMap)) diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java index f71cca497f..f0b22e87d6 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanSearchCriteria.java @@ -40,8 +40,8 @@ public class PlanSearchCriteria { @JsonProperty("planConfigurationId") private String planConfigurationId = null; - @JsonProperty("facilityId") - private String facilityId = null; + @JsonProperty("facilityIds") + private Set facilityIds = null; @JsonProperty("onRoadCondition") private String onRoadCondition = null; @@ -72,6 +72,6 @@ public class PlanSearchCriteria { private Integer limit = null; @JsonIgnore - private Map filtersMap = null; + private Map> filtersMap = null; } From b561a96710f48a38d7b4dda70a2afafe01614eee Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 27 Jan 2025 18:15:30 +0530 Subject: [PATCH 67/76] HCMPRE-2212 making facilityId in plan search a set for multiple drop down search, changes filterMap signature. --- .../src/main/java/digit/util/QueryUtil.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index 070f442a89..3333400e3f 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -102,7 +102,7 @@ public String addOrderByClause(String query, String orderByClause) { * @param filterMap * @return */ - public String preparePartialJsonStringFromFilterMap(Map filterMap) { + public String preparePartialJsonStringFromFilterMap(Map> filterMap) { Map queryMap = new HashMap<>(); filterMap.keySet().forEach(key -> { @@ -129,16 +129,16 @@ public String preparePartialJsonStringFromFilterMap(Map filterMa * @param index * @param nestedKeyArray * @param currentQueryMap - * @param value + * @param values */ - private void prepareNestedQueryMap(int index, String[] nestedKeyArray, Map currentQueryMap, String value) { + private void prepareNestedQueryMap(int index, String[] nestedKeyArray, Map currentQueryMap, Set values) { // Return when all levels have been reached. if (index == nestedKeyArray.length) return; // For the final level simply put the value in the map. else if (index == nestedKeyArray.length - 1) { - currentQueryMap.put(nestedKeyArray[index], value); + currentQueryMap.put(nestedKeyArray[index], values); return; } @@ -146,7 +146,7 @@ else if (index == nestedKeyArray.length - 1) { currentQueryMap.put(nestedKeyArray[index], new HashMap<>()); // Make a recursive call to enrich data in next level. - prepareNestedQueryMap(index + 1, nestedKeyArray, (Map) currentQueryMap.get(nestedKeyArray[index]), value); + prepareNestedQueryMap(index + 1, nestedKeyArray, (Map) currentQueryMap.get(nestedKeyArray[index]), values); } /** From fcce569226f3583f6a4fc6c76a2dc67435c2d2ce Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 27 Jan 2025 18:20:24 +0530 Subject: [PATCH 68/76] HCMPRE-2212 making facilityId in plan search a set for multiple drop down search, changes filterMap signature. --- .../java/digit/service/enrichment/PlanFacilityEnricher.java | 6 +++--- .../java/digit/web/models/PlanFacilitySearchCriteria.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java index fccb2de96d..c204f54c69 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java @@ -192,16 +192,16 @@ public void enrichSearchRequest(PlanFacilitySearchRequest planFacilitySearchRequ PlanFacilitySearchCriteria planFacilitySearchCriteria = planFacilitySearchRequest.getPlanFacilitySearchCriteria(); // Filter map for filtering facility meta data present in additional details - Map filtersMap = new LinkedHashMap<>(); + Map> filtersMap = new LinkedHashMap<>(); // Add facility status as a filter if present in search criteria if(!ObjectUtils.isEmpty(planFacilitySearchCriteria.getFacilityStatus())) { - filtersMap.put(FACILITY_STATUS_SEARCH_PARAMETER_KEY, planFacilitySearchCriteria.getFacilityStatus()); + filtersMap.put(FACILITY_STATUS_SEARCH_PARAMETER_KEY, Collections.singleton(planFacilitySearchCriteria.getFacilityStatus())); } // Add facility type as a filter if present in search criteria if(!ObjectUtils.isEmpty(planFacilitySearchCriteria.getFacilityType())) { - filtersMap.put(FACILITY_TYPE_SEARCH_PARAMETER_KEY, planFacilitySearchCriteria.getFacilityType()); + filtersMap.put(FACILITY_TYPE_SEARCH_PARAMETER_KEY, Collections.singleton(planFacilitySearchCriteria.getFacilityType())); } if(!CollectionUtils.isEmpty(filtersMap)) diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java index a5a4e49c42..bab8d1555f 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java @@ -59,6 +59,6 @@ public class PlanFacilitySearchCriteria { private Integer limit = null; @JsonIgnore - private Map filtersMap = null; + private Map> filtersMap = null; } From 06f635d61e83302115203d2dbe14a6acfc02d506 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 28 Jan 2025 13:54:38 +0530 Subject: [PATCH 69/76] HCMPRE-2212 making facilityId in plan search a set for multiple drop down search, changes filterMap signature. --- .../repository/impl/PlanRepositoryImpl.java | 1 + .../querybuilder/PlanQueryBuilder.java | 28 +++++---- .../enrichment/PlanFacilityEnricher.java | 6 +- .../src/main/java/digit/util/QueryUtil.java | 57 ++++++++++++++++--- .../models/PlanFacilitySearchCriteria.java | 2 +- 5 files changed, 70 insertions(+), 24 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index 90cdb199bf..d1e6ca2521 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -152,6 +152,7 @@ private List queryDatabaseForPlanIds(PlanSearchCriteria planSearchCriter List preparedStmtList = new ArrayList<>(); String query = planQueryBuilder.getPlanSearchQuery(planSearchCriteria, preparedStmtList); log.info("Plan search query: " + query); + log.info("PreparedStatment List " + preparedStmtList); return jdbcTemplate.query(query, new SingleColumnRowMapper<>(String.class), preparedStmtList.toArray()); } diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 27c53bb9cc..892f87147e 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -7,10 +7,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; +import java.util.*; @Component public class PlanQueryBuilder { @@ -172,13 +169,22 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< queryUtil.addToPreparedStatement(preparedStmtList, planSearchCriteria.getJurisdiction()); } - if(!CollectionUtils.isEmpty(planSearchCriteria.getFiltersMap())) { - queryUtil.addClauseIfRequired(builder, preparedStmtList); - builder.append(" additional_details @> CAST( ? AS jsonb )"); - String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap()); - preparedStmtList.add(partialQueryJsonString); + if (!CollectionUtils.isEmpty(planSearchCriteria.getFiltersMap())) { + Map> filtersMap = planSearchCriteria.getFiltersMap(); + for (String key : filtersMap.keySet()) { + if ("facilityId".equals(key)) { + String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList); + builder.append(partialQueryJsonString); + } else { + queryUtil.addClauseIfRequired(builder, preparedStmtList); + builder.append(" additional_details @> CAST( ? AS jsonb )"); + String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList); + preparedStmtList.add(partialQueryJsonString); + } + } } + StringBuilder countQuery = new StringBuilder(); if (isCount) { @@ -191,7 +197,7 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< if (isStatusCount) { return PLAN_STATUS_COUNT_QUERY.replace("{INTERNAL_QUERY}", builder); } - + System.out.println(preparedStmtList); return builder.toString(); } @@ -205,7 +211,7 @@ private String getPaginatedQuery(String query, PlanSearchCriteria planSearchCrit // Append limit paginatedQuery.append(" LIMIT ? "); preparedStmtList.add(ObjectUtils.isEmpty(planSearchCriteria.getLimit()) ? config.getDefaultLimit() : planSearchCriteria.getLimit()); - + System.out.println(preparedStmtList); return paginatedQuery.toString(); } diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java index c204f54c69..fccb2de96d 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java @@ -192,16 +192,16 @@ public void enrichSearchRequest(PlanFacilitySearchRequest planFacilitySearchRequ PlanFacilitySearchCriteria planFacilitySearchCriteria = planFacilitySearchRequest.getPlanFacilitySearchCriteria(); // Filter map for filtering facility meta data present in additional details - Map> filtersMap = new LinkedHashMap<>(); + Map filtersMap = new LinkedHashMap<>(); // Add facility status as a filter if present in search criteria if(!ObjectUtils.isEmpty(planFacilitySearchCriteria.getFacilityStatus())) { - filtersMap.put(FACILITY_STATUS_SEARCH_PARAMETER_KEY, Collections.singleton(planFacilitySearchCriteria.getFacilityStatus())); + filtersMap.put(FACILITY_STATUS_SEARCH_PARAMETER_KEY, planFacilitySearchCriteria.getFacilityStatus()); } // Add facility type as a filter if present in search criteria if(!ObjectUtils.isEmpty(planFacilitySearchCriteria.getFacilityType())) { - filtersMap.put(FACILITY_TYPE_SEARCH_PARAMETER_KEY, Collections.singleton(planFacilitySearchCriteria.getFacilityType())); + filtersMap.put(FACILITY_TYPE_SEARCH_PARAMETER_KEY, planFacilitySearchCriteria.getFacilityType()); } if(!CollectionUtils.isEmpty(filtersMap)) diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index 3333400e3f..ecdc7c075e 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -10,10 +10,7 @@ import org.springframework.util.ObjectUtils; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.IntStream; import static digit.config.ServiceConstants.DOT_REGEX; @@ -102,7 +99,7 @@ public String addOrderByClause(String query, String orderByClause) { * @param filterMap * @return */ - public String preparePartialJsonStringFromFilterMap(Map> filterMap) { + public String preparePartialJsonStringFromFilterMap(Map filterMap) { Map queryMap = new HashMap<>(); filterMap.keySet().forEach(key -> { @@ -121,6 +118,48 @@ public String preparePartialJsonStringFromFilterMap(Map> fil return partialJsonQueryString; } + public String preparePartialJsonStringFromFilterMap(Map> filterMap, List preparedStmtList) { + Map queryMap = new HashMap<>(); + StringBuilder finalJsonQuery = new StringBuilder(); + + for (String key : filterMap.keySet()) { + // Handle nested keys (dot separator) + if (key.contains(DOT_SEPARATOR)) { + String[] keyArray = key.split(DOT_REGEX); + Map nestedQueryMap = new HashMap<>(); + prepareNestedQueryMap(0, keyArray, nestedQueryMap, String.valueOf(filterMap.get(key))); + queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0])); + return gson.toJson(queryMap); + } else if ("facilityId".equals(key)) { + Set values = filterMap.get(key); + if (values != null && !values.isEmpty()) { + StringBuilder orClauseBuilder = new StringBuilder(); + + // For each value, add an OR condition with a placeholder for the value + for (String value : values) { + if (orClauseBuilder.length() > 0) { + orClauseBuilder.append(" OR "); + } + // Add the condition for the key-value pair + orClauseBuilder.append("additional_details @> ?::jsonb"); + // Add the actual value in the format { "facilityId": "value" } + preparedStmtList.add("{\"" + key + "\": \"" + value + "\"}"); + } + + // Append the OR clause as part of the AND conditions + finalJsonQuery.append(" AND (").append(orClauseBuilder.toString()).append(") "); + return finalJsonQuery.toString(); // Return the query with OR conditions for facilityId + } + } else { + queryMap.put(key, filterMap.get(key).toString()); + } + } + + return gson.toJson(queryMap); + // Return the dynamically constructed query string + } + + /** * Tail recursive method to prepare n-level nested partial json for queries on nested data in * master data. For e.g. , if the key is in the format a.b.c, it will construct a nested json @@ -129,16 +168,16 @@ public String preparePartialJsonStringFromFilterMap(Map> fil * @param index * @param nestedKeyArray * @param currentQueryMap - * @param values + * @param value */ - private void prepareNestedQueryMap(int index, String[] nestedKeyArray, Map currentQueryMap, Set values) { + private void prepareNestedQueryMap(int index, String[] nestedKeyArray, Map currentQueryMap, String value) { // Return when all levels have been reached. if (index == nestedKeyArray.length) return; // For the final level simply put the value in the map. else if (index == nestedKeyArray.length - 1) { - currentQueryMap.put(nestedKeyArray[index], values); + currentQueryMap.put(nestedKeyArray[index], value); return; } @@ -146,7 +185,7 @@ else if (index == nestedKeyArray.length - 1) { currentQueryMap.put(nestedKeyArray[index], new HashMap<>()); // Make a recursive call to enrich data in next level. - prepareNestedQueryMap(index + 1, nestedKeyArray, (Map) currentQueryMap.get(nestedKeyArray[index]), values); + prepareNestedQueryMap(index + 1, nestedKeyArray, (Map) currentQueryMap.get(nestedKeyArray[index]), value); } /** diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java b/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java index bab8d1555f..a5a4e49c42 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanFacilitySearchCriteria.java @@ -59,6 +59,6 @@ public class PlanFacilitySearchCriteria { private Integer limit = null; @JsonIgnore - private Map> filtersMap = null; + private Map filtersMap = null; } From 3ff5addc97f166564866c89dd1ee2fff8c9e6419 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 28 Jan 2025 13:56:06 +0530 Subject: [PATCH 70/76] HCMPRE-2212 making facilityId in plan search a set for multiple drop down search, changes filterMap signature. --- .../java/digit/repository/querybuilder/PlanQueryBuilder.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 892f87147e..349d08fdac 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -184,7 +184,6 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< } } - StringBuilder countQuery = new StringBuilder(); if (isCount) { @@ -197,7 +196,7 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< if (isStatusCount) { return PLAN_STATUS_COUNT_QUERY.replace("{INTERNAL_QUERY}", builder); } - System.out.println(preparedStmtList); + return builder.toString(); } @@ -211,7 +210,7 @@ private String getPaginatedQuery(String query, PlanSearchCriteria planSearchCrit // Append limit paginatedQuery.append(" LIMIT ? "); preparedStmtList.add(ObjectUtils.isEmpty(planSearchCriteria.getLimit()) ? config.getDefaultLimit() : planSearchCriteria.getLimit()); - System.out.println(preparedStmtList); + return paginatedQuery.toString(); } From 42cc2867eedd1dba1230131d08bb0b726efd3ad0 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 28 Jan 2025 16:11:22 +0530 Subject: [PATCH 71/76] HCMPRE-2212 making facilityId in plan search a set for multiple drop down search, changes filterMap signature. --- .../java/digit/config/ServiceConstants.java | 7 +++ .../querybuilder/PlanQueryBuilder.java | 11 ++-- .../src/main/java/digit/util/QueryUtil.java | 63 +++++++++---------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java index 69d0986f96..8597c1a2a5 100644 --- a/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java +++ b/health-services/plan-service/src/main/java/digit/config/ServiceConstants.java @@ -384,4 +384,11 @@ public class ServiceConstants { public static final String CONFIRMED_TARGET_POPULATION = "CONFIRMED_HCM_ADMIN_CONSOLE_TARGET_POPULATION"; + public static final String ADDITIONAL_DETAILS_QUERY = " additional_details @> CAST( ? AS jsonb )"; + + public static final String JSONB_QUERY_FORMAT = "additional_details @> ?::jsonb"; + + public static final String AND_CONDITION = " AND "; + + public static final String OR_CONDITION = " OR "; } diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 349d08fdac..93c0f18ae8 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -9,6 +9,9 @@ import java.util.*; +import static digit.config.ServiceConstants.ADDITIONAL_DETAILS_QUERY; +import static digit.config.ServiceConstants.FACILITY_ID_SEARCH_PARAMETER_KEY; + @Component public class PlanQueryBuilder { @@ -172,13 +175,13 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< if (!CollectionUtils.isEmpty(planSearchCriteria.getFiltersMap())) { Map> filtersMap = planSearchCriteria.getFiltersMap(); for (String key : filtersMap.keySet()) { - if ("facilityId".equals(key)) { - String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList); + if (FACILITY_ID_SEARCH_PARAMETER_KEY.equals(key)) { + String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList, key); builder.append(partialQueryJsonString); } else { queryUtil.addClauseIfRequired(builder, preparedStmtList); - builder.append(" additional_details @> CAST( ? AS jsonb )"); - String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList); + builder.append(ADDITIONAL_DETAILS_QUERY); + String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList, key); preparedStmtList.add(partialQueryJsonString); } } diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index ecdc7c075e..ff48890024 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -13,8 +13,7 @@ import java.util.*; import java.util.stream.IntStream; -import static digit.config.ServiceConstants.DOT_REGEX; -import static digit.config.ServiceConstants.DOT_SEPARATOR; +import static digit.config.ServiceConstants.*; @Component public class QueryUtil { @@ -118,45 +117,43 @@ public String preparePartialJsonStringFromFilterMap(Map filterMa return partialJsonQueryString; } - public String preparePartialJsonStringFromFilterMap(Map> filterMap, List preparedStmtList) { + public String preparePartialJsonStringFromFilterMap(Map> filterMap, List preparedStmtList, String key) { Map queryMap = new HashMap<>(); StringBuilder finalJsonQuery = new StringBuilder(); - - for (String key : filterMap.keySet()) { - // Handle nested keys (dot separator) - if (key.contains(DOT_SEPARATOR)) { - String[] keyArray = key.split(DOT_REGEX); - Map nestedQueryMap = new HashMap<>(); - prepareNestedQueryMap(0, keyArray, nestedQueryMap, String.valueOf(filterMap.get(key))); - queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0])); - return gson.toJson(queryMap); - } else if ("facilityId".equals(key)) { - Set values = filterMap.get(key); - if (values != null && !values.isEmpty()) { - StringBuilder orClauseBuilder = new StringBuilder(); - - // For each value, add an OR condition with a placeholder for the value - for (String value : values) { - if (orClauseBuilder.length() > 0) { - orClauseBuilder.append(" OR "); - } - // Add the condition for the key-value pair - orClauseBuilder.append("additional_details @> ?::jsonb"); - // Add the actual value in the format { "facilityId": "value" } - preparedStmtList.add("{\"" + key + "\": \"" + value + "\"}"); + // Handle nested keys (dot separator) + if (key.contains(DOT_SEPARATOR)) { + String[] keyArray = key.split(DOT_REGEX); + Map nestedQueryMap = new HashMap<>(); + prepareNestedQueryMap(0, keyArray, nestedQueryMap, (String) filterMap.get(key).toArray()[0]); + queryMap.put(keyArray[0], nestedQueryMap.get(keyArray[0])); + return gson.toJson(queryMap); + } else if (FACILITY_ID_SEARCH_PARAMETER_KEY.equals(key)) { + Set values = filterMap.get(key); + if (values != null && !values.isEmpty()) { + StringBuilder orClauseBuilder = new StringBuilder(); + + // For each value, add an OR condition with a placeholder for the value + for (String value : values) { + if (orClauseBuilder.length() > 0) { + orClauseBuilder.append(OR_CONDITION); } - - // Append the OR clause as part of the AND conditions - finalJsonQuery.append(" AND (").append(orClauseBuilder.toString()).append(") "); - return finalJsonQuery.toString(); // Return the query with OR conditions for facilityId + // Add the condition for the key-value pair + orClauseBuilder.append(JSONB_QUERY_FORMAT); + // Add the actual value in the format { "facilityId": "value" } + preparedStmtList.add("{\"" + key + "\": \"" + value + "\"}"); } - } else { - queryMap.put(key, filterMap.get(key).toString()); + + // Append the OR clause as part of the AND conditions + finalJsonQuery.append(AND_CONDITION).append("(").append(orClauseBuilder.toString()).append(") "); + return finalJsonQuery.toString(); // Return the query with OR conditions for facilityId } + } else { + queryMap.put(key, (String) filterMap.get(key).toArray()[0]); } - return gson.toJson(queryMap); + // Return the dynamically constructed query string + return gson.toJson(queryMap); } From 6f2066cabbbb192e8d830dff0b4b056f730bc565 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Tue, 28 Jan 2025 17:22:17 +0530 Subject: [PATCH 72/76] HCMPRE-2212 Adding comments --- .../repository/impl/PlanRepositoryImpl.java | 1 - .../querybuilder/PlanQueryBuilder.java | 2 ++ .../src/main/java/digit/util/QueryUtil.java | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index d1e6ca2521..90cdb199bf 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -152,7 +152,6 @@ private List queryDatabaseForPlanIds(PlanSearchCriteria planSearchCriter List preparedStmtList = new ArrayList<>(); String query = planQueryBuilder.getPlanSearchQuery(planSearchCriteria, preparedStmtList); log.info("Plan search query: " + query); - log.info("PreparedStatment List " + preparedStmtList); return jdbcTemplate.query(query, new SingleColumnRowMapper<>(String.class), preparedStmtList.toArray()); } diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 93c0f18ae8..0b0c7347aa 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -176,9 +176,11 @@ private String buildPlanSearchQuery(PlanSearchCriteria planSearchCriteria, List< Map> filtersMap = planSearchCriteria.getFiltersMap(); for (String key : filtersMap.keySet()) { if (FACILITY_ID_SEARCH_PARAMETER_KEY.equals(key)) { + // its for facility multi select then no need to add to preparedStmtList String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList, key); builder.append(partialQueryJsonString); } else { + // handle all other keys normally. queryUtil.addClauseIfRequired(builder, preparedStmtList); builder.append(ADDITIONAL_DETAILS_QUERY); String partialQueryJsonString = queryUtil.preparePartialJsonStringFromFilterMap(planSearchCriteria.getFiltersMap(), preparedStmtList, key); diff --git a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java index ff48890024..127dcd951a 100644 --- a/health-services/plan-service/src/main/java/digit/util/QueryUtil.java +++ b/health-services/plan-service/src/main/java/digit/util/QueryUtil.java @@ -95,6 +95,8 @@ public String addOrderByClause(String query, String orderByClause) { /** * This method prepares partial json string from the filter map to query on jsonb column * + * - For nested keys (keys containing dot separators), a nested JSON structure is constructed. + * - For other keys, a simple key-value JSON structure is returned. * @param filterMap * @return */ @@ -117,6 +119,23 @@ public String preparePartialJsonStringFromFilterMap(Map filterMa return partialJsonQueryString; } + /** + * This is an overloaded function, to handle facility multi select for plan search specifically. + * Prepares a partial JSON query string based on the provided filter map, key, and prepared statement list. + * + * @param filterMap A map containing filter keys and their corresponding set of values. + * @param preparedStmtList A list to which placeholder values for prepared statements are added. + * @param key The key used to construct the partial query. + * @return A partial JSON query string or a query fragment with OR conditions. + * + * This method dynamically constructs a JSON query or query fragment based on the structure of the `key`: + * - For nested keys (keys containing dot separators), a nested JSON structure is constructed. + * - For the "facilityId" key, an OR condition is generated for all values in the set. + * - For other keys, a simple key-value JSON structure is returned. + * + * Notes: + * - When constructing the query for "facilityId", placeholders for each value are added to the `preparedStmtList`. + */ public String preparePartialJsonStringFromFilterMap(Map> filterMap, List preparedStmtList, String key) { Map queryMap = new HashMap<>(); StringBuilder finalJsonQuery = new StringBuilder(); From 6814bc454fe93a81dec215760ad2f102a77c8b3d Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 30 Jan 2025 11:36:49 +0530 Subject: [PATCH 73/76] Code review - changed null to empty object --- .../src/main/java/org/egov/processor/util/CalculationUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java index c96169492c..d53a749cbf 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/CalculationUtil.java @@ -13,6 +13,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -78,7 +79,7 @@ public void calculateResources(JsonNode jsonNode, PlanConfigurationRequest planC resultMap.put(output, result); ((ObjectNode) feature.get("properties")).put(output, result); } - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, null); + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, new HashMap<>()); } } From 8b535655860b218ca6df819b7e048ae34f15179c Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 30 Jan 2025 12:42:15 +0530 Subject: [PATCH 74/76] HCMPRE-1922 Changelog and pom.xml changes --- health-services/plan-service/CHANGELOG.md | 5 +++++ health-services/plan-service/pom.xml | 2 +- health-services/resource-generator/CHANGELOG.md | 5 +++++ health-services/resource-generator/pom.xml | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/health-services/plan-service/CHANGELOG.md b/health-services/plan-service/CHANGELOG.md index a73439d765..df4b3b8523 100644 --- a/health-services/plan-service/CHANGELOG.md +++ b/health-services/plan-service/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All notable changes to this module will be documented in this file. + +## 1.0.1 - 2025-01-30 +1. Mixed Distribution Strategy for Registration and Service Delivery +2. Adding additional search filters for Estimation Dashboard + ## 1.0.0 - 2024-12-03 ### Plan Service diff --git a/health-services/plan-service/pom.xml b/health-services/plan-service/pom.xml index c41f44a9f0..d0dba48a76 100644 --- a/health-services/plan-service/pom.xml +++ b/health-services/plan-service/pom.xml @@ -4,7 +4,7 @@ plan-service jar plan-service - 1.0.0 + 1.0.1 17 ${java.version} diff --git a/health-services/resource-generator/CHANGELOG.md b/health-services/resource-generator/CHANGELOG.md index f56811de91..76d172ea14 100644 --- a/health-services/resource-generator/CHANGELOG.md +++ b/health-services/resource-generator/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.0.1 - 2025-01-30 +1. Microplan Estimation Downloadable Excel Report Enhancements +2. Mixed Distribution Strategy for Registration and Service Delivery +3. Changes for filters in Estimation Dashboard + ## 1.0.0 - 2024-12-03 #### Resource Generator Service The Resource Generator Service introduces comprehensive functionalities for microplanning resource estimation and campaign integration: diff --git a/health-services/resource-generator/pom.xml b/health-services/resource-generator/pom.xml index 33ac3c4c7d..f194f1e0e3 100644 --- a/health-services/resource-generator/pom.xml +++ b/health-services/resource-generator/pom.xml @@ -4,7 +4,7 @@ resource-generator jar file-processor-utility - 1.0.0 + 1.0.1 17 32-SNAPSHOT From 1e2ed04107f0c9bea808d200d212777559e0c775 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 30 Jan 2025 13:01:07 +0530 Subject: [PATCH 75/76] HCMPRE-1922 Changelog and pom.xml changes --- health-services/plan-service/CHANGELOG.md | 2 +- health-services/resource-generator/CHANGELOG.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/health-services/plan-service/CHANGELOG.md b/health-services/plan-service/CHANGELOG.md index df4b3b8523..7400e92614 100644 --- a/health-services/plan-service/CHANGELOG.md +++ b/health-services/plan-service/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this module will be documented in this file. ## 1.0.1 - 2025-01-30 -1. Mixed Distribution Strategy for Registration and Service Delivery +1. Enabled support Mixed Distribution Strategy for Registration and Service Delivery 2. Adding additional search filters for Estimation Dashboard ## 1.0.0 - 2024-12-03 diff --git a/health-services/resource-generator/CHANGELOG.md b/health-services/resource-generator/CHANGELOG.md index 76d172ea14..3a856828e7 100644 --- a/health-services/resource-generator/CHANGELOG.md +++ b/health-services/resource-generator/CHANGELOG.md @@ -1,9 +1,9 @@ # Changelog ## 1.0.1 - 2025-01-30 -1. Microplan Estimation Downloadable Excel Report Enhancements -2. Mixed Distribution Strategy for Registration and Service Delivery -3. Changes for filters in Estimation Dashboard +1. Enhancements for Microplan Estimation Downloadable Excel Report +2. Enabled support Mixed Distribution Strategy for Registration and Service Delivery +3. Changes for supporting filters in Estimation Dashboard ## 1.0.0 - 2024-12-03 #### Resource Generator Service From e9b5c96580fd75d18d0d41e9d5b66bd26d0f36c8 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Thu, 30 Jan 2025 13:01:43 +0530 Subject: [PATCH 76/76] HCMPRE-1922 Changelog and pom.xml changes --- health-services/plan-service/CHANGELOG.md | 2 +- health-services/resource-generator/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/health-services/plan-service/CHANGELOG.md b/health-services/plan-service/CHANGELOG.md index 7400e92614..bacefd74a2 100644 --- a/health-services/plan-service/CHANGELOG.md +++ b/health-services/plan-service/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this module will be documented in this file. ## 1.0.1 - 2025-01-30 -1. Enabled support Mixed Distribution Strategy for Registration and Service Delivery +1. Enabled support for Mixed Distribution Strategy for Registration and Service Delivery 2. Adding additional search filters for Estimation Dashboard ## 1.0.0 - 2024-12-03 diff --git a/health-services/resource-generator/CHANGELOG.md b/health-services/resource-generator/CHANGELOG.md index 3a856828e7..fcc5d765bd 100644 --- a/health-services/resource-generator/CHANGELOG.md +++ b/health-services/resource-generator/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.0.1 - 2025-01-30 1. Enhancements for Microplan Estimation Downloadable Excel Report -2. Enabled support Mixed Distribution Strategy for Registration and Service Delivery +2. Enabled support for Mixed Distribution Strategy for Registration and Service Delivery 3. Changes for supporting filters in Estimation Dashboard ## 1.0.0 - 2024-12-03