Commit 1c78a59fb2cde910954fc8d52ad87ea2789cf68a
Committed by
Andrew Shvayka
1 parent
5e990da0
Logic for inheritance in DynamicValue added
Showing
2 changed files
with
19 additions
and
0 deletions
@@ -16,18 +16,28 @@ | @@ -16,18 +16,28 @@ | ||
16 | package org.thingsboard.server.common.data.query; | 16 | package org.thingsboard.server.common.data.query; |
17 | 17 | ||
18 | import com.fasterxml.jackson.annotation.JsonIgnore; | 18 | import com.fasterxml.jackson.annotation.JsonIgnore; |
19 | +import lombok.AllArgsConstructor; | ||
19 | import lombok.Data; | 20 | import lombok.Data; |
20 | import lombok.Getter; | 21 | import lombok.Getter; |
21 | 22 | ||
22 | @Data | 23 | @Data |
24 | +@AllArgsConstructor | ||
23 | public class DynamicValue<T> { | 25 | public class DynamicValue<T> { |
24 | 26 | ||
25 | @JsonIgnore | 27 | @JsonIgnore |
26 | private T resolvedValue; | 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 | @Getter | 36 | @Getter |
29 | private final DynamicValueSourceType sourceType; | 37 | private final DynamicValueSourceType sourceType; |
30 | @Getter | 38 | @Getter |
31 | private final String sourceAttribute; | 39 | private final String sourceAttribute; |
40 | + @Getter | ||
41 | + private final boolean useInherit; | ||
32 | 42 | ||
33 | } | 43 | } |
@@ -393,6 +393,9 @@ class AlarmRuleState { | @@ -393,6 +393,9 @@ class AlarmRuleState { | ||
393 | break; | 393 | break; |
394 | case CURRENT_CUSTOMER: | 394 | case CURRENT_CUSTOMER: |
395 | ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute()); | 395 | ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute()); |
396 | + if(ekv == null && value.getDynamicValue().getUseInherit()) { | ||
397 | + ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute()); | ||
398 | + } | ||
396 | break; | 399 | break; |
397 | case CURRENT_DEVICE: | 400 | case CURRENT_DEVICE: |
398 | ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute())); | 401 | ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute())); |
@@ -405,6 +408,12 @@ class AlarmRuleState { | @@ -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 | return ekv; | 419 | return ekv; |