|
|
|
@ -33,15 +33,15 @@ import org.thingsboard.server.common.data.cf.CalculatedField; |
|
|
|
import org.thingsboard.server.common.data.cf.CalculatedFieldType; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.Argument; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.ArgumentType; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.AttributesOutput; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.CalculatedFieldConfiguration; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.Output; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.OutputType; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.PropagationCalculatedFieldConfiguration; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.ReferencedEntityKey; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.RelationPathQueryDynamicSourceConfiguration; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.ScriptCalculatedFieldConfiguration; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.SimpleCalculatedFieldConfiguration; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.TimeSeriesImmediateOutputStrategy; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.TimeSeriesOutput; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.geofencing.EntityCoordinates; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.geofencing.GeofencingCalculatedFieldConfiguration; |
|
|
|
import org.thingsboard.server.common.data.cf.configuration.geofencing.ZoneGroupConfiguration; |
|
|
|
@ -94,13 +94,11 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("(T * 9/5) + 32"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("fahrenheitTemp"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
calculatedField.setConfiguration(config); |
|
|
|
calculatedField.setVersion(1L); |
|
|
|
|
|
|
|
CalculatedField savedCalculatedField = doPost("/api/calculatedField", calculatedField, CalculatedField.class); |
|
|
|
|
|
|
|
@ -122,10 +120,12 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
assertThat(fahrenheitTemp.get("fahrenheitTemp").get(0).get("value").asText()).isEqualTo("86.0"); |
|
|
|
}); |
|
|
|
|
|
|
|
Output savedOutput = savedCalculatedField.getConfiguration().getOutput(); |
|
|
|
savedOutput.setType(OutputType.ATTRIBUTES); |
|
|
|
savedOutput.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
savedOutput.setName("temperatureF"); |
|
|
|
AttributesOutput newOutput = new AttributesOutput(); |
|
|
|
newOutput.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
newOutput.setName("temperatureF"); |
|
|
|
config.setOutput(newOutput); |
|
|
|
savedCalculatedField.setConfiguration(config); |
|
|
|
|
|
|
|
savedCalculatedField = doPost("/api/calculatedField", savedCalculatedField, CalculatedField.class); |
|
|
|
|
|
|
|
await().alias("update CF output -> perform calculation with updated output").atMost(TIMEOUT, TimeUnit.SECONDS) |
|
|
|
@ -180,9 +180,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("(T * 9/5) + 32"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("fahrenheitTemp"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
calculatedField.setConfiguration(config); |
|
|
|
@ -229,9 +228,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("(T * 9/5) + 32"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("fahrenheitTemp"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
calculatedField.setConfiguration(config); |
|
|
|
@ -293,9 +291,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
|
|
|
|
config.setExpression("x + y"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
AttributesOutput output = new AttributesOutput(); |
|
|
|
output.setName("z"); |
|
|
|
output.setType(OutputType.ATTRIBUTES); |
|
|
|
output.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
|
|
|
|
config.setOutput(output); |
|
|
|
@ -450,9 +447,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("(T * 9/0) + 32"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("fahrenheitTemp"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
calculatedField.setConfiguration(config); |
|
|
|
@ -500,9 +496,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("(T * 9/5) + 32"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("fahrenheitTemp"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
config.setUseLatestTs(true); |
|
|
|
@ -550,9 +545,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("a", argument1, "b", argument2)); |
|
|
|
config.setExpression("a + b"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("c"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
config.setUseLatestTs(true); |
|
|
|
@ -604,9 +598,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("return {\"ts\": ctx.latestTs, \"values\": {\"fahrenheitTemp\": (T * 1.8) + 32}};"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
config.setOutput(output); |
|
|
|
config.setOutput(new TimeSeriesOutput()); |
|
|
|
|
|
|
|
calculatedField.setConfiguration(config); |
|
|
|
|
|
|
|
@ -640,9 +632,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("m", argument)); |
|
|
|
config.setExpression("m + 1"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("m1"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
output.setDecimalsByDefault(0); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
@ -715,8 +706,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
cfg.setZoneGroups(Map.of("allowedZones", allowedZonesGroup, "restrictedZones", restrictedZonesGroup)); |
|
|
|
|
|
|
|
// Output to server attributes
|
|
|
|
Output out = new Output(); |
|
|
|
out.setType(OutputType.ATTRIBUTES); |
|
|
|
AttributesOutput out = new AttributesOutput(); |
|
|
|
out.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
cfg.setOutput(out); |
|
|
|
|
|
|
|
@ -826,8 +816,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
cfg.setZoneGroups(Map.of("allowedZones", allowedZonesGroup, "restrictedZones", restrictedZonesGroup)); |
|
|
|
|
|
|
|
// Output to server attributes
|
|
|
|
Output out = new Output(); |
|
|
|
out.setType(OutputType.ATTRIBUTES); |
|
|
|
AttributesOutput out = new AttributesOutput(); |
|
|
|
out.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
cfg.setOutput(out); |
|
|
|
|
|
|
|
@ -924,8 +913,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
cfg.setZoneGroups(Map.of("allowedZones", allowedZonesGroup)); |
|
|
|
|
|
|
|
// Server attributes output
|
|
|
|
Output out = new Output(); |
|
|
|
out.setType(OutputType.ATTRIBUTES); |
|
|
|
AttributesOutput out = new AttributesOutput(); |
|
|
|
out.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
cfg.setOutput(out); |
|
|
|
|
|
|
|
@ -1035,8 +1023,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
|
|
|
|
cfg.setExpression("{\"testResult\": t * 2}"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
output.setType(OutputType.ATTRIBUTES); |
|
|
|
AttributesOutput output = new AttributesOutput(); |
|
|
|
output.setScope(AttributeScope.SERVER_SCOPE); |
|
|
|
cfg.setOutput(output); |
|
|
|
|
|
|
|
@ -1112,9 +1099,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
arg.setRefEntityKey(new ReferencedEntityKey("temperature", ArgumentType.TS_LATEST, null)); |
|
|
|
cfg.setArguments(Map.of("temperatureComputed", arg)); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
cfg.setOutput(output); |
|
|
|
cfg.setOutput(new TimeSeriesOutput()); |
|
|
|
|
|
|
|
cf.setConfiguration(cfg); |
|
|
|
|
|
|
|
@ -1182,9 +1167,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("a", argumentA, "b", argumentB)); |
|
|
|
config.setExpression("a + b"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("c"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
output.setDecimalsByDefault(0); |
|
|
|
config.setOutput(output); |
|
|
|
|
|
|
|
@ -1231,9 +1215,8 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
config.setArguments(Map.of("T", argument)); |
|
|
|
config.setExpression("(T * 9/5) + 32"); |
|
|
|
|
|
|
|
Output output = new Output(); |
|
|
|
TimeSeriesOutput output = new TimeSeriesOutput(); |
|
|
|
output.setName("fahrenheitTemp"); |
|
|
|
output.setType(OutputType.TIME_SERIES); |
|
|
|
output.setDecimalsByDefault(1); |
|
|
|
output.setStrategy(new TimeSeriesImmediateOutputStrategy(1000L, true, true, true, true)); |
|
|
|
|
|
|
|
|