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:1782 - Plan-facility integration to fetch fixedPost details #1325

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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]+)?$";
Expand Down Expand Up @@ -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_";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -79,6 +87,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore
this.enrichmentUtil = enrichmentUtil;
this.planConfigurationUtil = planConfigurationUtil;
this.outputEstimationGenerationUtil = outputEstimationGenerationUtil;
this.planFacilityUtil = planFacilityUtil;
}

/**
Expand Down Expand Up @@ -230,12 +239,46 @@ 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 the map of boundary code to the facility assigned to that boundary.
Map<String, String> boundaryCodeToFacility = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(excelWorkbook, request, fileStoreId);
Map<String, String> facilityToFixedPost = fetchFixedPostDetails(request, boundaryCodeToFacility);
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved

enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues);
}
}
});
}

/**
* 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.
* @return returns a map of boundary code to it's fixed post facility details.
*/
private Map<String, String> fetchFixedPostDetails(PlanConfigurationRequest request, Map<String, String> boundaryCodeToFacility) {
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
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);
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved

// Create and return a map of facility name to fixed post details
return planFacilityResponse.getPlanFacility().stream()
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
.collect(Collectors.toMap(
planFacility -> findByValue(boundaryCodeToFacility, 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ
LinkedHashMap::new
));

// Get the map of boundary code to the facility assigned to that boundary.
// Create the map of boundary code to the facility assigned to that boundary.
Map<String, String> boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId);

// Iterate through all sheets in the workbook.
Expand All @@ -160,7 +160,7 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ
* @param fileStoreId the associated file store ID for filtering.
* @return a map of boundary codes to their assigned facility names.
*/
private Map<String, String> getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) {
public Map<String, String> getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) {
List<String> boundaryCodes = new ArrayList<>();

// Iterate through all sheets in the workbook.
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved

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())) {
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
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.
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
* @return
*/
private StringBuilder getPlanFacilitySearchUri() {
return new StringBuilder().append(config.getPlanConfigHost()).append(config.getPlanFacilitySearchEndPoint());
}
}
Original file line number Diff line number Diff line change
@@ -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<String> serviceBoundaries;

@JsonIgnore
private List<String> initiallySetServiceBoundaries;

@JsonProperty("jurisdictionMapping")
private Map<String, String> 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;
}



}
Original file line number Diff line number Diff line change
@@ -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> planFacility = null;

@JsonProperty("TotalCount")
@Valid
private Integer totalCount = null;
}
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> residingBoundaries = null;

@JsonProperty("jurisdiction")
private List<String> jurisdiction = null;

@JsonProperty("facilityId")
private String facilityId = null;

@JsonProperty("offset")
private Integer offset = null;

@JsonProperty("limit")
private Integer limit = null;

@JsonIgnore
private Map<String, String> filtersMap = null;

}
Loading
Loading