diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java index ec7a090ac2e..2c7afe3974c 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java @@ -54,6 +54,7 @@ @NonNullByDefault @Component(factory = "org.openhab.core.automation.module.script.transformation.factory") public class ScriptTransformationService implements TransformationService, RegistryChangeListener { + public static final String SCRIPT_TYPE_PROPERTY_NAME = "openhab.transform.script.scriptType"; public static final String OPENHAB_TRANSFORMATION_SCRIPT = "openhab-transformation-script-"; private static final Pattern INLINE_SCRIPT_CONFIG_PATTERN = Pattern.compile("\\|(?.+)"); @@ -75,16 +76,15 @@ public class ScriptTransformationService implements TransformationService, Regis @Activate public ScriptTransformationService(@Reference TransformationRegistry transformationRegistry, @Reference ScriptEngineManager scriptEngineManager, Map config) { - String servicePropertyName = ConfigParser.valueAs(config.get(TransformationService.SERVICE_PROPERTY_NAME), - String.class); - if (servicePropertyName == null) { + String scriptType = ConfigParser.valueAs(config.get(SCRIPT_TYPE_PROPERTY_NAME), String.class); + if (scriptType == null) { throw new IllegalStateException( - "'" + TransformationService.SERVICE_PROPERTY_NAME + "' must not be null in service configuration"); + "'" + SCRIPT_TYPE_PROPERTY_NAME + "' must not be null in service configuration"); } this.transformationRegistry = transformationRegistry; this.scriptEngineManager = scriptEngineManager; - this.scriptType = servicePropertyName.toLowerCase(); + this.scriptType = scriptType; transformationRegistry.addRegistryChangeListener(this); } diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java index f317fd472ae..3097857ed64 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationServiceFactory.java @@ -55,7 +55,8 @@ * * @author Jimmy Tanagra - Initial contribution */ -@Component(immediate = true, service = { ConfigDescriptionProvider.class, ConfigOptionProvider.class }) +@Component(immediate = true, service = { ScriptTransformationServiceFactory.class, ConfigDescriptionProvider.class, + ConfigOptionProvider.class }) @NonNullByDefault public class ScriptTransformationServiceFactory implements ConfigDescriptionProvider, ConfigOptionProvider { private final Logger logger = LoggerFactory.getLogger(ScriptTransformationServiceFactory.class); @@ -98,6 +99,7 @@ public void setScriptEngineFactory(ScriptEngineFactory engineFactory) { Dictionary properties = new Hashtable<>(); properties.put(TransformationService.SERVICE_PROPERTY_NAME, type.toUpperCase()); + properties.put(ScriptTransformationService.SCRIPT_TYPE_PROPERTY_NAME, type); ComponentInstance instance = scriptTransformationFactory .newInstance(properties); diff --git a/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/ScriptTransformationServiceTest.java b/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/ScriptTransformationServiceTest.java index 71e22101991..e30b2fdb468 100644 --- a/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/ScriptTransformationServiceTest.java +++ b/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/ScriptTransformationServiceTest.java @@ -40,7 +40,6 @@ import org.openhab.core.transform.Transformation; import org.openhab.core.transform.TransformationException; import org.openhab.core.transform.TransformationRegistry; -import org.openhab.core.transform.TransformationService; /** * The {@link ScriptTransformationServiceTest} holds tests for the {@link ScriptTransformationService} @@ -51,7 +50,7 @@ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class ScriptTransformationServiceTest { - private static final String SCRIPT_LANGUAGE = "customdsl"; + private static final String SCRIPT_LANGUAGE = "customDsl"; private static final String SCRIPT_UID = "scriptUid." + SCRIPT_LANGUAGE; private static final String INVALID_SCRIPT_UID = "invalidScriptUid"; @@ -76,7 +75,7 @@ public class ScriptTransformationServiceTest { @BeforeEach public void setUp() throws ScriptException { Map properties = new HashMap<>(); - properties.put(TransformationService.SERVICE_PROPERTY_NAME, SCRIPT_LANGUAGE); + properties.put(ScriptTransformationService.SCRIPT_TYPE_PROPERTY_NAME, SCRIPT_LANGUAGE); service = new ScriptTransformationService(transformationRegistry, scriptEngineManager, properties); when(scriptEngineManager.createScriptEngine(eq(SCRIPT_LANGUAGE), any())).thenReturn(scriptEngineContainer);