Skip to content

Commit

Permalink
HCMPRE-6407 download template changes (#1128)
Browse files Browse the repository at this point in the history
* HLM-6407 adding changes for facility template

* HLM-6407 adding changes for facility template

* HLM-6407 adding changes for facility template

* HLM-6407 codde review comment

* HCMPRE-91 code review comments

* HLM-6407 using same mdms schema for microplan

* HLM-6407 adding changes for facility template

* HLM-6407 adding changes for facility template

* HLM-6407 adding changes for facility template

* HLM-6407 codde review comment

* HCMPRE-91 code review comments

* HLM-6407 using same mdms schema for microplan

* HLM-6407 code review comments

* HLM-6407 code review comments
  • Loading branch information
Priyanka-eGov authored Jul 29, 2024
1 parent 8d3bd5b commit e610982
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 17 deletions.
33 changes: 29 additions & 4 deletions utilities/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { v4 as uuidv4 } from 'uuid';
import { httpRequest } from "../utils/request";
import { getFormattedStringForDebug, logger } from "../utils/logger";
import createAndSearch from '../config/createAndSearch';
import { getDataFromSheet, generateActivityMessage, throwError, translateSchema, replicateRequest } from "../utils/genericUtils";
import { getDataFromSheet, generateActivityMessage, throwError, translateSchema, replicateRequest, appendProjectTypeToCapacity } from "../utils/genericUtils";
import { immediateValidationForTargetSheet, validateSheetData, validateTargetSheetData } from '../validators/campaignValidators';
import { callMdmsTypeSchema, getCampaignNumber } from "./genericApis";
import { boundaryBulkUpload, convertToTypeData, generateHierarchy, generateProcessedFileAndPersist, getBoundaryOnWhichWeSplit, getLocalizedName, reorderBoundariesOfDataAndValidate } from "../utils/campaignUtils";
import { boundaryBulkUpload, convertToTypeData, generateHierarchy, generateProcessedFileAndPersist, getBoundaryOnWhichWeSplit, getLocalizedName, reorderBoundariesOfDataAndValidate, checkIfSourceIsMicroplan } from "../utils/campaignUtils";
const _ = require('lodash');
import { produceModifiedMessages } from "../kafka/Listener";
import { createDataService } from "../service/dataManageService";
Expand Down Expand Up @@ -730,7 +730,7 @@ async function performAndSaveResourceActivity(request: any, createAndSearchConfi
}
_.set(newRequestBody, createAndSearchConfig?.createBulkDetails?.createPath, chunkData);
creationTime = Date.now();
if (type == "facility") {
if (type == "facility" || type == "facilityMicroplan") {
await handeFacilityProcess(request, createAndSearchConfig, params, activities, newRequestBody);
}
else if (type == "user") {
Expand Down Expand Up @@ -843,14 +843,39 @@ async function processCreate(request: any, localizationMap?: any) {
boundaryBulkUpload(request, localizationMap);
}
else {
const createAndSearchConfig = createAndSearch[type]
// console.log(`Source is MICROPLAN -->`, source);
let createAndSearchConfig: any;
createAndSearchConfig = createAndSearch[type];
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignType = responseFromCampaignSearch?.CampaignDetails[0]?.projectType;
if (checkIfSourceIsMicroplan(request?.body?.ResourceDetails)) {
logger.info(`Data create Source is MICROPLAN`);
if (createAndSearchConfig?.parseArrayConfig?.parseLogic) {
createAndSearchConfig.parseArrayConfig.parseLogic = createAndSearchConfig.parseArrayConfig.parseLogic.map(
(item: any) => {
if (item.sheetColumn === "E") {
item.sheetColumnName += `_${campaignType}`;
}
return item;
}
);
}
}

const dataFromSheet = await getDataFromSheet(request, request?.body?.ResourceDetails?.fileStoreId, request?.body?.ResourceDetails?.tenantId, createAndSearchConfig, undefined, localizationMap)
let schema: any;

if (type == "facility") {
logger.info("Fetching schema to validate the created data for type: " + type);
const mdmsResponse = await callMdmsTypeSchema(request, tenantId, type);
schema = mdmsResponse
}
else if(type == "facilityMicroplan") {
const mdmsResponse = await callMdmsTypeSchema(request, tenantId, "facility", "microplan");
schema = mdmsResponse
logger.info("Appending project type to capacity for microplan " + campaignType);
schema = await appendProjectTypeToCapacity(schema, campaignType);
}
else if (type == "user") {
logger.info("Fetching schema to validate the created data for type: " + type);
const mdmsResponse = await callMdmsTypeSchema(request, tenantId, type);
Expand Down
6 changes: 1 addition & 5 deletions utilities/project-factory/src/server/api/genericApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ function getJsonData(sheetData: any, getRow = false, getSheetName = false, sheet
}

function validateFirstRowColumn(createAndSearchConfig: any, worksheet: any, localizationMap: any) {
if (
createAndSearchConfig &&
createAndSearchConfig.parseArrayConfig &&
createAndSearchConfig.parseArrayConfig.parseLogic
) {
if (createAndSearchConfig?.parseArrayConfig?.parseLogic) {
const parseLogic = createAndSearchConfig.parseArrayConfig.parseLogic;
// Iterate over each column configuration
for (const columnConfig of parseLogic) {
Expand Down
132 changes: 132 additions & 0 deletions utilities/project-factory/src/server/config/createAndSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,138 @@ const createAndSearch: any = {
searchPath: "Facilities"
}
},
"facilityMicroplan": {
requiresToSearchFromSheet: [
{
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
searchPath: "Facility.id"
}
],
boundaryValidation: {
column: "HCM_ADMIN_CONSOLE_BOUNDARY_CODE_MANDATORY"
},
sheetSchema: {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "FacilityTemplateSchema",
"type": "object",
"properties": {
"Facility Name": {
"type": "string",
"maxLength": 2000,
"minLength": 1
},
"Facility Type": {
// "type": "string",
"enum": ["Warehouse", "Health Facility", "Storing Resource"]
},
"Facility Status": {
// "type": "string",
"enum": ["Temporary", "Permanent"]
},
"Capacity": {
"type": "number",
"minimum": 1,
"maximum": 100000000
}
},
"required": [
"Facility Name",
"Facility Type",
"Facility Status",
"Capacity"
],
"unique": [
"Facility Name"
]
},
uniqueIdentifier: "id",
uniqueIdentifierColumn: "A",
activeColumn: "F",
activeColumnName: "HCM_ADMIN_CONSOLE_FACILITY_USAGE_MICROPLAN",
uniqueIdentifierColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
matchEachKey: true,
parseArrayConfig: {
sheetName: "HCM_ADMIN_CONSOLE_FACILITIES",
parseLogic: [
{
sheetColumn: "A",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
resultantPath: "id",
type: "string"
},
{
sheetColumn: "B",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_NAME_MICROPLAN",
resultantPath: "name",
type: "string"
},
{
sheetColumn: "C",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_TYPE_MICROPLAN",
resultantPath: "usage",
type: "string"
},
{
sheetColumn: "D",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_STATUS_MICROPLAN",
resultantPath: "isPermanent",
type: "boolean",
conversionCondition: {
"Permanent": "true",
"Temporary": ""
}
},
{
sheetColumn: "E",
sheetColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CAPACITY_MICROPLAN",
resultantPath: "storageCapacity",
type: "number"
},
{
sheetColumn: "J",
sheetColumnName: "HCM_ADMIN_CONSOLE_RESIDING_BOUNDARY_CODE_MICROPLAN"
}
],
tenantId: {
getValueViaPath: "ResourceDetails.tenantId",
resultantPath: "tenantId"
}
},
createBulkDetails: {
limit: 50,
createPath: "Facilities",
url: config.host.facilityHost + "facility/v1/bulk/_create"
},
searchDetails: {
searchElements: [
{
keyPath: "tenantId",
getValueViaPath: "ResourceDetails.tenantId",
isInParams: true,
isInBody: false,
},
{
keyPath: "Facility",
isInParams: false,
isInBody: true,
}
],
searchLimit: {
keyPath: "limit",
value: "200",
isInParams: true,
isInBody: false,
},
searchOffset: {
keyPath: "offset",
value: "0",
isInParams: true,
isInBody: false,
},
url: config.host.facilityHost + "facility/v1/_search",
searchPath: "Facilities"
}
},
"boundary": {
parseArrayConfig: {
sheetName: "HCM_ADMIN_CONSOLE_BOUNDARY_CODE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const createRequestSchema = {
"properties": {
"type": {
"type": "string",
"enum": ["boundary", "facility", "user", "boundaryWithTarget"]
"enum": ["boundary", "facility", "user", "boundaryWithTarget","facilityMicroplan"]
},
"tenantId": {
"type": "string",
Expand Down
4 changes: 2 additions & 2 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,8 @@ async function getBoundaryOnWhichWeSplit(request: any) {
}


function checkIfSourceIsMicroplan(campaignObject: any): boolean {
return campaignObject?.additionalDetails?.source === 'microplan';
function checkIfSourceIsMicroplan(objectWithAdditionalDetails: any): boolean {
return objectWithAdditionalDetails?.additionalDetails?.source === 'microplan';
}


Expand Down
83 changes: 78 additions & 5 deletions utilities/project-factory/src/server/utils/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,23 @@ async function createFacilitySheet(request: any, allFacilities: any[], localizat
const tenantId = request?.query?.tenantId;
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const isSourceMicroplan = checkIfSourceIsMicroplan(responseFromCampaignSearch?.CampaignDetails?.[0]);
let schema: any;
let schema;
if (isSourceMicroplan) {
schema = await callMdmsTypeSchema(request, tenantId, "facility", "microplan");
} else {
schema = await callMdmsTypeSchema(request, tenantId, "facility");
schema = await callMdmsTypeSchema(request, tenantId, "facility", "all");
}
const keys = schema?.columns;
setDropdownFromSchema(request, schema, localizationMap);
const headers = ["HCM_ADMIN_CONSOLE_FACILITY_CODE", ...keys]
const localizedHeaders = getLocalizedHeaders(headers, localizationMap);
let localizedHeaders;
if (isSourceMicroplan) {
localizedHeaders = getLocalizedHeadersForMicroplan(responseFromCampaignSearch, headers, localizationMap);

}
else {
localizedHeaders = getLocalizedHeaders(headers, localizationMap);
}
const facilities = allFacilities.map((facility: any) => {
return [
facility?.id,
Expand Down Expand Up @@ -577,6 +583,21 @@ function getLocalizedHeaders(headers: any, localizationMap?: { [key: string]: st
return messages;
}

function getLocalizedHeadersForMicroplan(responseFromCampaignSearch: any, headers: any, localizationMap?: { [key: string]: string }) {

const projectType = responseFromCampaignSearch?.CampaignDetails?.[0]?.projectType;

headers = headers.map((header: string) => {
if (header === 'HCM_ADMIN_CONSOLE_FACILITY_CAPACITY_MICROPLAN') {
return `${header}_${projectType}`;
}
return header;
});

const messages = headers.map((header: any) => (localizationMap ? localizationMap[header] || header : header));
return messages;
}



function modifyRequestForLocalisation(request: any, tenantId: string) {
Expand Down Expand Up @@ -1086,7 +1107,15 @@ function getDifferentDistrictTabs(boundaryData: any, differentTabsBasedOnLevel:

async function getConfigurableColumnHeadersFromSchemaForTargetSheet(request: any, hierarchy: any, boundaryData: any, differentTabsBasedOnLevel: any, campaignObject: any, localizationMap?: any) {
const districtIndex = hierarchy.indexOf(differentTabsBasedOnLevel);
var headers = getLocalizedHeaders(hierarchy.slice(districtIndex), localizationMap);
let headers: any;
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
if (isSourceMicroplan) {
logger.info(`Source is Microplan.`);
headers = getLocalizedHeaders(hierarchy, localizationMap);
}
else {
headers = getLocalizedHeaders(hierarchy.slice(districtIndex), localizationMap);
}
const headerColumnsAfterHierarchy = await generateDynamicTargetHeaders(request, campaignObject, localizationMap);
const localizedHeadersAfterHierarchy = getLocalizedHeaders(headerColumnsAfterHierarchy, localizationMap);
headers = [...headers, getLocalizedName(config?.boundary?.boundaryCode, localizationMap), ...localizedHeadersAfterHierarchy]
Expand All @@ -1105,6 +1134,49 @@ async function getMdmsDataBasedOnCampaignType(request: any, localizationMap?: an
}


function appendProjectTypeToCapacity(schema: any, projectType: string): any {
const updatedSchema = JSON.parse(JSON.stringify(schema)); // Deep clone the schema

const capacityKey = 'HCM_ADMIN_CONSOLE_FACILITY_CAPACITY_MICROPLAN';
const newCapacityKey = `${capacityKey}_${projectType}`;

// Update properties
if (updatedSchema.properties[capacityKey]) {
updatedSchema.properties[newCapacityKey] = {
...updatedSchema.properties[capacityKey],
name: `${updatedSchema.properties[capacityKey].name}_${projectType}`
};
delete updatedSchema.properties[capacityKey];
}

// Update required
updatedSchema.required = updatedSchema.required.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

// Update columns
updatedSchema.columns = updatedSchema.columns.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

// Update unique
updatedSchema.unique = updatedSchema.unique.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

// Update errorMessage
if (updatedSchema.errorMessage[capacityKey]) {
updatedSchema.errorMessage[newCapacityKey] = updatedSchema.errorMessage[capacityKey];
delete updatedSchema.errorMessage[capacityKey];
}

// Update columnsNotToBeFreezed
updatedSchema.columnsNotToBeFreezed = updatedSchema.columnsNotToBeFreezed.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

return updatedSchema;
}


export {
Expand Down Expand Up @@ -1152,7 +1224,8 @@ export {
getConfigurableColumnHeadersFromSchemaForTargetSheet,
createBoundaryDataMainSheet,
getMdmsDataBasedOnCampaignType,
shutdownGracefully
shutdownGracefully,
appendProjectTypeToCapacity
};


0 comments on commit e610982

Please sign in to comment.