use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageControllerTest method testFindTenantFirmwaresByHasData.
@Test
public void testFindTenantFirmwaresByHasData() throws Exception {
List<OtaPackageInfo> otaPackagesWithData = new ArrayList<>();
List<OtaPackageInfo> allOtaPackages = new ArrayList<>();
for (int i = 0; i < 165; i++) {
SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(VERSION + i);
firmwareInfo.setUsesUrl(false);
OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
if (i > 100) {
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
OtaPackageInfo savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
savedFirmwareInfo = new OtaPackageInfo(savedFirmware);
otaPackagesWithData.add(savedFirmwareInfo);
}
allOtaPackages.add(savedFirmwareInfo);
}
List<OtaPackageInfo> loadedOtaPackagesWithData = new ArrayList<>();
PageLink pageLink = new PageLink(24);
PageData<OtaPackageInfo> pageData;
do {
pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE?", new TypeReference<>() {
}, pageLink);
loadedOtaPackagesWithData.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
List<OtaPackageInfo> allLoadedOtaPackages = new ArrayList<>();
pageLink = new PageLink(24);
do {
pageData = doGetTypedWithPageLink("/api/otaPackages?", new TypeReference<>() {
}, pageLink);
allLoadedOtaPackages.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(otaPackagesWithData, idComparator);
Collections.sort(allOtaPackages, idComparator);
Collections.sort(loadedOtaPackagesWithData, idComparator);
Collections.sort(allLoadedOtaPackages, idComparator);
Assert.assertEquals(otaPackagesWithData, loadedOtaPackagesWithData);
Assert.assertEquals(allOtaPackages, allLoadedOtaPackages);
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class OtaPackageInfoEntity method toData.
@Override
public OtaPackageInfo toData() {
OtaPackageInfo otaPackageInfo = new OtaPackageInfo(new OtaPackageId(id));
otaPackageInfo.setCreatedTime(createdTime);
otaPackageInfo.setTenantId(TenantId.fromUUID(tenantId));
if (deviceProfileId != null) {
otaPackageInfo.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
}
otaPackageInfo.setType(type);
otaPackageInfo.setTitle(title);
otaPackageInfo.setVersion(version);
otaPackageInfo.setTag(tag);
otaPackageInfo.setUrl(url);
otaPackageInfo.setFileName(fileName);
otaPackageInfo.setContentType(contentType);
otaPackageInfo.setChecksumAlgorithm(checksumAlgorithm);
otaPackageInfo.setChecksum(checksum);
otaPackageInfo.setDataSize(dataSize);
otaPackageInfo.setAdditionalInfo(additionalInfo);
otaPackageInfo.setHasData(hasData);
return otaPackageInfo;
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageService method saveOtaPackageInfo.
@Override
public OtaPackageInfo saveOtaPackageInfo(OtaPackageInfo otaPackageInfo, boolean isUrl) {
log.trace("Executing saveOtaPackageInfo [{}]", otaPackageInfo);
if (isUrl && (StringUtils.isEmpty(otaPackageInfo.getUrl()) || otaPackageInfo.getUrl().trim().length() == 0)) {
throw new DataValidationException("Ota package URL should be specified!");
}
otaPackageInfoValidator.validate(otaPackageInfo, OtaPackageInfo::getTenantId);
try {
OtaPackageId otaPackageId = otaPackageInfo.getId();
if (otaPackageId != null) {
Cache cache = cacheManager.getCache(OTA_PACKAGE_CACHE);
cache.evict(toOtaPackageInfoKey(otaPackageId));
otaPackageDataCache.evict(otaPackageId.toString());
}
return otaPackageInfoDao.save(otaPackageInfo.getTenantId(), otaPackageInfo);
} 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 BaseOtaPackageServiceTest method testFindTenantFirmwaresByTenantIdAndHasData.
@Test
public void testFindTenantFirmwaresByTenantIdAndHasData() {
List<OtaPackageInfo> firmwares = new ArrayList<>();
for (int i = 0; i < 165; i++) {
firmwares.add(new OtaPackageInfo(otaPackageService.saveOtaPackage(createFirmware(tenantId, VERSION + i))));
}
OtaPackageInfo firmwareWithUrl = new OtaPackageInfo();
firmwareWithUrl.setTenantId(tenantId);
firmwareWithUrl.setDeviceProfileId(deviceProfileId);
firmwareWithUrl.setType(FIRMWARE);
firmwareWithUrl.setTitle(TITLE);
firmwareWithUrl.setVersion(VERSION);
firmwareWithUrl.setUrl(URL);
firmwareWithUrl.setDataSize(0L);
OtaPackageInfo savedFwWithUrl = otaPackageService.saveOtaPackageInfo(firmwareWithUrl, true);
savedFwWithUrl.setHasData(true);
firmwares.add(savedFwWithUrl);
List<OtaPackageInfo> loadedFirmwares = new ArrayList<>();
PageLink pageLink = new PageLink(16);
PageData<OtaPackageInfo> pageData;
do {
pageData = otaPackageService.findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(tenantId, deviceProfileId, FIRMWARE, pageLink);
loadedFirmwares.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
loadedFirmwares = new ArrayList<>();
pageLink = new PageLink(16);
do {
pageData = otaPackageService.findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(tenantId, deviceProfileId, FIRMWARE, pageLink);
loadedFirmwares.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(firmwares, idComparator);
Collections.sort(loadedFirmwares, idComparator);
assertThat(firmwares).isEqualTo(loadedFirmwares);
otaPackageService.deleteOtaPackagesByTenantId(tenantId);
pageLink = new PageLink(31);
pageData = otaPackageService.findTenantOtaPackagesByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testFindFirmwareInfoById.
@Test
public void testFindFirmwareInfoById() {
OtaPackageInfo firmware = new OtaPackageInfo();
firmware.setTenantId(tenantId);
firmware.setDeviceProfileId(deviceProfileId);
firmware.setType(FIRMWARE);
firmware.setTitle(TITLE);
firmware.setVersion(VERSION);
OtaPackageInfo savedFirmware = otaPackageService.saveOtaPackageInfo(firmware, false);
OtaPackageInfo foundFirmware = otaPackageService.findOtaPackageInfoById(tenantId, savedFirmware.getId());
Assert.assertNotNull(foundFirmware);
Assert.assertEquals(savedFirmware, foundFirmware);
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
}
Aggregations