in src/main/kotlin/org/opensearch/commons/notifications/model/NotificationEventInfo.kt [73:108]
fun parse(parser: XContentParser): NotificationEventInfo {
var eventId: String? = null
var lastUpdatedTime: Instant? = null
var createdTime: Instant? = null
var notificationEvent: NotificationEvent? = null
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_ID_TAG -> eventId = parser.text()
UPDATED_TIME_TAG -> lastUpdatedTime = Instant.ofEpochMilli(parser.longValue())
CREATED_TIME_TAG -> createdTime = Instant.ofEpochMilli(parser.longValue())
EVENT_TAG -> notificationEvent = NotificationEvent.parse(parser)
else -> {
parser.skipChildren()
log.info("Unexpected field: $fieldName, while parsing event info")
}
}
}
eventId ?: throw IllegalArgumentException("$EVENT_ID_TAG field absent")
lastUpdatedTime ?: throw IllegalArgumentException("$UPDATED_TIME_TAG field absent")
createdTime ?: throw IllegalArgumentException("$CREATED_TIME_TAG field absent")
notificationEvent ?: throw IllegalArgumentException("$EVENT_TAG field absent")
return NotificationEventInfo(
eventId,
lastUpdatedTime,
createdTime,
notificationEvent
)
}