fixed tenant attribute save by system admin
This commit is contained in:
parent
00bc14ab61
commit
5ee4ebea57
@ -79,6 +79,7 @@ import org.thingsboard.server.common.data.query.RelationsQueryFilter;
|
|||||||
import org.thingsboard.server.common.data.query.SingleEntityFilter;
|
import org.thingsboard.server.common.data.query.SingleEntityFilter;
|
||||||
import org.thingsboard.server.common.data.query.StringFilterPredicate;
|
import org.thingsboard.server.common.data.query.StringFilterPredicate;
|
||||||
import org.thingsboard.server.common.data.query.StringFilterPredicate.StringOperation;
|
import org.thingsboard.server.common.data.query.StringFilterPredicate.StringOperation;
|
||||||
|
import org.thingsboard.server.common.data.query.TsValue;
|
||||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||||
import org.thingsboard.server.common.data.relation.EntitySearchDirection;
|
import org.thingsboard.server.common.data.relation.EntitySearchDirection;
|
||||||
import org.thingsboard.server.common.data.relation.RelationEntityTypeFilter;
|
import org.thingsboard.server.common.data.relation.RelationEntityTypeFilter;
|
||||||
@ -1753,7 +1754,7 @@ public class EntityServiceTest extends AbstractControllerTest {
|
|||||||
BasicTsKvEntry timeseries = new BasicTsKvEntry(42L, new DoubleDataEntry("temperature", 45.5));
|
BasicTsKvEntry timeseries = new BasicTsKvEntry(42L, new DoubleDataEntry("temperature", 45.5));
|
||||||
timeseriesService.save(TenantId.SYS_TENANT_ID, tenantId, timeseries);
|
timeseriesService.save(TenantId.SYS_TENANT_ID, tenantId, timeseries);
|
||||||
|
|
||||||
AttributeKvEntry attr = new BaseAttributeKvEntry( new LongDataEntry("attr", 10L), 42L);
|
AttributeKvEntry attr = new BaseAttributeKvEntry(new LongDataEntry("attr", 10L), 42L);
|
||||||
attributesService.save(TenantId.SYS_TENANT_ID, tenantId, SERVER_SCOPE, List.of(attr));
|
attributesService.save(TenantId.SYS_TENANT_ID, tenantId, SERVER_SCOPE, List.of(attr));
|
||||||
|
|
||||||
SingleEntityFilter singleEntityFilter = new SingleEntityFilter();
|
SingleEntityFilter singleEntityFilter = new SingleEntityFilter();
|
||||||
@ -1772,8 +1773,9 @@ public class EntityServiceTest extends AbstractControllerTest {
|
|||||||
|
|
||||||
PageData<EntityData> result = findByQueryAndCheck(query, 1);
|
PageData<EntityData> result = findByQueryAndCheck(query, 1);
|
||||||
|
|
||||||
String tsValue = result.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature").getValue();
|
Map<EntityKeyType, Map<String, TsValue>> latest = result.getData().get(0).getLatest();
|
||||||
String attrValue = result.getData().get(0).getLatest().get(SERVER_ATTRIBUTE).get("attr").getValue();
|
String tsValue = latest.get(EntityKeyType.TIME_SERIES).get("temperature").getValue();
|
||||||
|
String attrValue = latest.get(SERVER_ATTRIBUTE).get("attr").getValue();
|
||||||
assertThat(tsValue).isEqualTo("45.5");
|
assertThat(tsValue).isEqualTo("45.5");
|
||||||
assertThat(attrValue).isEqualTo("10");
|
assertThat(attrValue).isEqualTo("10");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.thingsboard.server.cache.TbCacheValueWrapper;
|
import org.thingsboard.server.cache.TbCacheValueWrapper;
|
||||||
import org.thingsboard.server.cache.VersionedTbCache;
|
import org.thingsboard.server.cache.VersionedTbCache;
|
||||||
import org.thingsboard.server.common.data.AttributeScope;
|
import org.thingsboard.server.common.data.AttributeScope;
|
||||||
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.ObjectType;
|
import org.thingsboard.server.common.data.ObjectType;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
import org.thingsboard.server.common.data.edqs.AttributeKv;
|
import org.thingsboard.server.common.data.edqs.AttributeKv;
|
||||||
@ -239,7 +240,8 @@ public class CachedAttributesService implements AttributesService {
|
|||||||
ListenableFuture<Long> future = Futures.transform(attributesDao.save(tenantId, entityId, scope, attribute), version -> {
|
ListenableFuture<Long> future = Futures.transform(attributesDao.save(tenantId, entityId, scope, attribute), version -> {
|
||||||
BaseAttributeKvEntry attributeKvEntry = new BaseAttributeKvEntry(((BaseAttributeKvEntry) attribute).getKv(), attribute.getLastUpdateTs(), version);
|
BaseAttributeKvEntry attributeKvEntry = new BaseAttributeKvEntry(((BaseAttributeKvEntry) attribute).getKv(), attribute.getLastUpdateTs(), version);
|
||||||
put(entityId, scope, attributeKvEntry);
|
put(entityId, scope, attributeKvEntry);
|
||||||
edqsService.onUpdate(tenantId, ObjectType.ATTRIBUTE_KV, new AttributeKv(entityId, scope, attributeKvEntry, version));
|
TenantId edqsTenantId = entityId.getEntityType() == EntityType.TENANT ? (TenantId) entityId : tenantId;
|
||||||
|
edqsService.onUpdate(edqsTenantId, ObjectType.ATTRIBUTE_KV, new AttributeKv(entityId, scope, attributeKvEntry, version));
|
||||||
return version;
|
return version;
|
||||||
}, cacheExecutor);
|
}, cacheExecutor);
|
||||||
futures.add(future);
|
futures.add(future);
|
||||||
@ -263,7 +265,8 @@ public class CachedAttributesService implements AttributesService {
|
|||||||
Long version = keyVersionPair.getSecond();
|
Long version = keyVersionPair.getSecond();
|
||||||
cache.evict(new AttributeCacheKey(scope, entityId, key), version);
|
cache.evict(new AttributeCacheKey(scope, entityId, key), version);
|
||||||
if (version != null) {
|
if (version != null) {
|
||||||
edqsService.onDelete(tenantId, ObjectType.ATTRIBUTE_KV, new AttributeKv(entityId, scope, key, version));
|
TenantId edqsTenantId = entityId.getEntityType() == EntityType.TENANT ? (TenantId) entityId : tenantId;
|
||||||
|
edqsService.onDelete(edqsTenantId, ObjectType.ATTRIBUTE_KV, new AttributeKv(entityId, scope, key, version));
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
}, cacheExecutor)).toList());
|
}, cacheExecutor)).toList());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user