renamed property
This commit is contained in:
parent
da90d8f727
commit
58aa930d1d
@ -62,7 +62,7 @@ public class CalculatedFieldCtx {
|
|||||||
private final List<String> argNames;
|
private final List<String> argNames;
|
||||||
private Output output;
|
private Output output;
|
||||||
private String expression;
|
private String expression;
|
||||||
private boolean preserveMsgTs;
|
private boolean useLatestTs;
|
||||||
private TbelInvokeService tbelInvokeService;
|
private TbelInvokeService tbelInvokeService;
|
||||||
private CalculatedFieldScriptEngine calculatedFieldScriptEngine;
|
private CalculatedFieldScriptEngine calculatedFieldScriptEngine;
|
||||||
private ThreadLocal<Expression> customExpression;
|
private ThreadLocal<Expression> customExpression;
|
||||||
@ -96,7 +96,7 @@ public class CalculatedFieldCtx {
|
|||||||
this.argNames = new ArrayList<>(arguments.keySet());
|
this.argNames = new ArrayList<>(arguments.keySet());
|
||||||
this.output = configuration.getOutput();
|
this.output = configuration.getOutput();
|
||||||
this.expression = configuration.getExpression();
|
this.expression = configuration.getExpression();
|
||||||
this.preserveMsgTs = CalculatedFieldType.SIMPLE.equals(calculatedField.getType()) && ((SimpleCalculatedFieldConfiguration) configuration).isPreserveMsgTs();
|
this.useLatestTs = CalculatedFieldType.SIMPLE.equals(calculatedField.getType()) && ((SimpleCalculatedFieldConfiguration) configuration).isUseLatestTs();
|
||||||
this.tbelInvokeService = tbelInvokeService;
|
this.tbelInvokeService = tbelInvokeService;
|
||||||
|
|
||||||
this.maxDataPointsPerRollingArg = apiLimitService.getLimit(tenantId, DefaultTenantProfileConfiguration::getMaxDataPointsPerRollingArg);
|
this.maxDataPointsPerRollingArg = apiLimitService.getLimit(tenantId, DefaultTenantProfileConfiguration::getMaxDataPointsPerRollingArg);
|
||||||
|
|||||||
@ -68,7 +68,7 @@ public class SimpleCalculatedFieldState extends BaseCalculatedFieldState {
|
|||||||
|
|
||||||
Output output = ctx.getOutput();
|
Output output = ctx.getOutput();
|
||||||
Object result = formatResult(expressionResult, output.getDecimalsByDefault());
|
Object result = formatResult(expressionResult, output.getDecimalsByDefault());
|
||||||
JsonNode outputResult = createResultJson(ctx.isPreserveMsgTs(), output.getName(), result);
|
JsonNode outputResult = createResultJson(ctx.isUseLatestTs(), output.getName(), result);
|
||||||
|
|
||||||
return Futures.immediateFuture(new CalculatedFieldResult(output.getType(), output.getScope(), outputResult));
|
return Futures.immediateFuture(new CalculatedFieldResult(output.getType(), output.getScope(), outputResult));
|
||||||
}
|
}
|
||||||
@ -83,12 +83,12 @@ public class SimpleCalculatedFieldState extends BaseCalculatedFieldState {
|
|||||||
return TbUtils.toFixed(expressionResult, decimals);
|
return TbUtils.toFixed(expressionResult, decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonNode createResultJson(boolean preserveMsgTs, String outputName, Object result) {
|
private JsonNode createResultJson(boolean useLatestTs, String outputName, Object result) {
|
||||||
ObjectNode valuesNode = JacksonUtil.newObjectNode();
|
ObjectNode valuesNode = JacksonUtil.newObjectNode();
|
||||||
valuesNode.set(outputName, JacksonUtil.valueToTree(result));
|
valuesNode.set(outputName, JacksonUtil.valueToTree(result));
|
||||||
|
|
||||||
long latestTs = getLatestTimestamp();
|
long latestTs = getLatestTimestamp();
|
||||||
if (preserveMsgTs && latestTs != -1) {
|
if (useLatestTs && latestTs != -1) {
|
||||||
ObjectNode resultNode = JacksonUtil.newObjectNode();
|
ObjectNode resultNode = JacksonUtil.newObjectNode();
|
||||||
resultNode.put("ts", latestTs);
|
resultNode.put("ts", latestTs);
|
||||||
resultNode.set("values", valuesNode);
|
resultNode.set("values", valuesNode);
|
||||||
|
|||||||
@ -464,7 +464,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleCalculatedFieldWhenPreserveMsgTsIsTrue() throws Exception {
|
public void testSimpleCalculatedFieldWhenUseLatestTsIsTrue() throws Exception {
|
||||||
Device testDevice = createDevice("Test device", "1234567890");
|
Device testDevice = createDevice("Test device", "1234567890");
|
||||||
long ts = System.currentTimeMillis() - 300000L;
|
long ts = System.currentTimeMillis() - 300000L;
|
||||||
doPost("/api/plugins/telemetry/DEVICE/" + testDevice.getUuidId() + "/timeseries/" + DataConstants.SERVER_SCOPE, JacksonUtil.toJsonNode(String.format("{\"ts\": %s, \"values\": {\"temperature\":30}}", ts)));
|
doPost("/api/plugins/telemetry/DEVICE/" + testDevice.getUuidId() + "/timeseries/" + DataConstants.SERVER_SCOPE, JacksonUtil.toJsonNode(String.format("{\"ts\": %s, \"values\": {\"temperature\":30}}", ts)));
|
||||||
@ -489,7 +489,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes
|
|||||||
output.setType(OutputType.TIME_SERIES);
|
output.setType(OutputType.TIME_SERIES);
|
||||||
config.setOutput(output);
|
config.setOutput(output);
|
||||||
|
|
||||||
config.setPreserveMsgTs(true);
|
config.setUseLatestTs(true);
|
||||||
|
|
||||||
calculatedField.setConfiguration(config);
|
calculatedField.setConfiguration(config);
|
||||||
|
|
||||||
@ -506,7 +506,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleCalculatedFieldWhenPreserveMsgTsIsTrueAndTelemetryBeforeLatest() throws Exception {
|
public void testSimpleCalculatedFieldWhenUseLatestTsIsTrueAndTelemetryBeforeLatest() throws Exception {
|
||||||
Device testDevice = createDevice("Test device", "1234567890");
|
Device testDevice = createDevice("Test device", "1234567890");
|
||||||
long ts = System.currentTimeMillis();
|
long ts = System.currentTimeMillis();
|
||||||
|
|
||||||
@ -539,7 +539,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes
|
|||||||
output.setType(OutputType.TIME_SERIES);
|
output.setType(OutputType.TIME_SERIES);
|
||||||
config.setOutput(output);
|
config.setOutput(output);
|
||||||
|
|
||||||
config.setPreserveMsgTs(true);
|
config.setUseLatestTs(true);
|
||||||
|
|
||||||
calculatedField.setConfiguration(config);
|
calculatedField.setConfiguration(config);
|
||||||
|
|
||||||
@ -568,7 +568,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScriptCalculatedFieldWhenUsedMsgTsInScript() throws Exception {
|
public void testScriptCalculatedFieldWhenUsedLatestTsInScript() throws Exception {
|
||||||
Device testDevice = createDevice("Test device", "1234567890");
|
Device testDevice = createDevice("Test device", "1234567890");
|
||||||
long ts = System.currentTimeMillis() - 300000L;
|
long ts = System.currentTimeMillis() - 300000L;
|
||||||
doPost("/api/plugins/telemetry/DEVICE/" + testDevice.getUuidId() + "/timeseries/" + DataConstants.SERVER_SCOPE, JacksonUtil.toJsonNode(String.format("{\"ts\": %s, \"values\": {\"temperature\":30}}", ts)));
|
doPost("/api/plugins/telemetry/DEVICE/" + testDevice.getUuidId() + "/timeseries/" + DataConstants.SERVER_SCOPE, JacksonUtil.toJsonNode(String.format("{\"ts\": %s, \"values\": {\"temperature\":30}}", ts)));
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import org.thingsboard.server.common.data.cf.CalculatedFieldType;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class SimpleCalculatedFieldConfiguration extends BaseCalculatedFieldConfiguration implements CalculatedFieldConfiguration {
|
public class SimpleCalculatedFieldConfiguration extends BaseCalculatedFieldConfiguration implements CalculatedFieldConfiguration {
|
||||||
|
|
||||||
private boolean preserveMsgTs;
|
private boolean useLatestTs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatedFieldType getType() {
|
public CalculatedFieldType getType() {
|
||||||
|
|||||||
@ -190,7 +190,7 @@
|
|||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="tb-form-row" [formGroup]="configFormGroup" *ngIf="outputFormGroup.get('type').value === OutputType.Timeseries">
|
<div class="tb-form-row" [formGroup]="configFormGroup" *ngIf="outputFormGroup.get('type').value === OutputType.Timeseries">
|
||||||
<mat-slide-toggle class="mat-slide" formControlName="preserveMsgTs">
|
<mat-slide-toggle class="mat-slide" formControlName="useLatestTs">
|
||||||
<div tb-hint-tooltip-icon="{{ 'calculated-fields.hint.use-message-timestamp' | translate }}" translate>
|
<div tb-hint-tooltip-icon="{{ 'calculated-fields.hint.use-message-timestamp' | translate }}" translate>
|
||||||
calculated-fields.use-message-timestamp
|
calculated-fields.use-message-timestamp
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -77,7 +77,7 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
|
|||||||
type: [OutputType.Timeseries],
|
type: [OutputType.Timeseries],
|
||||||
decimalsByDefault: [null as number, [Validators.min(0), Validators.max(15), Validators.pattern(digitsRegex)]],
|
decimalsByDefault: [null as number, [Validators.min(0), Validators.max(15), Validators.pattern(digitsRegex)]],
|
||||||
}),
|
}),
|
||||||
preserveMsgTs: [false]
|
useLatestTs: [false]
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -212,12 +212,12 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
|
|||||||
}
|
}
|
||||||
if (this.fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
|
if (this.fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
|
||||||
if (type === OutputType.Attribute) {
|
if (type === OutputType.Attribute) {
|
||||||
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
|
this.configFormGroup.get('useLatestTs').disable({emitEvent: false});
|
||||||
} else {
|
} else {
|
||||||
this.configFormGroup.get('preserveMsgTs').enable({emitEvent: false});
|
this.configFormGroup.get('useLatestTs').enable({emitEvent: false});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
|
this.configFormGroup.get('useLatestTs').disable({emitEvent: false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,13 +227,13 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
|
|||||||
this.configFormGroup.get('expressionSIMPLE').enable({emitEvent: false});
|
this.configFormGroup.get('expressionSIMPLE').enable({emitEvent: false});
|
||||||
this.configFormGroup.get('expressionSCRIPT').disable({emitEvent: false});
|
this.configFormGroup.get('expressionSCRIPT').disable({emitEvent: false});
|
||||||
if (this.outputFormGroup.get('type').value === OutputType.Attribute) {
|
if (this.outputFormGroup.get('type').value === OutputType.Attribute) {
|
||||||
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
|
this.configFormGroup.get('useLatestTs').disable({emitEvent: false});
|
||||||
} else {
|
} else {
|
||||||
this.configFormGroup.get('preserveMsgTs').enable({emitEvent: false});
|
this.configFormGroup.get('useLatestTs').enable({emitEvent: false});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.outputFormGroup.get('name').disable({emitEvent: false});
|
this.outputFormGroup.get('name').disable({emitEvent: false});
|
||||||
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
|
this.configFormGroup.get('useLatestTs').disable({emitEvent: false});
|
||||||
this.configFormGroup.get('expressionSIMPLE').disable({emitEvent: false});
|
this.configFormGroup.get('expressionSIMPLE').disable({emitEvent: false});
|
||||||
this.configFormGroup.get('expressionSCRIPT').enable({emitEvent: false});
|
this.configFormGroup.get('expressionSCRIPT').enable({emitEvent: false});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user