mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
[DSL rule] Add tags to DSL file syntax (#5442)
* [DSL rule] Add tags to DSL file syntax Closes #5436 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
+6
-1
@@ -18,6 +18,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -279,7 +280,11 @@ public class DSLRuleProvider
|
||||
List<Action> actions = List.of(ActionBuilder.create().withId("script").withTypeUID("script.ScriptAction")
|
||||
.withConfiguration(cfg).build());
|
||||
|
||||
return RuleBuilder.create(uid).withName(name).withTriggers(triggers).withActions(actions).build();
|
||||
List<String> ruleTags = rule.getTags();
|
||||
Set<String> tags = ruleTags == null ? Set.of() : Set.copyOf(ruleTags);
|
||||
|
||||
return RuleBuilder.create(uid).withTags(tags).withName(name).withTriggers(triggers).withActions(actions)
|
||||
.build();
|
||||
}
|
||||
|
||||
private String removeIndentation(String script) {
|
||||
|
||||
@@ -12,7 +12,7 @@ VariableDeclaration:
|
||||
;
|
||||
|
||||
Rule:
|
||||
'rule' name=(STRING|ID)
|
||||
'rule' name=(STRING|ID) ('[' tags+=(ID|STRING) (',' tags+=(ID|STRING))* ']')?
|
||||
'when' eventtrigger+=EventTrigger ('or' eventtrigger+=EventTrigger)*
|
||||
'then' script=XExpressionInClosure
|
||||
'end'
|
||||
|
||||
+6
-1
@@ -14,6 +14,7 @@ package org.openhab.core.model.rule.runtime;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -93,7 +94,7 @@ public class DSLRuleProviderTest extends JavaOSGiTest {
|
||||
Collection<Rule> rules = dslRuleProvider.getAll();
|
||||
assertThat(rules.size(), is(0));
|
||||
|
||||
String model = "rule RuleNumberOne\n" + //
|
||||
String model = "rule RuleNumberOne [ Test, \"my test\" ]\n" + //
|
||||
"when\n" + //
|
||||
" System started\n" + //
|
||||
"then\n" + //
|
||||
@@ -117,6 +118,9 @@ public class DSLRuleProviderTest extends JavaOSGiTest {
|
||||
|
||||
assertThat(firstRule.getUID(), is("dslruletest-1"));
|
||||
assertThat(firstRule.getName(), is("RuleNumberOne"));
|
||||
assertThat(firstRule.getTags(), hasSize(2));
|
||||
assertThat(firstRule.getTags(), hasItem("Test"));
|
||||
assertThat(firstRule.getTags(), hasItem("my test"));
|
||||
assertThat(firstRule.getTriggers().getFirst().getTypeUID(), is(SystemTriggerHandler.STARTLEVEL_MODULE_TYPE_ID));
|
||||
assertThat(firstRule.getActions().getFirst().getTypeUID(), is(ScriptActionHandler.TYPE_ID));
|
||||
assertThat(firstRule.getActions().getFirst().getConfiguration()
|
||||
@@ -126,6 +130,7 @@ public class DSLRuleProviderTest extends JavaOSGiTest {
|
||||
|
||||
assertThat(secondRule.getUID(), is("dslruletest-2"));
|
||||
assertThat(secondRule.getName(), is("Rule Number Two"));
|
||||
assertThat(secondRule.getTags(), hasSize(0));
|
||||
assertThat(secondRule.getTriggers().getFirst().getTypeUID(), is(ItemStateTriggerHandler.CHANGE_MODULE_TYPE_ID));
|
||||
assertThat(secondRule.getTriggers().getFirst().getConfiguration().get(ItemStateTriggerHandler.CFG_ITEMNAME),
|
||||
is("X"));
|
||||
|
||||
Reference in New Issue
Block a user