Fix transformRaw validation errors in DSL rules (#3178)

Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
J-N-K 2022-11-30 23:12:12 +01:00 committed by GitHub
parent d7f8ec2375
commit dc2f5d54f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 33 deletions

View File

@ -35,6 +35,7 @@ Import-Package: \
org.openhab.core.thing,\
org.openhab.core.thing.binding,\
org.openhab.core.thing.events,\
org.openhab.core.transform,\
org.openhab.core.transform.actions,\
org.openhab.core.types,\
org.openhab.core.voice,\

View File

@ -0,0 +1,39 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.core.model.script.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link Transformation} is a wrapper for the {@link org.openhab.core.transform.actions.Transformation} class to
* allow DSL rules to properly use the {@link TransformationException}
*
* @author Jan N. Klug - Initial contribution
*/
@NonNullByDefault
public class Transformation {
public static @Nullable String transform(String type, String function, String value) {
return org.openhab.core.transform.actions.Transformation.transform(type, function, value);
}
public static @Nullable String transformRaw(String type, String function, String value)
throws TransformationException {
try {
return org.openhab.core.transform.actions.Transformation.transformRaw(type, function, value);
} catch (org.openhab.core.transform.TransformationException e) {
throw new TransformationException(e.getMessage(), e.getCause());
}
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.core.model.script.actions;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link TransformationException} is a clone of {@link org.openhab.core.transform.TransformationException} to
* make it available to DSL rules
*
* @author Jan N. Klug - Initial contribution
*/
@NonNullByDefault
public class TransformationException extends Exception {
private static final long serialVersionUID = -1L;
public TransformationException(@Nullable String message) {
super(message);
}
public TransformationException(@Nullable String message, @Nullable Throwable cause) {
super(message, cause);
}
}

View File

@ -1,31 +0,0 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.core.model.script.internal.engine.action;
import org.openhab.core.model.script.engine.action.ActionService;
import org.openhab.core.transform.actions.Transformation;
import org.osgi.service.component.annotations.Component;
/**
* This class registers an OSGi service for the Transformation action.
*
* @author Kai Kreuzer - Initial contribution
*/
@Component(immediate = true)
public class TransformationActionService implements ActionService {
@Override
public Class<?> getActionClass() {
return Transformation.class;
}
}

View File

@ -36,6 +36,7 @@ import org.openhab.core.model.script.actions.HTTP;
import org.openhab.core.model.script.actions.Log;
import org.openhab.core.model.script.actions.Ping;
import org.openhab.core.model.script.actions.ScriptExecution;
import org.openhab.core.model.script.actions.Transformation;
import org.openhab.core.model.script.engine.IActionServiceProvider;
import org.openhab.core.model.script.engine.IThingActionsProvider;
import org.openhab.core.model.script.engine.action.ActionService;
@ -80,10 +81,9 @@ public class ScriptImplicitlyImportedTypes extends ImplicitlyImportedFeatures {
result.add(HTTP.class);
result.add(Log.class);
result.add(Ping.class);
result.add(Transformation.class);
result.add(ScriptExecution.class);
result.add(URLEncoder.class);
result.addAll(getActionClasses());
return result;
}
@ -95,6 +95,7 @@ public class ScriptImplicitlyImportedTypes extends ImplicitlyImportedFeatures {
result.add(HTTP.class);
result.add(Log.class);
result.add(Ping.class);
result.add(Transformation.class);
result.add(ScriptExecution.class);
result.add(URLEncoder.class);