From 867e27a9a3da9efaa000d36a568d0bdd6d209787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Mon, 9 Oct 2023 12:23:07 +0200 Subject: [PATCH] [javarule] Adding tags to Rule annotation (#525) * [javarule] Adding tags to Rule annotation Adresses issue #504 Signed-off-by: clinique --- .../org/smarthomej/automation/javarule/annotation/Rule.java | 2 ++ .../automation/javarule/internal/script/RuleProcessor.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/annotation/Rule.java b/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/annotation/Rule.java index df71336ea6..20599e8bfe 100644 --- a/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/annotation/Rule.java +++ b/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/annotation/Rule.java @@ -33,5 +33,7 @@ public @interface Rule { String name() default ANNOTATION_DEFAULT; + String[] tags() default {}; + boolean disabled() default false; } diff --git a/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/internal/script/RuleProcessor.java b/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/internal/script/RuleProcessor.java index 4e7d037638..083e6061c5 100644 --- a/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/internal/script/RuleProcessor.java +++ b/bundles/org.smarthomej.automation.javarule/src/main/java/org/smarthomej/automation/javarule/internal/script/RuleProcessor.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -78,6 +79,8 @@ public static List getSimpleRules(String scriptIdentifier, JavaRule String ruleName = method.getName(); String ruleDescription = ruleAnnotation.name(); + Set ruleTags = Set.of(ruleAnnotation.tags()); + if (ruleDescription.isBlank() || ANNOTATION_DEFAULT.equals(ruleDescription)) { ruleDescription = script.getClass().getSimpleName() + "/" + method.getName(); } @@ -121,6 +124,7 @@ public Object execute(Action module, Map input) { simpleRule.setDescription(ruleDescription); simpleRule.setTriggers(triggers); simpleRule.setConditions(conditions); + simpleRule.setTags(ruleTags); rules.add(simpleRule);