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
sunbird-lms-service
Commits
bd4ca63b
Unverified
Commit
bd4ca63b
authored
3 years ago
by
AMIT KUMAR
Committed by
GitHub
3 years ago
Browse files
Options
Download
Patches
Plain Diff
Issue #SB-28384 feat: Merge release-4.5 to release-4.6 (#1039)
parent
c2b9510a
release-4.6.0
release-4.6.0_RC9
release-4.6.0_RC8
release-4.6.0_RC7
release-4.6.0_RC6
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/platform-common/src/main/java/org/sunbird/telemetry/util/TelemetryGenerator.java
+0
-3
...n/java/org/sunbird/telemetry/util/TelemetryGenerator.java
service/src/main/java/org/sunbird/client/NotificationServiceClient.java
+139
-124
...in/java/org/sunbird/client/NotificationServiceClient.java
with
139 additions
and
127 deletions
+139
-127
core/platform-common/src/main/java/org/sunbird/telemetry/util/TelemetryGenerator.java
+
0
−
3
View file @
bd4ca63b
...
@@ -54,7 +54,6 @@ public class TelemetryGenerator {
...
@@ -54,7 +54,6 @@ public class TelemetryGenerator {
}
}
Map
<
String
,
Object
>
edata
=
generateAuditEdata
(
params
);
Map
<
String
,
Object
>
edata
=
generateAuditEdata
(
params
);
edata
.
put
(
JsonKey
.
REQUEST_ID
,
reqId
);
Telemetry
telemetry
=
Telemetry
telemetry
=
new
Telemetry
(
TelemetryEvents
.
AUDIT
.
getName
(),
actor
,
eventContext
,
edata
,
targetObject
);
new
Telemetry
(
TelemetryEvents
.
AUDIT
.
getName
(),
actor
,
eventContext
,
edata
,
targetObject
);
telemetry
.
setMid
(
reqId
);
telemetry
.
setMid
(
reqId
);
...
@@ -208,7 +207,6 @@ public class TelemetryGenerator {
...
@@ -208,7 +207,6 @@ public class TelemetryGenerator {
eventContext
.
getCdata
().
add
(
map
);
eventContext
.
getCdata
().
add
(
map
);
}
}
Map
<
String
,
Object
>
edata
=
generateSearchEdata
(
params
);
Map
<
String
,
Object
>
edata
=
generateSearchEdata
(
params
);
edata
.
put
(
JsonKey
.
REQUEST_ID
,
reqId
);
Telemetry
telemetry
=
Telemetry
telemetry
=
new
Telemetry
(
TelemetryEvents
.
SEARCH
.
getName
(),
actor
,
eventContext
,
edata
);
new
Telemetry
(
TelemetryEvents
.
SEARCH
.
getName
(),
actor
,
eventContext
,
edata
);
telemetry
.
setMid
(
reqId
);
telemetry
.
setMid
(
reqId
);
...
@@ -264,7 +262,6 @@ public class TelemetryGenerator {
...
@@ -264,7 +262,6 @@ public class TelemetryGenerator {
}
}
Map
<
String
,
Object
>
edata
=
generateLogEdata
(
params
);
Map
<
String
,
Object
>
edata
=
generateLogEdata
(
params
);
edata
.
put
(
JsonKey
.
REQUEST_ID
,
reqId
);
Telemetry
telemetry
=
new
Telemetry
(
TelemetryEvents
.
LOG
.
getName
(),
actor
,
eventContext
,
edata
);
Telemetry
telemetry
=
new
Telemetry
(
TelemetryEvents
.
LOG
.
getName
(),
actor
,
eventContext
,
edata
);
telemetry
.
setMid
(
reqId
);
telemetry
.
setMid
(
reqId
);
return
getTelemetry
(
telemetry
);
return
getTelemetry
(
telemetry
);
...
...
This diff is collapsed.
Click to expand it.
service/src/main/java/org/sunbird/client/NotificationServiceClient.java
+
139
−
124
View file @
bd4ca63b
...
@@ -2,7 +2,9 @@ package org.sunbird.client;
...
@@ -2,7 +2,9 @@ package org.sunbird.client;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.apache.commons.codec.binary.StringUtils
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.sunbird.exception.ProjectCommonException
;
import
org.sunbird.exception.ProjectCommonException
;
import
org.sunbird.exception.ResponseCode
;
import
org.sunbird.exception.ResponseCode
;
import
org.sunbird.http.HttpClientUtil
;
import
org.sunbird.http.HttpClientUtil
;
...
@@ -14,137 +16,150 @@ import org.sunbird.response.Response;
...
@@ -14,137 +16,150 @@ import org.sunbird.response.Response;
import
org.sunbird.util.ProjectUtil
;
import
org.sunbird.util.ProjectUtil
;
import
org.sunbird.util.PropertiesCache
;
import
org.sunbird.util.PropertiesCache
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
NotificationServiceClient
{
public
class
NotificationServiceClient
{
private
final
LoggerUtil
logger
=
new
LoggerUtil
(
NotificationServiceClient
.
class
);
private
final
LoggerUtil
logger
=
new
LoggerUtil
(
NotificationServiceClient
.
class
);
private
ObjectMapper
mapper
=
new
ObjectMapper
();
private
ObjectMapper
mapper
=
new
ObjectMapper
();
private
Map
<
String
,
String
>
getHeader
(
RequestContext
context
)
{
private
Map
<
String
,
String
>
getHeader
(
RequestContext
context
){
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Accept"
,
"application/json"
);
headers
.
put
(
"Accept"
,
"application/json"
);
headers
.
put
(
"Content-type"
,
"application/json"
);
headers
.
put
(
"Content-type"
,
"application/json"
);
ProjectUtil
.
setTraceIdInHeader
(
headers
,
context
);
ProjectUtil
.
setTraceIdInHeader
(
headers
,
context
);
return
headers
;
return
headers
;
}
private
String
getJsonString
(
Request
req
)
throws
JsonProcessingException
{
String
json
=
mapper
.
writeValueAsString
(
req
);
json
=
new
String
(
json
.
getBytes
(),
StandardCharsets
.
UTF_8
);
return
json
;
}
/**
* Call Sync V2 send notification API to send notification feed
*
* @param reqObj
* @param context
* @return
*/
public
Response
sendSyncV2Notification
(
Request
reqObj
,
RequestContext
context
)
{
logger
.
debug
(
context
,
"NotificationServiceClient:sendSyncV2Notification method called : "
);
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V2_SEND_URL
);
logger
.
debug
(
context
,
"NotificationServiceClient:sendSyncV2Notification :: calling notification service URL :"
+
serviceUrl
);
try
{
Response
response
=
callCreateOrDeleteNotificationService
(
reqObj
,
context
,
serviceUrl
);
return
response
;
}
catch
(
Exception
ex
)
{
logger
.
error
(
context
,
"FeedServiceImpl:sendSyncV2Notification Exception occurred while mapping."
,
ex
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
}
}
private
String
getJsonString
(
Request
req
)
throws
JsonProcessingException
{
return
null
;
String
json
=
mapper
.
writeValueAsString
(
req
);
}
return
json
;
/**
* Call v1 Update notification service api to update feeds
*
* @param reqObj
* @param context
* @return
*/
public
Response
updateV1Notification
(
Request
reqObj
,
RequestContext
context
)
{
logger
.
debug
(
context
,
"NotificationServiceClient:updateV1Notification method called : "
);
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V1_UPDATE_URL
);
logger
.
debug
(
context
,
"NotificationServiceClient:updateV1Notification :: calling notification service URL :"
+
serviceUrl
);
try
{
String
json
=
getJsonString
(
reqObj
);
String
responseStr
=
HttpClientUtil
.
patch
(
serviceUrl
,
json
,
getHeader
(
context
),
context
);
Response
response
=
mapper
.
readValue
(
responseStr
,
Response
.
class
);
return
response
;
}
catch
(
Exception
ex
)
{
logger
.
error
(
context
,
"FeedServiceImpl:updateV1Notification Exception occurred while mapping."
,
ex
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
}
}
/**
return
null
;
* Call Sync V2 send notification API to send notification feed
}
* @param reqObj
* @param context
/**
* @return
* Call V1 read notification to read notifications
*/
*
public
Response
sendSyncV2Notification
(
Request
reqObj
,
RequestContext
context
)
{
* @param reqObj
logger
.
debug
(
context
,
"NotificationServiceClient:sendSyncV2Notification method called : "
);
* @param context
* @return
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V2_SEND_URL
);
*/
logger
.
debug
(
public
Response
readV1Notification
(
Request
reqObj
,
RequestContext
context
)
{
context
,
logger
.
debug
(
context
,
"NotificationServiceClient:readV1Notification method called : "
);
"NotificationServiceClient:sendSyncV2Notification :: calling notification service URL :"
+
serviceUrl
);
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V1_READ_URL
);
try
{
logger
.
debug
(
Response
response
=
callCreateOrDeleteNotificationService
(
reqObj
,
context
,
serviceUrl
);
context
,
return
response
;
"NotificationServiceClient:readV1Notification :: calling notification service URL :"
}
catch
(
Exception
ex
)
{
+
serviceUrl
);
logger
.
error
(
context
,
"FeedServiceImpl:sendSyncV2Notification Exception occurred while mapping."
,
ex
);
try
{
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
String
responseStr
=
}
HttpClientUtil
.
get
(
serviceUrl
+
"/"
+
reqObj
.
getRequest
().
get
(
JsonKey
.
USER_ID
),
return
null
;
getHeader
(
context
),
context
);
Response
response
=
mapper
.
readValue
(
responseStr
,
Response
.
class
);
return
response
;
}
catch
(
Exception
ex
)
{
logger
.
error
(
context
,
"FeedServiceImpl:readV1Notification Exception occurred while mapping."
,
ex
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
}
}
/**
return
null
;
* Call v1 Update notification service api to update feeds
}
* @param reqObj
* @param context
/**
* @return
* Call v1 delete notification service api
*/
*
public
Response
updateV1Notification
(
Request
reqObj
,
RequestContext
context
)
{
* @param reqObj
logger
.
debug
(
context
,
"NotificationServiceClient:updateV1Notification method called : "
);
* @param context
* @return
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V1_UPDATE_URL
);
*/
logger
.
debug
(
public
Response
deleteV1Notification
(
Request
reqObj
,
RequestContext
context
)
{
context
,
logger
.
debug
(
context
,
"NotificationServiceClient:deleteV1Notification method called : "
);
"NotificationServiceClient:updateV1Notification :: calling notification service URL :"
+
serviceUrl
);
try
{
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V1_DELETE_URL
);
String
json
=
getJsonString
(
reqObj
);
logger
.
debug
(
String
responseStr
=
HttpClientUtil
.
patch
(
serviceUrl
,
json
,
getHeader
(
context
),
context
);
context
,
Response
response
=
mapper
.
readValue
(
responseStr
,
Response
.
class
);
"NotificationServiceClient:deleteV1Notification :: calling notification service URL :"
return
response
;
+
serviceUrl
);
}
catch
(
Exception
ex
)
{
try
{
logger
.
error
(
context
,
"FeedServiceImpl:updateV1Notification Exception occurred while mapping."
,
ex
);
Response
response
=
callCreateOrDeleteNotificationService
(
reqObj
,
context
,
serviceUrl
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
return
response
;
}
}
catch
(
Exception
ex
)
{
logger
.
error
(
return
null
;
context
,
"FeedServiceImpl:deleteV1Notification Exception occurred while mapping."
,
ex
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
}
/**
* Call V1 read notification to read notifications
* @param reqObj
* @param context
* @return
*/
public
Response
readV1Notification
(
Request
reqObj
,
RequestContext
context
)
{
logger
.
debug
(
context
,
"NotificationServiceClient:readV1Notification method called : "
);
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V1_READ_URL
);
logger
.
debug
(
context
,
"NotificationServiceClient:readV1Notification :: calling notification service URL :"
+
serviceUrl
);
try
{
String
responseStr
=
HttpClientUtil
.
get
(
serviceUrl
+
"/"
+
reqObj
.
getRequest
().
get
(
JsonKey
.
USER_ID
),
getHeader
(
context
),
context
);
Response
response
=
mapper
.
readValue
(
responseStr
,
Response
.
class
);
return
response
;
}
catch
(
Exception
ex
)
{
logger
.
error
(
context
,
"FeedServiceImpl:readV1Notification Exception occurred while mapping."
,
ex
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
}
return
null
;
}
/**
* Call v1 delete notification service api
* @param reqObj
* @param context
* @return
*/
public
Response
deleteV1Notification
(
Request
reqObj
,
RequestContext
context
)
{
logger
.
debug
(
context
,
"NotificationServiceClient:deleteV1Notification method called : "
);
String
serviceUrl
=
getServiceApiUrl
(
JsonKey
.
NOTIFICATION_SERVICE_V1_DELETE_URL
);
logger
.
debug
(
context
,
"NotificationServiceClient:deleteV1Notification :: calling notification service URL :"
+
serviceUrl
);
try
{
Response
response
=
callCreateOrDeleteNotificationService
(
reqObj
,
context
,
serviceUrl
);
return
response
;
}
catch
(
Exception
ex
)
{
logger
.
error
(
context
,
"FeedServiceImpl:deleteV1Notification Exception occurred while mapping."
,
ex
);
ProjectCommonException
.
throwServerErrorException
(
ResponseCode
.
SERVER_ERROR
);
}
return
null
;
}
private
String
getServiceApiUrl
(
String
serviceUrlKey
){
String
NOTIFICATION_SERVICE_BASE_URL
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
NOTIFICATION_SERVICE_BASE_URL
);
String
NOTIFICATION_SERVICE_URL
=
PropertiesCache
.
getInstance
().
getProperty
(
serviceUrlKey
);
return
NOTIFICATION_SERVICE_BASE_URL
+
NOTIFICATION_SERVICE_URL
;
}
private
Response
callCreateOrDeleteNotificationService
(
Request
reqObj
,
RequestContext
context
,
String
serviceUrl
)
throws
JsonProcessingException
{
String
json
=
getJsonString
(
reqObj
);
String
responseStr
=
HttpClientUtil
.
post
(
serviceUrl
,
json
,
getHeader
(
context
),
context
);
return
mapper
.
readValue
(
responseStr
,
Response
.
class
);
}
}
return
null
;
}
private
String
getServiceApiUrl
(
String
serviceUrlKey
)
{
String
NOTIFICATION_SERVICE_BASE_URL
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
NOTIFICATION_SERVICE_BASE_URL
);
String
NOTIFICATION_SERVICE_URL
=
PropertiesCache
.
getInstance
().
getProperty
(
serviceUrlKey
);
return
NOTIFICATION_SERVICE_BASE_URL
+
NOTIFICATION_SERVICE_URL
;
}
private
Response
callCreateOrDeleteNotificationService
(
Request
reqObj
,
RequestContext
context
,
String
serviceUrl
)
throws
JsonProcessingException
{
String
json
=
getJsonString
(
reqObj
);
String
responseStr
=
HttpClientUtil
.
post
(
serviceUrl
,
json
,
getHeader
(
context
),
context
);
return
mapper
.
readValue
(
responseStr
,
Response
.
class
);
}
}
}
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