ReloadTaskDataModel.kt
/*
Copyright (C) 2026 Sber
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.archtool.data.model
import com.fasterxml.jackson.annotation.JsonInclude
import tools.jackson.databind.JsonNode
import tools.jackson.databind.json.JsonMapper
import java.io.Serializable
@JsonInclude(JsonInclude.Include.NON_NULL)
data class ReloadTaskDataModel(
val backend: String,
val reloadRoot: Boolean? = null,
val mode: String? = null,
val aliases: List<String>? = null,
val scheduleId: String? = null,
val additionalRequests: List<AdditionalRequest>? = null
) : Serializable {
/** Запрос сверх первого. Как и основные поля, не содержит secret: taskData отдаётся через API статуса. */
@JsonInclude(JsonInclude.Include.NON_NULL)
data class AdditionalRequest(
val reloadRoot: Boolean? = null,
val mode: String? = null,
val aliases: List<String>? = null,
val scheduleId: String? = null
) : Serializable
companion object {
fun toJsonNode(data: ManifestReloadTaskModel, jsonMapper: JsonMapper): JsonNode? {
val taskData = ReloadTaskDataModel(
backend = data.backend,
reloadRoot = data.reloadRoot,
mode = data.mode,
aliases = data.aliases,
scheduleId = data.scheduleId,
additionalRequests = data.additionalRequests
.map { AdditionalRequest(it.reloadRoot, it.mode, it.aliases, it.scheduleId) }
.ifEmpty { null }
)
val node = jsonMapper.valueToTree<JsonNode>(taskData)
return if (node.isEmpty) null else node
}
}
}