Implemented Json serialization, added custom serializer for the Device redis cache
This commit is contained in:
		
							parent
							
								
									cd0d2d4212
								
							
						
					
					
						commit
						5869378c2c
					
				@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
@ -31,6 +31,6 @@ import java.util.UUID;
 | 
			
		||||
public class VersionControlTaskRedisCache extends RedisTbTransactionalCache<UUID, VersionControlTaskCacheEntry> {
 | 
			
		||||
 | 
			
		||||
    public VersionControlTaskRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.VERSION_CONTROL_TASK_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.VERSION_CONTROL_TASK_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(VersionControlTaskCacheEntry.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.sync.vc.AutoCommitSettings;
 | 
			
		||||
@ -31,6 +31,6 @@ import org.thingsboard.server.common.data.sync.vc.AutoCommitSettings;
 | 
			
		||||
public class AutoCommitSettingsRedisCache extends RedisTbTransactionalCache<TenantId, AutoCommitSettings> {
 | 
			
		||||
 | 
			
		||||
    public AutoCommitSettingsRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.AUTO_COMMIT_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.AUTO_COMMIT_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(AutoCommitSettings.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.sync.vc.RepositorySettings;
 | 
			
		||||
@ -31,6 +31,6 @@ import org.thingsboard.server.common.data.sync.vc.RepositorySettings;
 | 
			
		||||
public class RepositorySettingsRedisCache extends RedisTbTransactionalCache<TenantId, RepositorySettings> {
 | 
			
		||||
 | 
			
		||||
    public RepositorySettingsRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.REPOSITORY_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.REPOSITORY_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(RepositorySettings.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -47,10 +47,6 @@ import org.thingsboard.server.common.data.TbResource;
 | 
			
		||||
import org.thingsboard.server.common.data.TenantProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials;
 | 
			
		||||
import org.thingsboard.server.common.data.device.credentials.ProvisionDeviceCredentialsData;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.CoapDeviceTransportConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.Lwm2mDeviceTransportConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.PowerMode;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.PowerSavingConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.device.profile.ProvisionDeviceProfileCredentials;
 | 
			
		||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
			
		||||
@ -70,6 +66,7 @@ import org.thingsboard.server.common.msg.EncryptionUtil;
 | 
			
		||||
import org.thingsboard.server.common.msg.TbMsg;
 | 
			
		||||
import org.thingsboard.server.common.msg.TbMsgDataType;
 | 
			
		||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
 | 
			
		||||
import org.thingsboard.server.common.util.ProtoUtils;
 | 
			
		||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
 | 
			
		||||
import org.thingsboard.server.dao.device.DeviceProfileService;
 | 
			
		||||
import org.thingsboard.server.dao.device.DeviceProvisionService;
 | 
			
		||||
@ -85,7 +82,6 @@ import org.thingsboard.server.dao.relation.RelationService;
 | 
			
		||||
import org.thingsboard.server.dao.resource.ResourceService;
 | 
			
		||||
import org.thingsboard.server.dao.tenant.TbTenantProfileCache;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.DeviceInfoProto;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceCredentialsRequestMsg;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceRequestMsg;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg;
 | 
			
		||||
@ -108,7 +104,6 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
import org.thingsboard.server.service.apiusage.TbApiUsageStateService;
 | 
			
		||||
import org.thingsboard.server.service.executors.DbCallbackExecutorService;
 | 
			
		||||
import org.thingsboard.server.service.profile.TbDeviceProfileCache;
 | 
			
		||||
import org.thingsboard.server.service.resource.TbResourceService;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.PostConstruct;
 | 
			
		||||
import javax.annotation.PreDestroy;
 | 
			
		||||
@ -390,7 +385,7 @@ public class DefaultTransportApiService implements TransportApiService {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            GetOrCreateDeviceFromGatewayResponseMsg.Builder builder = GetOrCreateDeviceFromGatewayResponseMsg.newBuilder()
 | 
			
		||||
                    .setDeviceInfo(getDeviceInfoProto(device));
 | 
			
		||||
                    .setDeviceInfo(ProtoUtils.toDeviceInfoProto(device));
 | 
			
		||||
            DeviceProfile deviceProfile = deviceProfileCache.get(device.getTenantId(), device.getDeviceProfileId());
 | 
			
		||||
            if (deviceProfile != null) {
 | 
			
		||||
                builder.setProfileBody(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile)));
 | 
			
		||||
@ -558,7 +553,7 @@ public class DefaultTransportApiService implements TransportApiService {
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            ValidateDeviceCredentialsResponseMsg.Builder builder = ValidateDeviceCredentialsResponseMsg.newBuilder();
 | 
			
		||||
            builder.setDeviceInfo(getDeviceInfoProto(device));
 | 
			
		||||
            builder.setDeviceInfo(ProtoUtils.toDeviceInfoProto(device));
 | 
			
		||||
            DeviceProfile deviceProfile = deviceProfileCache.get(device.getTenantId(), device.getDeviceProfileId());
 | 
			
		||||
            if (deviceProfile != null) {
 | 
			
		||||
                builder.setProfileBody(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile)));
 | 
			
		||||
@ -576,45 +571,6 @@ public class DefaultTransportApiService implements TransportApiService {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private DeviceInfoProto getDeviceInfoProto(Device device) throws JsonProcessingException {
 | 
			
		||||
        DeviceInfoProto.Builder builder = DeviceInfoProto.newBuilder()
 | 
			
		||||
                .setTenantIdMSB(device.getTenantId().getId().getMostSignificantBits())
 | 
			
		||||
                .setTenantIdLSB(device.getTenantId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setCustomerIdMSB(Optional.ofNullable(device.getCustomerId()).map(customerId -> customerId.getId().getMostSignificantBits()).orElse(0L))
 | 
			
		||||
                .setCustomerIdLSB(Optional.ofNullable(device.getCustomerId()).map(customerId -> customerId.getId().getLeastSignificantBits()).orElse(0L))
 | 
			
		||||
                .setDeviceIdMSB(device.getId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceIdLSB(device.getId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setDeviceName(device.getName())
 | 
			
		||||
                .setDeviceType(device.getType())
 | 
			
		||||
                .setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()));
 | 
			
		||||
 | 
			
		||||
        PowerSavingConfiguration psmConfiguration = null;
 | 
			
		||||
        switch (device.getDeviceData().getTransportConfiguration().getType()) {
 | 
			
		||||
            case LWM2M:
 | 
			
		||||
                psmConfiguration = (Lwm2mDeviceTransportConfiguration) device.getDeviceData().getTransportConfiguration();
 | 
			
		||||
                break;
 | 
			
		||||
            case COAP:
 | 
			
		||||
                psmConfiguration = (CoapDeviceTransportConfiguration) device.getDeviceData().getTransportConfiguration();
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (psmConfiguration != null) {
 | 
			
		||||
            PowerMode powerMode = psmConfiguration.getPowerMode();
 | 
			
		||||
            if (powerMode != null) {
 | 
			
		||||
                builder.setPowerMode(powerMode.name());
 | 
			
		||||
                if (powerMode.equals(PowerMode.PSM)) {
 | 
			
		||||
                    builder.setPsmActivityTimer(checkLong(psmConfiguration.getPsmActivityTimer()));
 | 
			
		||||
                } else if (powerMode.equals(PowerMode.E_DRX)) {
 | 
			
		||||
                    builder.setEdrxCycle(checkLong(psmConfiguration.getEdrxCycle()));
 | 
			
		||||
                    builder.setPagingTransmissionWindow(checkLong(psmConfiguration.getPagingTransmissionWindow()));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return builder.build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private ListenableFuture<TransportApiResponseMsg> getEmptyTransportApiResponseFuture() {
 | 
			
		||||
        return Futures.immediateFuture(getEmptyTransportApiResponse());
 | 
			
		||||
    }
 | 
			
		||||
@ -700,7 +656,7 @@ public class DefaultTransportApiService implements TransportApiService {
 | 
			
		||||
            }
 | 
			
		||||
            TransportProtos.LwM2MRegistrationResponseMsg registrationResponseMsg =
 | 
			
		||||
                    TransportProtos.LwM2MRegistrationResponseMsg.newBuilder()
 | 
			
		||||
                            .setDeviceInfo(getDeviceInfoProto(device)).build();
 | 
			
		||||
                            .setDeviceInfo(ProtoUtils.toDeviceInfoProto(device)).build();
 | 
			
		||||
            TransportProtos.LwM2MResponseMsg responseMsg = TransportProtos.LwM2MResponseMsg.newBuilder().setRegistrationMsg(registrationResponseMsg).build();
 | 
			
		||||
            return Futures.immediateFuture(TransportApiResponseMsg.newBuilder().setLwM2MResponseMsg(responseMsg).build());
 | 
			
		||||
        } catch (JsonProcessingException e) {
 | 
			
		||||
@ -729,11 +685,6 @@ public class DefaultTransportApiService implements TransportApiService {
 | 
			
		||||
                                .build()).collect(Collectors.toList())).build());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private Long checkLong(Long l) {
 | 
			
		||||
        return l != null ? l : 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private ProvisionRequest createProvisionRequest(String certificateValue) {
 | 
			
		||||
        return new ProvisionRequest(null, DeviceCredentialsType.X509_CERTIFICATE,
 | 
			
		||||
                new ProvisionDeviceCredentialsData(null, null, null, null, certificateValue),
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								common/cache/pom.xml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								common/cache/pom.xml
									
									
									
									
										vendored
									
									
								
							@ -40,6 +40,14 @@
 | 
			
		||||
            <groupId>org.thingsboard.common</groupId>
 | 
			
		||||
            <artifactId>data</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.thingsboard.common</groupId>
 | 
			
		||||
            <artifactId>util</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.thingsboard.common</groupId>
 | 
			
		||||
            <artifactId>proto</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-autoconfigure</artifactId>
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@ package org.thingsboard.server.cache;
 | 
			
		||||
import org.springframework.data.redis.serializer.SerializationException;
 | 
			
		||||
import org.thingsboard.server.common.data.FSTUtils;
 | 
			
		||||
 | 
			
		||||
@Deprecated(forRemoval = true, since = "3.6.3")
 | 
			
		||||
public class TbFSTRedisSerializer<K, V> implements TbRedisSerializer<K, V> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								common/cache/src/main/java/org/thingsboard/server/cache/TbJsonRedisSerializer.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								common/cache/src/main/java/org/thingsboard/server/cache/TbJsonRedisSerializer.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
package org.thingsboard.server.cache;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.redis.serializer.SerializationException;
 | 
			
		||||
import org.thingsboard.common.util.JacksonUtil;
 | 
			
		||||
 | 
			
		||||
public class TbJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> {
 | 
			
		||||
 | 
			
		||||
    private final Class<V> clazz;
 | 
			
		||||
 | 
			
		||||
    public TbJsonRedisSerializer(Class<V> clazz) {
 | 
			
		||||
        this.clazz = clazz;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public byte[] serialize(V v) throws SerializationException {
 | 
			
		||||
        return JacksonUtil.writeValueAsBytes(v);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public V deserialize(K key, byte[] bytes) throws SerializationException {
 | 
			
		||||
        return JacksonUtil.fromBytes(bytes, clazz);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								common/cache/src/main/java/org/thingsboard/server/cache/TbTypedJsonRedisSerializer.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								common/cache/src/main/java/org/thingsboard/server/cache/TbTypedJsonRedisSerializer.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
package org.thingsboard.server.cache;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.type.TypeReference;
 | 
			
		||||
import org.springframework.data.redis.serializer.SerializationException;
 | 
			
		||||
import org.thingsboard.common.util.JacksonUtil;
 | 
			
		||||
 | 
			
		||||
public class TbTypedJsonRedisSerializer<K, V> implements TbRedisSerializer<K, V> {
 | 
			
		||||
 | 
			
		||||
    private final TypeReference<V> valueTypeRef;
 | 
			
		||||
 | 
			
		||||
    public TbTypedJsonRedisSerializer(TypeReference<V> valueTypeRef) {
 | 
			
		||||
        this.valueTypeRef = valueTypeRef;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public byte[] serialize(V v) throws SerializationException {
 | 
			
		||||
        return JacksonUtil.writeValueAsBytes(v);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public V deserialize(K key, byte[] bytes) throws SerializationException {
 | 
			
		||||
        return JacksonUtil.fromBytes(bytes, valueTypeRef);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -15,21 +15,40 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.cache.device;
 | 
			
		||||
 | 
			
		||||
import com.google.protobuf.InvalidProtocolBufferException;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
 | 
			
		||||
import org.springframework.data.redis.serializer.SerializationException;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.util.ProtoUtils;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
 | 
			
		||||
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
 | 
			
		||||
@Service("DeviceCache")
 | 
			
		||||
public class DeviceRedisCache extends RedisTbTransactionalCache<DeviceCacheKey, Device> {
 | 
			
		||||
 | 
			
		||||
    public DeviceRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.DEVICE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.DEVICE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>(){
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public byte[] serialize(Device device) throws SerializationException {
 | 
			
		||||
                return ProtoUtils.toDeviceProto(device).toByteArray();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public Device deserialize(DeviceCacheKey key, byte[] bytes) throws SerializationException {
 | 
			
		||||
                try {
 | 
			
		||||
                    return ProtoUtils.fromDeviceProto(TransportProtos.DeviceProto.parseFrom(bytes));
 | 
			
		||||
                } catch (InvalidProtocolBufferException e) {
 | 
			
		||||
                    throw new SerializationException(e.getMessage());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.TbResourceInfo;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.TbResourceInfo;
 | 
			
		||||
public class ResourceInfoRedisCache extends RedisTbTransactionalCache<ResourceInfoCacheKey, TbResourceInfo> {
 | 
			
		||||
 | 
			
		||||
    public ResourceInfoRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.RESOURCE_INFO_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.RESOURCE_INFO_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(TbResourceInfo.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
 | 
			
		||||
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
 | 
			
		||||
@ -31,6 +31,6 @@ public class UsersSessionInvalidationRedisCache extends RedisTbTransactionalCach
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    public UsersSessionInvalidationRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.USERS_SESSION_INVALIDATION_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.USERS_SESSION_INVALIDATION_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(Long.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -58,6 +58,7 @@ public class Device extends BaseDataWithAdditionalInfo<DeviceId> implements HasL
 | 
			
		||||
    private DeviceProfileId deviceProfileId;
 | 
			
		||||
    private transient DeviceData deviceData;
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    @Getter @Setter
 | 
			
		||||
    private byte[] deviceDataBytes;
 | 
			
		||||
 | 
			
		||||
    private OtaPackageId firmwareId;
 | 
			
		||||
 | 
			
		||||
@ -44,6 +44,10 @@
 | 
			
		||||
            <groupId>org.thingsboard.common</groupId>
 | 
			
		||||
            <artifactId>message</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.thingsboard.common</groupId>
 | 
			
		||||
            <artifactId>util</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.google.protobuf</groupId>
 | 
			
		||||
            <artifactId>protobuf-java</artifactId>
 | 
			
		||||
 | 
			
		||||
@ -15,10 +15,22 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.common.util;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.JsonProcessingException;
 | 
			
		||||
import com.google.protobuf.ByteString;
 | 
			
		||||
import org.thingsboard.common.util.JacksonUtil;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityType;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.CoapDeviceTransportConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.Lwm2mDeviceTransportConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.PowerMode;
 | 
			
		||||
import org.thingsboard.server.common.data.device.data.PowerSavingConfiguration;
 | 
			
		||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EdgeId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityIdFactory;
 | 
			
		||||
import org.thingsboard.server.common.data.id.OtaPackageId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.kv.AttributeKey;
 | 
			
		||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
 | 
			
		||||
@ -496,4 +508,122 @@ public class ProtoUtils {
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static TransportProtos.DeviceProto toDeviceProto(Device device) {
 | 
			
		||||
        var builder = TransportProtos.DeviceProto.newBuilder()
 | 
			
		||||
                .setTenantIdMSB(device.getTenantId().getId().getMostSignificantBits())
 | 
			
		||||
                .setTenantIdLSB(device.getTenantId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setCustomerIdMSB(getMsb(device.getCustomerId()))
 | 
			
		||||
                .setCustomerIdLSB(getLsb(device.getCustomerId()))
 | 
			
		||||
                .setDeviceIdMSB(device.getId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceIdLSB(device.getId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setDeviceName(device.getName())
 | 
			
		||||
                .setDeviceType(device.getType())
 | 
			
		||||
                .setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()))
 | 
			
		||||
                .setFirmwareIdMSB(getMsb(device.getFirmwareId()))
 | 
			
		||||
                .setFirmwareIdLSB(getLsb(device.getFirmwareId()))
 | 
			
		||||
                .setSoftwareIdMSB(getMsb(device.getSoftwareId()))
 | 
			
		||||
                .setSoftwareIdLSB(getLsb(device.getSoftwareId()))
 | 
			
		||||
                .setExternalIdMSB(getMsb(device.getExternalId()))
 | 
			
		||||
                .setExternalIdLSB(getLsb(device.getExternalId()));
 | 
			
		||||
 | 
			
		||||
        if (device.getLabel() != null) {
 | 
			
		||||
            builder.setDeviceLabel(device.getLabel());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (device.getDeviceDataBytes() != null) {
 | 
			
		||||
            builder.setDeviceData(ByteString.copyFrom(device.getDeviceDataBytes()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return builder.build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Device fromDeviceProto(TransportProtos.DeviceProto deviceProto) {
 | 
			
		||||
        Device device = new Device(new DeviceId(new UUID(deviceProto.getDeviceIdMSB(), deviceProto.getDeviceIdLSB())));
 | 
			
		||||
        device.setTenantId(new TenantId(new UUID(deviceProto.getTenantIdMSB(), deviceProto.getTenantIdLSB())));
 | 
			
		||||
        device.setCustomerId(new CustomerId(new UUID(deviceProto.getCustomerIdMSB(), deviceProto.getCustomerIdLSB())));
 | 
			
		||||
        device.setName(deviceProto.getDeviceName());
 | 
			
		||||
        device.setLabel(deviceProto.getDeviceLabel());
 | 
			
		||||
        device.setType(deviceProto.getDeviceType());
 | 
			
		||||
        device.setDeviceProfileId(new DeviceProfileId(new UUID(deviceProto.getDeviceProfileIdMSB(), deviceProto.getDeviceProfileIdLSB())));
 | 
			
		||||
        device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceProto.getAdditionalInfo()));
 | 
			
		||||
        device.setFirmwareId(createOtaPackageId(deviceProto.getFirmwareIdMSB(), deviceProto.getFirmwareIdLSB()));
 | 
			
		||||
        device.setSoftwareId(createOtaPackageId(deviceProto.getSoftwareIdMSB(), deviceProto.getSoftwareIdLSB()));
 | 
			
		||||
        device.setExternalId(createDeviceId(deviceProto.getExternalIdMSB(), deviceProto.getExternalIdLSB()));
 | 
			
		||||
        device.setDeviceDataBytes(deviceProto.getDeviceData().toByteArray());
 | 
			
		||||
        return device;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static OtaPackageId createOtaPackageId(long msb, long lsb) {
 | 
			
		||||
        if (msb != 0 || lsb != 0) {
 | 
			
		||||
            return new OtaPackageId(new UUID(msb, lsb));
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static DeviceId createDeviceId(long msb, long lsb) {
 | 
			
		||||
        if (msb != 0 || lsb != 0) {
 | 
			
		||||
            return new DeviceId(new UUID(msb, lsb));
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static TransportProtos.DeviceInfoProto toDeviceInfoProto(Device device) throws JsonProcessingException {
 | 
			
		||||
        TransportProtos.DeviceInfoProto.Builder builder = TransportProtos.DeviceInfoProto.newBuilder()
 | 
			
		||||
                .setTenantIdMSB(device.getTenantId().getId().getMostSignificantBits())
 | 
			
		||||
                .setTenantIdLSB(device.getTenantId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setCustomerIdMSB(getMsb(device.getCustomerId()))
 | 
			
		||||
                .setCustomerIdLSB(getLsb(device.getCustomerId()))
 | 
			
		||||
                .setDeviceIdMSB(device.getId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceIdLSB(device.getId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setDeviceName(device.getName())
 | 
			
		||||
                .setDeviceType(device.getType())
 | 
			
		||||
                .setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits())
 | 
			
		||||
                .setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits())
 | 
			
		||||
                .setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()));
 | 
			
		||||
 | 
			
		||||
        PowerSavingConfiguration psmConfiguration = null;
 | 
			
		||||
        switch (device.getDeviceData().getTransportConfiguration().getType()) {
 | 
			
		||||
            case LWM2M:
 | 
			
		||||
                psmConfiguration = (Lwm2mDeviceTransportConfiguration) device.getDeviceData().getTransportConfiguration();
 | 
			
		||||
                break;
 | 
			
		||||
            case COAP:
 | 
			
		||||
                psmConfiguration = (CoapDeviceTransportConfiguration) device.getDeviceData().getTransportConfiguration();
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (psmConfiguration != null) {
 | 
			
		||||
            PowerMode powerMode = psmConfiguration.getPowerMode();
 | 
			
		||||
            if (powerMode != null) {
 | 
			
		||||
                builder.setPowerMode(powerMode.name());
 | 
			
		||||
                if (powerMode.equals(PowerMode.PSM)) {
 | 
			
		||||
                    builder.setPsmActivityTimer(checkLong(psmConfiguration.getPsmActivityTimer()));
 | 
			
		||||
                } else if (powerMode.equals(PowerMode.E_DRX)) {
 | 
			
		||||
                    builder.setEdrxCycle(checkLong(psmConfiguration.getEdrxCycle()));
 | 
			
		||||
                    builder.setPagingTransmissionWindow(checkLong(psmConfiguration.getPagingTransmissionWindow()));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return builder.build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Long getMsb(EntityId entityId) {
 | 
			
		||||
        if (entityId != null) {
 | 
			
		||||
            return entityId.getId().getMostSignificantBits();
 | 
			
		||||
        }
 | 
			
		||||
        return 0L;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Long getLsb(EntityId entityId) {
 | 
			
		||||
        if (entityId != null) {
 | 
			
		||||
            return entityId.getId().getLeastSignificantBits();
 | 
			
		||||
        }
 | 
			
		||||
        return 0L;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Long checkLong(Long l) {
 | 
			
		||||
        return l != null ? l : 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -183,6 +183,28 @@ message DeviceInfoProto {
 | 
			
		||||
  int64 pagingTransmissionWindow = 15;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message DeviceProto {
 | 
			
		||||
  int64 tenantIdMSB = 1;
 | 
			
		||||
  int64 tenantIdLSB = 2;
 | 
			
		||||
  int64 deviceIdMSB = 3;
 | 
			
		||||
  int64 deviceIdLSB = 4;
 | 
			
		||||
  string deviceName = 5;
 | 
			
		||||
  string deviceLabel = 6;
 | 
			
		||||
  string deviceType = 7;
 | 
			
		||||
  string additionalInfo = 8;
 | 
			
		||||
  int64 deviceProfileIdMSB = 9;
 | 
			
		||||
  int64 deviceProfileIdLSB = 10;
 | 
			
		||||
  int64 customerIdMSB = 11;
 | 
			
		||||
  int64 customerIdLSB = 12;
 | 
			
		||||
  bytes deviceData = 13;
 | 
			
		||||
  int64 firmwareIdMSB = 14;
 | 
			
		||||
  int64 firmwareIdLSB = 15;
 | 
			
		||||
  int64 softwareIdMSB = 16;
 | 
			
		||||
  int64 softwareIdLSB = 17;
 | 
			
		||||
  int64 externalIdMSB = 18;
 | 
			
		||||
  int64 externalIdLSB = 19;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Transport Service Messages;
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@ -126,6 +126,14 @@ public class JacksonUtil {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T> T fromBytes(byte[] bytes, TypeReference<T> valueTypeRef) {
 | 
			
		||||
        try {
 | 
			
		||||
            return bytes != null ? OBJECT_MAPPER.readValue(bytes, valueTypeRef) : null;
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            throw new IllegalArgumentException("The given string value cannot be transformed to Json object: " + Arrays.toString(bytes), e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static JsonNode fromBytes(byte[] bytes) {
 | 
			
		||||
        try {
 | 
			
		||||
            return OBJECT_MAPPER.readTree(bytes);
 | 
			
		||||
 | 
			
		||||
@ -15,13 +15,14 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.dao.alarm;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.type.TypeReference;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbTypedJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.EntitySubtype;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
@ -32,6 +33,6 @@ import org.thingsboard.server.common.data.page.PageData;
 | 
			
		||||
public class AlarmTypesRedisCache extends RedisTbTransactionalCache<TenantId, PageData<EntitySubtype>> {
 | 
			
		||||
 | 
			
		||||
    public AlarmTypesRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.ALARM_TYPES_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.ALARM_TYPES_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbTypedJsonRedisSerializer<>(new TypeReference<>() {}));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.asset.AssetProfile;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.asset.AssetProfile;
 | 
			
		||||
public class AssetProfileRedisCache extends RedisTbTransactionalCache<AssetProfileCacheKey, AssetProfile> {
 | 
			
		||||
 | 
			
		||||
    public AssetProfileRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.ASSET_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.ASSET_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(AssetProfile.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.asset.Asset;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.asset.Asset;
 | 
			
		||||
public class AssetRedisCache extends RedisTbTransactionalCache<AssetCacheKey, Asset> {
 | 
			
		||||
 | 
			
		||||
    public AssetRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.ASSET_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.ASSET_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(Asset.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DashboardId;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.id.DashboardId;
 | 
			
		||||
public class DashboardTitlesRedisCache extends RedisTbTransactionalCache<DashboardId, String> {
 | 
			
		||||
 | 
			
		||||
    public DashboardTitlesRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.DASHBOARD_TITLES_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.DASHBOARD_TITLES_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(String.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.security.DeviceCredentials;
 | 
			
		||||
public class DeviceCredentialsRedisCache extends RedisTbTransactionalCache<String, DeviceCredentials> {
 | 
			
		||||
 | 
			
		||||
    public DeviceCredentialsRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.DEVICE_CREDENTIALS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.DEVICE_CREDENTIALS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(DeviceCredentials.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
public class DeviceProfileRedisCache extends RedisTbTransactionalCache<DeviceProfileCacheKey, DeviceProfile> {
 | 
			
		||||
 | 
			
		||||
    public DeviceProfileRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.DEVICE_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.DEVICE_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(DeviceProfile.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.Edge;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.edge.Edge;
 | 
			
		||||
public class EdgeRedisCache extends RedisTbTransactionalCache<EdgeCacheKey, Edge> {
 | 
			
		||||
 | 
			
		||||
    public EdgeRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.EDGE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.EDGE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(Edge.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.dao.entity.EntityCountCacheKey;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.dao.entity.EntityCountCacheKey;
 | 
			
		||||
public class EntityCountRedisCache extends RedisTbTransactionalCache<EntityCountCacheKey, Long> {
 | 
			
		||||
 | 
			
		||||
    public EntityCountRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.ENTITY_COUNT_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.ENTITY_COUNT_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(Long.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
 | 
			
		||||
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
 | 
			
		||||
@ -29,6 +29,6 @@ import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
public class EntityViewRedisCache extends RedisTbTransactionalCache<EntityViewCacheKey, EntityViewCacheValue> {
 | 
			
		||||
 | 
			
		||||
    public EntityViewRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.ENTITY_VIEW_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.ENTITY_VIEW_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(EntityViewCacheValue.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.OtaPackageInfo;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.OtaPackageInfo;
 | 
			
		||||
public class OtaPackageRedisCache extends RedisTbTransactionalCache<OtaPackageCacheKey, OtaPackageInfo> {
 | 
			
		||||
 | 
			
		||||
    public OtaPackageRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.OTA_PACKAGE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.OTA_PACKAGE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(OtaPackageInfo.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
 | 
			
		||||
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
 | 
			
		||||
@ -29,6 +29,6 @@ import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
public class RelationRedisCache extends RedisTbTransactionalCache<RelationCacheKey, RelationCacheValue> {
 | 
			
		||||
 | 
			
		||||
    public RelationRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.RELATIONS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.RELATIONS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(RelationCacheValue.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
public class TenantExistsRedisCache extends RedisTbTransactionalCache<TenantId, Boolean> {
 | 
			
		||||
 | 
			
		||||
    public TenantExistsRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.TENANTS_EXIST_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.TENANTS_EXIST_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(Boolean.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.TenantProfile;
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,6 @@ import org.thingsboard.server.common.data.TenantProfile;
 | 
			
		||||
public class TenantProfileRedisCache extends RedisTbTransactionalCache<TenantProfileCacheKey, TenantProfile> {
 | 
			
		||||
 | 
			
		||||
    public TenantProfileRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.TENANT_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.TENANT_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(TenantProfile.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.Tenant;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
@ -31,6 +31,6 @@ import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
public class TenantRedisCache extends RedisTbTransactionalCache<TenantId, Tenant> {
 | 
			
		||||
 | 
			
		||||
    public TenantRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.TENANTS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.TENANTS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(Tenant.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.cache.CacheSpecsMap;
 | 
			
		||||
import org.thingsboard.server.cache.RedisTbTransactionalCache;
 | 
			
		||||
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
 | 
			
		||||
import org.thingsboard.server.cache.TbFSTRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.cache.TbJsonRedisSerializer;
 | 
			
		||||
import org.thingsboard.server.common.data.CacheConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.settings.UserSettings;
 | 
			
		||||
import org.thingsboard.server.common.data.settings.UserSettingsCompositeKey;
 | 
			
		||||
@ -31,6 +31,6 @@ import org.thingsboard.server.common.data.settings.UserSettingsCompositeKey;
 | 
			
		||||
public class UserSettingsRedisCache extends RedisTbTransactionalCache<UserSettingsCompositeKey, UserSettings> {
 | 
			
		||||
 | 
			
		||||
    public UserSettingsRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
 | 
			
		||||
        super(CacheConstants.USER_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbFSTRedisSerializer<>());
 | 
			
		||||
        super(CacheConstants.USER_SETTINGS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbJsonRedisSerializer<>(UserSettings.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user