GitHub - paul-griffith/tagKreator
So, I’m “releasing” v0.1 of a side project I’ve been working on for a little while.
It was mostly an exercise for me to learn more about Kotlin (an alternate JVM programming language, like Java or Jython) - but the end result might just be useful to some of you out there, so I figured I’ll post it up.
Basically, it’s a means to programatically generate (in a relatively type-safe way) JSON files that match the format of Ignition’s tag exports. What the heck does that mean? Well, basically, code like this (in Kotlin):
memory<Int>("Integer") {
value {
123
}
documentation = "My TagKreator tag"
history {
provider = "MySQL"
enabled = true
sampleRate = Duration.hours(1)
}
scripts {
valueChanged {
"""system.util.getLogger("log").info(str(currentValue.value))"""
}
}
security {
read(AllOf) {
levels {
level("Authenticated") {
level("Administrator")
}
}
}
}
}
Is output as the following JSON:
{
"tagType": "AtomicTag",
"name": "Integer",
"value": 123,
"documentation": "My TagKreator tag",
"readOnly": false,
"readPermissions": {
"securityLevels": [
{
"name": "Authenticated",
"children": [
{
"name": "Administrator",
"children": []
}
]
}
],
"type": "AllOf"
},
"eventScripts": [
{
"eventid": "valueChanged",
"script": "system.util.getLogger(\"log\").info(str(currentValue.value))"
}
],
"historyEnabled": true,
"historyProvider": "MySQL",
"historySampleRate": 3600,
"historySampleRateUnits": "SEC"
}
But more than that, you can also do whatever string interpolation, loops, etc you could possibly want - Kotlin is a full-featured programming language; one way to think of this is as a multi-instance wizard on steroids.
Another fun possibility - since Kotlin’s serialization to JSON is bidirectional, you could import a given tag export, run some code to change it, then dump the result back out to JSON.
Because it’s in such a raw state, this is very much something that should be approached with caution - this is a personal project I’m giving to the community in case it’s useful - don’t expect any guarantees of support, future features, etc. I’ve only done basic testing, but have successfully created a variety of tag exports - however, I’m at a point where I want to see if it’s actually useful to anyone before I invest too much more time (I’ve completed my primary objective of learning a bunch about Kotlin DSLs).
Please do let me know if you have questions or feedback on anything, though. If you’re interested, I’d recommend checking out the readme on Github - that’s probably going to stay up to date better than this post.