Refactoring

This commit is contained in:
Andrii Landiak 2025-06-19 17:09:08 +03:00
parent fbb7d5c415
commit 7dc8f10740
4 changed files with 20 additions and 17 deletions

View File

@ -52,12 +52,14 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
@Override
protected DeviceProfile saveOrUpdate(EntitiesImportCtx ctx, DeviceProfile deviceProfile, EntityExportData<DeviceProfile> exportData, IdProvider idProvider, CompareResult compareResult) {
boolean toUpdate = ctx.isFinalImportAttempt() || ctx.getCurrentImportResult().isUpdatedAllExternalIds();
if (toUpdate) {
deviceProfile.setFirmwareId(idProvider.getInternalId(deviceProfile.getFirmwareId()));
deviceProfile.setSoftwareId(idProvider.getInternalId(deviceProfile.getSoftwareId()));
}
DeviceProfile saved = deviceProfileService.saveDeviceProfile(deviceProfile);
if (ctx.isFinalImportAttempt() || ctx.getCurrentImportResult().isUpdatedAllExternalIds()) {
if (toUpdate) {
importCalculatedFields(ctx, saved, exportData, idProvider);
saved.setFirmwareId(idProvider.getInternalId(deviceProfile.getFirmwareId()));
saved.setSoftwareId(idProvider.getInternalId(deviceProfile.getSoftwareId()));
saved = deviceProfileService.saveDeviceProfile(saved);
}
return saved;
}

View File

@ -20,10 +20,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.thingsboard.server.common.data.EntityType;
import java.io.Serial;
import java.util.UUID;
public class OtaPackageId extends UUIDBased implements EntityId {
@Serial
private static final long serialVersionUID = 1L;
@JsonCreator

View File

@ -18,10 +18,13 @@ package org.thingsboard.server.common.data.sync.vc.request.create;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
@EqualsAndHashCode(callSuper = true)
@Data
public class AutoVersionCreateConfig extends VersionCreateConfig {
@Serial
private static final long serialVersionUID = 8245450889383315551L;
private String branch;

View File

@ -74,7 +74,7 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
@Override
public OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo, boolean isUrl) {
log.trace("Executing saveOtaPackageInfo [{}]", otaPackageInfo);
if (isUrl && (StringUtils.isEmpty(otaPackageInfo.getUrl()) || otaPackageInfo.getUrl().trim().isEmpty())) {
if (isUrl && (StringUtils.isEmpty(otaPackageInfo.getUrl()) || StringUtils.isBlank(otaPackageInfo.getUrl()))) {
throw new DataValidationException("Ota package URL should be specified!");
}
otaPackageInfoValidator.validate(otaPackageInfo, OtaPackageInfo::getTenantId);
@ -91,12 +91,10 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
if (otaPackageId != null) {
handleEvictEvent(new OtaPackageCacheEvictEvent(otaPackageId));
}
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("ota_package_tenant_title_version_unq_key")) {
throw new DataValidationException("OtaPackage with such title and version already exists!");
} else {
throw t;
}
checkConstraintViolation(t,
"ota_package_tenant_title_version_unq_key", "OtaPackage with such title and version already exists!",
"ota_package_external_id_unq_key", "OtaPackage with such external id already exists!");
throw t;
}
}
@ -117,12 +115,10 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
if (otaPackageId != null) {
handleEvictEvent(new OtaPackageCacheEvictEvent(otaPackageId));
}
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("ota_package_tenant_title_version_unq_key")) {
throw new DataValidationException("OtaPackage with such title and version already exists!");
} else {
throw t;
}
checkConstraintViolation(t,
"ota_package_tenant_title_version_unq_key", "OtaPackage with such title and version already exists!",
"ota_package_external_id_unq_key", "OtaPackage with such external id already exists!");
throw t;
}
}