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:1767 - Resource generator - add Village accessibility details from census into plans #1308

Open
wants to merge 12 commits into
base: HCMPRE-1768
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public enum DataTypeEnum {

MULTIVALUELIST("MultiValueList"),

FILE("File"),

BOOLEAN("Boolean");
FILE("File");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private PlanRequestDTO convertToPlanReqDTO(PlanRequest planRequest) {
.assignee(assignee)
.additionalDetails(plan.getAdditionalDetails())
.jurisdictionMapping(plan.getJurisdictionMapping())
.additionalFields(plan.getAdditionalFields())
.activities(plan.getActivities())
.resources(plan.getResources())
.targets(plan.getTargets())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public PlanQueryBuilder(Configuration config, QueryUtil queryUtil) {
"\t plan_activity.id as plan_activity_id, plan_activity.code as plan_activity_code, plan_activity.description as plan_activity_description, plan_activity.planned_start_date as plan_activity_planned_start_date, plan_activity.planned_end_date as plan_activity_planned_end_date, plan_activity.dependencies as plan_activity_dependencies, plan_activity.plan_id as plan_activity_plan_id, plan_activity.created_by as plan_activity_created_by, plan_activity.created_time as plan_activity_created_time, plan_activity.last_modified_by as plan_activity_last_modified_by, plan_activity.last_modified_time as plan_activity_last_modified_time,\n" +
"\t plan_activity_condition.id as plan_activity_condition_id, plan_activity_condition.entity as plan_activity_condition_entity, plan_activity_condition.entity_property as plan_activity_condition_entity_property, plan_activity_condition.expression as plan_activity_condition_expression, plan_activity_condition.activity_id as plan_activity_condition_activity_id, plan_activity_condition.is_active as plan_activity_condition_is_active, plan_activity_condition.created_by as plan_activity_condition_created_by, plan_activity_condition.created_time as plan_activity_condition_created_time, plan_activity_condition.last_modified_by as plan_activity_condition_last_modified_by, plan_activity_condition.last_modified_time as plan_activity_condition_last_modified_time,\n" +
"\t plan_resource.id as plan_resource_id, plan_resource.resource_type as plan_resource_resource_type, plan_resource.estimated_number as plan_resource_estimated_number, plan_resource.plan_id as plan_resource_plan_id, plan_resource.activity_code as plan_resource_activity_code, plan_resource.created_by as plan_resource_created_by, plan_resource.created_time as plan_resource_created_time, plan_resource.last_modified_by as plan_resource_last_modified_by, plan_resource.last_modified_time as plan_resource_last_modified_time,\n" +
"\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time\n" +
"\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time, \n" +
"\t paf.id as plan_additional_field_id, paf.plan_id as plan_additional_field_plan_id, paf.key as plan_additional_field_key, paf.value as plan_additional_field_value, paf.show_on_ui as plan_additional_field_show_on_ui, paf.editable as plan_additional_field_editable, paf.order as plan_additional_field_order \n" +
"\t FROM plan \n" +
"\t LEFT JOIN plan_activity ON plan.id = plan_activity.plan_id\n" +
"\t LEFT JOIN plan_activity_condition ON plan_activity.id = plan_activity_condition.activity_id\n" +
"\t LEFT JOIN plan_resource ON plan.id = plan_resource.plan_id\n" +
"\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id";
"\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id\n" +
"\t LEFT JOIN plan_additional_field paf ON plan.id = paf.plan_id";

private static final String BULK_PLAN_UPDATE_QUERY = "UPDATE plan SET status = ?, assignee = ?, last_modified_by = ?, last_modified_time = ? WHERE id = ?";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public List<Plan> extractData(ResultSet rs) throws SQLException, DataAccessExcep
Set<String> conditionSet = new HashSet<>();
Set<String> resourceSet = new HashSet<>();
Set<String> targetSet = new HashSet<>();
Set<String> additionalFieldSet = new HashSet<>();

// Traverse through result set and create plan objects
while (rs.next()) {
Expand All @@ -43,6 +44,7 @@ public List<Plan> extractData(ResultSet rs) throws SQLException, DataAccessExcep
conditionSet.clear();
resourceSet.clear();
targetSet.clear();
additionalFieldSet.clear();

// Prepare audit details
AuditDetails auditDetails = AuditDetails.builder()
Expand Down Expand Up @@ -72,6 +74,7 @@ public List<Plan> extractData(ResultSet rs) throws SQLException, DataAccessExcep
addActivities(rs, planEntry, activityMap, conditionSet);
addResources(rs, planEntry, resourceSet);
addTargets(rs, planEntry, targetSet);
addAdditionalField(rs, planEntry, additionalFieldSet);
planMap.put(planId, planEntry);
}

Expand Down Expand Up @@ -234,4 +237,39 @@ private void addTargets(ResultSet rs, Plan planEntry, Set<String> targetSet) thr
targetSet.add(target.getId());

}

/**
* Adds a AdditionalField object to the plan entry based on the result set.
*
* @param rs The ResultSet containing the data.
* @param additionalFieldSet A set to keep track of added AdditionalField objects.
* @param planEntry The Plan entry to which the AdditionalField object will be added.
* @throws SQLException If an SQL error occurs.
*/
private void addAdditionalField(ResultSet rs, Plan planEntry, Set<String> additionalFieldSet) throws SQLException {
String additionalFieldId = rs.getString("plan_additional_field_id");

if (ObjectUtils.isEmpty(additionalFieldId) || additionalFieldSet.contains(additionalFieldId)) {
return;
}

AdditionalField additionalField = new AdditionalField();
additionalField.setId(rs.getString("plan_additional_field_id"));
additionalField.setKey(rs.getString("plan_additional_field_key"));
additionalField.setValue(rs.getBigDecimal("plan_additional_field_value"));
additionalField.setShowOnUi(rs.getBoolean("plan_additional_field_show_on_ui"));
additionalField.setEditable(rs.getBoolean("plan_additional_field_editable"));
additionalField.setOrder(rs.getInt("plan_additional_field_order"));

if (CollectionUtils.isEmpty(planEntry.getAdditionalFields())) {
List<AdditionalField> additionalFields = new ArrayList<>();
additionalFields.add(additionalField);
planEntry.setAdditionalFields(additionalFields);
} else {
planEntry.getAdditionalFields().add(additionalField);
}

additionalFieldSet.add(additionalFieldId);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package digit.service;

import digit.repository.PlanRepository;
import digit.service.enrichment.PlanEnricher;
import digit.service.validator.PlanValidator;
import digit.service.workflow.WorkflowService;
import digit.web.models.*;
import org.egov.common.contract.response.ResponseInfo;
import org.egov.common.utils.ResponseInfoUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package digit.service;
package digit.service.enrichment;

import digit.web.models.*;
import digit.web.models.boundary.BoundaryTypeHierarchy;
Expand Down Expand Up @@ -54,6 +54,10 @@ public void enrichPlanCreate(PlanRequest body) {
// Generate id for targets
body.getPlan().getTargets().forEach(target -> UUIDEnrichmentUtil.enrichRandomUuid(target, "id"));

// Generate id for additional fields
if(!CollectionUtils.isEmpty(body.getPlan().getAdditionalFields()))
body.getPlan().getAdditionalFields().forEach(additionalField -> UUIDEnrichmentUtil.enrichRandomUuid(additionalField, "id"));

// Enrich audit details
body.getPlan().setAuditDetails(AuditDetailsEnrichmentUtil
.prepareAuditDetails(body.getPlan().getAuditDetails(), body.getRequestInfo(), Boolean.TRUE));
Expand Down Expand Up @@ -108,6 +112,13 @@ public void enrichPlanUpdate(PlanRequest body) {
}
});

// Generate uuid for new additionalFields
body.getPlan().getAdditionalFields().forEach(additionalFields -> {
if(ObjectUtils.isEmpty(additionalFields.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id");
}
});

// Enriching last modified time for update
body.getPlan().getAuditDetails().setLastModifiedTime(System.currentTimeMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import digit.util.BoundaryUtil;
import digit.util.CensusUtil;
import digit.util.CommonUtil;
import digit.web.models.PlanFacility;
import digit.web.models.PlanFacilityRequest;
import digit.web.models.PlanFacilitySearchCriteria;
import digit.web.models.PlanFacilitySearchRequest;
import digit.web.models.*;
import digit.web.models.boundary.BoundarySearchResponse;
import digit.web.models.boundary.EnrichedBoundary;
import digit.web.models.census.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package digit.service;
package digit.service.validator;

import com.jayway.jsonpath.JsonPath;
import digit.config.Configuration;
import digit.repository.PlanConfigurationRepository;
import digit.repository.PlanRepository;
import digit.service.PlanEmployeeService;
import digit.service.enrichment.PlanEnricher;
import digit.util.BoundaryUtil;
import digit.util.CampaignUtil;
import digit.util.CommonUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package digit.web.models.census;
package digit.web.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class Plan {
@JsonProperty("jurisdictionMapping")
private Map<String, String> jurisdictionMapping;

@JsonProperty("additionalFields")
@Valid
private List<AdditionalField> additionalFields = null;

@JsonIgnore
private String boundaryAncestralPath = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class PlanDTO {
@JsonProperty("jurisdictionMapping")
private Map<String, String> jurisdictionMapping;

@JsonProperty("additionalFields")
@Valid
private List<AdditionalField> additionalFields = null;

@JsonProperty("activities")
@Valid
private List<Activity> activities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.List;

import digit.web.models.AdditionalField;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Table: plan_additional_field
CREATE TABLE plan_additional_field (
id character varying(64) NOT NULL,
plan_id character varying(64) NOT NULL,
"key" character varying(64) NOT NULL,
"value" numeric(12,2) NOT NULL,
show_on_ui boolean DEFAULT true NOT NULL,
editable boolean DEFAULT true NOT NULL,
"order" bigint NOT NULL,
CONSTRAINT uk_plan_additional_field_id PRIMARY KEY (id),
FOREIGN KEY (plan_id) REFERENCES plan(id)
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import digit.models.coremodels.mdms.MasterDetail;
import digit.models.coremodels.mdms.MdmsCriteria;
import digit.models.coremodels.mdms.MdmsCriteriaReq;
import digit.models.coremodels.mdms.ModuleDetail;
import lombok.extern.slf4j.Slf4j;
import org.egov.common.contract.request.RequestInfo;
import org.egov.common.http.client.ServiceRequestClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class ServiceConstants {
public static final String BOUNDARY = "boundary";
public static final String DOT_SEPARATOR = ".";
public static final String MICROPLAN_PREFIX = "MP-";
public static final String ACCESSIBILITY_DETAILS = "accessibilityDetails";
public static final String SECURITY_DETAILS = "securityDetails";

//MDMS field Constants
public static final String DATA = "data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId,
excelWorkbook.forEach(excelWorkbookSheet -> {
if (isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) {
if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) {
Map<String, String> BCodeToFacilityDetails = new HashMap<>();
Map<String, Object> BCodeToCensusAdditionalDetails = new HashMap<>();

enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToFacilityDetails);
enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToCensusAdditionalDetails);
processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId,
campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails);
campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToCensusAdditionalDetails);
} else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerCensusRecordsStatus())) {
processRowsForCensusRecords(request, excelWorkbookSheet,
fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType());
Expand Down Expand Up @@ -248,9 +248,9 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId,
* @param boundaryCodeList List of boundary codes.
* @throws IOException If an I/O error occurs.
*/
private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List<Boundary> campaignBoundaryList, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, Map<String, String> BCodeToFacilityDetails) {
private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List<Boundary> campaignBoundaryList, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, Map<String, Object> BCodeToCensusAdditionalDetails) {
PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration();
performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails);
performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToCensusAdditionalDetails);
}

private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, String hierarchyType) {
Expand Down Expand Up @@ -341,7 +341,7 @@ private Map<String, Object> prepareAttributeVsIndexMap(PlanConfigurationRequest
*/
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, String> BCodeToFacilityDetails) {
PlanConfiguration planConfig, Map<String, Object> attributeNameVsDataTypeMap, List<String> boundaryCodeList, Map<String, Object> BCodeToCensusAdditionalDetails) {
Row firstRow = null;
Map<String, String> mappedValues = planConfig.getResourceMapping().stream()
.filter(f -> f.getFilestoreId().equals(fileStoreId))
Expand Down Expand Up @@ -371,8 +371,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat
if (config.isIntegrateWithAdminConsole())
campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues,
mapOfColumnNameAndIndex, campaignBoundaryList, resultMap);
planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToFacilityDetails));

planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToCensusAdditionalDetails));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void enrichResourceMapping(PlanConfigurationRequest request, LocaleRespon

}

public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map<String, String> mappedValues, Map<String, String> BCodeToFacilityDetails) {
public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map<String, String> mappedValues, Map<String, Object> BCodeToCensusAdditionalDetails) {
List<String> boundaryCodes = getBoundaryCodesFromTheSheet(sheet, planConfigurationRequest, fileStoreId);

Map<String, Integer> mapOfColumnNameAndIndex = parsingUtil.getAttributeNameIndexFromExcel(sheet);
Expand Down Expand Up @@ -144,9 +144,7 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR
}
}

String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(census.getAdditionalDetails(), FACILITY_NAME);
if(facilityName != null && !facilityName.isEmpty())
BCodeToFacilityDetails.put(boundaryCode, facilityName);
BCodeToCensusAdditionalDetails.put(boundaryCode, census.getAdditionalDetails());
}

log.info("Successfully update file with approved census data.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ public Object extractFieldsFromJsonObject(Object additionalDetails, String field
return node.asBoolean();
} else if (node.isTextual()) {
return node.asText();
} else if (node.isObject()) {
return objectMapper.convertValue(node, Map.class); // Return the object node as a Map
}
}
return null;
Expand Down
Loading
Loading