Commit e70df09b088e7b2c9e2c6a553ca84ab470ada7ac
Committed by
Andrew Shvayka
1 parent
6bf2b322
Code cleaning and fix of tests
Showing
3 changed files
with
11 additions
and
24 deletions
... | ... | @@ -18,8 +18,10 @@ package org.thingsboard.server.common.data.query; |
18 | 18 | import com.fasterxml.jackson.annotation.JsonIgnore; |
19 | 19 | import lombok.Data; |
20 | 20 | import lombok.Getter; |
21 | +import lombok.RequiredArgsConstructor; | |
21 | 22 | |
22 | 23 | @Data |
24 | +@RequiredArgsConstructor | |
23 | 25 | public class DynamicValue<T> { |
24 | 26 | |
25 | 27 | @JsonIgnore |
... | ... | @@ -31,12 +33,6 @@ public class DynamicValue<T> { |
31 | 33 | this.inherit = false; |
32 | 34 | } |
33 | 35 | |
34 | - public DynamicValue(DynamicValueSourceType sourceType, String sourceAttribute, boolean inherit) { | |
35 | - this.sourceAttribute = sourceAttribute; | |
36 | - this.sourceType = sourceType; | |
37 | - this.inherit = inherit; | |
38 | - } | |
39 | - | |
40 | 36 | @Getter |
41 | 37 | private final DynamicValueSourceType sourceType; |
42 | 38 | @Getter | ... | ... |
... | ... | @@ -388,15 +388,6 @@ class AlarmRuleState { |
388 | 388 | EntityKeyValue ekv = null; |
389 | 389 | if (value.getDynamicValue() != null) { |
390 | 390 | switch (value.getDynamicValue().getSourceType()) { |
391 | - case CURRENT_TENANT: | |
392 | - ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute()); | |
393 | - break; | |
394 | - case CURRENT_CUSTOMER: | |
395 | - ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute()); | |
396 | - if(ekv == null && value.getDynamicValue().isInherit()) { | |
397 | - ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute()); | |
398 | - } | |
399 | - break; | |
400 | 391 | case CURRENT_DEVICE: |
401 | 392 | ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute())); |
402 | 393 | if (ekv == null) { |
... | ... | @@ -408,12 +399,16 @@ class AlarmRuleState { |
408 | 399 | } |
409 | 400 | } |
410 | 401 | } |
411 | - if(ekv == null && value.getDynamicValue().isInherit()) { | |
412 | - ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute()); | |
413 | - if(ekv == null) { | |
414 | - ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute()); | |
415 | - } | |
402 | + if(ekv != null || !value.getDynamicValue().isInherit()) { | |
403 | + break; | |
416 | 404 | } |
405 | + case CURRENT_CUSTOMER: | |
406 | + ekv = dynamicPredicateValueCtx.getCustomerValue(value.getDynamicValue().getSourceAttribute()); | |
407 | + if(ekv != null || !value.getDynamicValue().isInherit()) { | |
408 | + break; | |
409 | + } | |
410 | + case CURRENT_TENANT: | |
411 | + ekv = dynamicPredicateValueCtx.getTenantValue(value.getDynamicValue().getSourceAttribute()); | |
417 | 412 | } |
418 | 413 | } |
419 | 414 | return ekv; | ... | ... |
... | ... | @@ -453,8 +453,6 @@ public class TbDeviceProfileNodeTest { |
453 | 453 | AttributeKvEntry entry = attributeKvEntity.toData(); |
454 | 454 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = |
455 | 455 | Futures.immediateFuture(Collections.singletonList(entry)); |
456 | - ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = | |
457 | - Futures.immediateFuture(Optional.of(entry)); | |
458 | 456 | |
459 | 457 | KeyFilter lowTempFilter = new KeyFilter(); |
460 | 458 | lowTempFilter.setKey(new EntityKey(EntityKeyType.TIME_SERIES, "temperature")); |
... | ... | @@ -490,8 +488,6 @@ public class TbDeviceProfileNodeTest { |
490 | 488 | Mockito.when(ctx.getAttributesService()).thenReturn(attributesService); |
491 | 489 | Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())) |
492 | 490 | .thenReturn(listListenableFutureWithLess); |
493 | - Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())) | |
494 | - .thenReturn(optionalListenableFutureWithLess); | |
495 | 491 | |
496 | 492 | TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), ""); |
497 | 493 | Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())) | ... | ... |