diff --git a/src/app.js b/src/app.js index 7e0a0c9584435c64a1a9f023c875a9a74a26f05c..41309ac9b1b75db7d8333c8d05e0d15ff496a108 100644 --- a/src/app.js +++ b/src/app.js @@ -38,14 +38,14 @@ const dialServiceBaseUrl = process.env.sunbird_dial_service_api_base_url || 'htt const whiteListedChannelList = process.env.sunbird_content_service_whitelisted_channels const blackListedChannelList = process.env.sunbird_content_service_blacklisted_channels -const whitelistedFrameworkList = process.env.sunbird_content_service_whitelisted_framework -const blacklistedFrameworkList = process.env.sunbird_content_service_blacklisted_framework -const whitelistedMimeTypeList = process.env.sunbird_content_service_whitelisted_mimeType -const blacklistedMimeTypeList = process.env.sunbird_content_service_blacklisted_mimeType -const whitelistedContentTypeList = process.env.sunbird_content_service_whitelisted_contentType -const blacklistedContentTypeList = process.env.sunbird_content_service_blacklisted_contentType -const whitelistedResourceTypeList = process.env.sunbird_content_service_whitelisted_resourceType -const blacklistedResourceTypeList = process.env.sunbird_content_service_blacklisted_resourceType +const whitelistedFrameworkList = process.env.sunbird_content_filter_framework_whitelist +const blacklistedFrameworkList = process.env.sunbird_content_filter_framework_blacklist +const whitelistedMimeTypeList = process.env.sunbird_content_filter_mimetype_whitelist +const blacklistedMimeTypeList = process.env.sunbird_content_filter_mimetype_blacklist +const whitelistedContentTypeList = process.env.sunbird_content_filter_contenttype_whitelist +const blacklistedContentTypeList = process.env.sunbird_content_filter_contenttype_blacklist +const whitelistedResourceTypeList = process.env.sunbird_content_filter_resourcetype_whitelist +const blacklistedResourceTypeList = process.env.sunbird_content_filter_resourcetype_blacklist const producerId = process.env.sunbird_environment + '.' + process.env.sunbird_instance + '.content-service' diff --git a/src/middlewares/filter.middleware.js b/src/middlewares/filter.middleware.js index b05351f783b999b8bd1015219c0381c55ff2a047..f5a43d23149505f58f2260b0bc965b4cba4a79c5 100644 --- a/src/middlewares/filter.middleware.js +++ b/src/middlewares/filter.middleware.js @@ -7,11 +7,41 @@ var filename = path.basename(__filename) function addMetaFilters (req, res, next) { // If the request body has filter by metaFilter data, continue with the same filter, do not alter the values - // else call the getMetaSearchData() function to generate the JSON Object for the meta filters - filterService.getMetaSearchData(function () { - // Generate JSON and return - return setFilterJSON() - }) + // else call the getMetaSearchString() function to generate the search string for the meta filters + if (req && req.body && req.body.request && req.body.request.filters && req.body.request.filters.channel && + req.body.request.filters.framework && req.body.request.filters.contentType && + req.body.request.filters.mimeType && req.body.request.filters.resourceType) { + next() + } else { + filterService.getMetaSearchString(function (err, searchJSON) { + console.log('err', err) + console.log('channels', searchJSON) + if (err) { + LOG.error(utilsService.getLoggerData({}, 'ERROR', filename, 'addChannelFilters', + 'failed to get channels')) + } else if (searchJSON && (!_.isEmpty(searchJSON))) { + if (req.body.request.filters.channel === undefined) { + req.body.request.filters.channel = searchJSON.channel + } + if (req.body.request.filters.framework === undefined) { + req.body.request.filters.framework = searchJSON.framework + } + if (req.body.request.filters.contentType === undefined) { + req.body.request.filters.contentType = searchJSON.contentType + } + if (req.body.request.filters.mimeType === undefined) { + req.body.request.filters.mimeType = searchJSON.mimeType + } + if (req.body.request.filters.resourceType === undefined) { + req.body.request.filters.resourceType = searchJSON.resourceType + } + LOG.info(utilsService.getLoggerData({}, 'INFO', + filename, 'addChannelFilters', 'added channel filter', req.body.request.filters)) + console.log('req filters', req.body.request.filters) + } + next() + }) + } } function setFilterJSON () { diff --git a/src/test/middlewares/filterMiddlewareSpec.js b/src/test/middlewares/filterMiddlewareSpec.js index cb0d2363c67d02dc538f723b84c5ef79aecb9b3c..f050f04a02734479c6300ccb1d6f55b8feaf3912 100644 --- a/src/test/middlewares/filterMiddlewareSpec.js +++ b/src/test/middlewares/filterMiddlewareSpec.js @@ -2,8 +2,10 @@ describe('Initialization of meta filters', function () { it('check for the request and then do next', function () {}) it('check for no request and get config', function () {}) it('check for the filter object property exists in the request body', function () {}) - it('if filter object property is equal to response body property then do not append property to filter', function () {}) - it('if the filter object property is not equal to response body property then append property to filter', function () {}) + it('if filter object property is equal to response body property then do not append ' + + 'property to filter', function () {}) + it('if the filter object property is not equal to response body property then append ' + + 'property to filter', function () {}) it('check for getMetaSearchData method creates proper whitelisted search data', function () {}) it('check for getMetaSearchData method creates proper blacklisted search data', function () {}) })