Skip to content

Commit 8deaf3f

Browse files
author
Ravi Nadahar
committed
Fix DSL implicit contexts variables for '.rules' based rules
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
1 parent b9c3646 commit 8deaf3f

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/jvmmodel/RulesJvmModelInferrer.xtend

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import org.slf4j.LoggerFactory
3939
import org.eclipse.xtext.common.types.JvmFormalParameter
4040
import org.eclipse.emf.common.util.EList
4141
import org.openhab.core.automation.module.script.rulesupport.shared.ValueCache
42+
import java.util.Map
43+
import org.openhab.core.events.Event
4244

4345
/**
4446
* <p>Infers a JVM model from the source model.</p>
@@ -108,6 +110,9 @@ class RulesJvmModelInferrer extends ScriptJvmModelInferrer {
108110
members += ruleModel.rules.map [ rule |
109111
rule.toMethod("_" + rule.name, typeRef(Void.TYPE)) [
110112
static = true
113+
parameters += rule.toParameter(VAR_EVENT_OBJECT, typeRef(Event))
114+
parameters += rule.toParameter(VAR_CTX, typeRef(Map, typeRef(String), typeRef(Object)))
115+
parameters += rule.toParameter(VAR_INPUTS, typeRef(Map, typeRef(String), typeRef(Map, typeRef(String), typeRef(Object))))
111116
val privateCacheTypeRef = typeRef(ValueCache)
112117
parameters += rule.toParameter(VAR_PRIVATE_CACHE, privateCacheTypeRef)
113118
val sharedCacheTypeRef = typeRef(ValueCache)

bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/DSLScriptEngine.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ private DefaultEvaluationContext createEvaluationContext(Script script, IEvaluat
208208
}
209209
}
210210
}
211-
evalContext.newValue(QualifiedName.create("ctx"), ctx);
212-
evalContext.newValue(QualifiedName.create("eventObject"), eventObject);
213-
evalContext.newValue(QualifiedName.create("inputs"), inputs);
211+
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_CTX), ctx);
212+
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_EVENT_OBJECT), eventObject);
213+
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_INPUTS), inputs);
214214

215215
Map<String, Object> cachePreset = scriptExtensionAccessor.findPreset("cache",
216216
(String) context.getAttribute("oh.engine-identifier", ScriptContext.ENGINE_SCOPE));

bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/jvmmodel/ScriptJvmModelInferrer.xtend

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer {
9191
/** Variable name for the cache */
9292
public static final String VAR_PRIVATE_CACHE = "privateCache";
9393
public static final String VAR_SHARED_CACHE = "sharedCache";
94+
95+
/** Variable names for the context objects */
96+
public static final String VAR_EVENT_OBJECT = "eventObject";
97+
public static final String VAR_CTX = "ctx";
98+
public static final String VAR_INPUTS = "inputs";
9499

95100
/**
96101
* convenience API to build and initialize JvmTypes and their members.
@@ -139,9 +144,9 @@ class ScriptJvmModelInferrer extends AbstractModelInferrer {
139144

140145
members += script.toMethod("_script", null) [
141146
static = true
142-
parameters += script.toParameter("eventObject", typeRef(Event))
143-
parameters += script.toParameter("ctx", typeRef(Map, typeRef(String), typeRef(Object)))
144-
parameters += script.toParameter("inputs", typeRef(Map, typeRef(String), typeRef(Map, typeRef(String), typeRef(Object))))
147+
parameters += script.toParameter(VAR_EVENT_OBJECT, typeRef(Event))
148+
parameters += script.toParameter(VAR_CTX, typeRef(Map, typeRef(String), typeRef(Object)))
149+
parameters += script.toParameter(VAR_INPUTS, typeRef(Map, typeRef(String), typeRef(Map, typeRef(String), typeRef(Object))))
145150
val inputTypeRef = typeRef(String)
146151
parameters += script.toParameter(VAR_INPUT, inputTypeRef)
147152
val groupTypeRef = typeRef(Item)

0 commit comments

Comments
 (0)