in src/main/kotlin/org/opensearch/commons/notifications/model/NotificationEvent.kt [68:97]
fun parse(parser: XContentParser): NotificationEvent {
var eventSource: EventSource? = null
var statusList: List<EventStatus> = listOf()
XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_OBJECT,
parser.currentToken(),
parser
)
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
val fieldName = parser.currentName()
parser.nextToken()
when (fieldName) {
EVENT_SOURCE_TAG -> eventSource = EventSource.parse(parser)
STATUS_LIST_TAG -> statusList = parser.objectList { EventStatus.parse(it) }
else -> {
parser.skipChildren()
log.info("Unexpected field: $fieldName, while parsing notification event")
}
}
}
eventSource ?: throw IllegalArgumentException("$EVENT_SOURCE_TAG field absent")
if (statusList.isEmpty()) {
throw IllegalArgumentException("$STATUS_LIST_TAG field absent or empty")
}
return NotificationEvent(
eventSource,
statusList
)
}