@ -32,6 +32,8 @@ import org.thingsboard.server.common.data.plugin.ComponentType;
import org.thingsboard.server.common.data.script.ScriptLanguage ;
import org.thingsboard.server.common.msg.TbMsg ;
import java.util.Objects ;
@Slf4j
@RuleNode (
type = ComponentType . ACTION ,
@ -54,7 +56,7 @@ public class TbLogNode implements TbNode {
@Override
public void init ( TbContext ctx , TbNodeConfiguration configuration ) throws TbNodeException {
this . config = TbNodeUtils . convert ( configuration , TbLogNodeConfiguration . class ) ;
this . standard = new TbLogNodeConfiguration ( ) . defaultConfiguration ( ) . getJsScript ( ) . equals ( config . getJsScript ( ) ) ;
this . standard = isStandard ( config ) ;
this . scriptEngine = this . standard ? null : ctx . createScriptEngine ( config . getScriptLang ( ) ,
ScriptLanguage . TBEL . equals ( config . getScriptLang ( ) ) ? config . getTbelScript ( ) : config . getJsScript ( ) ) ;
}
@ -83,6 +85,17 @@ public class TbLogNode implements TbNode {
} , MoreExecutors . directExecutor ( ) ) ; //usually js responses runs on js callback executor
}
boolean isStandard ( TbLogNodeConfiguration conf ) {
Objects . requireNonNull ( conf , "node config is null" ) ;
final TbLogNodeConfiguration defaultConfig = new TbLogNodeConfiguration ( ) . defaultConfiguration ( ) ;
switch ( conf . getScriptLang ( ) ) {
case JS : return defaultConfig . getJsScript ( ) . equals ( conf . getJsScript ( ) ) ;
case TBEL : return defaultConfig . getTbelScript ( ) . equals ( conf . getTbelScript ( ) ) ;
}
log . warn ( "No rule to define isStandard script for script language [{}], assuming that is non-standard" , conf . getScriptLang ( ) ) ;
return false ;
}
void logStandard ( TbContext ctx , TbMsg msg ) {
log . info ( toLogMessage ( msg ) ) ;
ctx . tellSuccess ( msg ) ;