Showing
9 changed files
with
92 additions
and
70 deletions
... | ... | @@ -37,6 +37,7 @@ public class OtaPackageInfo extends SearchTextBasedWithAdditionalInfo<OtaPackage |
37 | 37 | private OtaPackageType type; |
38 | 38 | private String title; |
39 | 39 | private String version; |
40 | + private String tag; | |
40 | 41 | private String url; |
41 | 42 | private boolean hasData; |
42 | 43 | private String fileName; | ... | ... |
... | ... | @@ -499,6 +499,7 @@ public class ModelConstants { |
499 | 499 | public static final String OTA_PACKAGE_TYPE_COLUMN = "type"; |
500 | 500 | public static final String OTA_PACKAGE_TILE_COLUMN = TITLE_PROPERTY; |
501 | 501 | public static final String OTA_PACKAGE_VERSION_COLUMN = "version"; |
502 | + public static final String OTA_PACKAGE_TAG_COLUMN = "tag"; | |
502 | 503 | public static final String OTA_PACKAGE_URL_COLUMN = "url"; |
503 | 504 | public static final String OTA_PACKAGE_FILE_NAME_COLUMN = "file_name"; |
504 | 505 | public static final String OTA_PACKAGE_CONTENT_TYPE_COLUMN = "content_type"; | ... | ... |
... | ... | @@ -48,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_S |
48 | 48 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; |
49 | 49 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; |
50 | 50 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; |
51 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TAG_COLUMN; | |
51 | 52 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; |
52 | 53 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; |
53 | 54 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; |
... | ... | @@ -78,6 +79,9 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc |
78 | 79 | @Column(name = OTA_PACKAGE_VERSION_COLUMN) |
79 | 80 | private String version; |
80 | 81 | |
82 | + @Column(name = OTA_PACKAGE_TAG_COLUMN) | |
83 | + private String tag; | |
84 | + | |
81 | 85 | @Column(name = OTA_PACKAGE_URL_COLUMN) |
82 | 86 | private String url; |
83 | 87 | |
... | ... | @@ -112,24 +116,25 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc |
112 | 116 | super(); |
113 | 117 | } |
114 | 118 | |
115 | - public OtaPackageEntity(OtaPackage firmware) { | |
116 | - this.createdTime = firmware.getCreatedTime(); | |
117 | - this.setUuid(firmware.getUuidId()); | |
118 | - this.tenantId = firmware.getTenantId().getId(); | |
119 | - if (firmware.getDeviceProfileId() != null) { | |
120 | - this.deviceProfileId = firmware.getDeviceProfileId().getId(); | |
119 | + public OtaPackageEntity(OtaPackage otaPackage) { | |
120 | + this.createdTime = otaPackage.getCreatedTime(); | |
121 | + this.setUuid(otaPackage.getUuidId()); | |
122 | + this.tenantId = otaPackage.getTenantId().getId(); | |
123 | + if (otaPackage.getDeviceProfileId() != null) { | |
124 | + this.deviceProfileId = otaPackage.getDeviceProfileId().getId(); | |
121 | 125 | } |
122 | - this.type = firmware.getType(); | |
123 | - this.title = firmware.getTitle(); | |
124 | - this.version = firmware.getVersion(); | |
125 | - this.url = firmware.getUrl(); | |
126 | - this.fileName = firmware.getFileName(); | |
127 | - this.contentType = firmware.getContentType(); | |
128 | - this.checksumAlgorithm = firmware.getChecksumAlgorithm(); | |
129 | - this.checksum = firmware.getChecksum(); | |
130 | - this.data = firmware.getData().array(); | |
131 | - this.dataSize = firmware.getDataSize(); | |
132 | - this.additionalInfo = firmware.getAdditionalInfo(); | |
126 | + this.type = otaPackage.getType(); | |
127 | + this.title = otaPackage.getTitle(); | |
128 | + this.version = otaPackage.getVersion(); | |
129 | + this.tag = otaPackage.getTag(); | |
130 | + this.url = otaPackage.getUrl(); | |
131 | + this.fileName = otaPackage.getFileName(); | |
132 | + this.contentType = otaPackage.getContentType(); | |
133 | + this.checksumAlgorithm = otaPackage.getChecksumAlgorithm(); | |
134 | + this.checksum = otaPackage.getChecksum(); | |
135 | + this.data = otaPackage.getData().array(); | |
136 | + this.dataSize = otaPackage.getDataSize(); | |
137 | + this.additionalInfo = otaPackage.getAdditionalInfo(); | |
133 | 138 | } |
134 | 139 | |
135 | 140 | @Override |
... | ... | @@ -144,26 +149,27 @@ public class OtaPackageEntity extends BaseSqlEntity<OtaPackage> implements Searc |
144 | 149 | |
145 | 150 | @Override |
146 | 151 | public OtaPackage toData() { |
147 | - OtaPackage firmware = new OtaPackage(new OtaPackageId(id)); | |
148 | - firmware.setCreatedTime(createdTime); | |
149 | - firmware.setTenantId(new TenantId(tenantId)); | |
152 | + OtaPackage otaPackage = new OtaPackage(new OtaPackageId(id)); | |
153 | + otaPackage.setCreatedTime(createdTime); | |
154 | + otaPackage.setTenantId(new TenantId(tenantId)); | |
150 | 155 | if (deviceProfileId != null) { |
151 | - firmware.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); | |
156 | + otaPackage.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); | |
152 | 157 | } |
153 | - firmware.setType(type); | |
154 | - firmware.setTitle(title); | |
155 | - firmware.setVersion(version); | |
156 | - firmware.setUrl(url); | |
157 | - firmware.setFileName(fileName); | |
158 | - firmware.setContentType(contentType); | |
159 | - firmware.setChecksumAlgorithm(checksumAlgorithm); | |
160 | - firmware.setChecksum(checksum); | |
161 | - firmware.setDataSize(dataSize); | |
158 | + otaPackage.setType(type); | |
159 | + otaPackage.setTitle(title); | |
160 | + otaPackage.setVersion(version); | |
161 | + otaPackage.setTag(tag); | |
162 | + otaPackage.setUrl(url); | |
163 | + otaPackage.setFileName(fileName); | |
164 | + otaPackage.setContentType(contentType); | |
165 | + otaPackage.setChecksumAlgorithm(checksumAlgorithm); | |
166 | + otaPackage.setChecksum(checksum); | |
167 | + otaPackage.setDataSize(dataSize); | |
162 | 168 | if (data != null) { |
163 | - firmware.setData(ByteBuffer.wrap(data)); | |
164 | - firmware.setHasData(true); | |
169 | + otaPackage.setData(ByteBuffer.wrap(data)); | |
170 | + otaPackage.setHasData(true); | |
165 | 171 | } |
166 | - firmware.setAdditionalInfo(additionalInfo); | |
167 | - return firmware; | |
172 | + otaPackage.setAdditionalInfo(additionalInfo); | |
173 | + return otaPackage; | |
168 | 174 | } |
169 | 175 | } | ... | ... |
... | ... | @@ -48,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DATA_S |
48 | 48 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_DEVICE_PROFILE_ID_COLUMN; |
49 | 49 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_FILE_NAME_COLUMN; |
50 | 50 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TABLE_NAME; |
51 | +import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TAG_COLUMN; | |
51 | 52 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TENANT_ID_COLUMN; |
52 | 53 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TILE_COLUMN; |
53 | 54 | import static org.thingsboard.server.dao.model.ModelConstants.OTA_PACKAGE_TYPE_COLUMN; |
... | ... | @@ -78,6 +79,9 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen |
78 | 79 | @Column(name = OTA_PACKAGE_VERSION_COLUMN) |
79 | 80 | private String version; |
80 | 81 | |
82 | + @Column(name = OTA_PACKAGE_TAG_COLUMN) | |
83 | + private String tag; | |
84 | + | |
81 | 85 | @Column(name = OTA_PACKAGE_URL_COLUMN) |
82 | 86 | private String url; |
83 | 87 | |
... | ... | @@ -111,26 +115,27 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen |
111 | 115 | super(); |
112 | 116 | } |
113 | 117 | |
114 | - public OtaPackageInfoEntity(OtaPackageInfo firmware) { | |
115 | - this.createdTime = firmware.getCreatedTime(); | |
116 | - this.setUuid(firmware.getUuidId()); | |
117 | - this.tenantId = firmware.getTenantId().getId(); | |
118 | - this.type = firmware.getType(); | |
119 | - if (firmware.getDeviceProfileId() != null) { | |
120 | - this.deviceProfileId = firmware.getDeviceProfileId().getId(); | |
118 | + public OtaPackageInfoEntity(OtaPackageInfo otaPackageInfo) { | |
119 | + this.createdTime = otaPackageInfo.getCreatedTime(); | |
120 | + this.setUuid(otaPackageInfo.getUuidId()); | |
121 | + this.tenantId = otaPackageInfo.getTenantId().getId(); | |
122 | + this.type = otaPackageInfo.getType(); | |
123 | + if (otaPackageInfo.getDeviceProfileId() != null) { | |
124 | + this.deviceProfileId = otaPackageInfo.getDeviceProfileId().getId(); | |
121 | 125 | } |
122 | - this.title = firmware.getTitle(); | |
123 | - this.version = firmware.getVersion(); | |
124 | - this.url = firmware.getUrl(); | |
125 | - this.fileName = firmware.getFileName(); | |
126 | - this.contentType = firmware.getContentType(); | |
127 | - this.checksumAlgorithm = firmware.getChecksumAlgorithm(); | |
128 | - this.checksum = firmware.getChecksum(); | |
129 | - this.dataSize = firmware.getDataSize(); | |
130 | - this.additionalInfo = firmware.getAdditionalInfo(); | |
126 | + this.title = otaPackageInfo.getTitle(); | |
127 | + this.version = otaPackageInfo.getVersion(); | |
128 | + this.tag = otaPackageInfo.getTag(); | |
129 | + this.url = otaPackageInfo.getUrl(); | |
130 | + this.fileName = otaPackageInfo.getFileName(); | |
131 | + this.contentType = otaPackageInfo.getContentType(); | |
132 | + this.checksumAlgorithm = otaPackageInfo.getChecksumAlgorithm(); | |
133 | + this.checksum = otaPackageInfo.getChecksum(); | |
134 | + this.dataSize = otaPackageInfo.getDataSize(); | |
135 | + this.additionalInfo = otaPackageInfo.getAdditionalInfo(); | |
131 | 136 | } |
132 | 137 | |
133 | - public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, | |
138 | + public OtaPackageInfoEntity(UUID id, long createdTime, UUID tenantId, UUID deviceProfileId, OtaPackageType type, String title, String version, String tag, | |
134 | 139 | String url, String fileName, String contentType, ChecksumAlgorithm checksumAlgorithm, String checksum, Long dataSize, |
135 | 140 | Object additionalInfo, boolean hasData) { |
136 | 141 | this.id = id; |
... | ... | @@ -162,23 +167,24 @@ public class OtaPackageInfoEntity extends BaseSqlEntity<OtaPackageInfo> implemen |
162 | 167 | |
163 | 168 | @Override |
164 | 169 | public OtaPackageInfo toData() { |
165 | - OtaPackageInfo firmware = new OtaPackageInfo(new OtaPackageId(id)); | |
166 | - firmware.setCreatedTime(createdTime); | |
167 | - firmware.setTenantId(new TenantId(tenantId)); | |
170 | + OtaPackageInfo otaPackageInfo = new OtaPackageInfo(new OtaPackageId(id)); | |
171 | + otaPackageInfo.setCreatedTime(createdTime); | |
172 | + otaPackageInfo.setTenantId(new TenantId(tenantId)); | |
168 | 173 | if (deviceProfileId != null) { |
169 | - firmware.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); | |
174 | + otaPackageInfo.setDeviceProfileId(new DeviceProfileId(deviceProfileId)); | |
170 | 175 | } |
171 | - firmware.setType(type); | |
172 | - firmware.setTitle(title); | |
173 | - firmware.setVersion(version); | |
174 | - firmware.setUrl(url); | |
175 | - firmware.setFileName(fileName); | |
176 | - firmware.setContentType(contentType); | |
177 | - firmware.setChecksumAlgorithm(checksumAlgorithm); | |
178 | - firmware.setChecksum(checksum); | |
179 | - firmware.setDataSize(dataSize); | |
180 | - firmware.setAdditionalInfo(additionalInfo); | |
181 | - firmware.setHasData(hasData); | |
182 | - return firmware; | |
176 | + otaPackageInfo.setType(type); | |
177 | + otaPackageInfo.setTitle(title); | |
178 | + otaPackageInfo.setVersion(version); | |
179 | + otaPackageInfo.setTag(tag); | |
180 | + otaPackageInfo.setUrl(url); | |
181 | + otaPackageInfo.setFileName(fileName); | |
182 | + otaPackageInfo.setContentType(contentType); | |
183 | + otaPackageInfo.setChecksumAlgorithm(checksumAlgorithm); | |
184 | + otaPackageInfo.setChecksum(checksum); | |
185 | + otaPackageInfo.setDataSize(dataSize); | |
186 | + otaPackageInfo.setAdditionalInfo(additionalInfo); | |
187 | + otaPackageInfo.setHasData(hasData); | |
188 | + return otaPackageInfo; | |
183 | 189 | } |
184 | 190 | } | ... | ... |
... | ... | @@ -51,6 +51,7 @@ import org.thingsboard.server.dao.tenant.TenantDao; |
51 | 51 | import java.nio.ByteBuffer; |
52 | 52 | import java.util.Collections; |
53 | 53 | import java.util.List; |
54 | +import java.util.Objects; | |
54 | 55 | import java.util.Optional; |
55 | 56 | |
56 | 57 | import static org.thingsboard.server.common.data.CacheConstants.OTA_PACKAGE_CACHE; |
... | ... | @@ -318,6 +319,10 @@ public class BaseOtaPackageService implements OtaPackageService { |
318 | 319 | throw new DataValidationException("Updating otaPackage version is prohibited!"); |
319 | 320 | } |
320 | 321 | |
322 | + if (!Objects.equals(otaPackage.getTag(), otaPackageOld.getTag())) { | |
323 | + throw new DataValidationException("Updating otaPackage tag is prohibited!"); | |
324 | + } | |
325 | + | |
321 | 326 | if (!otaPackageOld.getDeviceProfileId().equals(otaPackage.getDeviceProfileId())) { |
322 | 327 | throw new DataValidationException("Updating otaPackage deviceProfile is prohibited!"); |
323 | 328 | } | ... | ... |
... | ... | @@ -26,14 +26,14 @@ import org.thingsboard.server.dao.model.sql.OtaPackageInfoEntity; |
26 | 26 | import java.util.UUID; |
27 | 27 | |
28 | 28 | public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoEntity, UUID> { |
29 | - @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 " + | |
29 | + @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 " + | |
30 | 30 | "f.tenantId = :tenantId " + |
31 | 31 | "AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
32 | 32 | Page<OtaPackageInfoEntity> findAllByTenantId(@Param("tenantId") UUID tenantId, |
33 | 33 | @Param("searchText") String searchText, |
34 | 34 | Pageable pageable); |
35 | 35 | |
36 | - @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 " + | |
36 | + @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 " + | |
37 | 37 | "f.tenantId = :tenantId " + |
38 | 38 | "AND f.deviceProfileId = :deviceProfileId " + |
39 | 39 | "AND f.type = :type " + |
... | ... | @@ -45,7 +45,7 @@ public interface OtaPackageInfoRepository extends CrudRepository<OtaPackageInfoE |
45 | 45 | @Param("searchText") String searchText, |
46 | 46 | Pageable pageable); |
47 | 47 | |
48 | - @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") | |
48 | + @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") | |
49 | 49 | OtaPackageInfoEntity findOtaPackageInfoById(@Param("id") UUID id); |
50 | 50 | |
51 | 51 | @Query(value = "SELECT exists(SELECT * " + | ... | ... |
... | ... | @@ -173,6 +173,7 @@ CREATE TABLE IF NOT EXISTS ota_package ( |
173 | 173 | type varchar(32) NOT NULL, |
174 | 174 | title varchar(255) NOT NULL, |
175 | 175 | version varchar(255) NOT NULL, |
176 | + tag varchar(255), | |
176 | 177 | url varchar(255), |
177 | 178 | file_name varchar(255), |
178 | 179 | content_type varchar(255), | ... | ... |
... | ... | @@ -188,6 +188,7 @@ CREATE TABLE IF NOT EXISTS ota_package ( |
188 | 188 | type varchar(32) NOT NULL, |
189 | 189 | title varchar(255) NOT NULL, |
190 | 190 | version varchar(255) NOT NULL, |
191 | + tag varchar(255), | |
191 | 192 | url varchar(255), |
192 | 193 | file_name varchar(255), |
193 | 194 | content_type varchar(255), | ... | ... |