Logic for inheritance in DynamicValue added

This commit is contained in:
AndrewVolosytnykhThingsboard 2021-02-12 03:12:11 +02:00 committed by Andrew Shvayka
parent 5e990da0ba
commit 1c78a59fb2
2 changed files with 19 additions and 0 deletions

View File

@ -16,18 +16,28 @@
package org.thingsboard.server.common.data.query;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
@Data
@AllArgsConstructor
public class DynamicValue<T> {
@JsonIgnore
private T resolvedValue;
public DynamicValue(DynamicValueSourceType sourceType, String sourceAttribute) {
this.sourceAttribute = sourceAttribute;
this.sourceType = sourceType;
this.useInherit = false;
}
@Getter
private final DynamicValueSourceType sourceType;
@Getter
private final String sourceAttribute;
@Getter
private final boolean useInherit;
}

View File

@ -393,6 +393,9 @@ class AlarmRuleState {
break;
case CURRENT_CUSTOMER:
ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute());
if(ekv == null && value.getDynamicValue().getUseInherit()) {
ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute());
}
break;
case CURRENT_DEVICE:
ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute()));
@ -405,6 +408,12 @@ class AlarmRuleState {
}
}
}
if(ekv == null && value.getDynamicValue().getUseInherit()) {
ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute());
if(ekv == null) {
ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute());
}
}
}
}
return ekv;