Skip to content

Commit

Permalink
Merge pull request #1320 from egovernments/HCMPRE-1729-new
Browse files Browse the repository at this point in the history
HCMPRE:1729 - Change the mdms master to adminSchemas in resource generator
  • Loading branch information
Priyanka-eGov authored Jan 9, 2025
2 parents 1ba656a + dad46a2 commit 99eed5c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ public class ServiceConstants {
public static final String FILE_NAME = "output.xls";
public static final String FILE_TYPE = "boundaryWithTarget";
public static final String FILE_TEMPLATE_IDENTIFIER_POPULATION = "Population";
public static final String FILE_TEMPLATE_IDENTIFIER_BOUNDARY = "boundaryWithTarget";
public static final String FILE_TEMPLATE_IDENTIFIER_FACILITY = "Facilities";
public static final String INPUT_IS_NOT_VALID = "File does not contain valid input for row ";

public static final String MDMS_SCHEMA_TYPE = "type";
public static final String MDMS_SCHEMA_SECTION = "section";
public static final String MDMS_SCHEMA_TITLE = "title";
public static final String MDMS_PLAN_MODULE_NAME = "hcm-microplanning";
public static final String MDMS_MASTER_SCHEMAS = "Schemas";
public static final String MDMS_MASTER_ADMIN_SCHEMA = "adminSchema";
public static final String MDMS_CAMPAIGN_TYPE = "campaignType";
public static final String MDMS_SCHEMA_ADMIN_SCHEMA = "adminSchema";
public static final String MDMS_ADMIN_CONSOLE_MODULE_NAME = "HCM-ADMIN-CONSOLE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ private Map<String, Object> prepareAttributeVsIndexMap(PlanConfigurationRequest
String fileStoreId, CampaignResponse campaign, PlanConfiguration planConfig, Object mdmsData) {
org.egov.processor.web.models.File file = planConfig.getFiles().stream()
.filter(f -> f.getFilestoreId().equalsIgnoreCase(fileStoreId)).findFirst().get();
return mdmsUtil.filterMasterData(mdmsData.toString(), file.getInputFileType(),
file.getTemplateIdentifier(), campaign.getCampaign().get(0).getProjectType());
return mdmsUtil.filterMasterData(mdmsData.toString(), campaign.getCampaign().get(0).getProjectType());
}


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


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.egov.processor.util;

import static org.egov.processor.config.ServiceConstants.ERROR_WHILE_FETCHING_FROM_MDMS;
import static org.egov.processor.config.ServiceConstants.NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE;
import static org.egov.processor.config.ServiceConstants.NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -31,6 +27,8 @@

import lombok.extern.slf4j.Slf4j;

import static org.egov.processor.config.ServiceConstants.*;

@Slf4j
@Component
public class MdmsUtil {
Expand All @@ -41,11 +39,14 @@ public class MdmsUtil {

private Configuration configs;

public MdmsUtil(RestTemplate restTemplate, ObjectMapper mapper, Configuration configs) {
private ParsingUtil parsingUtil;

public MdmsUtil(RestTemplate restTemplate, ObjectMapper mapper, Configuration configs, ParsingUtil parsingUtil) {
this.restTemplate = restTemplate;
this.mapper = mapper;
this.configs = configs;
}
this.parsingUtil = parsingUtil;
}

/**
* Fetches MDMS (Municipal Data Management System) data using the provided
Expand Down Expand Up @@ -74,7 +75,7 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) {
if (result == null || ObjectUtils.isEmpty(result)) {
log.error(NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_MESSAGE + " - " + tenantId);
throw new CustomException(NO_MDMS_DATA_FOUND_FOR_GIVEN_TENANT_CODE,
"no data found for the given tenantid "+tenantId + " for master name "+ServiceConstants.MDMS_MASTER_SCHEMAS);
"no data found for the given tenantid "+tenantId + " for master name "+ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA);
}
return result;
}
Expand All @@ -87,10 +88,9 @@ public Object fetchMdmsData(RequestInfo requestInfo, String tenantId) {
* @return The MDMS criteria request object.
*/
public MdmsCriteriaReq getMdmsRequest(RequestInfo requestInfo, String tenantId) {

ModuleDetail moduleDetail = getPlanModuleDetail();
ModuleDetail adminConsoleModuleDetail = getAdminConsoleModuleDetail();
List<ModuleDetail> moduleDetails = new LinkedList<>();
moduleDetails.add(moduleDetail);
moduleDetails.add(adminConsoleModuleDetail);
MdmsCriteria mdmsCriteria = MdmsCriteria.builder().moduleDetails(moduleDetails).tenantId(tenantId).build();
return MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build();
}
Expand All @@ -109,33 +109,53 @@ private ModuleDetail getPlanModuleDetail() {
.moduleName(ServiceConstants.MDMS_PLAN_MODULE_NAME).build();
}

/**
* Retrieves the module details for the HCM-ADMIN-CONSOLE module.
*
* @return ModuleDetail object containing master details for the HCM-ADMIN-CONSOLE module.
*/
private ModuleDetail getAdminConsoleModuleDetail() {
List<MasterDetail> adminSchemaMasterDetails = new ArrayList<>();
MasterDetail schemaDetails = MasterDetail.builder().name(ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA).build();
adminSchemaMasterDetails.add(schemaDetails);

return ModuleDetail.builder().masterDetails(adminSchemaMasterDetails)
.moduleName(ServiceConstants.MDMS_ADMIN_CONSOLE_MODULE_NAME).build();
}

/**
* Filters master data based on the provided parameters.
*
* @param masterDataJson The JSON string representing the master data.
* @param fileType The type of input file.
* @param templateIdentifier The template identifier.
* @param campaignType The campaign type.
* @return A map containing filtered properties from the master data.
* @throws JsonMappingException if there's an issue mapping JSON.
* @throws JsonProcessingException if there's an issue processing JSON.
*/
public Map<String, Object> filterMasterData(String masterDataJson, File.InputFileTypeEnum fileType,
String templateIdentifier, String campaignType) {
public Map<String, Object> filterMasterData(String masterDataJson, String campaignType) {
Map<String, Object> properties = new HashMap<>();
Map<String, Object> masterData = JsonUtils.parseJson(masterDataJson, Map.class);
Map<String, Object> planModule = (Map<String, Object>) masterData.get(ServiceConstants.MDMS_PLAN_MODULE_NAME);
List<Map<String, Object>> schemas = (List<Map<String, Object>>) planModule
.get(ServiceConstants.MDMS_MASTER_SCHEMAS);
log.info("masterDataJson ==>" + schemas);
for (Map<String, Object> schema : schemas) {
String type = (String) schema.get(ServiceConstants.MDMS_SCHEMA_TYPE);
Map<String, Object> adminConsoleModule = (Map<String, Object>) masterData.get(ServiceConstants.MDMS_ADMIN_CONSOLE_MODULE_NAME);
List<Map<String, Object>> adminSchema = (List<Map<String, Object>>) adminConsoleModule
.get(ServiceConstants.MDMS_MASTER_ADMIN_SCHEMA);
log.debug("masterDataJson ==> " + adminSchema);

for (Map<String, Object> schema : adminSchema) {
String campaign = (String) schema.get(ServiceConstants.MDMS_CAMPAIGN_TYPE);
// String fileT = InputFileTypeEnum.valueOf(type);
if (schema.get(ServiceConstants.MDMS_SCHEMA_SECTION).equals(ServiceConstants.FILE_TEMPLATE_IDENTIFIER_POPULATION)
&& campaign.equals(campaignType) && type.equals(fileType.toString())) {
Map<String, Object> schemaProperties = (Map<String, Object>) schema.get("schema");
properties = (Map<String, Object>) schemaProperties.get("Properties");

// Check if the schema's title matches the required template identifier
// and the campaign matches the specified campaign type.
if (schema.get(ServiceConstants.MDMS_SCHEMA_TITLE).equals(ServiceConstants.FILE_TEMPLATE_IDENTIFIER_BOUNDARY)
&& campaign.equals(MICROPLAN_PREFIX + campaignType)) {
Map<String, List<Object>> schemaProperties = (Map<String, List<Object>>) schema.get("properties");

schemaProperties.forEach((propertyType, propertyList) ->
// For each property in the property list, extract its name and add it to the map with the property.
propertyList.forEach(property -> {
String propertyName = (String) parsingUtil.extractFieldsFromJsonObject(property, "name");
properties.put(propertyName, property);
})
);
}
}

Expand Down

0 comments on commit 99eed5c

Please sign in to comment.