Commit e70df09b088e7b2c9e2c6a553ca84ab470ada7ac

Authored by Andrew Volostnykh
Committed by Andrew Shvayka
1 parent 6bf2b322

Code cleaning and fix of tests

@@ -18,8 +18,10 @@ package org.thingsboard.server.common.data.query; @@ -18,8 +18,10 @@ package org.thingsboard.server.common.data.query;
18 import com.fasterxml.jackson.annotation.JsonIgnore; 18 import com.fasterxml.jackson.annotation.JsonIgnore;
19 import lombok.Data; 19 import lombok.Data;
20 import lombok.Getter; 20 import lombok.Getter;
  21 +import lombok.RequiredArgsConstructor;
21 22
22 @Data 23 @Data
  24 +@RequiredArgsConstructor
23 public class DynamicValue<T> { 25 public class DynamicValue<T> {
24 26
25 @JsonIgnore 27 @JsonIgnore
@@ -31,12 +33,6 @@ public class DynamicValue<T> { @@ -31,12 +33,6 @@ public class DynamicValue<T> {
31 this.inherit = false; 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 @Getter 36 @Getter
41 private final DynamicValueSourceType sourceType; 37 private final DynamicValueSourceType sourceType;
42 @Getter 38 @Getter
@@ -388,15 +388,6 @@ class AlarmRuleState { @@ -388,15 +388,6 @@ class AlarmRuleState {
388 EntityKeyValue ekv = null; 388 EntityKeyValue ekv = null;
389 if (value.getDynamicValue() != null) { 389 if (value.getDynamicValue() != null) {
390 switch (value.getDynamicValue().getSourceType()) { 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 case CURRENT_DEVICE: 391 case CURRENT_DEVICE:
401 ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute())); 392 ekv = data.getValue(new EntityKey(EntityKeyType.ATTRIBUTE, value.getDynamicValue().getSourceAttribute()));
402 if (ekv == null) { 393 if (ekv == null) {
@@ -408,12 +399,16 @@ class AlarmRuleState { @@ -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 return ekv; 414 return ekv;
@@ -453,8 +453,6 @@ public class TbDeviceProfileNodeTest { @@ -453,8 +453,6 @@ public class TbDeviceProfileNodeTest {
453 AttributeKvEntry entry = attributeKvEntity.toData(); 453 AttributeKvEntry entry = attributeKvEntity.toData();
454 ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = 454 ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess =
455 Futures.immediateFuture(Collections.singletonList(entry)); 455 Futures.immediateFuture(Collections.singletonList(entry));
456 - ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess =  
457 - Futures.immediateFuture(Optional.of(entry));  
458 456
459 KeyFilter lowTempFilter = new KeyFilter(); 457 KeyFilter lowTempFilter = new KeyFilter();
460 lowTempFilter.setKey(new EntityKey(EntityKeyType.TIME_SERIES, "temperature")); 458 lowTempFilter.setKey(new EntityKey(EntityKeyType.TIME_SERIES, "temperature"));
@@ -490,8 +488,6 @@ public class TbDeviceProfileNodeTest { @@ -490,8 +488,6 @@ public class TbDeviceProfileNodeTest {
490 Mockito.when(ctx.getAttributesService()).thenReturn(attributesService); 488 Mockito.when(ctx.getAttributesService()).thenReturn(attributesService);
491 Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())) 489 Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet()))
492 .thenReturn(listListenableFutureWithLess); 490 .thenReturn(listListenableFutureWithLess);
493 - Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString()))  
494 - .thenReturn(optionalListenableFutureWithLess);  
495 491
496 TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), ""); 492 TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
497 Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())) 493 Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString()))