Change signature for ctx to be first parameter
This commit is contained in:
		
							parent
							
								
									651107be2f
								
							
						
					
					
						commit
						e12b0ea8ea
					
				@ -242,7 +242,7 @@ public class CalculatedFieldEntityMessageProcessor extends AbstractContextAwareM
 | 
			
		||||
            justRestored = true;
 | 
			
		||||
        }
 | 
			
		||||
        if (state.isSizeOk()) {
 | 
			
		||||
            if (state.updateState(newArgValues, ctx) || justRestored) {
 | 
			
		||||
            if (state.updateState(ctx, newArgValues) || justRestored) {
 | 
			
		||||
                cfIdList = new ArrayList<>(cfIdList);
 | 
			
		||||
                cfIdList.add(ctx.getCfId());
 | 
			
		||||
                processStateIfReady(ctx, cfIdList, state, tbMsgId, tbMsgType, callback);
 | 
			
		||||
 | 
			
		||||
@ -125,7 +125,7 @@ public class DefaultCalculatedFieldProcessingService implements CalculatedFieldP
 | 
			
		||||
        }
 | 
			
		||||
        return Futures.whenAllComplete(argFutures.values()).call(() -> {
 | 
			
		||||
            var result = createStateByType(ctx);
 | 
			
		||||
            result.updateState(argFutures.entrySet().stream()
 | 
			
		||||
            result.updateState(ctx, argFutures.entrySet().stream()
 | 
			
		||||
                    .collect(Collectors.toMap(
 | 
			
		||||
                            Entry::getKey, // Keep the key as is
 | 
			
		||||
                            entry -> {
 | 
			
		||||
@ -136,7 +136,7 @@ public class DefaultCalculatedFieldProcessingService implements CalculatedFieldP
 | 
			
		||||
                                    throw new RuntimeException("Error getting future result for key: " + entry.getKey(), e);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                    )), ctx);
 | 
			
		||||
                    )));
 | 
			
		||||
            return result;
 | 
			
		||||
        }, calculatedFieldCallbackExecutor);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,7 @@ public abstract class BaseCalculatedFieldState implements CalculatedFieldState {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean updateState(Map<String, ArgumentEntry> argumentValues, CalculatedFieldCtx ctx) {
 | 
			
		||||
    public boolean updateState(CalculatedFieldCtx ctx, Map<String, ArgumentEntry> argumentValues) {
 | 
			
		||||
        if (arguments == null) {
 | 
			
		||||
            arguments = new HashMap<>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -44,7 +44,7 @@ public interface CalculatedFieldState {
 | 
			
		||||
 | 
			
		||||
    void setRequiredArguments(List<String> requiredArguments);
 | 
			
		||||
 | 
			
		||||
    boolean updateState(Map<String, ArgumentEntry> argumentValues, CalculatedFieldCtx ctx);
 | 
			
		||||
    boolean updateState(CalculatedFieldCtx ctx, Map<String, ArgumentEntry> argumentValues);
 | 
			
		||||
 | 
			
		||||
    ListenableFuture<CalculatedFieldResult> performCalculation(CalculatedFieldCtx ctx);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -90,7 +90,7 @@ public class ScriptCalculatedFieldStateTest {
 | 
			
		||||
        state.arguments = new HashMap<>(Map.of("assetHumidity", assetHumidityArgEntry));
 | 
			
		||||
 | 
			
		||||
        Map<String, ArgumentEntry> newArgs = Map.of("deviceTemperature", deviceTemperatureArgEntry);
 | 
			
		||||
        boolean stateUpdated = state.updateState(newArgs, ctx);
 | 
			
		||||
        boolean stateUpdated = state.updateState(ctx, newArgs);
 | 
			
		||||
 | 
			
		||||
        assertThat(stateUpdated).isTrue();
 | 
			
		||||
        assertThat(state.getArguments()).containsExactlyInAnyOrderEntriesOf(
 | 
			
		||||
@ -107,7 +107,7 @@ public class ScriptCalculatedFieldStateTest {
 | 
			
		||||
 | 
			
		||||
        SingleValueArgumentEntry newArgEntry = new SingleValueArgumentEntry(ts, new LongDataEntry("assetHumidity", 41L), 349L);
 | 
			
		||||
        Map<String, ArgumentEntry> newArgs = Map.of("assetHumidity", newArgEntry);
 | 
			
		||||
        boolean stateUpdated = state.updateState(newArgs, ctx);
 | 
			
		||||
        boolean stateUpdated = state.updateState(ctx, newArgs);
 | 
			
		||||
 | 
			
		||||
        assertThat(stateUpdated).isTrue();
 | 
			
		||||
        assertThat(state.getArguments()).containsExactlyInAnyOrderEntriesOf(
 | 
			
		||||
 | 
			
		||||
@ -88,7 +88,7 @@ public class SimpleCalculatedFieldStateTest {
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        Map<String, ArgumentEntry> newArgs = Map.of("key3", key3ArgEntry);
 | 
			
		||||
        boolean stateUpdated = state.updateState(newArgs, ctx);
 | 
			
		||||
        boolean stateUpdated = state.updateState(ctx, newArgs);
 | 
			
		||||
 | 
			
		||||
        assertThat(stateUpdated).isTrue();
 | 
			
		||||
        assertThat(state.getArguments()).containsExactlyInAnyOrderEntriesOf(
 | 
			
		||||
@ -106,7 +106,7 @@ public class SimpleCalculatedFieldStateTest {
 | 
			
		||||
 | 
			
		||||
        SingleValueArgumentEntry newArgEntry = new SingleValueArgumentEntry(System.currentTimeMillis(), new LongDataEntry("key1", 18L), 190L);
 | 
			
		||||
        Map<String, ArgumentEntry> newArgs = Map.of("key1", newArgEntry);
 | 
			
		||||
        boolean stateUpdated = state.updateState(newArgs, ctx);
 | 
			
		||||
        boolean stateUpdated = state.updateState(ctx, newArgs);
 | 
			
		||||
 | 
			
		||||
        assertThat(stateUpdated).isTrue();
 | 
			
		||||
        assertThat(state.getArguments()).containsExactlyInAnyOrderEntriesOf(Map.of("key1", newArgEntry));
 | 
			
		||||
@ -120,7 +120,7 @@ public class SimpleCalculatedFieldStateTest {
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        Map<String, ArgumentEntry> newArgs = Map.of("key3", new TsRollingArgumentEntry(10, 30000L));
 | 
			
		||||
        assertThatThrownBy(() -> state.updateState(newArgs, ctx))
 | 
			
		||||
        assertThatThrownBy(() -> state.updateState(ctx, newArgs))
 | 
			
		||||
                .isInstanceOf(IllegalArgumentException.class)
 | 
			
		||||
                .hasMessage("Rolling argument entry is not supported for simple calculated fields.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user