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.StringFilterPredicate;
 | 
			
		||||
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.EntitySearchDirection;
 | 
			
		||||
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));
 | 
			
		||||
        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));
 | 
			
		||||
 | 
			
		||||
        SingleEntityFilter singleEntityFilter = new SingleEntityFilter();
 | 
			
		||||
@ -1772,8 +1773,9 @@ public class EntityServiceTest extends AbstractControllerTest {
 | 
			
		||||
 | 
			
		||||
        PageData<EntityData> result = findByQueryAndCheck(query, 1);
 | 
			
		||||
 | 
			
		||||
        String tsValue = result.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature").getValue();
 | 
			
		||||
        String attrValue = result.getData().get(0).getLatest().get(SERVER_ATTRIBUTE).get("attr").getValue();
 | 
			
		||||
        Map<EntityKeyType, Map<String, TsValue>> latest = result.getData().get(0).getLatest();
 | 
			
		||||
        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(attrValue).isEqualTo("10");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.TbCacheValueWrapper;
 | 
			
		||||
import org.thingsboard.server.cache.VersionedTbCache;
 | 
			
		||||
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.StringUtils;
 | 
			
		||||
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 -> {
 | 
			
		||||
                BaseAttributeKvEntry attributeKvEntry = new BaseAttributeKvEntry(((BaseAttributeKvEntry) attribute).getKv(), attribute.getLastUpdateTs(), version);
 | 
			
		||||
                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;
 | 
			
		||||
            }, cacheExecutor);
 | 
			
		||||
            futures.add(future);
 | 
			
		||||
@ -263,7 +265,8 @@ public class CachedAttributesService implements AttributesService {
 | 
			
		||||
            Long version = keyVersionPair.getSecond();
 | 
			
		||||
            cache.evict(new AttributeCacheKey(scope, entityId, key), version);
 | 
			
		||||
            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;
 | 
			
		||||
        }, cacheExecutor)).toList());
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user