Skip to content

Commit

Permalink
Updated few loggers (#759)
Browse files Browse the repository at this point in the history
* updated few loggers flow

* Update utilities/project-factory/src/server/api/campaignApis.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update utilities/project-factory/src/server/utils/campaignMappingUtils.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update utilities/project-factory/src/server/utils/campaignUtils.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update utilities/project-factory/src/server/validators/campaignValidators.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update utilities/project-factory/src/server/api/campaignApis.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update utilities/project-factory/src/server/utils/campaignMappingUtils.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update utilities/project-factory/src/server/utils/genericUtils.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
jagankumar-egov and coderabbitai[bot] authored May 31, 2024
1 parent 2bd4928 commit e34a1a7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
17 changes: 8 additions & 9 deletions utilities/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ async function getFacilitiesViaIds(tenantId: string, ids: any[], requestBody: an
for (let i = 0; i < ids.length; i += 50) {
const chunkIds = ids.slice(i, i + 50);
facilitySearchBody.Facility.id = chunkIds;
logger.info("facilitySearchBody : " + JSON.stringify(facilitySearchBody));
await getAllFacilitiesInLoop(searchedFacilities, facilitySearchParams, facilitySearchBody);
}

Expand Down Expand Up @@ -200,7 +199,6 @@ function updateErrors(newCreatedData: any[], newSearchedData: any[], errors: any
for (const searchedElement of newSearchedData) {
let match = true;
for (const key in createdElement) {
// console.log(key, createdElement[key], searchedElement[key], " ssssssssssssssssssssssssssssssssss");
if (createdElement.hasOwnProperty(key) && !searchedElement.hasOwnProperty(key) && key != '!row#number!') {
match = false;
break;
Expand Down Expand Up @@ -269,7 +267,7 @@ async function getUserWithMobileNumbers(request: any, mobileNumbers: any[]) {
tenantId: request?.body?.ResourceDetails?.tenantId,
includeDeleted: true
};

logger.info("Individual search to validate the mobile no initiated");
const response = await httpRequest(config.host.healthIndividualHost + "health-individual/v1/_search", searchBody, params);

if (!response) {
Expand All @@ -284,7 +282,7 @@ async function getUserWithMobileNumbers(request: any, mobileNumbers: any[]) {

// Convert the results array to a Set to eliminate duplicates
const resultSet = new Set(allResults);
logger.info("Already Exsisted mobile numbers : " + JSON.stringify(resultSet));
logger.info(`Already Existing mobile numbers : ${JSON.stringify(resultSet)}`);
return resultSet;
}

Expand Down Expand Up @@ -515,8 +513,7 @@ async function enrichEmployees(employees: any[], request: any) {
}

async function performAndSaveResourceActivity(request: any, createAndSearchConfig: any, params: any, type: any, localizationMap?: { [key: string]: string }) {
logger.info(type + " create data : " + JSON.stringify(request?.body?.dataToCreate));
logger.info(type + " bulk create url : " + createAndSearchConfig?.createBulkDetails?.url, params);
logger.info(type + " create data " );
if (createAndSearchConfig?.createBulkDetails?.limit) {
const limit = createAndSearchConfig?.createBulkDetails?.limit;
const dataToCreate = request?.body?.dataToCreate;
Expand All @@ -541,7 +538,6 @@ async function performAndSaveResourceActivity(request: any, createAndSearchConfi
for (const facility of newRequestBody.Facilities) {
facility.address = {}
}
logger.info("Facility create data : " + JSON.stringify(newRequestBody));
var responsePayload = await httpRequest(createAndSearchConfig?.createBulkDetails?.url, newRequestBody, params, "post", undefined, undefined, true);
}
else if (type == "user") {
Expand All @@ -558,7 +554,7 @@ async function performAndSaveResourceActivity(request: any, createAndSearchConfi
throw e;
}
var activity = await generateActivityMessage(request?.body?.ResourceDetails?.tenantId, request.body, newRequestBody, responsePayload, type, createAndSearchConfig?.createBulkDetails?.url, responsePayload?.statusCode)
logger.info("Activity : " + JSON.stringify(activity));
logger.info(`Activity : ${createAndSearchConfig?.createBulkDetails?.url} status: ${responsePayload?.statusCode}` );
activities.push(activity);
}
await new Promise(resolve => setTimeout(resolve, 5000));
Expand Down Expand Up @@ -639,11 +635,14 @@ async function processCreate(request: any, localizationMap?: any) {
const dataFromSheet = await getDataFromSheet(request, request?.body?.ResourceDetails?.fileStoreId, request?.body?.ResourceDetails?.tenantId, createAndSearchConfig, undefined, localizationMap)
let schema: any;
if (type == "facility" || type == "user") {
logger.info("Fetching schema to validate the created data for type: " + type);
const mdmsResponse = await callMdmsSchema(request, config?.values?.moduleName, type, tenantId);
schema = mdmsResponse
}
logger.info("translating schema")
const translatedSchema = await translateSchema(schema, localizationMap);
await validateSheetData(dataFromSheet, request, translatedSchema, createAndSearchConfig?.boundaryValidation, localizationMap)
await validateSheetData(dataFromSheet, request, translatedSchema, createAndSearchConfig?.boundaryValidation, localizationMap);
logger.info("validation done sucessfully")
processAfterValidation(dataFromSheet, createAndSearchConfig, request, localizationMap)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createAndSearch from "../config/createAndSearch";
import config from "../config";
import { getDataFromSheet, throwError } from "./genericUtils";
import { logger } from "./logger";
import { getFormattedStringForDebug, logger } from "./logger";
import { httpRequest } from "./request";
import { produceModifiedMessages } from "../kafka/Listener";
import { getLocalizedName } from "./campaignUtils";
Expand Down Expand Up @@ -83,12 +83,11 @@ async function enrichBoundaryWithProject(messageObject: any, boundaryWithProject
limit: 100,
includeDescendants: true
}
logger.info("projectSearchBody : " + JSON.stringify(projectSearchBody));
logger.info("params : " + JSON.stringify(params));
logger.info("boundaryCodes : " + JSON.stringify(boundaryCodes));
const response = await httpRequest(config.host.projectHost + "health-project/v1/_search", projectSearchBody, params);
await createBoundaryWithProjectMapping(response?.Project, boundaryWithProject);
logger.info("boundaryWithProject mapping : " + JSON.stringify(boundaryWithProject));
logger.debug(`boundaryWise Project mapping : ${getFormattedStringForDebug(boundaryWithProject)}`);
logger.info("boundaryCodes mapping : " + JSON.stringify(boundaryCodes));
}

Expand Down Expand Up @@ -141,9 +140,9 @@ async function fetchAndMap(resources: any[], messageObject: any) {
var boundaryWithProject: any = {};
await enrichBoundaryWithProject(messageObject, boundaryWithProject, boundaryCodes);
const projectMappingBody = await getProjectMappingBody(messageObject, boundaryWithProject, boundaryCodes);
logger.info("projectMappingBody : " + JSON.stringify(projectMappingBody));
logger.info("projectMapping started ");
const projectMappingResponse: any = await createCampaignService(projectMappingBody);
logger.info("Project Mapping Response : " + JSON.stringify(projectMappingResponse));
logger.info("Project Mapping Response received");
if (projectMappingResponse) {
logger.info("Campaign Mapping done")
messageObject.CampaignDetails.status = campaignStatuses.inprogress
Expand Down Expand Up @@ -172,7 +171,6 @@ async function validateMappingId(messageObject: any, id: string) {
}
}
const response: any = await httpRequest(config.host.projectFactoryBff + "project-factory/v1/project-type/search", searchBody);
logger.info("searchBody for campaign search : " + JSON.stringify(searchBody));
if (!response?.CampaignDetails?.[0]) {
throwError("COMMON", 400, "INTERNAL_SERVER_ERROR", "Campaign with id " + id + " does not exist");
}
Expand All @@ -196,7 +194,8 @@ async function processCampaignMapping(messageObject: any) {
var retry = 30;
while (retry--) {
const response = await searchResourceDetailsById(resourceDetailId, messageObject);
logger.info(`response for resourceDetailId ${resourceDetailId} : ` + JSON.stringify(response));
logger.info(`response for resourceDetailId: ${resourceDetailId}`);
logger.debug(` response : ${getFormattedStringForDebug(response)}`)
if (response?.status == "invalid") {
logger.error(`resource with id ${resourceDetailId} is invalid`);
throwError("COMMON", 400, "INTERNAL_SERVER_ERROR", "resource with id " + resourceDetailId + " is invalid");
Expand Down
10 changes: 5 additions & 5 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ async function generateProcessedFileAndPersist(request: any, localizationMap?: {
additionalDetails: { ...request?.body?.ResourceDetails?.additionalDetails, sheetErrors: request?.body?.additionalDetailsErrors } || {}
};
produceModifiedMessages(request?.body, config?.kafka?.KAFKA_UPDATE_RESOURCE_DETAILS_TOPIC);
logger.info("ResourceDetails to persist : " + JSON.stringify(request?.body?.ResourceDetails));
logger.info(`ResourceDetails to persist : ${request.body.ResourceDetails.type}`);
if (request?.body?.Activities && Array.isArray(request?.body?.Activities && request?.body?.Activities.length > 0)) {
logger.info("Activities to persist : " + JSON.stringify(request?.body?.Activities));
logger.info("Activities to persist : " )
logger.debug(getFormattedStringForDebug(request?.body?.Activities));
await new Promise(resolve => setTimeout(resolve, 2000));
produceModifiedMessages(request?.body, config?.kafka?.KAFKA_CREATE_RESOURCE_ACTIVITY_TOPIC);
}
Expand Down Expand Up @@ -526,7 +527,8 @@ async function persistForCampaignProjectMapping(request: any, createResourceDeta
requestBody.CampaignDetails = request?.body?.CampaignDetails
requestBody.CampaignDetails.campaignDetails = updatedInnerCampaignDetails
requestBody.localizationMap = localizationMap
logger.info("Persisting CampaignProjectMapping : " + JSON.stringify(requestBody));
logger.info("Persisting CampaignProjectMapping...");
logger.debug(`CampaignProjectMapping: ${getFormattedStringForDebug(requestBody)}`);
produceModifiedMessages(requestBody, config?.kafka?.KAFKA_START_CAMPAIGN_MAPPING_TOPIC);
}
}
Expand Down Expand Up @@ -1087,8 +1089,6 @@ async function getRelatedProjects(request: any) {
includeDescendants: true
}
logger.info("Project search params " + JSON.stringify(projectSearchParams))
logger.info("Project search body " + JSON.stringify(projectSearchBody))
logger.info("Project search url " + config?.host?.projectHost + config?.paths?.projectSearch)
const projectSearchResponse = await httpRequest(config?.host?.projectHost + config?.paths?.projectSearch, projectSearchBody, projectSearchParams);
if (projectSearchResponse?.Project && Array.isArray(projectSearchResponse?.Project) && projectSearchResponse?.Project?.length > 0) {
return convertToProjectsArray(projectSearchResponse?.Project)
Expand Down
3 changes: 2 additions & 1 deletion utilities/project-factory/src/server/utils/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ async function createFacilitySheet(request: any, allFacilities: any[], localizat
""
]
})
logger.info("facilities : " + JSON.stringify(facilities));
logger.info("facilities generation done ");
logger.debug(`facility response ${JSON.stringify(facilities)}`)
const localizedFacilityTab = getLocalizedName(config?.facility?.facilityTab, localizationMap);
const facilitySheetData: any = await createExcelSheet(facilities, localizedHeaders, localizedFacilityTab);
return facilitySheetData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function validateUniqueBoundaries(uniqueBoundaries: any[], request: any) {

async function validateBoundaryData(data: any[], request: any, boundaryColumn: any) {
const boundarySet = new Set(); // Create a Set to store unique boundaries

logger.info("validating for the boundary data")
data.forEach((element, index) => {
const boundaries = element[boundaryColumn];
if (!boundaries) {
Expand Down Expand Up @@ -829,7 +829,7 @@ async function validateById(request: any) {
const searchResponse: any = await searchProjectTypeCampaignService(req)
if (Array.isArray(searchResponse?.CampaignDetails)) {
if (searchResponse?.CampaignDetails?.length > 0) {
logger.info("CampaignDetails : " + JSON.stringify(searchResponse?.CampaignDetails));
logger.debug(`CampaignDetails : ${getFormattedStringForDebug(searchResponse?.CampaignDetails)}`);
request.body.ExistingCampaignDetails = searchResponse?.CampaignDetails[0];
if (action != "changeDates") {
if (request.body.ExistingCampaignDetails?.status != campaignStatuses?.drafted) {
Expand Down

0 comments on commit e34a1a7

Please sign in to comment.