Add optional rule UID to DSL Rule file syntax#5449
Add optional rule UID to DSL Rule file syntax#5449lolodomo wants to merge 1 commit intoopenhab:mainfrom
Conversation
Closes openhab#5437 Allow avoiding iussue described in openhab#5415 by setting an UID. Also avoid notifying the rule registry for isolated models. Signed-off-by: Laurent Garnier <lg.hc@free.fr>
|
Going into draft mode until I check what happens if several same UID are used. |
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/rules-and-rule-templates-yaml-integration/168568/143 |
No problem, it is detected by the registry (as for other stuff - items, things, ...). I realized that the syntax did not accept hyphen inside the UID and not a number at the beginning of the ID, I will have to extend that and implement the same control on the UID as what @Nadahar implemented in the YAML provider (":" also accepted). @florian-h05 or @jsjames : can you please tell me what is the syntax accepted in Main UI for the rule UID ? We need the same to allow "conversions". |
|
So Main UI accepts leading hypen and does not accept colon |
It might be that it's time to formalize the format for the UID. I think it's probably "a bit random" what has been done until now, when I made "my choice", I did so by looking around and trying to "sum it up". It probably shouldn't be very restricted though, to avoid breaking existing rules. |
|
For compatibility reason, I propose to at least cover Main UI pattern. |
I support that. |
|
I plan to create a new RuleUID extending AbstractUID. |
Unless you're a C programmer 😝 |
I'm not sure what the benefit is of such encoding. I mean, as far as I know, "any string" will work here (as that's basically what we have today). We have URL encoding to apply if used as a URL parameter, JSON has its way to encode this. I think we should ideally only restrict what can cause problems somewhere. I'm not sure what that is, but some of the "symbols" can probably collide with something somewhere..? |
|
I propose to be consistent with other UID like thing UID. |
Isn't that much more restrictive than it is now, and will break a lot of existing rules. Is that really "worth it"? |
| return rulesMap.keySet().stream().filter(name -> !isIsolatedModel(name)) | ||
| .map(name -> rulesMap.getOrDefault(name, List.of())).flatMap(list -> list.stream()).toList(); |
There was a problem hiding this comment.
| return rulesMap.keySet().stream().filter(name -> !isIsolatedModel(name)) | |
| .map(name -> rulesMap.getOrDefault(name, List.of())).flatMap(list -> list.stream()).toList(); | |
| return rulesMap.entrySet().stream().filter(e -> !isIsolatedModel(e.getKey())) | |
| .flatMap(e -> e.getValue().stream()).toList(); |
There was a problem hiding this comment.
This is more efficient and prevents lookup in the map from inside the iteration. Neither of these solutions are thread-safe, but that goes for the whole logic around rules/rulesMap and is nothing new.
| Collection<Rule> oldRules = rulesMap.getOrDefault(modelFileName, List.of()); | ||
| Rule oldRule = null; | ||
| if (oldRules.size() == 1) { | ||
| oldRule = oldRules.iterator().next(); |
There was a problem hiding this comment.
It would be better to use a List than a Collection, then you could just call first().
...ore.model.rule.runtime/src/org/openhab/core/model/rule/runtime/internal/DSLRuleProvider.java
Show resolved
Hide resolved
| Iterator<Entry<String, XExpression>> it = xExpressions.entrySet().iterator(); | ||
| while (it.hasNext()) { |
There was a problem hiding this comment.
| Iterator<Entry<String, XExpression>> it = xExpressions.entrySet().iterator(); | |
| while (it.hasNext()) { | |
| for (Iterator<Entry<String, XExpression>> it = xExpressions.entrySet().iterator(); it.hasNext();) { |
|
I think there's a thing you have overlooked (unless I have overlooked your solution in the code): The The rule actions are stored as "scripts" in this map, using the "indexed UID scheme". To let the rules continue to work, non-generated rule UIDs must be handled here (and in |


Closes #5437
Allow avoiding iussue described in #5415 by setting an UID.
Also avoid notifying the rule registry for isolated models.