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
program-service
Commits
e06d0a9d
Commit
e06d0a9d
authored
4 years ago
by
Kartheek Palla
Browse files
Options
Download
Patches
Plain Diff
Issue #DP-373 fix: program content publish api changes
parent
f3bdda4a
publish_changes
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers/kafkaUtil.js
+43
-0
src/helpers/kafkaUtil.js
src/helpers/publishHelper.js
+72
-0
src/helpers/publishHelper.js
with
115 additions
and
0 deletions
+115
-0
src/helpers/kafkaUtil.js
0 → 100644
+
43
−
0
View file @
e06d0a9d
const
kafka
=
require
(
'
kafka-node
'
)
const
_
=
require
(
'
lodash
'
)
var
logger
=
require
(
'
sb_logger_util_v2
'
)
const
envVariables
=
require
(
"
../envVariables
"
);
const
client
=
new
kafka
.
KafkaClient
({
kafkaHost
:
envVariables
.
SUNBIRD_KAFKA_HOST
,
maxAsyncRequests
:
100
})
const
producer
=
new
kafka
.
HighLevelProducer
(
client
)
producer
.
on
(
'
ready
'
,
function
()
{
console
.
log
(
'
Kafka Producer is connected and ready.
'
)
logger
.
info
({
msg
:
'
Kafka Producer is connected and ready.
'
})
})
// For this demo we just log producer errors to the console.
producer
.
on
(
'
error
'
,
function
(
error
)
{
logger
.
error
({
msg
:
'
Error from Kafka producer
'
,
error
})
console
.
error
(
error
)
})
const
KafkaService
=
{
sendRecord
:
(
data
,
callback
=
()
=>
{
})
=>
{
if
(
_
.
isEmpty
(
data
))
{
logger
.
error
({
msg
:
'
Data must be provided to send Record
'
,
additionalInfo
:
{
data
}})
return
callback
(
new
Error
(
'
Event Data must be provided.
'
))
}
// Create a new payload
const
record
=
[
{
topic
:
envVariables
.
SUNBIRD_AUTO_CREATION_TOPIC
,
messages
:
JSON
.
stringify
(
data
)
}
]
logger
.
info
({
msg
:
'
Kafka record
'
,
additionalInfo
:
{
record
}})
// Send record to Kafka and log result/error
producer
.
send
(
record
,
callback
)
}
}
module
.
exports
=
KafkaService
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/helpers/publishHelper.js
0 → 100644
+
72
−
0
View file @
e06d0a9d
const
uuid
=
require
(
"
uuid/v1
"
)
const
_
=
require
(
"
lodash
"
);
const
envVariables
=
require
(
"
../envVariables
"
);
const
axios
=
require
(
"
axios
"
);
const
{
from
}
=
require
(
"
rxjs
"
);
function
getContentMetaData
(
contentId
,
reqHeaders
){
const
url
=
`
${
envVariables
.
baseURL
}
/action/content/v3/read/
${
contentId
}
`
;
const
option
=
{
url
:
url
,
method
:
"
get
"
,
headers
:
reqHeaders
};
return
from
(
axios
(
option
));
}
function
getPublishContentEvent
(
metadata
,
textbookId
,
units
)
{
metadata
.
pkgVersion
=
`
${
metadata
.
pkgVersion
}
.0`
;
if
(
metadata
.
subject
){
metadata
.
subject
=
_
.
isArray
(
metadata
.
subject
)
?
metadata
.
subject
:
[
metadata
.
subject
];
}
if
(
metadata
.
medium
){
metadata
.
medium
=
_
.
isArray
(
metadata
.
medium
)
?
metadata
.
medium
:
[
metadata
.
medium
];
}
metadata
=
_
.
omit
(
metadata
,
[
"
downloadUrl
"
,
"
variants
"
,
"
previewUrl
"
,
"
streamingUrl
"
,
"
unitIdentifiers
"
,
"
itemSets
"
]);
var
ets
=
Date
.
now
();
var
dataObj
=
{
'
eid
'
:
'
BE_JOB_REQUEST
'
,
'
ets
'
:
ets
,
'
mid
'
:
`LP.
${
ets
}
.
${
uuid
()}
`
,
'
actor
'
:
{
'
id
'
:
'
Auto Creator
'
,
'
type
'
:
'
System
'
},
'
context
'
:
{
'
pdata
'
:
{
'
ver
'
:
'
1.0
'
,
'
id
'
:
'
org.ekstep.platform
'
},
'
channel
'
:
metadata
.
channel
,
'
env
'
:
envVariables
.
PUBLISH_ENV
},
'
object
'
:
{
'
ver
'
:
'
1.0
'
,
'
id
'
:
metadata
.
identifier
},
'
edata
'
:
{
'
action
'
:
'
auto-create
'
,
'
iteration
'
:
1
,
'
objectType
'
:
'
Content
'
,
'
repository
'
:
`
${
envVariables
.
baseURL
}
/api/content/v1/read/
${
metadata
.
identifier
}
`
,
'
metadata
'
:
metadata
,
'
textbookInfo
'
:
{
'
identifier
'
:
textbookId
,
'
unitIdentifiers
'
:
units
}
}
}
return
dataObj
;
}
module
.
exports
.
getPublishContentEvent
=
getPublishContentEvent
module
.
exports
.
getContentMetaData
=
getContentMetaData
\ No newline at end of file
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