in src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/Policy.kt [134:201]
fun parse(
xcp: XContentParser,
id: String = NO_ID,
seqNo: Long = SequenceNumbers.UNASSIGNED_SEQ_NO,
primaryTerm: Long = SequenceNumbers.UNASSIGNED_PRIMARY_TERM
): Policy {
var description: String? = null
var defaultState: String? = null
var errorNotification: ErrorNotification? = null
var lastUpdatedTime: Instant? = null
var schemaVersion: Long = IndexUtils.DEFAULT_SCHEMA_VERSION
val states: MutableList<State> = mutableListOf()
var ismTemplates: List<ISMTemplate>? = null
var user: User? = null
ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != Token.END_OBJECT) {
val fieldName = xcp.currentName()
xcp.nextToken()
when (fieldName) {
SCHEMA_VERSION_FIELD -> schemaVersion = xcp.longValue()
LAST_UPDATED_TIME_FIELD -> lastUpdatedTime = xcp.instant()
POLICY_ID_FIELD -> { /* do nothing as this is an internal field */ }
DESCRIPTION_FIELD -> description = xcp.text()
ERROR_NOTIFICATION_FIELD -> errorNotification = if (xcp.currentToken() == Token.VALUE_NULL) null else ErrorNotification.parse(xcp)
DEFAULT_STATE_FIELD -> defaultState = xcp.text()
STATES_FIELD -> {
ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp)
while (xcp.nextToken() != Token.END_ARRAY) {
states.add(State.parse(xcp))
}
}
ISM_TEMPLATE -> {
if (xcp.currentToken() != Token.VALUE_NULL) {
ismTemplates = mutableListOf()
when (xcp.currentToken()) {
Token.START_ARRAY -> {
while (xcp.nextToken() != Token.END_ARRAY) {
ismTemplates.add(ISMTemplate.parse(xcp))
}
}
Token.START_OBJECT -> {
ismTemplates.add(ISMTemplate.parse(xcp))
}
else -> ensureExpectedToken(Token.START_ARRAY, xcp.currentToken(), xcp)
}
}
}
USER_FIELD -> user = if (xcp.currentToken() == Token.VALUE_NULL) null else User.parse(xcp)
else -> throw IllegalArgumentException("Invalid field: [$fieldName] found in Policy.")
}
}
return Policy(
id = id,
seqNo = seqNo,
primaryTerm = primaryTerm,
description = requireNotNull(description) { "$DESCRIPTION_FIELD is null" },
schemaVersion = schemaVersion,
lastUpdatedTime = lastUpdatedTime ?: Instant.now(),
errorNotification = errorNotification,
defaultState = requireNotNull(defaultState) { "$DEFAULT_STATE_FIELD is null" },
states = states.toList(),
ismTemplate = ismTemplates,
user = user
)
}