mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(context): add urgency attribute/label to BlockContent
This commit is contained in:
@@ -5,6 +5,7 @@ import org.w3c.dom.Element
|
||||
import java.io.StringWriter
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
import javax.xml.transform.OutputKeys
|
||||
@@ -195,11 +196,19 @@ data class ContextBlock @JvmOverloads constructor(
|
||||
)
|
||||
}
|
||||
|
||||
abstract class BlockContent protected constructor(
|
||||
abstract class BlockContent @JvmOverloads protected constructor(
|
||||
val blockName: String,
|
||||
val source: String,
|
||||
val urgency: Urgency = Urgency.NORMAL
|
||||
) {
|
||||
|
||||
enum class Urgency {
|
||||
LOW,
|
||||
NORMAL,
|
||||
HIGH,
|
||||
CRITICAL
|
||||
}
|
||||
|
||||
fun encodeToXml(): Element {
|
||||
val document = DocumentBuilderFactory.newInstance()
|
||||
.newDocumentBuilder()
|
||||
@@ -207,6 +216,7 @@ abstract class BlockContent protected constructor(
|
||||
|
||||
val root = document.createElement(blockName)
|
||||
root.setAttribute("source", source)
|
||||
root.setAttribute("urgency", urgency.name.lowercase(Locale.ROOT))
|
||||
document.appendChild(root)
|
||||
|
||||
fillXml(document, root)
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ActionPlanner extends AbstractAgentModule.Running<PartnerRunningFlo
|
||||
}
|
||||
|
||||
private BlockContent buildPendingBlock(String blockName, ExecutableAction executableAction, EvaluatorResult evaluatorResult) {
|
||||
return new BlockContent(blockName, PENDING_BLOCK_SOURCE) {
|
||||
return new BlockContent(blockName, PENDING_BLOCK_SOURCE, BlockContent.Urgency.HIGH) {
|
||||
@Override
|
||||
protected void fillXml(@NotNull Document document, @NotNull Element root) {
|
||||
appendTextElement(document, root, "state", "waiting_confirm");
|
||||
@@ -190,7 +190,7 @@ public class ActionPlanner extends AbstractAgentModule.Running<PartnerRunningFlo
|
||||
}
|
||||
|
||||
private BlockContent buildPendingCompactBlock(String blockName, ExecutableAction executableAction, EvaluatorResult evaluatorResult) {
|
||||
return new BlockContent(blockName, PENDING_BLOCK_SOURCE) {
|
||||
return new BlockContent(blockName, PENDING_BLOCK_SOURCE, BlockContent.Urgency.HIGH) {
|
||||
@Override
|
||||
protected void fillXml(@NotNull Document document, @NotNull Element root) {
|
||||
appendTextElement(document, root, "state", "waiting_confirm");
|
||||
@@ -202,7 +202,7 @@ public class ActionPlanner extends AbstractAgentModule.Running<PartnerRunningFlo
|
||||
}
|
||||
|
||||
private BlockContent buildPendingAbstractBlock(String blockName, ExecutableAction executableAction, EvaluatorResult evaluatorResult) {
|
||||
return new BlockContent(blockName, PENDING_BLOCK_SOURCE) {
|
||||
return new BlockContent(blockName, PENDING_BLOCK_SOURCE, BlockContent.Urgency.HIGH) {
|
||||
@Override
|
||||
protected void fillXml(@NotNull Document document, @NotNull Element root) {
|
||||
appendTextElement(document, root, "pending_tendency", executableAction.getTendency());
|
||||
|
||||
Reference in New Issue
Block a user