From 2a62e70ba1352f243e6be4accf2854baa86d98f4 Mon Sep 17 00:00:00 2001 From: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:28:55 +0530 Subject: [PATCH 1/5] added configuration for term retire (#9) * added configuration for term retire * Update frameworkTermRoutes.js * Update frameworkTermService.js * Update frameworkTermService.js * added configuration for frameworkTermRetire --------- Co-authored-by: anilkumar --- src/libs | 2 +- src/routes/frameworkTermRoutes.js | 6 +++ src/service/frameworkTermService.js | 58 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/libs b/src/libs index 6df14e66..08a79841 160000 --- a/src/libs +++ b/src/libs @@ -1 +1 @@ -Subproject commit 6df14e662e7d814c1a2973f0945433b4bf3961aa +Subproject commit 08a798410965a86aa50ecac8da4876dca1623bd6 diff --git a/src/routes/frameworkTermRoutes.js b/src/routes/frameworkTermRoutes.js index 1f9de038..1f3187f6 100644 --- a/src/routes/frameworkTermRoutes.js +++ b/src/routes/frameworkTermRoutes.js @@ -33,4 +33,10 @@ module.exports = function (app) { .patch(healthService.checkDependantServiceHealth(dependentServiceHealth), requestMiddleware.gzipCompression(), requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermUpdate) + + app.route(baseUrl + '/retire/:categoryID') + .patch(healthService.checkDependantServiceHealth(dependentServiceHealth), + requestMiddleware.gzipCompression(), + requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermRetire) + } diff --git a/src/service/frameworkTermService.js b/src/service/frameworkTermService.js index fd159fd5..db59cd81 100644 --- a/src/service/frameworkTermService.js +++ b/src/service/frameworkTermService.js @@ -231,7 +231,65 @@ function frameworkTermUpdate (req, response) { ]) } + +function frameworkTermRetire (req, response) { + var data = {} + var rspObj = req.rspObj + + data.body = req.body + data.category = req.params.categoryID + data.queryParams = req.query + // Adding telemetry object data + if (rspObj.telemetryData) { + rspObj.telemetryData.object = utilsService.getObjectData(data.category, 'frameworkTerm', '', {}) + } + + if (!data.queryParams) { + rspObj.responseCode = responseCode.CLIENT_ERROR + logger.error({ + msg: 'Error due to missing query Parameters', + err: {responseCode: rspObj.responseCode}, + additionalInfo: { data } + }, req) + return response.status(400).send(respUtil.errorResponse(rspObj)) + } + + async.waterfall([ + + function (CBW) { + logger.debug({ msg: 'Request to get Framework Terms', additionalInfo: { data } }, req) + ekStepUtil.frameworkTermRetire(data.category, req.headers, data.queryParams, function (err, res) { + if (err || res.responseCode !== responseCode.SUCCESS) { + rspObj.responseCode = res && res.responseCode ? res.responseCode : responseCode.SERVER_ERROR + logger.error({ + msg: 'Error while fetching framework terms from ekstep', + err: { + err, + responseCode: rspObj.responseCode + }, + additionalInfo: {data} + }, req) + var httpStatus = res && res.statusCode >= 100 && res.statusCode < 600 ? res.statusCode : 500 + rspObj.result = res && res.result ? res.result : {} + rspObj = utilsService.getErrorResponse(rspObj, res) + return response.status(httpStatus).send(respUtil.errorResponse(rspObj)) + } else { + CBW(null, res) + } + }) + }, + + function (res) { + rspObj.result = res.result + return response.status(200).send(respUtil.successResponse(rspObj)) + } + ]) +} + + + module.exports.getFrameworkTerm = getFrameworkTerm module.exports.frameworkTermSearch = frameworkTermSearch module.exports.frameworkTermCreate = frameworkTermCreate module.exports.frameworkTermUpdate = frameworkTermUpdate +module.exports.frameworkTermRetire = frameworkTermRetire From 904e8eaf23288c777fffbad9e36d3c92b72659cd Mon Sep 17 00:00:00 2001 From: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:51:47 +0530 Subject: [PATCH 2/5] Termretire (#11) * added configuration for term retire * Update frameworkTermRoutes.js * Update frameworkTermService.js * Update frameworkTermService.js * added configuration for frameworkTermRetire * update configruation for term retire * removed content * updated config for framework term retire api * updated configuration for term retire --------- Co-authored-by: anilkumar --- src/routes/frameworkTermRoutes.js | 4 +- src/service/frameworkTermService.js | 111 +++++++++++++++++----------- 2 files changed, 68 insertions(+), 47 deletions(-) diff --git a/src/routes/frameworkTermRoutes.js b/src/routes/frameworkTermRoutes.js index 1f3187f6..a0f6294a 100644 --- a/src/routes/frameworkTermRoutes.js +++ b/src/routes/frameworkTermRoutes.js @@ -34,8 +34,8 @@ module.exports = function (app) { requestMiddleware.gzipCompression(), requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermUpdate) - app.route(baseUrl + '/retire/:categoryID') - .patch(healthService.checkDependantServiceHealth(dependentServiceHealth), + app.route(baseUrl + '/retire') + .delete(healthService.checkDependantServiceHealth(dependentServiceHealth), requestMiddleware.gzipCompression(), requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermRetire) diff --git a/src/service/frameworkTermService.js b/src/service/frameworkTermService.js index db59cd81..096dc378 100644 --- a/src/service/frameworkTermService.js +++ b/src/service/frameworkTermService.js @@ -232,58 +232,79 @@ function frameworkTermUpdate (req, response) { } -function frameworkTermRetire (req, response) { - var data = {} - var rspObj = req.rspObj - - data.body = req.body - data.category = req.params.categoryID - data.queryParams = req.query - // Adding telemetry object data - if (rspObj.telemetryData) { - rspObj.telemetryData.object = utilsService.getObjectData(data.category, 'frameworkTerm', '', {}) - } - - if (!data.queryParams) { - rspObj.responseCode = responseCode.CLIENT_ERROR +function frameworkTermRetire(req, response) { + var data = req.body; + var rspObj = req.rspObj; + data.queryParams = req.query; + var failedContent = []; + var userId = req.headers['x-authenticated-userid']; + var errCode, errMsg, respCode, httpStatus; + + logger.debug({ + msg: 'frameworkTermService.frameworkTermRetire() called', additionalInfo: { rspObj } + }, req); + + if (!data.request || !data.request.contentIds) { + rspObj.errCode = contentMessage.RETIRE.MISSING_CODE; + rspObj.errMsg = contentMessage.RETIRE.MISSING_MESSAGE; + rspObj.responseCode = responseCode.CLIENT_ERROR; logger.error({ - msg: 'Error due to missing query Parameters', - err: {responseCode: rspObj.responseCode}, + msg: 'Error due to required request || request.contentIds are missing', + err: { + errCode: rspObj.errCode, + errMsg: rspObj.errMsg, + responseCode: rspObj.responseCode + }, additionalInfo: { data } - }, req) - return response.status(400).send(respUtil.errorResponse(rspObj)) + }, req); + return response.status(400).send(respUtil.errorResponse(rspObj)); } - async.waterfall([ + async.each(data.request.contentIds, function (contentId, CBE) { + logger.debug({ + msg: 'Request to retire the term', + additionalInfo: { contentId: contentId } + }, req); - function (CBW) { - logger.debug({ msg: 'Request to get Framework Terms', additionalInfo: { data } }, req) - ekStepUtil.frameworkTermRetire(data.category, req.headers, data.queryParams, function (err, res) { - if (err || res.responseCode !== responseCode.SUCCESS) { - rspObj.responseCode = res && res.responseCode ? res.responseCode : responseCode.SERVER_ERROR - logger.error({ - msg: 'Error while fetching framework terms from ekstep', - err: { - err, - responseCode: rspObj.responseCode - }, - additionalInfo: {data} - }, req) - var httpStatus = res && res.statusCode >= 100 && res.statusCode < 600 ? res.statusCode : 500 - rspObj.result = res && res.result ? res.result : {} - rspObj = utilsService.getErrorResponse(rspObj, res) - return response.status(httpStatus).send(respUtil.errorResponse(rspObj)) - } else { - CBW(null, res) - } - }) - }, + // Adding objectData in telemetry + if (rspObj.telemetryData) { + rspObj.telemetryData.object = utilsService.getObjectData(contentId, 'term', '', {}); + } - function (res) { - rspObj.result = res.result - return response.status(200).send(respUtil.successResponse(rspObj)) + ekStepUtil.frameworkTermRetire(contentId, req.headers, data.queryParams, function (err, res) { + if (err || res.responseCode !== responseCode.SUCCESS) { + errCode = res && res.params ? res.params.err : contentMessage.GET_MY.FAILED_CODE; + errMsg = res && res.params ? res.params.errmsg : contentMessage.GET_MY.FAILED_MESSAGE; + respCode = res && res.responseCode ? res.responseCode : responseCode.SERVER_ERROR; + logger.error({ + msg: 'Getting error from framework term provider while retiring term', + err: { + err, + errCode: rspObj.errCode, + errMsg: rspObj.errMsg, + responseCode: rspObj.responseCode + }, + additionalInfo: { contentId } + }, req); + httpStatus = res && res.statusCode >= 100 && res.statusCode < 600 ? res.statusCode : 500; + rspObj.result = res && res.result ? res.result : {}; + failedContent.push({ contentId: contentId, errCode: errCode, errMsg: errMsg }); + } + CBE(null, null); + }); + }, function () { + if (failedContent.length > 0) { + rspObj.errCode = errCode; + rspObj.errMsg = errMsg; + rspObj.responseCode = respCode; + rspObj.result = failedContent; + return response.status(httpStatus).send(respUtil.errorResponse(rspObj)); + } else { + rspObj.result = failedContent; + logger.debug({ msg: 'Sending response back to user', res: rspObj }, req); + return response.status(200).send(respUtil.successResponse(rspObj)); } - ]) + }); } From 804235db9e25492c6162f70a4a4edd0772cd71c2 Mon Sep 17 00:00:00 2001 From: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:13:56 +0530 Subject: [PATCH 3/5] frameworkConfigChange (#14) Co-authored-by: anilkumar --- src/config/contentProviderApiConfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/contentProviderApiConfig.json b/src/config/contentProviderApiConfig.json index 1d07ec80..3657b948 100644 --- a/src/config/contentProviderApiConfig.json +++ b/src/config/contentProviderApiConfig.json @@ -59,6 +59,7 @@ "FRAMEWORK_TERM_SEARCH_URI": "/framework/v3/term/search", "FRAMEWORK_TERM_CREATE_URI": "/framework/v3/term/create", "FRAMEWORK_TERM_UPDATE_URI": "/framework/v3/term/update", + "FRAMEWORK_Term_Retire_URI": "/framework/v3/term/retire", "FRAMEWORK_CATEGORY_INSTANCE_URI": "/framework/v3/category/read", "FRAMEWORK_CATEGORY_INSTANCE_SEARCH_URI": "/framework/v3/category/search", From f286a1b8416f7ea95347d12996e95a18995e319c Mon Sep 17 00:00:00 2001 From: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:45:36 +0530 Subject: [PATCH 4/5] added contentMessage (#15) Co-authored-by: anilkumar --- src/service/frameworkTermService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/frameworkTermService.js b/src/service/frameworkTermService.js index 096dc378..305502cc 100644 --- a/src/service/frameworkTermService.js +++ b/src/service/frameworkTermService.js @@ -11,7 +11,7 @@ var ekStepUtil = require('sb_content_provider_util') var logger = require('sb_logger_util_v2') var messageUtils = require('./messageUtil') var utilsService = require('../service/utilsService') - +var contentMessage = messageUtils.CONTENT var filename = path.basename(__filename) var responseCode = messageUtils.RESPONSE_CODE From 66800ccdc9dafb21d596a3a8df44356bad096921 Mon Sep 17 00:00:00 2001 From: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:06:31 +0530 Subject: [PATCH 5/5] changed http method from delete to post (#16) Co-authored-by: anilkumar --- src/routes/frameworkTermRoutes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/frameworkTermRoutes.js b/src/routes/frameworkTermRoutes.js index a0f6294a..0e92b495 100644 --- a/src/routes/frameworkTermRoutes.js +++ b/src/routes/frameworkTermRoutes.js @@ -35,7 +35,7 @@ module.exports = function (app) { requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermUpdate) app.route(baseUrl + '/retire') - .delete(healthService.checkDependantServiceHealth(dependentServiceHealth), + .post(healthService.checkDependantServiceHealth(dependentServiceHealth), requestMiddleware.gzipCompression(), requestMiddleware.createAndValidateRequestBody, frameworkTermService.frameworkTermRetire)