fun parse()

in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexMetaData.kt [220:292]


        fun parse(
            xcp: XContentParser,
            id: String = NO_ID,
            seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO,
            primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM
        ): ManagedIndexMetaData {
            var index: String? = null
            var indexUuid: String? = null
            var policyID: String? = null
            var policySeqNo: Long? = null
            var policyPrimaryTerm: Long? = null
            var policyCompleted: Boolean? = null
            var rolledOver: Boolean? = null
            var transitionTo: String? = null

            var state: StateMetaData? = null
            var action: ActionMetaData? = null
            var step: StepMetaData? = null
            var retryInfo: PolicyRetryInfoMetaData? = null

            var info: Map<String, Any>? = null

            ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp)
            while (xcp.nextToken() != Token.END_OBJECT) {
                val fieldName = xcp.currentName()
                xcp.nextToken()

                when (fieldName) {
                    INDEX -> index = xcp.text()
                    INDEX_UUID -> indexUuid = xcp.text()
                    POLICY_ID -> policyID = xcp.text()
                    POLICY_SEQ_NO -> policySeqNo = if (xcp.currentToken() == Token.VALUE_NULL) null else xcp.longValue()
                    POLICY_PRIMARY_TERM -> policyPrimaryTerm = if (xcp.currentToken() == Token.VALUE_NULL) null else xcp.longValue()
                    POLICY_COMPLETED -> policyCompleted = if (xcp.currentToken() == Token.VALUE_NULL) null else xcp.booleanValue()
                    ROLLED_OVER -> rolledOver = if (xcp.currentToken() == Token.VALUE_NULL) null else xcp.booleanValue()
                    TRANSITION_TO -> transitionTo = if (xcp.currentToken() == Token.VALUE_NULL) null else xcp.text()
                    StateMetaData.STATE -> {
                        state = if (xcp.currentToken() == Token.VALUE_NULL) null else StateMetaData.parse(xcp)
                    }
                    ActionMetaData.ACTION -> {
                        action = if (xcp.currentToken() == Token.VALUE_NULL) null else ActionMetaData.parse(xcp)
                    }
                    StepMetaData.STEP -> {
                        step = if (xcp.currentToken() == Token.VALUE_NULL) null else StepMetaData.parse(xcp)
                    }
                    PolicyRetryInfoMetaData.RETRY_INFO -> {
                        retryInfo = PolicyRetryInfoMetaData.parse(xcp)
                    }
                    INFO -> info = xcp.map()
                    // below line will break when getting metadata for explain or history
                    // else -> throw IllegalArgumentException("Invalid field: [$fieldName] found in ManagedIndexMetaData.")
                }
            }

            return ManagedIndexMetaData(
                requireNotNull(index) { "$INDEX is null" },
                requireNotNull(indexUuid) { "$INDEX_UUID is null" },
                requireNotNull(policyID) { "$POLICY_ID is null" },
                policySeqNo,
                policyPrimaryTerm,
                policyCompleted,
                rolledOver,
                transitionTo,
                state,
                action,
                step,
                retryInfo,
                info,
                id,
                seqNo,
                primaryTerm
            )
        }