use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveFirmwareInfoWithExistingTitleAndVersion.
@Test
public void testSaveFirmwareInfoWithExistingTitleAndVersion() {
OtaPackageInfo firmwareInfo = new OtaPackageInfo();
firmwareInfo.setTenantId(tenantId);
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(VERSION);
otaPackageService.saveOtaPackageInfo(firmwareInfo, false);
OtaPackageInfo newFirmwareInfo = new OtaPackageInfo();
newFirmwareInfo.setTenantId(tenantId);
newFirmwareInfo.setDeviceProfileId(deviceProfileId);
newFirmwareInfo.setType(FIRMWARE);
newFirmwareInfo.setTitle(TITLE);
newFirmwareInfo.setVersion(VERSION);
thrown.expect(DataValidationException.class);
thrown.expectMessage("OtaPackage with such title and version already exists!");
otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false);
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveOtaPackageUrlCantBeUpdated.
@Test
public void testSaveOtaPackageUrlCantBeUpdated() {
OtaPackageInfo firmwareInfo = new OtaPackageInfo();
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(VERSION);
firmwareInfo.setUrl(URL);
firmwareInfo.setTenantId(tenantId);
OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
thrown.expect(DataValidationException.class);
thrown.expectMessage("Updating otaPackage URL is prohibited!");
savedFirmwareInfo.setUrl("https://newurl.com");
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true);
}
use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveOtaPackageCantViolateSizeOfTitle.
@Test
public void testSaveOtaPackageCantViolateSizeOfTitle() {
OtaPackageInfo firmwareInfo = new OtaPackageInfo();
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(RandomStringUtils.random(257));
firmwareInfo.setVersion(VERSION);
firmwareInfo.setUrl(URL);
firmwareInfo.setTenantId(tenantId);
thrown.expect(ValidationException.class);
thrown.expectMessage("length of title 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 testFindTenantFirmwaresByTenantId.
@Test
public void testFindTenantFirmwaresByTenantId() {
List<OtaPackageInfo> firmwares = new ArrayList<>();
for (int i = 0; i < 165; i++) {
OtaPackageInfo info = new OtaPackageInfo(createFirmware(tenantId, VERSION + i));
info.setHasData(true);
firmwares.add(info);
}
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.findTenantOtaPackagesByTenantId(tenantId, 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 OtaPackageController method saveOtaPackageData.
@ApiOperation(value = "Save OTA Package data (saveOtaPackageData)", notes = "Update the OTA Package. Adds the date to the existing OTA Package Info" + TENANT_AUTHORITY_PARAGRAPH, produces = "application/json")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST)
@ResponseBody
public OtaPackageInfo saveOtaPackageData(@ApiParam(value = OTA_PACKAGE_ID_PARAM_DESCRIPTION) @PathVariable(OTA_PACKAGE_ID) String strOtaPackageId, @ApiParam(value = "OTA Package checksum. For example, '0xd87f7e0c'") @RequestParam(required = false) String checksum, @ApiParam(value = "OTA Package checksum algorithm.", allowableValues = OTA_PACKAGE_CHECKSUM_ALGORITHM_ALLOWABLE_VALUES) @RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr, @ApiParam(value = "OTA Package data.") @RequestBody MultipartFile file) throws ThingsboardException {
checkParameter(OTA_PACKAGE_ID, strOtaPackageId);
checkParameter(CHECKSUM_ALGORITHM, checksumAlgorithmStr);
try {
OtaPackageId otaPackageId = new OtaPackageId(toUUID(strOtaPackageId));
OtaPackageInfo info = checkOtaPackageInfoId(otaPackageId, Operation.READ);
OtaPackage otaPackage = new OtaPackage(otaPackageId);
otaPackage.setCreatedTime(info.getCreatedTime());
otaPackage.setTenantId(getTenantId());
otaPackage.setDeviceProfileId(info.getDeviceProfileId());
otaPackage.setType(info.getType());
otaPackage.setTitle(info.getTitle());
otaPackage.setVersion(info.getVersion());
otaPackage.setTag(info.getTag());
otaPackage.setAdditionalInfo(info.getAdditionalInfo());
ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.valueOf(checksumAlgorithmStr.toUpperCase());
byte[] bytes = file.getBytes();
if (StringUtils.isEmpty(checksum)) {
checksum = otaPackageService.generateChecksum(checksumAlgorithm, ByteBuffer.wrap(bytes));
}
otaPackage.setChecksumAlgorithm(checksumAlgorithm);
otaPackage.setChecksum(checksum);
otaPackage.setFileName(file.getOriginalFilename());
otaPackage.setContentType(file.getContentType());
otaPackage.setData(ByteBuffer.wrap(bytes));
otaPackage.setDataSize((long) bytes.length);
OtaPackageInfo savedOtaPackage = otaPackageService.saveOtaPackage(otaPackage);
logEntityAction(savedOtaPackage.getId(), savedOtaPackage, null, ActionType.UPDATED, null);
return savedOtaPackage;
} catch (Exception e) {
logEntityAction(emptyId(EntityType.OTA_PACKAGE), null, null, ActionType.UPDATED, e, strOtaPackageId);
throw handleException(e);
}
}
Aggregations