Commit 10dda013cbd9b990bc8fd3214f2d5cadc58935a1

Authored by YevhenBondarenko
1 parent 43b4f446

improvements

... ... @@ -285,18 +285,34 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
285 285 List<AttributeKvEntry> attributes = new ArrayList<>();
286 286 attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TITLE), otaPackage.getTitle())));
287 287 attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, VERSION), otaPackage.getVersion())));
288   - if (StringUtils.isEmpty(otaPackage.getUrl())) {
  288 + if (otaPackage.hasUrl()) {
  289 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, URL), otaPackage.getUrl())));
  290 + List<String> attrToRemove = new ArrayList<>();
  291 +
  292 + if (otaPackage.getDataSize() == null) {
  293 + attrToRemove.add(getAttributeKey(otaPackageType, SIZE));
  294 + } else {
  295 + attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(getAttributeKey(otaPackageType, SIZE), otaPackage.getDataSize())));
  296 + }
  297 +
  298 + if (otaPackage.getChecksumAlgorithm() != null) {
  299 + attrToRemove.add(getAttributeKey(otaPackageType, CHECKSUM_ALGORITHM));
  300 + } else {
  301 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, CHECKSUM_ALGORITHM), otaPackage.getChecksumAlgorithm().name())));
  302 + }
  303 +
  304 + if (StringUtils.isEmpty(otaPackage.getChecksum())) {
  305 + attrToRemove.add(getAttributeKey(otaPackageType, CHECKSUM));
  306 + } else {
  307 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, CHECKSUM), otaPackage.getChecksum())));
  308 + }
  309 +
  310 + remove(device, otaPackageType, attrToRemove);
  311 + } else {
289 312 attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(getAttributeKey(otaPackageType, SIZE), otaPackage.getDataSize())));
290 313 attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, CHECKSUM_ALGORITHM), otaPackage.getChecksumAlgorithm().name())));
291 314 attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, CHECKSUM), otaPackage.getChecksum())));
292 315 remove(device, otaPackageType, Collections.singletonList(getAttributeKey(otaPackageType, URL)));
293   - } else {
294   - List<String> attrToRemove = new ArrayList<>();
295   - attrToRemove.add(getAttributeKey(otaPackageType, SIZE));
296   - attrToRemove.add(getAttributeKey(otaPackageType, CHECKSUM_ALGORITHM));
297   - attrToRemove.add(getAttributeKey(otaPackageType, CHECKSUM));
298   - remove(device, otaPackageType, attrToRemove);
299   - attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, URL), otaPackage.getUrl())));
300 316 }
301 317
302 318 telemetryService.saveAndNotify(tenantId, deviceId, DataConstants.SHARED_SCOPE, attributes, new FutureCallback<>() {
... ...
... ... @@ -50,7 +50,7 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
50 50 private static final String FILE_NAME = "filename.txt";
51 51 private static final String VERSION = "v1.0";
52 52 private static final String CONTENT_TYPE = "text/plain";
53   - private static final String CHECKSUM_ALGORITHM = "sha256";
  53 + private static final String CHECKSUM_ALGORITHM = "SHA256";
54 54 private static final String CHECKSUM = "4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a";
55 55 private static final ByteBuffer DATA = ByteBuffer.wrap(new byte[]{1});
56 56
... ... @@ -257,7 +257,7 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
257 257 @Test
258 258 public void testFindTenantFirmwaresByHasData() throws Exception {
259 259 List<OtaPackageInfo> otaPackagesWithData = new ArrayList<>();
260   - List<OtaPackageInfo> otaPackagesWithoutData = new ArrayList<>();
  260 + List<OtaPackageInfo> allOtaPackages = new ArrayList<>();
261 261
262 262 for (int i = 0; i < 165; i++) {
263 263 OtaPackageInfo firmwareInfo = new OtaPackageInfo();
... ... @@ -272,44 +272,45 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
272 272 MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
273 273
274 274 OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
275   - otaPackagesWithData.add(new OtaPackageInfo(savedFirmware));
276   - } else {
277   - otaPackagesWithoutData.add(savedFirmwareInfo);
  275 + savedFirmwareInfo = new OtaPackageInfo(savedFirmware);
  276 + otaPackagesWithData.add(savedFirmwareInfo);
278 277 }
  278 +
  279 + allOtaPackages.add(savedFirmwareInfo);
279 280 }
280 281
281   - List<OtaPackageInfo> loadedFirmwaresWithData = new ArrayList<>();
  282 + List<OtaPackageInfo> loadedOtaPackagesWithData = new ArrayList<>();
282 283 PageLink pageLink = new PageLink(24);
283 284 PageData<OtaPackageInfo> pageData;
284 285 do {
285   - pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE/true?",
  286 + pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE?",
286 287 new TypeReference<>() {
287 288 }, pageLink);
288   - loadedFirmwaresWithData.addAll(pageData.getData());
  289 + loadedOtaPackagesWithData.addAll(pageData.getData());
289 290 if (pageData.hasNext()) {
290 291 pageLink = pageLink.nextPageLink();
291 292 }
292 293 } while (pageData.hasNext());
293 294
294   - List<OtaPackageInfo> loadedFirmwaresWithoutData = new ArrayList<>();
  295 + List<OtaPackageInfo> allLoadedOtaPackages = new ArrayList<>();
295 296 pageLink = new PageLink(24);
296 297 do {
297   - pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE/false?",
  298 + pageData = doGetTypedWithPageLink("/api/otaPackages?",
298 299 new TypeReference<>() {
299 300 }, pageLink);
300   - loadedFirmwaresWithoutData.addAll(pageData.getData());
  301 + allLoadedOtaPackages.addAll(pageData.getData());
301 302 if (pageData.hasNext()) {
302 303 pageLink = pageLink.nextPageLink();
303 304 }
304 305 } while (pageData.hasNext());
305 306
306 307 Collections.sort(otaPackagesWithData, idComparator);
307   - Collections.sort(otaPackagesWithoutData, idComparator);
308   - Collections.sort(loadedFirmwaresWithData, idComparator);
309   - Collections.sort(loadedFirmwaresWithoutData, idComparator);
  308 + Collections.sort(allOtaPackages, idComparator);
  309 + Collections.sort(loadedOtaPackagesWithData, idComparator);
  310 + Collections.sort(allLoadedOtaPackages, idComparator);
310 311
311   - Assert.assertEquals(otaPackagesWithData, loadedFirmwaresWithData);
312   - Assert.assertEquals(otaPackagesWithoutData, loadedFirmwaresWithoutData);
  312 + Assert.assertEquals(otaPackagesWithData, loadedOtaPackagesWithData);
  313 + Assert.assertEquals(allOtaPackages, allLoadedOtaPackages);
313 314 }
314 315
315 316
... ...
... ... @@ -253,7 +253,7 @@ public class BaseOtaPackageService implements OtaPackageService {
253 253 protected void validateDataImpl(TenantId tenantId, OtaPackage otaPackage) {
254 254 validateImpl(otaPackage);
255 255
256   - if (StringUtils.isEmpty(otaPackage.getUrl())) {
  256 + if (!otaPackage.hasUrl()) {
257 257 if (StringUtils.isEmpty(otaPackage.getFileName())) {
258 258 throw new DataValidationException("OtaPackage file name should be specified!");
259 259 }
... ...
... ... @@ -24,10 +24,10 @@ import java.util.Arrays;
24 24
25 25 @RunWith(ClasspathSuite.class)
26 26 @ClassnameFilters({
27   - "org.thingsboard.server.dao.service.sql.OtaPackageServiceSqlTest",
28   -// "org.thingsboard.server.dao.service.attributes.sql.*SqlTest",
29   -// "org.thingsboard.server.dao.service.event.sql.*SqlTest",
30   -// "org.thingsboard.server.dao.service.timeseries.sql.*SqlTest"
  27 + "org.thingsboard.server.dao.service.sql.*SqlTest",
  28 + "org.thingsboard.server.dao.service.attributes.sql.*SqlTest",
  29 + "org.thingsboard.server.dao.service.event.sql.*SqlTest",
  30 + "org.thingsboard.server.dao.service.timeseries.sql.*SqlTest"
31 31
32 32 })
33 33 public class SqlDaoServiceTestSuite {
... ...