use of org.thingsboard.server.common.data.OtaPackage in project thingsboard by thingsboard.
the class BaseOtaPackageControllerTest method testFindFirmwareById.
@Test
public void testFindFirmwareById() throws Exception {
SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
firmwareInfo.setDeviceProfileId(deviceProfileId);
firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(VERSION);
firmwareInfo.setUsesUrl(false);
OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
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);
OtaPackage foundFirmware = doGet("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString(), OtaPackage.class);
Assert.assertNotNull(foundFirmware);
Assert.assertEquals(savedFirmware, new OtaPackageInfo(foundFirmware));
Assert.assertEquals(DATA, foundFirmware.getData());
}
use of org.thingsboard.server.common.data.OtaPackage in project thingsboard by thingsboard.
the class OtaPackageEntity method toData.
@Override
public OtaPackage toData() {
OtaPackage otaPackage = new OtaPackage(new OtaPackageId(id));
otaPackage.setCreatedTime(createdTime);
otaPackage.setTenantId(TenantId.fromUUID(tenantId));
if (deviceProfileId != null) {
otaPackage.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
}
otaPackage.setType(type);
otaPackage.setTitle(title);
otaPackage.setVersion(version);
otaPackage.setTag(tag);
otaPackage.setUrl(url);
otaPackage.setFileName(fileName);
otaPackage.setContentType(contentType);
otaPackage.setChecksumAlgorithm(checksumAlgorithm);
otaPackage.setChecksum(checksum);
otaPackage.setDataSize(dataSize);
if (data != null) {
otaPackage.setData(ByteBuffer.wrap(data));
otaPackage.setHasData(true);
}
otaPackage.setAdditionalInfo(additionalInfo);
return otaPackage;
}
use of org.thingsboard.server.common.data.OtaPackage in project thingsboard by thingsboard.
the class BaseController method checkOtaPackageId.
OtaPackage checkOtaPackageId(OtaPackageId otaPackageId, Operation operation) throws ThingsboardException {
try {
validateId(otaPackageId, "Incorrect otaPackageId " + otaPackageId);
OtaPackage otaPackage = otaPackageService.findOtaPackageById(getCurrentUser().getTenantId(), otaPackageId);
checkNotNull(otaPackage, "OTA package with id [" + otaPackageId + "] is not found");
accessControlService.checkPermission(getCurrentUser(), Resource.OTA_PACKAGE, operation, otaPackageId, otaPackage);
return otaPackage;
} catch (Exception e) {
throw handleException(e, false);
}
}
use of org.thingsboard.server.common.data.OtaPackage in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testUpdateDeviceProfileId.
@Test
public void testUpdateDeviceProfileId() {
OtaPackage savedFirmware = createFirmware(tenantId, VERSION);
try {
thrown.expect(DataValidationException.class);
thrown.expectMessage("Updating otaPackage deviceProfile is prohibited!");
savedFirmware.setDeviceProfileId(null);
otaPackageService.saveOtaPackage(savedFirmware);
} finally {
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
}
}
use of org.thingsboard.server.common.data.OtaPackage in project thingsboard by thingsboard.
the class BaseOtaPackageServiceTest method testSaveFirmwareWithEmptyFileName.
@Test
public void testSaveFirmwareWithEmptyFileName() {
OtaPackage firmware = new OtaPackage();
firmware.setTenantId(tenantId);
firmware.setDeviceProfileId(deviceProfileId);
firmware.setType(FIRMWARE);
firmware.setTitle(TITLE);
firmware.setVersion(VERSION);
firmware.setContentType(CONTENT_TYPE);
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM);
firmware.setChecksum(CHECKSUM);
firmware.setData(DATA);
thrown.expect(DataValidationException.class);
thrown.expectMessage("OtaPackage file name should be specified!");
otaPackageService.saveOtaPackage(firmware);
}
Aggregations