Improvements/originator&device attributes node (#1733)
* update rule-node-configurations * typo * backward compatibility
This commit is contained in:
		
							parent
							
								
									2cf410eb1e
								
							
						
					
					
						commit
						2fa861670e
					
				@ -18,6 +18,7 @@ package org.thingsboard.rule.engine.metadata;
 | 
			
		||||
import com.google.common.util.concurrent.Futures;
 | 
			
		||||
import com.google.common.util.concurrent.ListenableFuture;
 | 
			
		||||
import org.apache.commons.collections.CollectionUtils;
 | 
			
		||||
import org.apache.commons.lang3.BooleanUtils;
 | 
			
		||||
import org.thingsboard.rule.engine.api.TbContext;
 | 
			
		||||
import org.thingsboard.rule.engine.api.TbNode;
 | 
			
		||||
import org.thingsboard.rule.engine.api.TbNodeConfiguration;
 | 
			
		||||
@ -80,11 +81,18 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
 | 
			
		||||
        ListenableFuture<List<AttributeKvEntry>> latest = ctx.getAttributesService().find(ctx.getTenantId(), entityId, scope, keys);
 | 
			
		||||
        return Futures.transform(latest, l -> {
 | 
			
		||||
            l.forEach(r -> {
 | 
			
		||||
                if (r.getValue() != null) {
 | 
			
		||||
                    msg.getMetaData().putValue(prefix + r.getKey(), r.getValueAsString());
 | 
			
		||||
                if (BooleanUtils.toBooleanDefaultIfNull(this.config.isTellFailureIfAbsent(), true)) {
 | 
			
		||||
                    if (r.getValue() != null) {
 | 
			
		||||
                        msg.getMetaData().putValue(prefix + r.getKey(), r.getValueAsString());
 | 
			
		||||
                    } else {
 | 
			
		||||
                        throw new RuntimeException("[" + scope + "][" + r.getKey() + "] attribute value is not present in the DB!");
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    throw new RuntimeException("[" + scope + "][" + r.getKey() + "] attribute value is not present in the DB!");
 | 
			
		||||
                    if (r.getValue() != null) {
 | 
			
		||||
                        msg.getMetaData().putValue(prefix + r.getKey(), r.getValueAsString());
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            });
 | 
			
		||||
            return null;
 | 
			
		||||
        });
 | 
			
		||||
@ -97,10 +105,16 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
 | 
			
		||||
        ListenableFuture<List<TsKvEntry>> latest = ctx.getTimeseriesService().findLatest(ctx.getTenantId(), entityId, keys);
 | 
			
		||||
        return Futures.transform(latest, l -> {
 | 
			
		||||
            l.forEach(r -> {
 | 
			
		||||
                if (r.getValue() != null) {
 | 
			
		||||
                    msg.getMetaData().putValue(r.getKey(), r.getValueAsString());
 | 
			
		||||
                if (BooleanUtils.toBooleanDefaultIfNull(this.config.isTellFailureIfAbsent(), true)) {
 | 
			
		||||
                    if (r.getValue() != null) {
 | 
			
		||||
                        msg.getMetaData().putValue(r.getKey(), r.getValueAsString());
 | 
			
		||||
                    } else {
 | 
			
		||||
                        throw new RuntimeException("[" + r.getKey() + "] telemetry value is not present in the DB!");
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    throw new RuntimeException("[" + r.getKey() + "] telemetry value is not present in the DB!");
 | 
			
		||||
                    if (r.getValue() != null) {
 | 
			
		||||
                        msg.getMetaData().putValue(r.getKey(), r.getValueAsString());
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
@ -33,6 +33,8 @@ public class TbGetAttributesNodeConfiguration implements NodeConfiguration<TbGet
 | 
			
		||||
 | 
			
		||||
    private List<String> latestTsKeyNames;
 | 
			
		||||
 | 
			
		||||
    private boolean tellFailureIfAbsent;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public TbGetAttributesNodeConfiguration defaultConfiguration() {
 | 
			
		||||
        TbGetAttributesNodeConfiguration configuration = new TbGetAttributesNodeConfiguration();
 | 
			
		||||
@ -40,6 +42,7 @@ public class TbGetAttributesNodeConfiguration implements NodeConfiguration<TbGet
 | 
			
		||||
        configuration.setSharedAttributeNames(Collections.emptyList());
 | 
			
		||||
        configuration.setServerAttributeNames(Collections.emptyList());
 | 
			
		||||
        configuration.setLatestTsKeyNames(Collections.emptyList());
 | 
			
		||||
        configuration.setTellFailureIfAbsent(true);
 | 
			
		||||
        return configuration;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -34,6 +34,7 @@ public class TbGetDeviceAttrNodeConfiguration extends TbGetAttributesNodeConfigu
 | 
			
		||||
        configuration.setSharedAttributeNames(Collections.emptyList());
 | 
			
		||||
        configuration.setServerAttributeNames(Collections.emptyList());
 | 
			
		||||
        configuration.setLatestTsKeyNames(Collections.emptyList());
 | 
			
		||||
        configuration.setTellFailureIfAbsent(true);
 | 
			
		||||
 | 
			
		||||
        DeviceRelationsQuery deviceRelationsQuery = new DeviceRelationsQuery();
 | 
			
		||||
        deviceRelationsQuery.setDirection(EntitySearchDirection.FROM);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user