Skip to content

Commit cff580f

Browse files
committed
deserialize notifs from file
1 parent fd2d1fb commit cff580f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPollingService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ interface NotificationPollingService {
3636
}
3737

3838
object NotificationFileValidator : RemoteResolveParser {
39-
private val mapper = jacksonObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
4039
override fun canBeParsed(data: InputStream): Boolean {
4140
return try {
42-
mapper.readValue<NotificationsList>(data)
41+
NotificationMapperUtil.mapper.readValue<NotificationsList>(data)
4342
true
4443
} catch (e: Exception) {
4544
false

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBase.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33

44
package software.aws.toolkits.jetbrains.core.notifications
55

6+
import com.fasterxml.jackson.databind.DeserializationFeature
7+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
8+
import com.fasterxml.jackson.module.kotlin.readValue
69
import com.intellij.openapi.project.Project
10+
import software.aws.toolkits.core.utils.inputStream
11+
import java.io.InputStream
712
import java.nio.file.Path
813

14+
object NotificationMapperUtil{
15+
val mapper = jacksonObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
16+
}
17+
918
class ProcessNotificationsBase {
1019
init {
1120
NotificationPollingServiceImpl.getInstance().addObserver { path ->
1221
getNotificationsFromFile(path)
1322
}
1423
}
1524

16-
fun getNotificationsFromFile(path: Path) {
17-
// TODO: returns a notification list
18-
}
25+
fun getNotificationsFromFile(path: Path): NotificationsList =
26+
path.inputStream().use { data ->
27+
NotificationMapperUtil.mapper.readValue<NotificationsList>(data)
28+
}
29+
1930

2031
fun retrieveStartupAndEmergencyNotifications() {
2132
// TODO: separates notifications into startup and emergency

0 commit comments

Comments
 (0)