Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
knowledge-mw-service
Commits
54ef046a
Commit
54ef046a
authored
6 years ago
by
loganathan.shanmugam@tarento.com
Committed by
kochhar
6 years ago
Browse files
Options
Download
Patches
Plain Diff
Issue #SB-4854 fix: resolved conflicts
parent
56fba618
master
dependabot/npm_and_yarn/src/async-2.6.4
dependabot/npm_and_yarn/src/decode-uri-component-0.2.2
dependabot/npm_and_yarn/src/flat-and-mocha-5.0.2
dependabot/npm_and_yarn/src/handlebars-4.7.7
dependabot/npm_and_yarn/src/jsonwebtoken-9.0.0
dependabot/npm_and_yarn/src/lodash-4.17.21
dependabot/npm_and_yarn/src/minimist-and-project-sunbird/telemetry-sdk-and-handlebars-and-mkdirp-1.2.8
release-3.6.0
release-4.3.0
release-4.8.0
release-5.2.0
release-5.3.0
release-5.6.0
release-6.0.0
v1.13.3
v1.13
v1.12
v1.11.1
v1.11
v1.10.1
v1.10
v1.9
tmp-testPR
tmp-sunbird-bootcamp
tmp-rjshrjndrn-patch-1
tmp-revert-118-testPR
tmp-revert-110-logs
tmp-revert-99-revert-98-revert-97-revert-96-rjshrjndrn-patch-1
tmp-revert-98-revert-97-revert-96-rjshrjndrn-patch-1
tmp-revert-97-revert-96-rjshrjndrn-patch-1
tmp-revert-96-rjshrjndrn-patch-1
tmp-release-sonarcloud
tmp-release-2.6.0
tmp-release-2.3.0
tmp-release-2.1.1
tmp-release-2.1.0
tmp-release-2.1.0_pluginSearch
tmp-release-2.0.0
tmp-release-1.15
tmp-release-1.14.3
tmp-release-1.14
tmp-release-1.14-sp3
tmp-refactored-dev-deploy
tmp-master
tmp-loadtest
tmp-load-testing
tmp-jenkins-test
tmp-jenkins-pipeline
tmp-final-variable-refac
tmp-dial-assemble-api
tmp-content-update-read
tmp-circleci
release-5.6.0_RC1
release-5.2.0_RC1
release-4.8.5_RC1
release-4.8.0_RC2
release-4.8.0_RC1
release-4.3.0_RC1
release-3.8.0_RC3
release-3.8.0_RC2
release-3.8.0_RC1
release-3.7.0_RC2
release-3.7.0_RC1
release-3.6.0_RC1
release-3.2.0_RC2
release-3.2.0_RC1
release-3.1.0
release-3.1.0_RC2
release-3.1.0_RC1
release-3.0.1_RC1
release-3.0.0
release-3.0.0_RC1
release-2.10.0
release-2.10.0_RC2
release-2.10.0_RC1
release-2.9.0_RC3
release-2.9.0_RC2
release-2.9.0_RC1
release-2.8.0
release-2.8.0_RC4
release-2.8.0_RC3
release-2.8.0_RC2
release-2.8.0_RC1
release-2.7.0
release-2.7.0_RC2
release-2.7.0_RC1
release-2.6.0
release-2.6.0_RC4
release-2.6.0_RC3
release-2.6.0_RC2
release-2.6.0_RC1
release-2.3.0
release-2.3.0_RC2
release-2.3.0_RC1
release-2.1.1_RC1
release-2.1.0_RC2
release-2.1.0_RC1
release-2.0.0
release-2.0.0_RC5
release-2.0.0_RC4
release-2.0.0_RC3
release-2.0.0_RC2
release-2.0.0_RC1
release-1.15.0
release-1.15_RC7
release-1.15_RC6
release-1.15_RC5
release-1.15_RC4
release-1.15_RC3
release-1.15_RC2
release-1.15_RC1
release-1.14.0
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/app.js
+5
-1
src/app.js
src/gulpfile.js
+2
-1
src/gulpfile.js
src/helpers/configHelper.js
+177
-0
src/helpers/configHelper.js
src/test/helpers/configHelperSpec.js
+32
-0
src/test/helpers/configHelperSpec.js
with
216 additions
and
2 deletions
+216
-2
src/app.js
+
5
−
1
View file @
54ef046a
...
...
@@ -11,6 +11,7 @@ var configUtil = require('sb-config-util')
const
contentProvider
=
require
(
'
sb_content_provider_util
'
)
var
contentMetaProvider
=
require
(
'
./contentMetaFilter
'
)
var
configHelper
=
require
(
'
./helpers/configHelper
'
)
// TODO below configuration should to be refactored in a seperate file
const
contentProviderConfigPath
=
path
.
join
(
__dirname
,
'
/config/contentProviderApiConfig.json
'
)
...
...
@@ -61,7 +62,9 @@ const bodyParserJsonMiddleware = function () {
if
(
isEkStepProxyRequest
(
req
))
{
return
next
()
}
else
{
return
bodyParser
.
json
({
limit
:
reqDataLimitOfContentUpload
})(
req
,
res
,
next
)
return
bodyParser
.
json
({
limit
:
reqDataLimitOfContentUpload
})(
req
,
res
,
next
)
}
}
}
...
...
@@ -119,6 +122,7 @@ if (defaultChannel) {
process
.
exit
(
1
)
}
configUtil
.
setConfig
(
'
META_FILTER_REQUEST_JSON
'
,
contentMetaProvider
.
getMetaFilterConfig
())
configHelper
.
updateConfig
()
})
}
else
{
console
.
log
(
'
error in fetching default channel
'
,
defaultChannel
,
err
,
res
)
...
...
This diff is collapsed.
Click to expand it.
src/gulpfile.js
+
2
−
1
View file @
54ef046a
...
...
@@ -4,7 +4,8 @@ var jasmineNode = require('gulp-jasmine-node')
var
istanbul
=
require
(
'
gulp-istanbul
'
)
var
paths
=
{
scripts
:
[
'
middlewares/*.js
'
,
'
models/*.js
'
,
'
routes/*.js
'
,
'
service/*.js
'
,
'
app.js
'
,
'
!service/conceptService.js
'
],
scripts
:
[
'
middlewares/*.js
'
,
'
helpers/*.js
'
,
'
models/*.js
'
,
'
routes/*.js
'
,
'
service/*.js
'
,
'
app.js
'
,
'
!service/conceptService.js
'
],
tests
:
[
'
test/*.js
'
,
'
test/**/*.js
'
],
coverage
:
'
coverage
'
}
...
...
This diff is collapsed.
Click to expand it.
src/helpers/configHelper.js
0 → 100644
+
177
−
0
View file @
54ef046a
var
path
=
require
(
'
path
'
)
var
filename
=
path
.
basename
(
__filename
)
var
utilsService
=
require
(
'
../service/utilsService
'
)
var
LOG
=
require
(
'
sb_logger_util
'
)
const
contentProvider
=
require
(
'
sb_content_provider_util
'
)
var
async
=
require
(
'
async
'
)
var
_
=
require
(
'
lodash
'
)
var
configUtil
=
require
(
'
sb-config-util
'
)
var
channelRefreshCronStr
=
process
.
env
.
sunbird_content_service_channel_refresh_cron
var
cron
=
require
(
'
node-cron
'
)
const
whiteListedChannelList
=
process
.
env
.
sunbird_content_service_whitelisted_channels
const
blackListedChannelList
=
process
.
env
.
sunbird_content_service_blacklisted_channels
var
ischannelRefreshEnabled
=
false
/**
* This function executes the org search lms API to get all orgs
* @param requestObj js object which contains the search request with filters,offset,limit,query etc
* @param cb callback after success or error
*/
function
getRootOrgs
(
requestObj
,
cb
)
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getRootOrgs
'
,
'
getRootOrgs called
'
,
requestObj
))
contentProvider
.
getAllRootOrgs
(
requestObj
,
(
err
,
res
)
=>
{
if
(
!
err
&&
res
&&
res
.
result
.
response
.
count
>
0
&&
res
.
result
.
response
.
content
)
{
cb
(
err
,
res
)
}
else
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
getRootOrgs
'
,
'
error in getting root orgs.
'
,
err
))
process
.
exit
(
1
)
}
})
}
/**
* This function returns the config string based on condition for channel filters which
* contains the whitelisted channels
* @returns Js object or array which contains the allowed whitelisted channels
*/
function
getFilterConfig
(
cb
)
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
environment info
'
,
process
.
env
))
var
allowedChannels
=
whiteListedChannelList
?
whiteListedChannelList
.
split
(
'
,
'
)
:
[]
var
blackListedChannels
=
blackListedChannelList
?
blackListedChannelList
.
split
(
'
,
'
)
:
[]
if
(
_
.
includes
(
allowedChannels
,
'
$.instance.all
'
))
{
if
(
channelRefreshCronStr
&&
!
ischannelRefreshEnabled
)
{
setChannelRefreshTask
()
ischannelRefreshEnabled
=
true
}
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
allowed channels
'
,
allowedChannels
))
getAllChannelsFromAPI
(
function
(
err
,
allChannels
)
{
if
(
err
)
{
console
.
log
(
err
)
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
getFilterConfig
'
,
'
getAllChannelsFromAPI callback
'
,
err
))
}
allowedChannels
=
_
.
pull
(
allowedChannels
,
'
$.instance.all
'
).
concat
(
allChannels
)
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
all whitelisted channels count
'
,
allowedChannels
.
length
))
cb
(
null
,
getconfigStringFromChannels
(
allowedChannels
,
blackListedChannels
))
})
}
else
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
allowed channels
'
,
allowedChannels
))
cb
(
null
,
getconfigStringFromChannels
(
allowedChannels
,
blackListedChannels
))
}
}
/**
* This function generates the config string for given allowed and blacklisted channels
* @param allowedChannels array of channels to be allowed in filters
* @param blacklistedchannels array of channels to be blacklisted or ignored
* @returns Js object or array which contains the allowed whitelisted channels
*/
function
getconfigStringFromChannels
(
allowedChannels
,
blackListedChannels
)
{
var
configString
=
{}
if
((
allowedChannels
&&
allowedChannels
.
length
>
0
)
&&
(
blackListedChannels
&&
blackListedChannels
.
length
>
0
))
{
configString
=
_
.
difference
(
allowedChannels
,
blackListedChannels
)
}
else
if
(
allowedChannels
&&
allowedChannels
.
length
>
0
)
{
configString
=
allowedChannels
}
else
if
(
blackListedChannels
&&
blackListedChannels
.
length
>
0
)
{
configString
=
{
'
ne
'
:
blackListedChannels
}
}
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getconfigStringFromChannels
'
,
'
config string
'
,
configString
))
return
configString
}
/**
* This method gets all channels through 'getRootOrgs' method response
* data asynchronously and return callback
* @param cb callback method which takes error and allchannels as param
* @returns callback
*/
function
getAllChannelsFromAPI
(
cb
)
{
var
limit
=
200
var
offset
=
0
var
allChannels
=
[]
var
channelReqObj
=
{
'
request
'
:
{
'
filters
'
:
{
'
isRootOrg
'
:
true
},
'
offset
'
:
offset
,
'
limit
'
:
limit
}
}
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getAllChannelsFromAPI
'
,
'
fetching all channels req
'
,
channelReqObj
))
getRootOrgs
(
channelReqObj
,
function
(
err
,
res
)
{
if
(
err
)
{
cb
(
err
,
null
)
}
const
orgCount
=
res
.
result
.
response
.
count
allChannels
=
_
.
without
(
_
.
map
(
res
.
result
.
response
.
content
,
'
hashTagId
'
),
null
)
// if more orgs are there get them iteratively using async
if
(
limit
<
orgCount
)
{
var
channelReqArr
=
[]
while
((
offset
+
limit
)
<
orgCount
)
{
offset
=
offset
+
limit
channelReqObj
.
request
.
offset
=
offset
channelReqArr
.
push
(
_
.
cloneDeep
(
channelReqObj
))
}
async
.
map
(
channelReqArr
,
getRootOrgs
,
function
(
err
,
mappedResArr
)
{
if
(
err
)
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
getFilterConfig
'
,
'
getAllChannelsFromAPI callback
'
,
err
))
}
/** extract hashTagId which represents the channelID from each response
* of responseMap to generate the whitelisted channels array
* */
_
.
forEach
(
mappedResArr
,
function
(
item
)
{
allChannels
.
push
(
_
.
map
(
item
.
result
.
response
.
content
,
'
hashTagId
'
))
})
allChannels
=
_
.
without
(
_
.
flatten
(
allChannels
),
null
)
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getAllChannelsFromAPI
'
,
'
all channels arr
'
,
allChannels
))
cb
(
null
,
allChannels
)
})
}
else
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getAllChannelsFromAPI
'
,
'
all channels arr
'
,
allChannels
))
cb
(
null
,
allChannels
)
}
})
}
/**
* This method sets the given channel filter value to the config utils
* @param configString configstring which contains the whitelisted channels
*/
function
updateConfig
()
{
getFilterConfig
(
function
(
err
,
configString
)
{
if
(
err
)
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
updateConfig
'
,
'
error
'
,
err
))
}
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
updateConfig
'
,
'
config string
'
,
configString
))
configUtil
.
setConfig
(
'
CHANNEL_FILTER_QUERY_STRING
'
,
configString
)
})
}
/**
* This function executes the scheduler cron job to refresh the whitelisted
* channels based given cron interval string 'channelRefreshCronStr'
*/
function
setChannelRefreshTask
()
{
cron
.
schedule
(
channelRefreshCronStr
,
function
()
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
setChannelRefreshTask
'
,
'
running scheduler task
'
,
channelRefreshCronStr
))
updateConfig
()
})
}
module
.
exports
=
{
updateConfig
:
updateConfig
,
getFilterConfig
:
getFilterConfig
}
This diff is collapsed.
Click to expand it.
src/test/helpers/configHelperSpec.js
0 → 100644
+
32
−
0
View file @
54ef046a
var
configHelper
=
require
(
'
../../helpers/configHelper
'
)
var
configUtil
=
require
(
'
sb-config-util
'
)
describe
(
'
configuration settings
'
,
function
()
{
it
(
'
should set the configuration
'
,
function
(
done
)
{
configHelper
.
updateConfig
()
expect
(
configUtil
.
getConfig
(
'
CHANNEL_FILTER_QUERY_STRING
'
)).
toEqual
([])
done
()
})
})
describe
(
'
configuration string
'
,
function
()
{
it
(
'
should return the config string with all channels
'
,
function
(
done
)
{
process
.
env
.
sunbird_content_service_whitelisted_channels
=
'
505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d,$.instance.all
'
process
.
env
.
sunbird_content_service_blacklisted_channels
=
'
b00bc992ef25f1a9a8d63291e20efc8d
'
configHelper
.
getFilterConfig
(
function
(
err
,
configStr
)
{
expect
(
err
).
toBeNull
()
expect
(
configStr
.
length
).
toBeGreaterThanOrEqual
(
process
.
env
.
sunbird_content_service_whitelisted_channels
.
length
)
done
()
})
})
it
(
'
should return the config string with whitelisted channels
'
,
function
(
done
)
{
process
.
env
.
sunbird_content_service_whitelisted_channels
=
'
505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d
'
process
.
env
.
sunbird_content_service_blacklisted_channels
=
'
b00bc992ef25f1a9a8d63291e20efc8d
'
configHelper
.
getFilterConfig
(
function
(
err
,
configStr
)
{
expect
(
err
).
toBeNull
()
expect
(
configStr
.
length
).
toBeLessThanOrEqual
(
process
.
env
.
sunbird_content_service_whitelisted_channels
.
length
)
done
()
})
})
})
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets