Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCMPRE-1808 adding changes for Mixed Strategy #1331

Merged
merged 17 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class Resource {
private String resourceType = null;

@JsonProperty("estimatedNumber")
@NotNull
private BigDecimal estimatedNumber = null;

@JsonProperty("activityCode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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";
Expand All @@ -86,13 +88,16 @@ public class ServiceConstants {
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_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 = ".";
public static final String MICROPLAN_PREFIX = "MP-";
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,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;
Expand Down Expand Up @@ -69,11 +71,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;
Expand All @@ -88,6 +92,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore
this.enrichmentUtil = enrichmentUtil;
this.planConfigurationUtil = planConfigurationUtil;
this.outputEstimationGenerationUtil = outputEstimationGenerationUtil;
this.mixedStartegyUtil = mixedStartegyUtil;
this.planFacilityUtil = planFacilityUtil;
}

Expand Down Expand Up @@ -243,10 +248,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<String, String> boundaryCodeToFixedPostMap = fetchFixedPostDetails(request, excelWorkbook, fileStoreId);

enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues);
}
}
Expand All @@ -256,17 +257,14 @@ 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<String, String> fetchFixedPostDetails(PlanConfigurationRequest request, Workbook excelWorkbook, String fileStoreId) {
private Map<String, Boolean> 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<String, String> boundaryCodeToFacilityNameMap = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(excelWorkbook, request, fileStoreId);

//Create plan facility search request
PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder()
.requestInfo(request.getRequestInfo())
Expand All @@ -283,19 +281,24 @@ private Map<String, String> fetchFixedPostDetails(PlanConfigurationRequest reque
}

// Create a Boundary Code to Facility's fixed post detail map.
Map<String, String> boundaryCodeToFixedPostMap = new HashMap<>();
Map<String, Boolean> 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 are 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);
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved

// Populate the map.
boundaryCodeToFixedPostMap.put(boundaryCode, fixedPostValue);
}
// Normalize the value and determine boolean equivalent.
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
Boolean isFixedPost = !ObjectUtils.isEmpty(fixedPostValue) && fixedPostValue.trim().equalsIgnoreCase(FIXED_POST_YES);

// Populate the map with boundary code and isFixedPost.
planFacility.getServiceBoundaries().forEach((String boundary) ->
boundaryCodeToFixedPostMap.put(boundary, isFixedPost)
);
}
}
return boundaryCodeToFixedPostMap;
}

Expand All @@ -318,8 +321,10 @@ private Map<String, String> fetchFixedPostDetails(PlanConfigurationRequest reque
* @throws IOException If an I/O error occurs.
*/
private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List<Boundary> campaignBoundaryList, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, Map<String, Object> boundaryCodeToCensusAdditionalDetails) {
PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration();
performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, boundaryCodeToCensusAdditionalDetails);

// Create a Map of Boundary Code to Facility's fixed post detail.
Map<String, Boolean> boundaryCodeToFixedPostMap = fetchFixedPostDetails(planConfigurationRequest, sheet, fileStoreId);
performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, boundaryCodeToFixedPostMap, boundaryCodeToCensusAdditionalDetails);
}

private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, String hierarchyType) {
Expand Down Expand Up @@ -401,14 +406,15 @@ private Map<String, Object> 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<Boundary> campaignBoundaryList,
PlanConfiguration planConfig, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, Map<String, Object> boundaryCodeToCensusAdditionalDetails) {
Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList,
Map<String, Boolean> boundaryCodeToFixedPostMap, Map<String, Object> boundaryCodeToCensusAdditionalDetails) {
Row firstRow = null;
PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration();
Map<String, String> mappedValues = planConfig.getResourceMapping().stream()
.filter(f -> f.getFilestoreId().equals(fileStoreId))
.collect(Collectors.toMap(ResourceMapping::getMappedTo, ResourceMapping::getMappedFrom));
Expand All @@ -419,6 +425,9 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat
Integer indexOfBoundaryCode = parsingUtil.getIndexOfBoundaryCode(0,
parsingUtil.sortColumnByIndex(mapOfColumnNameAndIndex), mappedValues);

List<MixedStrategyOperationLogic> mixedStrategyOperationLogicList = mixedStartegyUtil
.fetchMixedStrategyOperationLogicFromMDMS(planConfigurationRequest);

for (Row row : sheet) {
if(parsingUtil.isRowEmpty(row))
continue;
Expand All @@ -434,9 +443,10 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat
JsonNode feature = createFeatureNodeFromRow(row, mapOfColumnNameAndIndex);
performCalculationsOnOperations(sheet, planConfig, row, resultMap, mappedValues,
assumptionValueMap, feature);
if (config.isIntegrateWithAdminConsole())
campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues,
mapOfColumnNameAndIndex, campaignBoundaryList, resultMap);

// 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));
planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, boundaryCodeToCensusAdditionalDetails);

}
Expand Down Expand Up @@ -787,6 +797,6 @@ public List<String> getAllBoundaryPresentforHierarchyType(List<EnrichedBoundary>
}
return boundaryList;
}


}
Loading
Loading