Search in sources :

Example 36 with Device

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

the class DeviceEntity method toData.

@Override
public Device toData() {
    Device device = new Device(new DeviceId(id));
    device.setCreatedTime(UUIDs.unixTimestamp(id));
    if (tenantId != null) {
        device.setTenantId(new TenantId(tenantId));
    }
    if (customerId != null) {
        device.setCustomerId(new CustomerId(customerId));
    }
    device.setName(name);
    device.setType(type);
    device.setAdditionalInfo(additionalInfo);
    return device;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Device(org.thingsboard.server.common.data.Device) DeviceId(org.thingsboard.server.common.data.id.DeviceId) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Example 37 with Device

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

the class DeviceEntity method toData.

@Override
public Device toData() {
    Device device = new Device(new DeviceId(getId()));
    device.setCreatedTime(UUIDs.unixTimestamp(getId()));
    if (tenantId != null) {
        device.setTenantId(new TenantId(toUUID(tenantId)));
    }
    if (customerId != null) {
        device.setCustomerId(new CustomerId(toUUID(customerId)));
    }
    device.setName(name);
    device.setType(type);
    device.setAdditionalInfo(additionalInfo);
    return device;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Device(org.thingsboard.server.common.data.Device) DeviceId(org.thingsboard.server.common.data.id.DeviceId) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Example 38 with Device

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

the class CassandraDeviceDao method save.

@Override
public Device save(Device domain) {
    Device savedDevice = super.save(domain);
    EntitySubtype entitySubtype = new EntitySubtype(savedDevice.getTenantId(), EntityType.DEVICE, savedDevice.getType());
    EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype);
    Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity);
    executeWrite(saveStatement);
    return savedDevice;
}
Also used : Device(org.thingsboard.server.common.data.Device) EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Statement(com.datastax.driver.core.Statement) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype)

Example 39 with Device

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

the class BaseDeviceCredentialsCacheTest method testSaveDeviceCredentials_EvictsPreviousCache.

@Test
public void testSaveDeviceCredentials_EvictsPreviousCache() throws Exception {
    when(deviceCredentialsDao.findByCredentialsId(CREDENTIALS_ID_1)).thenReturn(createDummyDeviceCredentialsEntity(CREDENTIALS_ID_1));
    deviceCredentialsService.findDeviceCredentialsByCredentialsId(CREDENTIALS_ID_1);
    deviceCredentialsService.findDeviceCredentialsByCredentialsId(CREDENTIALS_ID_1);
    verify(deviceCredentialsDao, times(1)).findByCredentialsId(CREDENTIALS_ID_1);
    when(deviceCredentialsDao.findByDeviceId(deviceId)).thenReturn(createDummyDeviceCredentialsEntity(CREDENTIALS_ID_1));
    UUID deviceCredentialsId = UUID.randomUUID();
    when(deviceCredentialsDao.findById(deviceCredentialsId)).thenReturn(createDummyDeviceCredentialsEntity(CREDENTIALS_ID_1));
    when(deviceService.findDeviceById(new DeviceId(deviceId))).thenReturn(new Device());
    deviceCredentialsService.updateDeviceCredentials(createDummyDeviceCredentials(deviceCredentialsId, CREDENTIALS_ID_2, deviceId));
    when(deviceCredentialsDao.findByCredentialsId(CREDENTIALS_ID_1)).thenReturn(null);
    deviceCredentialsService.findDeviceCredentialsByCredentialsId(CREDENTIALS_ID_1);
    deviceCredentialsService.findDeviceCredentialsByCredentialsId(CREDENTIALS_ID_1);
    verify(deviceCredentialsDao, times(3)).findByCredentialsId(CREDENTIALS_ID_1);
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Device(org.thingsboard.server.common.data.Device) UUID(java.util.UUID) Test(org.junit.Test)

Example 40 with Device

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

the class BaseDeviceCredentialsServiceTest method testFindDeviceCredentialsByDeviceId.

@Test
public void testFindDeviceCredentialsByDeviceId() {
    Device device = new Device();
    device.setTenantId(tenantId);
    device.setName("My device");
    device.setType("default");
    Device savedDevice = deviceService.saveDevice(device);
    DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
    Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    deviceService.deleteDevice(savedDevice.getId());
    deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
    Assert.assertNull(deviceCredentials);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Aggregations

Device (org.thingsboard.server.common.data.Device)53 Test (org.junit.Test)31 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)18 ArrayList (java.util.ArrayList)11 DeviceId (org.thingsboard.server.common.data.id.DeviceId)11 CustomerId (org.thingsboard.server.common.data.id.CustomerId)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Customer (org.thingsboard.server.common.data.Customer)7 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)7 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)7 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)7 TenantId (org.thingsboard.server.common.data.id.TenantId)6 UUID (java.util.UUID)5 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 Tenant (org.thingsboard.server.common.data.Tenant)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 List (java.util.List)2 Before (org.junit.Before)2