added tag for OtaPackage

This commit is contained in:
YevhenBondarenko 2021-07-22 17:44:45 +03:00
parent afc2959633
commit 2af3be7827
9 changed files with 92 additions and 70 deletions

View File

@ -67,6 +67,7 @@ CREATE TABLE IF NOT EXISTS ota_package (
type varchar(32) NOT NULL, type varchar(32) NOT NULL,
title varchar(255) NOT NULL, title varchar(255) NOT NULL,
version varchar(255) NOT NULL, version varchar(255) NOT NULL,
tag varchar(255),
url varchar(255), url varchar(255),
file_name varchar(255), file_name varchar(255),
content_type varchar(255), content_type varchar(255),

View File

@ -37,6 +37,7 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage
private OtaPackageType type; private OtaPackageType type;
private String title; private String title;
private String version; private String version;
private String tag;
private String url; private String url;
private boolean hasData; private boolean hasData;
private String fileName; private String fileName;

View File

@ -499,6 +499,7 @@ public class ModelConstants {
public static final String OTA_PACKAGE_TYPE_COLUMN = "type"; public static final String OTA_PACKAGE_TYPE_COLUMN = "type";
public static final String OTA_PACKAGE_TILE_COLUMN = TITLE_PROPERTY; public static final String OTA_PACKAGE_TILE_COLUMN = TITLE_PROPERTY;
public static final String OTA_PACKAGE_VERSION_COLUMN = "version"; public static final String OTA_PACKAGE_VERSION_COLUMN = "version";
public static final String OTA_PACKAGE_TAG_COLUMN = "tag";
public static final String OTA_PACKAGE_URL_COLUMN = "url"; public static final String OTA_PACKAGE_URL_COLUMN = "url";
public static final String OTA_PACKAGE_FILE_NAME_COLUMN = "file_name"; public static final String OTA_PACKAGE_FILE_NAME_COLUMN = "file_name";
public static final String OTA_PACKAGE_CONTENT_TYPE_COLUMN = "content_type"; public static final String OTA_PACKAGE_CONTENT_TYPE_COLUMN = "content_type";

View File

@ -48,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_S
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TAG_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN;
@ -78,6 +79,9 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc
@Column(name = OTA_PACKAGE_VERSION_COLUMN) @Column(name = OTA_PACKAGE_VERSION_COLUMN)
private String version; private String version;
@Column(name = OTA_PACKAGE_TAG_COLUMN)
private String tag;
@Column(name = OTA_PACKAGE_URL_COLUMN) @Column(name = OTA_PACKAGE_URL_COLUMN)
private String url; private String url;
@ -112,24 +116,25 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc
super(); super();
} }
public OtaPackageEntity(OtaPackage firmware) { public OtaPackageEntity(OtaPackage otaPackage) {
this.createdTime = firmware.getCreatedTime(); this.createdTime = otaPackage.getCreatedTime();
this.setUuid(firmware.getUuidId()); this.setUuid(otaPackage.getUuidId());
this.tenantId = firmware.getTenantId().getId(); this.tenantId = otaPackage.getTenantId().getId();
if (firmware.getDeviceProfileId() != null) { if (otaPackage.getDeviceProfileId() != null) {
this.deviceProfileId = firmware.getDeviceProfileId().getId(); this.deviceProfileId = otaPackage.getDeviceProfileId().getId();
} }
this.type = firmware.getType(); this.type = otaPackage.getType();
this.title = firmware.getTitle(); this.title = otaPackage.getTitle();
this.version = firmware.getVersion(); this.version = otaPackage.getVersion();
this.url = firmware.getUrl(); this.tag = otaPackage.getTag();
this.fileName = firmware.getFileName(); this.url = otaPackage.getUrl();
this.contentType = firmware.getContentType(); this.fileName = otaPackage.getFileName();
this.checksumAlgorithm = firmware.getChecksumAlgorithm(); this.contentType = otaPackage.getContentType();
this.checksum = firmware.getChecksum(); this.checksumAlgorithm = otaPackage.getChecksumAlgorithm();
this.data = firmware.getData().array(); this.checksum = otaPackage.getChecksum();
this.dataSize = firmware.getDataSize(); this.data = otaPackage.getData().array();
this.additionalInfo = firmware.getAdditionalInfo(); this.dataSize = otaPackage.getDataSize();
this.additionalInfo = otaPackage.getAdditionalInfo();
} }
@Override @Override
@ -144,26 +149,27 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc
@Override @Override
public OtaPackage toData() { public OtaPackage toData() {
OtaPackage firmware = new OtaPackage(new OtaPackageId(id)); OtaPackage otaPackage = new OtaPackage(new OtaPackageId(id));
firmware.setCreatedTime(createdTime); otaPackage.setCreatedTime(createdTime);
firmware.setTenantId(new TenantId(tenantId)); otaPackage.setTenantId(new TenantId(tenantId));
if (deviceProfileId != null) { if (deviceProfileId != null) {
firmware.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); otaPackage.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
} }
firmware.setType(type); otaPackage.setType(type);
firmware.setTitle(title); otaPackage.setTitle(title);
firmware.setVersion(version); otaPackage.setVersion(version);
firmware.setUrl(url); otaPackage.setTag(tag);
firmware.setFileName(fileName); otaPackage.setUrl(url);
firmware.setContentType(contentType); otaPackage.setFileName(fileName);
firmware.setChecksumAlgorithm(checksumAlgorithm); otaPackage.setContentType(contentType);
firmware.setChecksum(checksum); otaPackage.setChecksumAlgorithm(checksumAlgorithm);
firmware.setDataSize(dataSize); otaPackage.setChecksum(checksum);
otaPackage.setDataSize(dataSize);
if (data != null) { if (data != null) {
firmware.setData(ByteBuffer.wrap(data)); otaPackage.setData(ByteBuffer.wrap(data));
firmware.setHasData(true); otaPackage.setHasData(true);
} }
firmware.setAdditionalInfo(additionalInfo); otaPackage.setAdditionalInfo(additionalInfo);
return firmware; return otaPackage;
} }
} }

View File

@ -48,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_S
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TAG_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN;
import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN;
@ -78,6 +79,9 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
@Column(name = OTA_PACKAGE_VERSION_COLUMN) @Column(name = OTA_PACKAGE_VERSION_COLUMN)
private String version; private String version;
@Column(name = OTA_PACKAGE_TAG_COLUMN)
private String tag;
@Column(name = OTA_PACKAGE_URL_COLUMN) @Column(name = OTA_PACKAGE_URL_COLUMN)
private String url; private String url;
@ -111,26 +115,27 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
super(); super();
} }
public OtaPackageInfoEntity(OtaPackageInfo firmware) { public OtaPackageInfoEntity(OtaPackageInfo otaPackageInfo) {
this.createdTime = firmware.getCreatedTime(); this.createdTime = otaPackageInfo.getCreatedTime();
this.setUuid(firmware.getUuidId()); this.setUuid(otaPackageInfo.getUuidId());
this.tenantId = firmware.getTenantId().getId(); this.tenantId = otaPackageInfo.getTenantId().getId();
this.type = firmware.getType(); this.type = otaPackageInfo.getType();
if (firmware.getDeviceProfileId() != null) { if (otaPackageInfo.getDeviceProfileId() != null) {
this.deviceProfileId = firmware.getDeviceProfileId().getId(); this.deviceProfileId = otaPackageInfo.getDeviceProfileId().getId();
} }
this.title = firmware.getTitle(); this.title = otaPackageInfo.getTitle();
this.version = firmware.getVersion(); this.version = otaPackageInfo.getVersion();
this.url = firmware.getUrl(); this.tag = otaPackageInfo.getTag();
this.fileName = firmware.getFileName(); this.url = otaPackageInfo.getUrl();
this.contentType = firmware.getContentType(); this.fileName = otaPackageInfo.getFileName();
this.checksumAlgorithm = firmware.getChecksumAlgorithm(); this.contentType = otaPackageInfo.getContentType();
this.checksum = firmware.getChecksum(); this.checksumAlgorithm = otaPackageInfo.getChecksumAlgorithm();
this.dataSize = firmware.getDataSize(); this.checksum = otaPackageInfo.getChecksum();
this.additionalInfo = firmware.getAdditionalInfo(); this.dataSize = otaPackageInfo.getDataSize();
this.additionalInfo = otaPackageInfo.getAdditionalInfo();
} }
public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, String tag,
String url, String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize, String url, String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize,
Object additionalInfo, boolean hasData) { Object additionalInfo, boolean hasData) {
this.id = id; this.id = id;
@ -162,23 +167,24 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen
@Override @Override
public OtaPackageInfo toData() { public OtaPackageInfo toData() {
OtaPackageInfo firmware = new OtaPackageInfo(new OtaPackageId(id)); OtaPackageInfo otaPackageInfo = new OtaPackageInfo(new OtaPackageId(id));
firmware.setCreatedTime(createdTime); otaPackageInfo.setCreatedTime(createdTime);
firmware.setTenantId(new TenantId(tenantId)); otaPackageInfo.setTenantId(new TenantId(tenantId));
if (deviceProfileId != null) { if (deviceProfileId != null) {
firmware.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); otaPackageInfo.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
} }
firmware.setType(type); otaPackageInfo.setType(type);
firmware.setTitle(title); otaPackageInfo.setTitle(title);
firmware.setVersion(version); otaPackageInfo.setVersion(version);
firmware.setUrl(url); otaPackageInfo.setTag(tag);
firmware.setFileName(fileName); otaPackageInfo.setUrl(url);
firmware.setContentType(contentType); otaPackageInfo.setFileName(fileName);
firmware.setChecksumAlgorithm(checksumAlgorithm); otaPackageInfo.setContentType(contentType);
firmware.setChecksum(checksum); otaPackageInfo.setChecksumAlgorithm(checksumAlgorithm);
firmware.setDataSize(dataSize); otaPackageInfo.setChecksum(checksum);
firmware.setAdditionalInfo(additionalInfo); otaPackageInfo.setDataSize(dataSize);
firmware.setHasData(hasData); otaPackageInfo.setAdditionalInfo(additionalInfo);
return firmware; otaPackageInfo.setHasData(hasData);
return otaPackageInfo;
} }
} }

View File

@ -51,6 +51,7 @@ import org.thingsboard.server.dao.tenant.TenantDao;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE; import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE;
@ -318,6 +319,10 @@ public class BaseOtaPackageService implements OtaPackageService {
throw new DataValidationException("Updating otaPackage version is prohibited!"); throw new DataValidationException("Updating otaPackage version is prohibited!");
} }
if (!Objects.equals(otaPackage.getTag(), otaPackageOld.getTag())) {
throw new DataValidationException("Updating otaPackage tag is prohibited!");
}
if (!otaPackageOld.getDeviceProfileId().equals(otaPackage.getDeviceProfileId())) { if (!otaPackageOld.getDeviceProfileId().equals(otaPackage.getDeviceProfileId())) {
throw new DataValidationException("Updating otaPackage deviceProfile is prohibited!"); throw new DataValidationException("Updating otaPackage deviceProfile is prohibited!");
} }

View File

@ -26,14 +26,14 @@ import org.thingsboard.server.dao.model.sql.OtaPackageInfoEntity;
import java.util.UUID; import java.util.UUID;
public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoEntity, UUID> { public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoEntity, UUID> {
@Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE " + @Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.tag, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE " +
"f.tenantId = :tenantId " + "f.tenantId = :tenantId " +
"AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") "AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
Page<OtaPackageInfoEntity> findAllByTenantId(@Param("tenantId") UUID tenantId, Page<OtaPackageInfoEntity> findAllByTenantId(@Param("tenantId") UUID tenantId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, true) FROM OtaPackageEntity f WHERE " + @Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.tag, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, true) FROM OtaPackageEntity f WHERE " +
"f.tenantId = :tenantId " + "f.tenantId = :tenantId " +
"AND f.deviceProfileId = :deviceProfileId " + "AND f.deviceProfileId = :deviceProfileId " +
"AND f.type = :type " + "AND f.type = :type " +
@ -45,7 +45,7 @@ public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoE
@Param("searchText") String searchText, @Param("searchText") String searchText,
Pageable pageable); Pageable pageable);
@Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE f.id = :id") @Query("SELECT new OtaPackageInfoEntity(f.id, f.createdTime, f.tenantId, f.deviceProfileId, f.type, f.title, f.version, f.tag, f.url, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, CASE WHEN (f.data IS NOT NULL OR f.url IS NOT NULL) THEN true ELSE false END) FROM OtaPackageEntity f WHERE f.id = :id")
OtaPackageInfoEntity findOtaPackageInfoById(@Param("id") UUID id); OtaPackageInfoEntity findOtaPackageInfoById(@Param("id") UUID id);
@Query(value = "SELECT exists(SELECT * " + @Query(value = "SELECT exists(SELECT * " +

View File

@ -173,6 +173,7 @@ CREATE TABLE IF NOT EXISTS ota_package (
type varchar(32) NOT NULL, type varchar(32) NOT NULL,
title varchar(255) NOT NULL, title varchar(255) NOT NULL,
version varchar(255) NOT NULL, version varchar(255) NOT NULL,
tag varchar(255),
url varchar(255), url varchar(255),
file_name varchar(255), file_name varchar(255),
content_type varchar(255), content_type varchar(255),

View File

@ -188,6 +188,7 @@ CREATE TABLE IF NOT EXISTS ota_package (
type varchar(32) NOT NULL, type varchar(32) NOT NULL,
title varchar(255) NOT NULL, title varchar(255) NOT NULL,
version varchar(255) NOT NULL, version varchar(255) NOT NULL,
tag varchar(255),
url varchar(255), url varchar(255),
file_name varchar(255), file_name varchar(255),
content_type varchar(255), content_type varchar(255),