fixed updates of non-dynamic zone group arguments
This commit is contained in:
		
							parent
							
								
									c678634344
								
							
						
					
					
						commit
						995ca2e4a8
					
				@ -48,6 +48,7 @@ import org.thingsboard.server.service.cf.ctx.state.ArgumentEntry;
 | 
			
		||||
import org.thingsboard.server.service.cf.ctx.state.CalculatedFieldCtx;
 | 
			
		||||
import org.thingsboard.server.service.cf.ctx.state.CalculatedFieldState;
 | 
			
		||||
import org.thingsboard.server.service.cf.ctx.state.SingleValueArgumentEntry;
 | 
			
		||||
import org.thingsboard.server.service.cf.ctx.state.geofencing.GeofencingArgumentEntry;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
@ -390,7 +391,7 @@ public class CalculatedFieldEntityMessageProcessor extends AbstractContextAwareM
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Map<String, ArgumentEntry> mapToArguments(CalculatedFieldCtx ctx, AttributeScopeProto scope, List<AttributeValueProto> attrDataList) {
 | 
			
		||||
        return mapToArguments(ctx.getMainEntityArguments(), scope, attrDataList);
 | 
			
		||||
        return mapToArguments(ctx.getEntityId(), ctx.getMainEntityArguments(), ctx.getMainEntityGeofencingArgumentNames(), scope, attrDataList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Map<String, ArgumentEntry> mapToArguments(CalculatedFieldCtx ctx, EntityId entityId, AttributeScopeProto scope, List<AttributeValueProto> attrDataList) {
 | 
			
		||||
@ -398,17 +399,23 @@ public class CalculatedFieldEntityMessageProcessor extends AbstractContextAwareM
 | 
			
		||||
        if (argNames.isEmpty()) {
 | 
			
		||||
            return Collections.emptyMap();
 | 
			
		||||
        }
 | 
			
		||||
        return mapToArguments(argNames, scope, attrDataList);
 | 
			
		||||
        List<String> geofencingArgumentNames = ctx.getLinkedEntityGeofencingArgumentNames();
 | 
			
		||||
        return mapToArguments(entityId, argNames, geofencingArgumentNames, scope, attrDataList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Map<String, ArgumentEntry> mapToArguments(Map<ReferencedEntityKey, String> argNames, AttributeScopeProto scope, List<AttributeValueProto> attrDataList) {
 | 
			
		||||
    private Map<String, ArgumentEntry> mapToArguments(EntityId entityId, Map<ReferencedEntityKey, String> argNames, List<String> geoArgNames, AttributeScopeProto scope, List<AttributeValueProto> attrDataList) {
 | 
			
		||||
        Map<String, ArgumentEntry> arguments = new HashMap<>();
 | 
			
		||||
        for (AttributeValueProto item : attrDataList) {
 | 
			
		||||
            ReferencedEntityKey key = new ReferencedEntityKey(item.getKey(), ArgumentType.ATTRIBUTE, AttributeScope.valueOf(scope.name()));
 | 
			
		||||
            String argName = argNames.get(key);
 | 
			
		||||
            if (argName != null) {
 | 
			
		||||
                arguments.put(argName, new SingleValueArgumentEntry(item));
 | 
			
		||||
            if (argName == null) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if (geoArgNames.contains(argName)) {
 | 
			
		||||
                arguments.put(argName, new GeofencingArgumentEntry(entityId, item));
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            arguments.put(argName, new SingleValueArgumentEntry(item));
 | 
			
		||||
        }
 | 
			
		||||
        return arguments;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -50,7 +50,7 @@ public class MultipleTbCallback implements TbCallback {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onFailure(Throwable t) {
 | 
			
		||||
        log.warn("[{}][{}] onFailure.", id, callback.getId());
 | 
			
		||||
        log.warn("[{}][{}] onFailure.", id, callback.getId(), t);
 | 
			
		||||
        callback.onFailure(t);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.cf.configuration.Output;
 | 
			
		||||
import org.thingsboard.server.common.data.cf.configuration.ReferencedEntityKey;
 | 
			
		||||
import org.thingsboard.server.common.data.cf.configuration.ScheduledUpdateSupportedCalculatedFieldConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.cf.configuration.SimpleCalculatedFieldConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.cf.configuration.geofencing.GeofencingCalculatedFieldConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
@ -77,6 +78,9 @@ public class CalculatedFieldCtx {
 | 
			
		||||
    private long maxStateSize;
 | 
			
		||||
    private long maxSingleValueArgumentSize;
 | 
			
		||||
 | 
			
		||||
    private List<String> mainEntityGeofencingArgumentNames;
 | 
			
		||||
    private List<String> linkedEntityGeofencingArgumentNames;
 | 
			
		||||
 | 
			
		||||
    public CalculatedFieldCtx(CalculatedField calculatedField, TbelInvokeService tbelInvokeService, ApiLimitService apiLimitService, RelationService relationService) {
 | 
			
		||||
        this.calculatedField = calculatedField;
 | 
			
		||||
 | 
			
		||||
@ -88,6 +92,8 @@ public class CalculatedFieldCtx {
 | 
			
		||||
        this.mainEntityArguments = new HashMap<>();
 | 
			
		||||
        this.linkedEntityArguments = new HashMap<>();
 | 
			
		||||
        this.argNames = new ArrayList<>();
 | 
			
		||||
        this.mainEntityGeofencingArgumentNames = new ArrayList<>();
 | 
			
		||||
        this.linkedEntityGeofencingArgumentNames = new ArrayList<>();
 | 
			
		||||
        this.output = calculatedField.getConfiguration().getOutput();
 | 
			
		||||
        if (calculatedField.getConfiguration() instanceof ArgumentsBasedCalculatedFieldConfiguration argBasedConfig) {
 | 
			
		||||
            this.arguments.putAll(argBasedConfig.getArguments());
 | 
			
		||||
@ -108,6 +114,17 @@ public class CalculatedFieldCtx {
 | 
			
		||||
                this.expression = expressionBasedConfig.getExpression();
 | 
			
		||||
                this.useLatestTs = CalculatedFieldType.SIMPLE.equals(calculatedField.getType()) && ((SimpleCalculatedFieldConfiguration) argBasedConfig).isUseLatestTs();
 | 
			
		||||
            }
 | 
			
		||||
            if (calculatedField.getConfiguration() instanceof GeofencingCalculatedFieldConfiguration geofencingConfig) {
 | 
			
		||||
                geofencingConfig.getZoneGroups().forEach((zoneGroupName, config) -> {
 | 
			
		||||
                    if (config.isCfEntitySource(entityId)) {
 | 
			
		||||
                        mainEntityGeofencingArgumentNames.add(zoneGroupName);
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                    if (config.isLinkedCfEntitySource(entityId)) {
 | 
			
		||||
                        linkedEntityGeofencingArgumentNames.add(zoneGroupName);
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        this.tbelInvokeService = tbelInvokeService;
 | 
			
		||||
        this.relationService = relationService;
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,8 @@ import org.thingsboard.script.api.tbel.TbelCfArg;
 | 
			
		||||
import org.thingsboard.script.api.tbel.TbelCfTsGeofencingArg;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityId;
 | 
			
		||||
import org.thingsboard.server.common.data.kv.KvEntry;
 | 
			
		||||
import org.thingsboard.server.common.util.ProtoUtils;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
import org.thingsboard.server.service.cf.ctx.state.ArgumentEntry;
 | 
			
		||||
import org.thingsboard.server.service.cf.ctx.state.ArgumentEntryType;
 | 
			
		||||
 | 
			
		||||
@ -38,6 +40,10 @@ public class GeofencingArgumentEntry implements ArgumentEntry {
 | 
			
		||||
    public GeofencingArgumentEntry() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public GeofencingArgumentEntry(EntityId entityId, TransportProtos.AttributeValueProto entry) {
 | 
			
		||||
        this.zoneStates = toZones(Map.of(entityId, ProtoUtils.fromProto(entry)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public GeofencingArgumentEntry(Map<EntityId, KvEntry> entityIdkvEntryMap) {
 | 
			
		||||
        this.zoneStates = toZones(entityIdkvEntryMap);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.common.data.cf.configuration.geofencing;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonInclude;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import org.springframework.lang.Nullable;
 | 
			
		||||
@ -71,6 +72,19 @@ public class ZoneGroupConfiguration {
 | 
			
		||||
        return refDynamicSourceConfiguration != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    public boolean isCfEntitySource(EntityId cfEntityId) {
 | 
			
		||||
        if (refEntityId == null && refDynamicSourceConfiguration == null) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return refEntityId != null && refEntityId.equals(cfEntityId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    public boolean isLinkedCfEntitySource(EntityId cfEntityId) {
 | 
			
		||||
        return refEntityId != null && !refEntityId.equals(cfEntityId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Argument toArgument() {
 | 
			
		||||
        var argument = new Argument();
 | 
			
		||||
        argument.setRefEntityId(refEntityId);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user