use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceServiceImpl method findDevicesByQuery.
@Override
public ListenableFuture<List<Device>> findDevicesByQuery(DeviceSearchQuery query) {
ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(query.toEntitySearchQuery());
ListenableFuture<List<Device>> devices = Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<Device>>) relations1 -> {
EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
List<ListenableFuture<Device>> futures = new ArrayList<>();
for (EntityRelation relation : relations1) {
EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
if (entityId.getEntityType() == EntityType.DEVICE) {
futures.add(findDeviceByIdAsync(new DeviceId(entityId.getId())));
}
}
return Futures.successfulAsList(futures);
});
devices = Futures.transform(devices, new Function<List<Device>, List<Device>>() {
@Nullable
@Override
public List<Device> apply(@Nullable List<Device> deviceList) {
return deviceList == null ? Collections.emptyList() : deviceList.stream().filter(device -> query.getDeviceTypes().contains(device.getType())).collect(Collectors.toList());
}
});
return devices;
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceCredentialsEntity method toData.
@Override
public DeviceCredentials toData() {
DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(getId()));
deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(getId()));
if (deviceId != null) {
deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId)));
}
deviceCredentials.setCredentialsType(credentialsType);
deviceCredentials.setCredentialsId(credentialsId);
deviceCredentials.setCredentialsValue(credentialsValue);
return deviceCredentials;
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceCredentialsEntity method toData.
@Override
public DeviceCredentials toData() {
DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id));
deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id));
if (deviceId != null) {
deviceCredentials.setDeviceId(new DeviceId(deviceId));
}
deviceCredentials.setCredentialsType(credentialsType);
deviceCredentials.setCredentialsId(credentialsId);
deviceCredentials.setCredentialsValue(credentialsValue);
return deviceCredentials;
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseDeviceControllerTest method testSaveDeviceCredentialsWithNonExistentDevice.
@Test
public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception {
Device device = new Device();
device.setName("My device");
device.setType("default");
Device savedDevice = doPost("/api/device", device, Device.class);
DeviceCredentials deviceCredentials = doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
doPost("/api/device/credentials", deviceCredentials).andExpect(status().isNotFound());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method getDevice.
private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) {
Device device = new Device();
device.setId(new DeviceId(deviceId));
device.setTenantId(new TenantId(tenantId));
device.setCustomerId(new CustomerId(customerID));
device.setName("SEARCH_TEXT");
return device;
}
Aggregations