Skip to content

Commit 80f1b3e

Browse files
author
Ravi Nadahar
committed
Revert "[automation] AbstractScriptModuleHandler: Remove prefixes from context entries before injecting ctx into execution context (openhab#4919)"
This reverts commit 9c27b89.
1 parent 2169fe0 commit 80f1b3e

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,21 @@ protected void setExecutionContext(ScriptEngine engine, Map<String, ?> context)
202202

203203
// Add the rule's UID to the context and make it available as "ctx".
204204
// Note: We don't use "context" here as it doesn't work on all JVM versions!
205-
final Map<String, Object> contextNew = new HashMap<>();
206-
// add the single context entries without their prefix to contextNew
205+
final Map<String, Object> contextNew = new HashMap<>(context);
206+
contextNew.put("ruleUID", this.ruleUID);
207+
executionContext.setAttribute("ctx", contextNew, ScriptContext.ENGINE_SCOPE);
208+
209+
// Add the rule's UID to the global namespace.
210+
executionContext.setAttribute("ruleUID", this.ruleUID, ScriptContext.ENGINE_SCOPE);
211+
212+
// add the single context entries without their prefix to the scope
207213
for (Entry<String, ?> entry : context.entrySet()) {
208214
Object value = entry.getValue();
209215
String key = entry.getKey();
210216
int dotIndex = key.indexOf('.');
211217
if (dotIndex != -1) {
212218
key = key.substring(dotIndex + 1);
213219
}
214-
contextNew.put(key, value);
215-
}
216-
contextNew.put("ruleUID", this.ruleUID);
217-
executionContext.setAttribute("ctx", contextNew, ScriptContext.ENGINE_SCOPE);
218-
219-
// add the single contextNew entries to the scope
220-
for (Entry<String, ?> entry : contextNew.entrySet()) {
221-
Object value = entry.getValue();
222-
String key = entry.getKey();
223220
executionContext.setAttribute(key, value, ScriptContext.ENGINE_SCOPE);
224221
}
225222
}

0 commit comments

Comments
 (0)