Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HLM-6407-template' into test-cam…
Browse files Browse the repository at this point in the history
…paign-changes
  • Loading branch information
ashish-egov committed Jul 24, 2024
2 parents df26406 + c72c7d7 commit 0564766
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 19 deletions.
38 changes: 34 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,44 @@ async function processCreate(request: any, localizationMap?: any) {
boundaryBulkUpload(request, localizationMap);
}
else {
const createAndSearchConfig = createAndSearch[type]
const source = request?.body?.ResourceDetails?.additionalDetails?.source;
// 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(source)) {
logger.info(`Data create Source is MICROPLAN --> ${source}`);
if (
createAndSearchConfig &&
createAndSearchConfig.parseArrayConfig &&
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", "HCM-ADMIN-CONSOLE.adminSchemaMicroplan");
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
7 changes: 5 additions & 2 deletions utilities/project-factory/src/server/api/genericApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,17 +1205,20 @@ async function callMdmsTypeSchema(
request: any,
tenantId: string,
type: any,
campaignType = "all"
campaignType: string = "all",
additionalParam?: string
) {
const { RequestInfo = {} } = request?.body || {};
const schemaCode = additionalParam && additionalParam.trim() !== "" ? additionalParam : "HCM-ADMIN-CONSOLE.adminSchema";

const requestBody = {
RequestInfo,
MdmsCriteria: {
tenantId: tenantId,
uniqueIdentifiers: [
`${type}.${campaignType}`
],
schemaCode: "HCM-ADMIN-CONSOLE.adminSchema"
schemaCode: schemaCode
}
};
const url = config.host.mdmsV2 + config.paths.mdms_v2_search;
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
8 changes: 4 additions & 4 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ async function appendSheetsToWorkbook(request: any, boundaryData: any[], differe
const [mainSheetData, uniqueDistrictsForMainSheet, districtLevelRowBoundaryCodeMap] = createBoundaryDataMainSheet(request, boundaryData, differentTabsBasedOnLevel, hierarchy, localizationMap)
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0];
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject?.additionalDetails?.source);
if (!(isSourceMicroplan)) {
const mainSheet = workbook.addWorksheet(getLocalizedName(getBoundaryTabName(), localizationMap));
const columnWidths = Array(12).fill(30);
Expand Down Expand Up @@ -1777,7 +1777,7 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async (request: any, loc
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0];
let campaignType = campaignObject?.projectType;
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject);
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject?.additionalDetails?.source);
campaignType = (isSourceMicroplan) ? `${config?.prefixForMicroplanCampaigns}-${campaignType}` : campaignType;
const mdmsResponse = await callMdmsTypeSchema(request, request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, request?.query?.type || request?.body?.ResourceDetails?.type, campaignType)
if (!mdmsResponse || mdmsResponse?.columns.length === 0) {
Expand Down Expand Up @@ -1838,8 +1838,8 @@ async function getBoundaryOnWhichWeSplit(request: any) {
}


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


Expand Down
Loading

0 comments on commit 0564766

Please sign in to comment.