use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageService method saveOtaPackage.
@Override
public OtaPackage saveOtaPackage(OtaPackage otaPackage) {
log.trace("Executing saveOtaPackage [{}]", otaPackage);
otaPackageValidator.validate(otaPackage, OtaPackageInfo::getTenantId);
try {
OtaPackageId otaPackageId = otaPackage.getId();
if (otaPackageId != null) {
Cache cache = cacheManager.getCache(OTA_PACKAGE_CACHE);
cache.evict(toOtaPackageInfoKey(otaPackageId));
otaPackageDataCache.evict(otaPackageId.toString());
}
return otaPackageDao.save(otaPackage.getTenantId(), otaPackage);
} catch (Exception t) {
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;
}
}
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class OtaPackageInfoDataValidator method validateUpdate.
@Override
protected void validateUpdate(TenantId tenantId, OtaPackageInfo otaPackage) {
OtaPackageInfo otaPackageOld = otaPackageInfoDao.findById(tenantId, otaPackage.getUuidId());
validateUpdate(otaPackage, otaPackageOld);
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveOtaPackageCantViolateSizeOfVersion.
@Test
public void testSaveOtaPackageCantViolateSizeOfVersion() {
OtaPackageInfo firmwareInfo = new OtaPackageInfo();
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setUrl(URL);
firmwareInfo.setTenantId(tenantId);
firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(RandomStringUtils.random(257));
thrown.expectMessage("length of version must be equal or less than 255");
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveOtaPackageInfoWithBlankAndEmptyUrl.
@Test
public void testSaveOtaPackageInfoWithBlankAndEmptyUrl() {
OtaPackageInfo firmwareInfo = new OtaPackageInfo();
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(VERSION);
firmwareInfo.setUrl(" ");
thrown.expect(DataValidationException.class);
thrown.expectMessage("Ota package URL should be specified!");
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
firmwareInfo.setUrl("");
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveFirmwareWithUrl.
@Test
public void testSaveFirmwareWithUrl() {
OtaPackageInfo firmware = new OtaPackageInfo();
firmware.setTenantId(tenantId);
firmware.setDeviceProfileId(deviceProfileId);
firmware.setType(FIRMWARE);
firmware.setTitle(TITLE);
firmware.setVersion(VERSION);
firmware.setUrl(URL);
firmware.setDataSize(0L);
OtaPackageInfo savedFirmware = otaPackageService.saveOtaPackageInfo(firmware, true);
Assert.assertNotNull(savedFirmware);
Assert.assertNotNull(savedFirmware.getId());
Assert.assertTrue(savedFirmware.getCreatedTime() > 0);
Assert.assertEquals(firmware.getTenantId(), savedFirmware.getTenantId());
Assert.assertEquals(firmware.getTitle(), savedFirmware.getTitle());
Assert.assertEquals(firmware.getFileName(), savedFirmware.getFileName());
Assert.assertEquals(firmware.getContentType(), savedFirmware.getContentType());
savedFirmware.setAdditionalInfo(JacksonUtil.newObjectNode());
otaPackageService.saveOtaPackageInfo(savedFirmware, true);
OtaPackage foundFirmware = otaPackageService.findOtaPackageById(tenantId, savedFirmware.getId());
Assert.assertEquals(foundFirmware.getTitle(), savedFirmware.getTitle());
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
}
Aggregations