Skip to content

Commit

Permalink
User usage column changes (#1293)
Browse files Browse the repository at this point in the history
* Ashish egov patch 1 (#1280)

* Update campaignApis.ts

* Update campaignUtils.ts (#1279)

* Update publishProjectFactory.yml (#1281)

* feat: Add parentId and isActive columns to eg_cm_campaign_details, re… (#1285)

feat: Add parentId and isActive columns to eg_cm_campaign_details, remove unique constraint on campaignName

* Usage user column (#1291)

* Update campaignApis.ts (#1278)

* Update campaignApis.ts

* Update campaignUtils.ts (#1279)

* feat: Add parentId and isActive columns to eg_cm_campaign_details, remove unique constraint on campaignName

* Feat : adding usage column in user create

* User mapping campaign (#1292)

* feat: Add parentId and isActive columns to eg_cm_campaign_details, remove unique constraint on campaignName

* Fix : user mapping

* Update publishProjectFactory.yml (#1294)

* Update utilities/project-factory/src/server/validators/campaignValidators.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
ashish-egov and coderabbitai[bot] authored Aug 16, 2024
1 parent 529a1bb commit 0a419be
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE eg_cm_campaign_details
ADD COLUMN "parentId" character varying(128);

ALTER TABLE eg_cm_campaign_details
ADD COLUMN "isActive" boolean;

ALTER TABLE eg_cm_campaign_details
DROP CONSTRAINT eg_cm_campaign_details_campaignName_key;

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Drop the columns if they exist
ALTER TABLE eg_cm_campaign_details
DROP COLUMN IF EXISTS "parentId";

ALTER TABLE eg_cm_campaign_details
DROP COLUMN IF EXISTS "isActive";

-- Add the columns with lowercase names
ALTER TABLE eg_cm_campaign_details
ADD COLUMN parentid character varying(128);

ALTER TABLE eg_cm_campaign_details
ADD COLUMN isactive boolean;
1 change: 1 addition & 0 deletions utilities/project-factory/src/server/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const CONSTANTS: any = {
RESOURCE_CREATION_ERROR: "Some error occured during resource creation",
CAMPAIGN_NAME_ERROR: "Campaign name already exists",
CAMPAIGN_ALREADY_MAPPED: "Campaign is already mapped",
PARENT_CAMPAIGN_ERROR: "Parent campaign not found",
},
BOUNDARY: {
BOUNDARY_DATA_NOT_FOUND: "No boundary data found in the system.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ const createAndSearch: any = {
}
},
uniqueIdentifier: "user.userServiceUuid",
uniqueIdentifierColumn: "H",
uniqueIdentifierColumn: "I",
uniqueIdentifierColumnName: "UserService Uuids",
activeColumn: "F",
activeColumnName: "HCM_ADMIN_CONSOLE_USER_USAGE",
createBulkDetails: {
limit: 50,
createPath: "Employees",
Expand Down
2 changes: 1 addition & 1 deletion utilities/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getDBSchemaName = (dbSchema = "") => {
}
// Configuration object containing various environment variables
const config = {
cacheTime : 300,
cacheTime: 300,
enableDynamicTemplateFor: process.env.ENABLE_DYNAMIC_TEMPLATE_FOR || "",
isCallGenerateWhenDeliveryConditionsDiffer: (process.env.IS_CALL_GENERATE_WHEN_DELIVERY_CONDITIONS_DIFFER === "true") || false,
prefixForMicroplanCampaigns: "MP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const campaignDetailsSchema = {
},
"action": {
"type": "string",
"enum": ["create", "draft", "changeDates"],
"enum": ["create", "draft"],
"maxLength": 64,
"minLength": 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const searchCampaignDetailsSchema = {
"campaignNumber": {
"type": "string"
},
"isActive": {
"type": "boolean"
},
"pagination": {
"type": "object",
"properties": {
Expand Down
5 changes: 2 additions & 3 deletions utilities/project-factory/src/server/kafka/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ export function listener() {
try {
const messageObject = JSON.parse(message.value?.toString() || '{}');

logger.info(`KAFKA :: LISTENER :: Received a message from topic ${message.topic}`);
logger.debug(`KAFKA :: LISTENER :: Message: ${getFormattedStringForDebug(messageObject)}`);
switch (message.topic) {
case config.kafka.KAFKA_START_CAMPAIGN_MAPPING_TOPIC:
await handleCampaignMapping(messageObject);
break;
default:
logger.warn(`Unhandled topic: ${message.topic}`);
}

logger.info(`KAFKA :: LISTENER :: Received a message from topic ${message.topic}`);
logger.debug(`KAFKA :: LISTENER :: Message: ${getFormattedStringForDebug(messageObject)}`);
} catch (error) {
logger.error(`KAFKA :: LISTENER :: Error processing message: ${error}`);
console.error(error);
Expand Down
167 changes: 92 additions & 75 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,32 +190,32 @@ function deterMineLastColumnAndEnrichUserDetails(worksheet: any, errorDetailsCol
}

if (userNameAndPassword) {
worksheet.getCell("I1").value = "UserName";
worksheet.getCell("J1").value = "Password";
worksheet.getCell("J1").value = "UserName";
worksheet.getCell("K1").value = "Password";

// Set the fill color to green for cell I1
worksheet.getCell("I1").fill = {
worksheet.getCell("J1").fill = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'ff9248' } // Green color
};
worksheet.getCell("I1").font = { bold: true };
worksheet.getCell("J1").font = { bold: true };

// Set the fill color to green for cell J1
worksheet.getCell("J1").fill = {
worksheet.getCell("K1").fill = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'ff9248' } // Green color
};
worksheet.getCell("J1").font = { bold: true };
worksheet.getCell("K1").font = { bold: true };

userNameAndPassword.forEach((data: any) => {
const rowIndex = data.rowNumber;
worksheet.getCell(`I${rowIndex}`).value = data?.userName;
worksheet.getCell(`J${rowIndex}`).value = data?.password;
worksheet.getCell(`J${rowIndex}`).value = data?.userName;
worksheet.getCell(`K${rowIndex}`).value = data?.password;
});

lastColumn = "J";
lastColumn = "K";
request.body.userNameAndPassword = undefined;
}

Expand Down Expand Up @@ -490,7 +490,7 @@ async function generateProcessedFileAndPersist(request: any, localizationMap?: {
}
}

function getRootBoundaryCode(boundaries: any[] = []) {
export function getRootBoundaryCode(boundaries: any[] = []) {
for (const boundary of boundaries) {
if (boundary.isRoot) {
return boundary.code;
Expand Down Expand Up @@ -564,6 +564,8 @@ async function enrichAndPersistCampaignForCreate(request: any, firstPersist: boo
request.body.CampaignDetails.additionalDetails = request?.body?.CampaignDetails?.additionalDetails || {};
request.body.CampaignDetails.startDate = request?.body?.CampaignDetails?.startDate || null
request.body.CampaignDetails.endDate = request?.body?.CampaignDetails?.endDate || null
request.body.CampaignDetails.isActive = true
request.body.CampaignDetails.parentId = request?.body?.CampaignDetails?.parentId || null
request.body.CampaignDetails.auditDetails = {
createdBy: request?.body?.RequestInfo?.userInfo?.uuid,
createdTime: Date.now(),
Expand Down Expand Up @@ -606,7 +608,7 @@ async function enrichAndPersistCampaignForUpdate(request: any, firstPersist: boo
enrichInnerCampaignDetails(request, updatedInnerCampaignDetails)
request.body.CampaignDetails.campaignNumber = ExistingCampaignDetails?.campaignNumber
request.body.CampaignDetails.campaignDetails = updatedInnerCampaignDetails
request.body.CampaignDetails.status = action == "changeDates" ? request.body.CampaignDetails.status : (action == "create" ? campaignStatuses.started : campaignStatuses.drafted);
request.body.CampaignDetails.status = action == "create" ? campaignStatuses.started : campaignStatuses.drafted;
const boundaryCode = !(request?.body?.CampaignDetails?.projectId) ? getRootBoundaryCode(request.body.CampaignDetails.boundaries) : (request?.body?.CampaignDetails?.boundaryCode || ExistingCampaignDetails?.boundaryCode)
request.body.CampaignDetails.boundaryCode = boundaryCode
request.body.CampaignDetails.startDate = request?.body?.CampaignDetails?.startDate || ExistingCampaignDetails?.startDate || null
Expand Down Expand Up @@ -635,6 +637,18 @@ async function enrichAndPersistCampaignForUpdate(request: any, firstPersist: boo
delete request.body.CampaignDetails.campaignDetails
}

async function makeParentInactive(request: any) {
let parentCampaign = request?.body?.parentCampaign
parentCampaign.isActive = false
parentCampaign.campaignDetails = { deliveryRules: parentCampaign?.deliveryRules || [], resources: parentCampaign?.resources || [], boundaries: parentCampaign?.boundaries || [] };
parentCampaign.auditDetails.lastModifiedTime = Date.now()
parentCampaign.auditDetails.lastModifiedBy = request?.body?.RequestInfo?.userInfo?.uuid
const produceMessage: any = {
CampaignDetails: parentCampaign
}
await produceModifiedMessages(produceMessage, config?.kafka?.KAFKA_UPDATE_PROJECT_CAMPAIGN_DETAILS_TOPIC);
}

function getCreateResourceIds(resources: any[]) {
return resources
.filter((resource: any) => typeof resource.createResourceId === 'string' && resource.createResourceId.trim() !== '')
Expand Down Expand Up @@ -688,6 +702,9 @@ async function enrichAndPersistProjectCampaignForFirst(request: any, actionInUrl
else if (actionInUrl == "update") {
await enrichAndPersistCampaignForUpdate(request, firstPersist)
}
if (request?.body?.parentCampaign?.isActive) {
await makeParentInactive(request)
}
if (request?.body?.CampaignDetails?.action == "create") {
await createProcessTracks(request.body.CampaignDetails.id)
}
Expand Down Expand Up @@ -1221,69 +1238,69 @@ async function reorderBoundaries(request: any, localizationMap?: any) {
logger.debug("Reordered Boundaries " + getFormattedStringForDebug(request?.body?.CampaignDetails?.boundaries));
}

function convertToProjectsArray(Projects: any, currentArray: any = []) {
for (const project of Projects) {
const descendants = project?.descendants
delete project?.descendants
currentArray.push(project);
if (descendants && Array.isArray(descendants) && descendants?.length > 0) {
convertToProjectsArray(descendants, currentArray)
}
}
return currentArray;
}

async function getRelatedProjects(request: any) {
const { projectId, tenantId } = request?.body?.CampaignDetails;
const projectSearchBody = {
RequestInfo: request?.body?.RequestInfo,
Projects: [
{
id: projectId,
tenantId: tenantId
}
]
}
const projectSearchParams = {
tenantId: tenantId,
offset: 0,
limit: 1,
includeDescendants: true
}
logger.info("Project search params " + JSON.stringify(projectSearchParams))
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)
}
else {
throwError("PROJECT", 500, "PROJECT_SEARCH_ERROR")
return []
}
}

async function updateProjectDates(request: any, actionInUrl: any) {
const { startDate, endDate, projectId } = request?.body?.CampaignDetails
if ((startDate || endDate) && projectId && actionInUrl == "update") {
const projects = await getRelatedProjects(request);
for (const project of projects) {
project.startDate = startDate || project.startDate;
project.endDate = endDate || project.endDate;
delete project?.address;
}
logger.info("Projects related to current Campaign : " + JSON.stringify(projects));
const projectUpdateBody = {
RequestInfo: request?.body?.RequestInfo,
Projects: projects
}
const projectUpdateResponse = await httpRequest(config?.host?.projectHost + config?.paths?.projectUpdate, projectUpdateBody);
if (projectUpdateResponse?.Project && Array.isArray(projectUpdateResponse?.Project) && projectUpdateResponse?.Project?.length == projects?.length) {
logger.info("Project dates updated successfully")
}
else {
throwError("PROJECT", 500, "PROJECT_UPDATE_ERROR")
}
}
}
// function convertToProjectsArray(Projects: any, currentArray: any = []) {
// for (const project of Projects) {
// const descendants = project?.descendants
// delete project?.descendants
// currentArray.push(project);
// if (descendants && Array.isArray(descendants) && descendants?.length > 0) {
// convertToProjectsArray(descendants, currentArray)
// }
// }
// return currentArray;
// }

// async function getRelatedProjects(request: any) {
// const { projectId, tenantId } = request?.body?.CampaignDetails;
// const projectSearchBody = {
// RequestInfo: request?.body?.RequestInfo,
// Projects: [
// {
// id: projectId,
// tenantId: tenantId
// }
// ]
// }
// const projectSearchParams = {
// tenantId: tenantId,
// offset: 0,
// limit: 1,
// includeDescendants: true
// }
// logger.info("Project search params " + JSON.stringify(projectSearchParams))
// 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)
// }
// else {
// throwError("PROJECT", 500, "PROJECT_SEARCH_ERROR")
// return []
// }
// }

// async function updateProjectDates(request: any, actionInUrl: any) {
// const { startDate, endDate, projectId } = request?.body?.CampaignDetails
// if ((startDate || endDate) && projectId && actionInUrl == "update") {
// const projects = await getRelatedProjects(request);
// for (const project of projects) {
// project.startDate = startDate || project.startDate;
// project.endDate = endDate || project.endDate;
// delete project?.address;
// }
// logger.info("Projects related to current Campaign : " + JSON.stringify(projects));
// const projectUpdateBody = {
// RequestInfo: request?.body?.RequestInfo,
// Projects: projects
// }
// const projectUpdateResponse = await httpRequest(config?.host?.projectHost + config?.paths?.projectUpdate, projectUpdateBody);
// if (projectUpdateResponse?.Project && Array.isArray(projectUpdateResponse?.Project) && projectUpdateResponse?.Project?.length == projects?.length) {
// logger.info("Project dates updated successfully")
// }
// else {
// throwError("PROJECT", 500, "PROJECT_UPDATE_ERROR")
// }
// }
// }

async function getCodesTarget(request: any, localizationMap?: any) {
const { tenantId, resources } = request?.body?.CampaignDetails;
Expand Down Expand Up @@ -1365,7 +1382,7 @@ async function processAfterPersist(request: any, actionInUrl: any) {
await enrichAndPersistProjectCampaignRequest(request, actionInUrl, false, localizationMap)
}
else {
await updateProjectDates(request, actionInUrl);
// await updateProjectDates(request, actionInUrl);
await enrichAndPersistProjectCampaignRequest(request, actionInUrl, false, localizationMap)
}
} catch (error: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const campaignDetailsTransformer = (dbRows: any[] = []) => {
status: row?.status,
action: row?.action,
campaignNumber: row?.campaignnumber,
isActive: row?.isactive,
parentId: row?.parentid,
campaignName: row?.campaignname,
projectType: row?.projecttype,
hierarchyType: row?.hierarchytype,
Expand Down
Loading

0 comments on commit 0a419be

Please sign in to comment.