Refactoring
This commit is contained in:
parent
fbb7d5c415
commit
7dc8f10740
@ -52,12 +52,14 @@ public class DeviceProfileImportService extends BaseEntityImportService<DevicePr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DeviceProfile saveOrUpdate(EntitiesImportCtx ctx, DeviceProfile deviceProfile, EntityExportData<DeviceProfile> exportData, IdProvider idProvider, CompareResult compareResult) {
|
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);
|
DeviceProfile saved = deviceProfileService.saveDeviceProfile(deviceProfile);
|
||||||
if (ctx.isFinalImportAttempt() || ctx.getCurrentImportResult().isUpdatedAllExternalIds()) {
|
if (toUpdate) {
|
||||||
importCalculatedFields(ctx, saved, exportData, idProvider);
|
importCalculatedFields(ctx, saved, exportData, idProvider);
|
||||||
saved.setFirmwareId(idProvider.getInternalId(deviceProfile.getFirmwareId()));
|
|
||||||
saved.setSoftwareId(idProvider.getInternalId(deviceProfile.getSoftwareId()));
|
|
||||||
saved = deviceProfileService.saveDeviceProfile(saved);
|
|
||||||
}
|
}
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class OtaPackageId extends UUIDBased implements EntityId {
|
public class OtaPackageId extends UUIDBased implements EntityId {
|
||||||
|
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
|||||||
@ -18,10 +18,13 @@ package org.thingsboard.server.common.data.sync.vc.request.create;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class AutoVersionCreateConfig extends VersionCreateConfig {
|
public class AutoVersionCreateConfig extends VersionCreateConfig {
|
||||||
|
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 8245450889383315551L;
|
private static final long serialVersionUID = 8245450889383315551L;
|
||||||
|
|
||||||
private String branch;
|
private String branch;
|
||||||
|
|||||||
@ -74,7 +74,7 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
|
|||||||
@Override
|
@Override
|
||||||
public OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo, boolean isUrl) {
|
public OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo, boolean isUrl) {
|
||||||
log.trace("Executing saveOtaPackageInfo [{}]", otaPackageInfo);
|
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!");
|
throw new DataValidationException("Ota package URL should be specified!");
|
||||||
}
|
}
|
||||||
otaPackageInfoValidator.validate(otaPackageInfo, OtaPackageInfo::getTenantId);
|
otaPackageInfoValidator.validate(otaPackageInfo, OtaPackageInfo::getTenantId);
|
||||||
@ -91,14 +91,12 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
|
|||||||
if (otaPackageId != null) {
|
if (otaPackageId != null) {
|
||||||
handleEvictEvent(new OtaPackageCacheEvictEvent(otaPackageId));
|
handleEvictEvent(new OtaPackageCacheEvictEvent(otaPackageId));
|
||||||
}
|
}
|
||||||
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
|
checkConstraintViolation(t,
|
||||||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("ota_package_tenant_title_version_unq_key")) {
|
"ota_package_tenant_title_version_unq_key", "OtaPackage with such title and version already exists!",
|
||||||
throw new DataValidationException("OtaPackage with such title and version already exists!");
|
"ota_package_external_id_unq_key", "OtaPackage with such external id already exists!");
|
||||||
} else {
|
|
||||||
throw t;
|
throw t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OtaPackage saveOtaPackage(OtaPackage otaPackage) {
|
public OtaPackage saveOtaPackage(OtaPackage otaPackage) {
|
||||||
@ -117,14 +115,12 @@ public class BaseOtaPackageService extends AbstractCachedEntityService<OtaPackag
|
|||||||
if (otaPackageId != null) {
|
if (otaPackageId != null) {
|
||||||
handleEvictEvent(new OtaPackageCacheEvictEvent(otaPackageId));
|
handleEvictEvent(new OtaPackageCacheEvictEvent(otaPackageId));
|
||||||
}
|
}
|
||||||
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
|
checkConstraintViolation(t,
|
||||||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("ota_package_tenant_title_version_unq_key")) {
|
"ota_package_tenant_title_version_unq_key", "OtaPackage with such title and version already exists!",
|
||||||
throw new DataValidationException("OtaPackage with such title and version already exists!");
|
"ota_package_external_id_unq_key", "OtaPackage with such external id already exists!");
|
||||||
} else {
|
|
||||||
throw t;
|
throw t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data) {
|
public String generateChecksum(ChecksumAlgorithm checksumAlgorithm, ByteBuffer data) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user