use of org.thingsboard.server.common.data.id.DeviceId 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.id.DeviceId 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.id.DeviceId in project thingsboard by thingsboard.
the class DeviceServiceImpl method saveDevice.
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}")
@Override
public Device saveDevice(Device device) {
log.trace("Executing saveDevice [{}]", device);
deviceValidator.validate(device);
Device savedDevice = deviceDao.save(device);
if (device.getId() == null) {
DeviceCredentials deviceCredentials = new DeviceCredentials();
deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId()));
deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
deviceCredentialsService.createDeviceCredentials(deviceCredentials);
}
return savedDevice;
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseDeviceCredentialsCacheTest method createDummyDeviceCredentials.
private DeviceCredentials createDummyDeviceCredentials(UUID id, String deviceCredentialsId, UUID deviceId) {
DeviceCredentials result = new DeviceCredentials();
result.setId(new DeviceCredentialsId(id));
result.setDeviceId(new DeviceId(deviceId));
result.setCredentialsId(deviceCredentialsId);
result.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
return result;
}
use of org.thingsboard.server.common.data.id.DeviceId 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);
}
Aggregations