Fix version in proto; fix some tests

This commit is contained in:
ViacheslavKlimov 2024-07-01 13:49:17 +03:00
parent 67b8ded9f4
commit 4b7b69313f
6 changed files with 24 additions and 15 deletions

View File

@ -183,7 +183,7 @@ public class DefaultTbDeviceService extends AbstractTbEntityService implements T
try {
DeviceCredentials result = checkNotNull(deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials));
logEntityActionService.logEntityAction(tenantId, deviceId, device, device.getCustomerId(),
actionType, user, deviceCredentials);
actionType, user, result);
return result;
} catch (Exception e) {
logEntityActionService.logEntityAction(tenantId, emptyId(EntityType.DEVICE),

View File

@ -148,9 +148,9 @@ public abstract class AbstractBulkImportService<E extends HasId<? extends Entity
if (entity.getId() != null) {
importedEntityInfo.setOldEntity((E) entity.getClass().getConstructor(entity.getClass()).newInstance(entity));
importedEntityInfo.setUpdated(true);
if (entity instanceof HasVersion versionedEntity) {
versionedEntity.setVersion(null); // to overwrite the entity regardless of concurrent changes
}
// if (entity instanceof HasVersion versionedEntity) { // FIXME: TMP
// versionedEntity.setVersion(null); // to overwrite the entity regardless of concurrent changes
// }
} else {
setOwners(entity, user);
}

View File

@ -749,8 +749,7 @@ public class DeviceControllerTest extends AbstractControllerTest {
Mockito.reset(tbClusterService, auditLogService, gatewayNotificationsService);
doPost("/api/device/credentials", deviceCredentials)
.andExpect(status().isOk());
deviceCredentials = doPost("/api/device/credentials", deviceCredentials, DeviceCredentials.class);
testNotifyEntityMsgToEdgePushMsgToCoreOneTime(savedDevice, savedDevice.getId(), savedDevice.getId(), savedTenant.getId(),
tenantAdmin.getCustomerId(), tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.CREDENTIALS_UPDATED, deviceCredentials);

View File

@ -551,6 +551,9 @@ public class ProtoUtils {
if (isNotNull(device.getDeviceDataBytes())) {
builder.setDeviceData(ByteString.copyFrom(device.getDeviceDataBytes()));
}
if (isNotNull(device.getVersion())) {
builder.setVersion(device.getVersion());
}
return builder.build();
}
@ -582,6 +585,9 @@ public class ProtoUtils {
if (proto.hasDeviceData()) {
device.setDeviceDataBytes(proto.getDeviceData().toByteArray());
}
if (proto.hasVersion()) {
device.setVersion(proto.getVersion());
}
return device;
}
@ -637,6 +643,9 @@ public class ProtoUtils {
builder.setDefaultEdgeRuleChainIdMSB(getMsb(deviceProfile.getDefaultEdgeRuleChainId()))
.setDefaultEdgeRuleChainIdLSB(getLsb(deviceProfile.getDefaultEdgeRuleChainId()));
}
if (isNotNull(deviceProfile.getVersion())) {
builder.setVersion(deviceProfile.getVersion());
}
return builder.build();
}
@ -682,6 +691,9 @@ public class ProtoUtils {
if (proto.hasDefaultEdgeRuleChainIdMSB() && proto.hasDefaultEdgeRuleChainIdLSB()) {
deviceProfile.setDefaultEdgeRuleChainId(getEntityId(proto.getDefaultEdgeRuleChainIdMSB(), proto.getDefaultEdgeRuleChainIdLSB(), RuleChainId::new));
}
if (proto.hasVersion()) {
deviceProfile.setVersion(proto.getVersion());
}
return deviceProfile;
}
@ -969,6 +981,9 @@ public class ProtoUtils {
if (deviceCredentials.getCredentialsValue() != null) {
builder.setCredentialsValue(deviceCredentials.getCredentialsValue());
}
if (deviceCredentials.getVersion() != null) {
builder.setVersion(deviceCredentials.getVersion());
}
return builder.build();
}
@ -980,6 +995,7 @@ public class ProtoUtils {
deviceCredentials.setCredentialsId(proto.getCredentialsId());
deviceCredentials.setCredentialsType(DeviceCredentialsType.valueOf(proto.getCredentialsType().name()));
deviceCredentials.setCredentialsValue(proto.hasCredentialsValue() ? proto.getCredentialsValue() : null);
deviceCredentials.setVersion(proto.hasVersion() ? proto.getVersion() : null);
return deviceCredentials;
}

View File

@ -209,6 +209,7 @@ message DeviceProto {
optional int64 softwareIdLSB = 18;
optional int64 externalIdMSB = 19;
optional int64 externalIdLSB = 20;
optional int32 version = 21;
}
message DeviceProfileProto {
@ -239,6 +240,7 @@ message DeviceProfileProto {
optional int64 defaultEdgeRuleChainIdLSB = 25;
optional int64 externalIdMSB = 26;
optional int64 externalIdLSB = 27;
optional int32 version = 28;
}
message TenantProto {
@ -667,6 +669,7 @@ message DeviceCredentialsProto {
CredentialsType credentialsType = 6;
string credentialsId = 7;
optional string credentialsValue = 8;
optional int32 version = 9;
}
message CredentialsDataProto {

View File

@ -19,7 +19,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.security.DeviceCredentials;
@ -52,14 +51,6 @@ public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEnt
return deviceCredentialsRepository;
}
@Transactional
@Override
public DeviceCredentials saveAndFlush(TenantId tenantId, DeviceCredentials deviceCredentials) {
DeviceCredentials result = save(tenantId, deviceCredentials);
deviceCredentialsRepository.flush();
return result;
}
@Override
public DeviceCredentials findByDeviceId(TenantId tenantId, UUID deviceId) {
return DaoUtil.getData(deviceCredentialsRepository.findByDeviceId(deviceId));