fun parse()

in src/main/kotlin/org/opensearch/commons/notifications/model/NotificationConfig.kt [89:132]


        fun parse(parser: XContentParser): NotificationConfig {
            var name: String? = null
            var description = ""
            var configType: ConfigType? = null
            var features: Set<String>? = null
            var isEnabled = true
            var configData: BaseConfigData? = 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) {
                    NAME_TAG -> name = parser.text()
                    DESCRIPTION_TAG -> description = parser.text()
                    CONFIG_TYPE_TAG -> configType = ConfigType.fromTagOrDefault(parser.text())
                    FEATURE_LIST_TAG -> features = parser.stringList().toSet()
                    IS_ENABLED_TAG -> isEnabled = parser.booleanValue()
                    else -> {
                        val configTypeForTag = ConfigType.fromTagOrDefault(fieldName)
                        if (configTypeForTag != ConfigType.NONE && configData == null) {
                            configData = createConfigData(configTypeForTag, parser)
                        } else {
                            parser.skipChildren()
                            log.info("Unexpected field: $fieldName, while parsing configuration")
                        }
                    }
                }
            }
            name ?: throw IllegalArgumentException("$NAME_TAG field absent")
            configType ?: throw IllegalArgumentException("$CONFIG_TYPE_TAG field absent")
            features ?: throw IllegalArgumentException("$FEATURE_LIST_TAG field absent")
            return NotificationConfig(
                name,
                description,
                configType,
                features,
                configData,
                isEnabled
            )
        }