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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations