Skip to content

Commit 58c5ee0

Browse files
authored
Various fixes to tag parsing logic for legacy providers. (#322)
1 parent 63627fb commit 58c5ee0

File tree

4 files changed

+62
-15
lines changed

4 files changed

+62
-15
lines changed

src/main/kotlin/io/github/inductiveautomation/kindling/tagconfig/ProviderStatisticsPanel.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import io.github.inductiveautomation.kindling.utils.PopupMenuCustomizer
1313
import io.github.inductiveautomation.kindling.utils.ReifiedJXTable
1414
import io.github.inductiveautomation.kindling.utils.ReifiedListTableModel
1515
import io.github.inductiveautomation.kindling.utils.ReifiedTableModel
16+
import io.github.inductiveautomation.kindling.utils.jFrame
1617
import kotlinx.coroutines.Dispatchers
1718
import kotlinx.coroutines.launch
1819
import kotlinx.coroutines.withContext
1920
import net.miginfocom.swing.MigLayout
21+
import javax.swing.JButton
2022
import javax.swing.JLabel
23+
import javax.swing.JList
2124
import javax.swing.JPanel
2225
import javax.swing.JPopupMenu
2326
import javax.swing.table.AbstractTableModel
@@ -55,6 +58,11 @@ class ProviderStatisticsPanel :
5558
}
5659

5760
loading = false
61+
62+
if (newProvider.providerStatistics.missingUdtDefinition.value.isEmpty()) {
63+
missingUdtsLabel.isVisible = false
64+
missingUdtsButton.isVisible = false
65+
}
5866
}
5967
}
6068

@@ -77,6 +85,12 @@ class ProviderStatisticsPanel :
7785
putClientProperty("FlatLaf.styleClass", "h3")
7886
}
7987

88+
private val missingUdtsLabel = JLabel("⚠ Some UDT Definitions are missing.").apply {
89+
putClientProperty("FlatLaf.styleClass", "h3")
90+
}
91+
92+
private val missingUdtsButton = JButton("Click to view")
93+
8094
private var loading: Boolean = false
8195
set(value) {
8296
field = value
@@ -88,11 +102,21 @@ class ProviderStatisticsPanel :
88102
it.isVisible = !value
89103
}
90104

105+
val showMissingUdts =
106+
provider?.providerStatistics?.missingUdtDefinition?.value?.isNotEmpty() == true || !value
107+
108+
missingUdtsLabel.isVisible = showMissingUdts
109+
missingUdtsButton.isVisible = showMissingUdts
110+
91111
throbber.isVisible = value
92112
}
93113

94114
init {
95115
add(throbber, "push, grow, span")
116+
117+
add(missingUdtsLabel)
118+
add(missingUdtsButton, "wrap")
119+
96120
add(generalStatsLabel, "growx, span")
97121
add(generalStatsScrollPane, "growx, span, h 250!")
98122

@@ -103,6 +127,14 @@ class ProviderStatisticsPanel :
103127

104128
// Show nothing on startup
105129
components.forEach { it.isVisible = false }
130+
131+
missingUdtsButton.addActionListener {
132+
jFrame("Missing UDT Definitions", 300, 600) {
133+
contentPane.add(
134+
FlatScrollPane(JList<String>(provider!!.providerStatistics.missingUdtDefinition.value.toTypedArray())),
135+
)
136+
}
137+
}
106138
}
107139

108140
override fun customizePopupMenu(menu: JPopupMenu) = menu.removeAll()
@@ -125,7 +157,7 @@ class MappedStatModel(
125157
it.key
126158
}
127159

128-
val statValue by column("Value") {
160+
val statValue by column("Count") {
129161
it.value
130162
}
131163
}

src/main/kotlin/io/github/inductiveautomation/kindling/tagconfig/model/LegacyTagProvider.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ class LegacyTagProvider(
9494
if (orphanedParentNode.config.tags.isNotEmpty()) {
9595
providerNode.addChildTag(orphanedParentNode)
9696
}
97+
98+
// Make the missing definitions list distinct
99+
val seen = HashSet<String>()
100+
val iterator = providerStatistics.missingUdtDefinition.value.iterator()
101+
while (iterator.hasNext()) {
102+
val element = iterator.next()
103+
if (!seen.add(element)) {
104+
iterator.remove()
105+
}
106+
}
97107
}
98108

99109
// Effectively just the TagConfig table in memory.
@@ -210,12 +220,11 @@ class LegacyTagProvider(
210220
}
211221
}
212222

213-
override val Node.parentType: Node?
223+
override val Node.parentType: IdbNode?
214224
get() {
215-
require((statistics.isUdtDefinition || statistics.isUdtInstance) && config.typeId != null) {
216-
"Not a top level UDT Instance or type! $this"
217-
}
218-
return udtDefinitions[config.typeId]
225+
val typeId = config.typeId ?: return null
226+
// Some typeIds start with _types_, or even [ProviderName]_types_. It's unclear why.
227+
return udtDefinitions[typeId.substringAfter("_types_/")]
219228
}
220229

221230
override fun Node.copyChildrenFrom(other: Node) {
@@ -224,14 +233,21 @@ class LegacyTagProvider(
224233

225234
val thisNodeGroup = checkNotNull(nodeGroups[id]) { "This should never happen" }
226235

227-
val otherDefinition = checkNotNull(other.parentType as IdbNode?) { "Parent type is null!" }
236+
val otherDefinition = other.parentType ?: run {
237+
other.config.typeId?.let {
238+
providerStatistics.missingUdtDefinition.value.add(it)
239+
}
240+
return
241+
}
228242
val inheritedNodeGroup = checkNotNull(nodeGroups[otherDefinition.id]) { "This should never happen" }
229243

230244
if (!otherDefinition.resolved) {
231245
otherDefinition.resolveInheritance()
232246
}
233247

234-
check(other.statistics.isUdtInstance) { "Not a UDT Instance!" }
248+
check(other.statistics.isUdtInstance || other.statistics.isUdtDefinition) {
249+
"Not a UDT Structure!"
250+
}
235251

236252
inheritedNodeGroup.drop(1).forEach { childNode ->
237253
val newId = childNode.id.replace(otherDefinition.id, other.id)

src/main/kotlin/io/github/inductiveautomation/kindling/tagconfig/model/ProviderStatistics.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class ProviderStatistics private constructor(
1313
) : Map<String, ProviderStatistics.ProviderStatistic<*>> by statsMap {
1414
constructor() : this(mutableMapOf())
1515

16-
val orphanedTags = ListStatistic("orphanedTags", fun(_: ListStatistic<Node>, _: Node) = Unit)
16+
val orphanedTags = ListStatistic<Node>("orphanedTags")
17+
18+
val missingUdtDefinition = ListStatistic<String>("missingUdtDefinitions")
1719

1820
val totalAtomicTags by quantitativeStatistic {
1921
if (it.statistics.isAtomicTag) value++
@@ -77,7 +79,7 @@ class ProviderStatistics private constructor(
7779

7880
companion object {
7981
private const val DEFAULT_DATA_TYPE = "Int4"
80-
private const val DEFAULT_VALUE_SOURCE = "memory"
82+
private const val DEFAULT_VALUE_SOURCE = "MEMORY"
8183
}
8284

8385
sealed class ProviderStatistic<T>(val name: String) {
@@ -143,7 +145,7 @@ class ProviderStatistics private constructor(
143145

144146
class ListStatistic<T>(
145147
name: String,
146-
private val processNode: ListStatistic<T>.(node: Node) -> Unit,
148+
private val processNode: ListStatistic<T>.(node: Node) -> Unit = {},
147149
) : ProviderStatistic<MutableList<T>>(name) {
148150
override val value: MutableList<T> = mutableListOf()
149151
override fun processNode(node: Node) = processNode(this, node)

src/main/kotlin/io/github/inductiveautomation/kindling/tagconfig/model/TagProvider.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,7 @@ class TagProvider private constructor(
340340

341341
lastSeen = folderConfig
342342
} else {
343-
val tags: List<Node> = currentPath.inputStream().use {
344-
Json.decodeFromStream(it)
345-
}
346-
343+
val tags: List<Node> = currentPath.inputStream().use(Json::decodeFromStream)
347344
lastSeen.addChildTags(tags)
348345
}
349346
}

0 commit comments

Comments
 (0)