Skip to content

Commit

Permalink
added changes for configurable column in target sheet (#779)
Browse files Browse the repository at this point in the history
* change in filter recursive

* lowest level

* made target headers  genearte through mdms schema

* changed config index.ts

* changed config index.ts

* changes for now

* added configurable column logic from schema HLM-6169

* updated validate of target columns through schema

* added masterForColumnSchema in index.ts

* formatted dataManageService

* refactored lock TargetFields func

* removed console.log
  • Loading branch information
nitish-egov committed Jun 5, 2024
1 parent 705c59c commit b395579
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 118 deletions.
29 changes: 14 additions & 15 deletions utilities/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,20 +833,19 @@ const getHeadersOfBoundarySheet = async (fileUrl: string, sheetName: string, get
}


async function getFiltersFromCampaignSearchResponse(request: any) {
logger.info(`searching for campaign details to get the filters for boundary generation`);
const requestInfo = { "RequestInfo": request?.body?.RequestInfo };
const campaignDetails = { "CampaignDetails": { tenantId: request?.query?.tenantId, "ids": [request?.query?.campaignId] } }
const requestBody = { ...requestInfo, ...campaignDetails };
const req: any = replicateRequest(request, requestBody)
const projectTypeSearchResponse: any = await searchProjectTypeCampaignService(req);
const boundaries = projectTypeSearchResponse?.CampaignDetails?.[0]?.boundaries?.map((ele: any) => ({ ...ele, boundaryType: ele?.type }));
if (!boundaries) {
logger.info(`no boundaries found so considering the complete hierarchy`);
return { Filters: null };
}
logger.info(`boundaries found for filtering`);
return { Filters: { boundaries: boundaries } };
async function getCampaignSearchResponse(request: any) {
try {
logger.info(`searching for campaign details`);
const requestInfo = { "RequestInfo": request?.body?.RequestInfo };
const campaignDetails = { "CampaignDetails": { tenantId: request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, "ids": [request?.query?.campaignId || request?.body?.ResourceDetails?.campaignId] } }
const requestBody = { ...requestInfo, ...campaignDetails };
const req: any = replicateRequest(request, requestBody)
const projectTypeSearchResponse: any = await searchProjectTypeCampaignService(req);
return projectTypeSearchResponse;
} catch (error: any) {
logger.error(`Error while searching for campaign details: ${error.message}`);
throwError("COMMON", 400, "RESPONSE_NOT_FOUND_ERROR", error?.message)
}
}

export {
Expand All @@ -864,6 +863,6 @@ export {
getHierarchy,
getHeadersOfBoundarySheet,
handleResouceDetailsError,
getFiltersFromCampaignSearchResponse,
getCampaignSearchResponse,
confirmProjectParentCreation
};
48 changes: 40 additions & 8 deletions utilities/project-factory/src/server/api/genericApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { httpRequest } from "../utils/request"; // Import httpRequest function f
import { getFormattedStringForDebug, logger } from "../utils/logger"; // Import logger for logging
import { correctParentValues, findMapValue, generateActivityMessage, getBoundaryRelationshipData, getDataSheetReady, getLocalizedHeaders, sortCampaignDetails, throwError } from "../utils/genericUtils"; // Import utility functions
import { validateProjectFacilityResponse, validateProjectResourceResponse, validateStaffResponse } from "../validators/genericValidator"; // Import validation functions
import { extractCodesFromBoundaryRelationshipResponse, generateFilteredBoundaryData, getLocalizedName } from '../utils/campaignUtils'; // Import utility functions
import { getFiltersFromCampaignSearchResponse, getHierarchy } from './campaignApis';
import { extractCodesFromBoundaryRelationshipResponse, generateFilteredBoundaryData, getConfigurableColumnHeadersBasedOnCampaignType, getFiltersFromCampaignSearchResponse, getLocalizedName } from '../utils/campaignUtils'; // Import utility functions
import { getCampaignSearchResponse, getHierarchy } from './campaignApis';
import { validateMappingId } from '../utils/campaignMappingUtils';
import { campaignStatuses } from '../config/constants';
const _ = require('lodash'); // Import lodash library
Expand Down Expand Up @@ -559,10 +559,12 @@ async function getBoundarySheetData(
const modifiedHierarchy = hierarchy.map((ele) =>
`${hierarchyType}_${ele}`.toUpperCase()
);
const localizedHeaders = getLocalizedHeaders(
const localizedHeadersUptoHierarchy = getLocalizedHeaders(
modifiedHierarchy,
localizationMap
);
const headerColumnsAfterHierarchy = await getConfigurableColumnHeadersBasedOnCampaignType(request,localizationMap);
const headers = [...localizedHeadersUptoHierarchy,...headerColumnsAfterHierarchy];
// create empty sheet if no boundary present in system
// const localizedBoundaryTab = getLocalizedName(
// getBoundaryTabName(),
Expand All @@ -571,16 +573,17 @@ async function getBoundarySheetData(
logger.info(`generated a empty template for boundary`);
return await createExcelSheet(
boundaryData,
localizedHeaders
headers
);
} else {
// logger.info("boundaryData for sheet " + JSON.stringify(boundaryData))
const responseFromCampaignSearch =
await getFiltersFromCampaignSearchResponse(request);
if (responseFromCampaignSearch?.Filters != null) {
await getCampaignSearchResponse(request);
const FiltersFromCampaignId = getFiltersFromCampaignSearchResponse(responseFromCampaignSearch)
if (FiltersFromCampaignId?.Filters != null) {
const filteredBoundaryData = await generateFilteredBoundaryData(
request,
responseFromCampaignSearch
FiltersFromCampaignId
);
return await getDataSheetReady(
filteredBoundaryData,
Expand All @@ -592,6 +595,7 @@ async function getBoundarySheetData(
}
}
}

async function createStaff(resouceBody: any) {
// Create staff
const staffCreateUrl =
Expand Down Expand Up @@ -979,6 +983,33 @@ async function callMdmsData(
return response;
}



async function callMdmsV2Data(
request: any,
moduleName: string,
masterName: string,
tenantId: string, filters: any) {
try {
const { RequestInfo = {} } = request?.body || {};
const requestBody = {
RequestInfo,
MdmsCriteria: {
tenantId: tenantId,
filters,
schemaCode: moduleName + "." + config?.masterNameForSchemaOfColumnHeaders,
limit: 10,
offset: 0
},
};
const url = config.host.mdmsV2 + config.paths.mdms_v2_search;
const response = await httpRequest(url, requestBody, { tenantId: tenantId });
return response;
} catch (error: any) {
throwError("MDMS", 400, "MDMS_DATA_NOT_FOUND_ERROR", `Mdms Data not found for ${moduleName}"-"${masterName}`)
}
}

async function callMdmsSchema(
request: any,
moduleName: string,
Expand Down Expand Up @@ -1028,5 +1059,6 @@ export {
getTargetSheetData,
callMdmsData,
getMDMSV1Data,
callMdmsSchema
callMdmsSchema,
callMdmsV2Data
}
10 changes: 7 additions & 3 deletions utilities/project-factory/src/server/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export const CONSTANTS: any = {
VALIDATION_ERROR: "Validation error",
INTERNAL_SERVER_ERROR: "Internal server error",
INVALID_PAGINATION: "Invalid pagination",
KAFKA_ERROR: "Some error occured in kafka"
KAFKA_ERROR: "Some error occured in kafka",
SCHEMA_ERROR : " Schema related error",
RESPONSE_NOT_FOUND_ERROR: "Response not found"
},
FILE: {
INVALID_FILE: "No download URL returned for the given fileStoreId",
Expand All @@ -18,7 +20,8 @@ export const CONSTANTS: any = {
INVALID_FILE_ERROR: "Invalid file",
DOWNLOAD_URL_NOT_FOUND: "Not any download URL returned for the given fileStoreId",
INVALID_FILE_FORMAT: "The uploaded file is not a valid excel file (xlsx or xls).",
INVALID_COLUMNS: "Columns are invalid"
INVALID_COLUMNS: "Columns are invalid",
FETCHING_COLUMN_ERROR: "Error fetching Column Headers From Schema"
},
FACILITY: {
FACILITY_SEARCH_FAILED: "Search failed for facility. Check logs",
Expand Down Expand Up @@ -50,7 +53,8 @@ export const CONSTANTS: any = {
PROJECT_CONFIRMATION_FAILED: "Error occured in project creation and peristence",
},
MDMS: {
INVALID_README_CONFIG: "Invalid readme config"
INVALID_README_CONFIG: "Invalid readme config",
MDMS_DATA_NOT_FOUND_ERROR: "Mdms Data not present"
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion utilities/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (!HOST) {
}
// Configuration object containing various environment variables
const config = {
masterNameForSchemaOfColumnHeaders: "boundary",
boundary: {
boundaryCode: process.env.BOUNDARY_CODE_HEADER_NAME || "HCM_ADMIN_CONSOLE_BOUNDARY_CODE",
boundaryTab: process.env.BOUNDARY_TAB_NAME || "HCM_ADMIN_CONSOLE_BOUNDARY_DATA",
Expand Down Expand Up @@ -110,7 +111,8 @@ const config = {
localizationCreate: "localization/messages/v1/_upsert",
projectTypeSearch: "project-factory/v1/project-type/search",
boundaryRelationshipCreate: "boundary-service/boundary-relationships/_create",
mdmsV2SchemaSearch: "mdms-v2/schema/v1/_search"
mdmsV2SchemaSearch: "mdms-v2/schema/v1/_search",
mdms_v2_search: "mdms-v2/v2/_search",
},
// Values configuration
values: {
Expand Down
45 changes: 25 additions & 20 deletions utilities/project-factory/src/server/service/dataManageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,38 @@ const downloadDataService = async (request: express.Request) => {
}

const getBoundaryDataService = async (
request: express.Request
) => {
const workbook=getNewExcelWorkbook();
const { hierarchyType } = request?.query;
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType));
const localizationMapModule = await getLocalizedMessagesHandler(request, request?.query?.tenantId);
const localizationMap = { ...localizationMapHierarchy, ...localizationMapModule };
// Retrieve boundary sheet data
const boundarySheetData: any = await getBoundarySheetData(request, localizationMap);
request: express.Request) => {
try {
const workbook = getNewExcelWorkbook();
const { hierarchyType } = request?.query;
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType));
const localizationMapModule = await getLocalizedMessagesHandler(request, request?.query?.tenantId);
const localizationMap = { ...localizationMapHierarchy, ...localizationMapModule };
// Retrieve boundary sheet data
const boundarySheetData: any = await getBoundarySheetData(request, localizationMap);

const localizedBoundaryTab = getLocalizedName(getBoundaryTabName(), localizationMap);
const boundarySheet = workbook.addWorksheet(localizedBoundaryTab);
addDataToSheet(boundarySheet, boundarySheetData);
const BoundaryFileDetails: any = await createAndUploadFile(workbook, request);
// Return boundary file details
logger.info("RETURNS THE BOUNDARY RESPONSE");
return BoundaryFileDetails;
const localizedBoundaryTab = getLocalizedName(getBoundaryTabName(), localizationMap);
const boundarySheet = workbook.addWorksheet(localizedBoundaryTab);
addDataToSheet(boundarySheet, boundarySheetData);
const BoundaryFileDetails: any = await createAndUploadFile(workbook, request);
// Return boundary file details
logger.info("RETURNS THE BOUNDARY RESPONSE");
return BoundaryFileDetails;
} catch (e: any) {
logger.error(String(e))
// Handle errors and send error response
throw (e);
}
};


const createDataService = async (request: any) => {
// Validate the create request
await validateCreateRequest(request);
logger.info("VALIDATED THE DATA CREATE REQUEST");


const localizationMap = await getLocalizedMessagesHandler(request, request?.body?.ResourceDetails?.tenantId);
// Validate the create request
logger.info("Validating data create request")
await validateCreateRequest(request, localizationMap);
logger.info("VALIDATED THE DATA CREATE REQUEST");

// Enrich resource details
await enrichResourceDetails(request);
Expand Down
Loading

0 comments on commit b395579

Please sign in to comment.