From c4ba102badeabe3327b0dcbe159edd2fba0106e6 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Wed, 8 Jan 2025 16:15:45 +0530 Subject: [PATCH 01/13] 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 1dcb9bd1ae9..b7dfbf5d322 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 018a2652b42..3fbaa58ff47 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 330a391484e..18a5592c249 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 00000000000..d46111ceef8 --- /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 97c9810e0c5..01b8eec8af1 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 00000000000..d48f5077a75 --- /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 1a926cf7507bf328814f7c56fbb49bde3c14fed6 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 8 Jan 2025 17:19:58 +0530 Subject: [PATCH 02/13] 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 d0d8ce2500b..2a614db0ba6 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 ec0e93c8e8c8654f39574e76de4edb624f94d295 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 12:57:04 +0530 Subject: [PATCH 03/13] 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 3fbaa58ff47..b46414a2ccf 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 d46111ceef8..31f4faa1779 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 cec7afccb06..2b6149595b3 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 01b8eec8af1..97c9810e0c5 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 693ba12ef32..c33fd233ec9 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 04/13] 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 2b6149595b3..382cbea83d2 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 2d388cc744bc95899771282a1aa0df37e3c8df1d Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Thu, 9 Jan 2025 20:34:10 +0530 Subject: [PATCH 05/13] 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 8fe68badb93..caeb1371613 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 85b87872658..e9d7026ef02 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 e95cc887305..040d842670d 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 ec20dbd2bdc..4e34aa871d9 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 f895f6c75f1..8db4e8b6ec6 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 06/13] 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 2b989edb103..ad052ca93ce 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 8c69a08d23a05db6a1f035769918cdfbe3d2f0a4 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 13 Jan 2025 17:57:56 +0530 Subject: [PATCH 07/13] 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 9bfbe7cb62c..6665e411dea 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 8cc80556b185f3ee90a115f4a5e1edc23343e76f Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Mon, 20 Jan 2025 15:46:12 +0530 Subject: [PATCH 08/13] 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 527e2f06fba..3b014de22c6 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 4c5f3b3c8702e9a671ac360c1d0200fe85e2e906 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Tue, 21 Jan 2025 15:48:26 +0530 Subject: [PATCH 09/13] 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 24db89cb8e2..af945c1b5de 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 10/13] 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 1f49dc085e1..c0e08a02aa2 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 e9d7026ef02..5430e0e55c6 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 ce74288a820..f5f8ba1c4f1 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 54660efe6017c4118e344ee41e8f02d6d6204365 Mon Sep 17 00:00:00 2001 From: Tanishi Goyal Date: Wed, 22 Jan 2025 12:24:38 +0530 Subject: [PATCH 11/13] 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 31f4faa1779..0bfc1c49b5f 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 12/13] 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 cab79abd8fd..09ba679d818 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 3b014de22c6..3a37e0d04a7 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 af945c1b5de..2ca5b2c5c70 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 13/13] 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 3a37e0d04a7..f892f5a4053 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 6665e411dea..aa394c5a338 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. *