Search in sources :

Example 1 with OtaPackage

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());
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) OtaPackage(org.thingsboard.server.common.data.OtaPackage) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 2 with OtaPackage

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;
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) OtaPackage(org.thingsboard.server.common.data.OtaPackage) OtaPackageId(org.thingsboard.server.common.data.id.OtaPackageId)

Example 3 with 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);
    }
}
Also used : OtaPackage(org.thingsboard.server.common.data.OtaPackage) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with OtaPackage

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());
    }
}
Also used : OtaPackage(org.thingsboard.server.common.data.OtaPackage) Test(org.junit.Test)

Example 5 with OtaPackage

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);
}
Also used : OtaPackage(org.thingsboard.server.common.data.OtaPackage) Test(org.junit.Test)

Aggregations

OtaPackage (org.thingsboard.server.common.data.OtaPackage)29 Test (org.junit.Test)21 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)5 OtaPackageInfo (org.thingsboard.server.common.data.OtaPackageInfo)5 Device (org.thingsboard.server.common.data.Device)4 OtaPackageId (org.thingsboard.server.common.data.id.OtaPackageId)4 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)3 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 MessagingException (javax.mail.MessagingException)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1 DashboardInfo (org.thingsboard.server.common.data.DashboardInfo)1