Search in sources :

Example 46 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileServiceTest method testFindDeviceProfileInfoById.

@Test
public void testFindDeviceProfileInfoById() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    DeviceProfileInfo foundDeviceProfileInfo = deviceProfileService.findDeviceProfileInfoById(tenantId, savedDeviceProfile.getId());
    Assert.assertNotNull(foundDeviceProfileInfo);
    Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
    Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
    Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Example 47 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileServiceTest method testFindDefaultDeviceProfile.

@Test
public void testFindDefaultDeviceProfile() {
    DeviceProfile foundDefaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId);
    Assert.assertNotNull(foundDefaultDeviceProfile);
    Assert.assertNotNull(foundDefaultDeviceProfile.getId());
    Assert.assertNotNull(foundDefaultDeviceProfile.getName());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

Example 48 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileServiceTest method testDeleteDeviceProfileWithExistingDevice.

@Test(expected = DataValidationException.class)
public void testDeleteDeviceProfileWithExistingDevice() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    Device device = new Device();
    device.setTenantId(tenantId);
    device.setName("Test device");
    device.setType("default");
    device.setDeviceProfileId(savedDeviceProfile.getId());
    deviceService.saveDevice(device);
    deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Device(org.thingsboard.server.common.data.Device) Test(org.junit.Test)

Example 49 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileServiceTest method testSetDefaultDeviceProfile.

@Test
public void testSetDefaultDeviceProfile() {
    DeviceProfile deviceProfile1 = this.createDeviceProfile(tenantId, "Device Profile 1");
    DeviceProfile deviceProfile2 = this.createDeviceProfile(tenantId, "Device Profile 2");
    DeviceProfile savedDeviceProfile1 = deviceProfileService.saveDeviceProfile(deviceProfile1);
    DeviceProfile savedDeviceProfile2 = deviceProfileService.saveDeviceProfile(deviceProfile2);
    boolean result = deviceProfileService.setDefaultDeviceProfile(tenantId, savedDeviceProfile1.getId());
    Assert.assertTrue(result);
    DeviceProfile defaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId);
    Assert.assertNotNull(defaultDeviceProfile);
    Assert.assertEquals(savedDeviceProfile1.getId(), defaultDeviceProfile.getId());
    result = deviceProfileService.setDefaultDeviceProfile(tenantId, savedDeviceProfile2.getId());
    Assert.assertTrue(result);
    defaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId);
    Assert.assertNotNull(defaultDeviceProfile);
    Assert.assertEquals(savedDeviceProfile2.getId(), defaultDeviceProfile.getId());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

Example 50 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DeviceProfileController method setDefaultDeviceProfile.

@ApiOperation(value = "Make Device Profile Default (setDefaultDeviceProfile)", notes = "Marks device profile as default within a tenant scope." + TENANT_AUTHORITY_PARAGRAPH, produces = "application/json")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/deviceProfile/{deviceProfileId}/default", method = RequestMethod.POST)
@ResponseBody
public DeviceProfile setDefaultDeviceProfile(@ApiParam(value = DEVICE_PROFILE_ID_PARAM_DESCRIPTION) @PathVariable(DEVICE_PROFILE_ID) String strDeviceProfileId) throws ThingsboardException {
    checkParameter(DEVICE_PROFILE_ID, strDeviceProfileId);
    try {
        DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(strDeviceProfileId));
        DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.WRITE);
        DeviceProfile previousDefaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(getTenantId());
        if (deviceProfileService.setDefaultDeviceProfile(getTenantId(), deviceProfileId)) {
            if (previousDefaultDeviceProfile != null) {
                previousDefaultDeviceProfile = deviceProfileService.findDeviceProfileById(getTenantId(), previousDefaultDeviceProfile.getId());
                logEntityAction(previousDefaultDeviceProfile.getId(), previousDefaultDeviceProfile, null, ActionType.UPDATED, null);
            }
            deviceProfile = deviceProfileService.findDeviceProfileById(getTenantId(), deviceProfileId);
            logEntityAction(deviceProfile.getId(), deviceProfile, null, ActionType.UPDATED, null);
        }
        return deviceProfile;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DEVICE_PROFILE), null, null, ActionType.UPDATED, e, strDeviceProfileId);
        throw handleException(e);
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)110 Test (org.junit.Test)48 Device (org.thingsboard.server.common.data.Device)30 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)26 List (java.util.List)20 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)19 TbMsg (org.thingsboard.server.common.msg.TbMsg)19 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)18 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)18 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)17 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)17 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)16 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)16 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)16 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)14 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)13 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13 AttributeKvEntity (org.thingsboard.server.dao.model.sql.AttributeKvEntity)13 UUID (java.util.UUID)12