use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method testFindDevicesByTenantIdAndIdsAsync.
@Test
public void testFindDevicesByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException {
UUID tenantId1 = UUIDs.timeBased();
UUID customerId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
UUID customerId2 = UUIDs.timeBased();
List<UUID> deviceIds = new ArrayList<>();
for (int i = 0; i < 5; i++) {
UUID deviceId1 = UUIDs.timeBased();
UUID deviceId2 = UUIDs.timeBased();
deviceDao.save(getDevice(tenantId1, customerId1, deviceId1));
deviceDao.save(getDevice(tenantId2, customerId2, deviceId2));
deviceIds.add(deviceId1);
deviceIds.add(deviceId2);
}
ListenableFuture<List<Device>> devicesFuture = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId1, deviceIds);
List<Device> devices = devicesFuture.get();
assertEquals(5, devices.size());
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method testFindDevicesByTenantIdAndCustomerIdAndIdsAsync.
@Test
public void testFindDevicesByTenantIdAndCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException {
UUID tenantId1 = UUIDs.timeBased();
UUID customerId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
UUID customerId2 = UUIDs.timeBased();
List<UUID> deviceIds = new ArrayList<>();
for (int i = 0; i < 20; i++) {
UUID deviceId1 = UUIDs.timeBased();
UUID deviceId2 = UUIDs.timeBased();
deviceDao.save(getDevice(tenantId1, customerId1, deviceId1));
deviceDao.save(getDevice(tenantId2, customerId2, deviceId2));
deviceIds.add(deviceId1);
deviceIds.add(deviceId2);
}
ListenableFuture<List<Device>> devicesFuture = deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId1, customerId1, deviceIds);
List<Device> devices = devicesFuture.get();
assertEquals(20, devices.size());
}
use of org.thingsboard.server.common.data.Device 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;
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method testFindDevicesByTenantId.
@Test
public void testFindDevicesByTenantId() {
UUID tenantId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
UUID customerId1 = UUIDs.timeBased();
UUID customerId2 = UUIDs.timeBased();
createDevices(tenantId1, tenantId2, customerId1, customerId2, 40);
TextPageLink pageLink1 = new TextPageLink(15, "SEARCH_TEXT");
List<Device> devices1 = deviceDao.findDevicesByTenantId(tenantId1, pageLink1);
assertEquals(15, devices1.size());
TextPageLink pageLink2 = new TextPageLink(15, "SEARCH_TEXT", devices1.get(14).getId().getId(), null);
List<Device> devices2 = deviceDao.findDevicesByTenantId(tenantId1, pageLink2);
assertEquals(5, devices2.size());
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class DeviceMessagingRuleMsgHandler method processSendMsg.
private void processSendMsg(PluginContext ctx, PendingRpcRequestMetadata requestMd, ToServerRpcRequestMsg request) {
JsonObject params = new JsonParser().parse(request.getParams()).getAsJsonObject();
String targetDeviceIdStr = params.get(DEVICE_ID).getAsString();
DeviceId targetDeviceId = DeviceId.fromString(targetDeviceIdStr);
boolean oneWay = isOneWay(params);
long timeout = getTimeout(params);
if (timeout <= 0) {
replyWithError(ctx, requestMd, "Timeout can't be negative!");
} else if (timeout > configuration.getMaxTimeout()) {
replyWithError(ctx, requestMd, "Timeout is too large!");
} else {
ctx.getDevice(targetDeviceId, new PluginCallback<Device>() {
@Override
public void onSuccess(PluginContext ctx, Device targetDevice) {
UUID uid = UUID.randomUUID();
if (targetDevice == null) {
replyWithError(ctx, requestMd, RpcError.NOT_FOUND);
} else if (!requestMd.getCustomerId().isNullUid() && requestMd.getTenantId().equals(targetDevice.getTenantId()) && requestMd.getCustomerId().equals(targetDevice.getCustomerId())) {
pendingMsgs.put(uid, requestMd);
log.trace("[{}] Forwarding {} to [{}]", uid, params, targetDeviceId);
ToDeviceRpcRequestBody requestBody = new ToDeviceRpcRequestBody(ON_MSG_METHOD_NAME, GSON.toJson(params.get("body")));
ctx.sendRpcRequest(new ToDeviceRpcRequest(uid, null, targetDevice.getTenantId(), targetDeviceId, oneWay, System.currentTimeMillis() + timeout, requestBody));
} else {
replyWithError(ctx, requestMd, RpcError.FORBIDDEN);
}
}
@Override
public void onFailure(PluginContext ctx, Exception e) {
replyWithError(ctx, requestMd, RpcError.INTERNAL);
}
});
}
}
Aggregations