Commit 1c78a59fb2cde910954fc8d52ad87ea2789cf68a

Authored by AndrewVolosytnykhThingsboard
Committed by Andrew Shvayka
1 parent 5e990da0

Logic for inheritance in DynamicValue added

... ... @@ -16,18 +16,28 @@
16 16 package org.thingsboard.server.common.data.query;
17 17
18 18 import com.fasterxml.jackson.annotation.JsonIgnore;
  19 +import lombok.AllArgsConstructor;
19 20 import lombok.Data;
20 21 import lombok.Getter;
21 22
22 23 @Data
  24 +@AllArgsConstructor
23 25 public class DynamicValue<T> {
24 26
25 27 @JsonIgnore
26 28 private T resolvedValue;
27 29
  30 + public DynamicValue(DynamicValueSourceType sourceType, String sourceAttribute) {
  31 + this.sourceAttribute = sourceAttribute;
  32 + this.sourceType = sourceType;
  33 + this.useInherit = false;
  34 + }
  35 +
28 36 @Getter
29 37 private final DynamicValueSourceType sourceType;
30 38 @Getter
31 39 private final String sourceAttribute;
  40 + @Getter
  41 + private final boolean useInherit;
32 42
33 43 }
... ...
... ... @@ -393,6 +393,9 @@ class AlarmRuleState {
393 393 break;
394 394 case CURRENT_CUSTOMER:
395 395 ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute());
  396 + if(ekv == null && value.getDynamicValue().getUseInherit()) {
  397 + ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute());
  398 + }
396 399 break;
397 400 case CURRENT_DEVICE:
398 401 ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute()));
... ... @@ -405,6 +408,12 @@ class AlarmRuleState {
405 408 }
406 409 }
407 410 }
  411 + if(ekv == null && value.getDynamicValue().getUseInherit()) {
  412 + ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute());
  413 + if(ekv == null) {
  414 + ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute());
  415 + }
  416 + }
408 417 }
409 418 }
410 419 return ekv;
... ...