use of org.thingsboard.server.common.data.EntitySubtype in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDeviceTypesByTenantId.
@Test
public void testFindDeviceTypesByTenantId() throws Exception {
List<Device> devices = new ArrayList<>();
try {
for (int i = 0; i < 3; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("My device B" + i);
device.setType("typeB");
devices.add(deviceService.saveDevice(device));
}
for (int i = 0; i < 7; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("My device C" + i);
device.setType("typeC");
devices.add(deviceService.saveDevice(device));
}
for (int i = 0; i < 9; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("My device A" + i);
device.setType("typeA");
devices.add(deviceService.saveDevice(device));
}
List<EntitySubtype> deviceTypes = deviceService.findDeviceTypesByTenantId(tenantId).get();
Assert.assertNotNull(deviceTypes);
Assert.assertEquals(3, deviceTypes.size());
Assert.assertEquals("typeA", deviceTypes.get(0).getType());
Assert.assertEquals("typeB", deviceTypes.get(1).getType());
Assert.assertEquals("typeC", deviceTypes.get(2).getType());
} finally {
devices.forEach((device) -> {
deviceService.deleteDevice(device.getId());
});
}
}
use of org.thingsboard.server.common.data.EntitySubtype in project thingsboard by thingsboard.
the class CassandraDeviceDao method findTenantDeviceTypesAsync.
@Override
public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) {
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME);
Select.Where query = select.where();
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId));
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.DEVICE));
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = executeAsyncRead(query);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() {
@Nullable
@Override
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) {
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet);
if (result != null) {
List<EntitySubtype> entitySubtypes = new ArrayList<>();
result.all().forEach((entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()));
return entitySubtypes;
} else {
return Collections.emptyList();
}
}
});
}
use of org.thingsboard.server.common.data.EntitySubtype in project thingsboard by thingsboard.
the class EntitySubtypeEntity method toEntitySubtype.
public EntitySubtype toEntitySubtype() {
EntitySubtype entitySubtype = new EntitySubtype();
entitySubtype.setTenantId(new TenantId(tenantId));
entitySubtype.setEntityType(entityType);
entitySubtype.setType(type);
return entitySubtype;
}
use of org.thingsboard.server.common.data.EntitySubtype in project thingsboard by thingsboard.
the class BaseAssetControllerTest method testFindAssetTypesByTenantId.
@Test
public void testFindAssetTypesByTenantId() throws Exception {
List<Asset> assets = new ArrayList<>();
for (int i = 0; i < 3; i++) {
Asset asset = new Asset();
asset.setName("My asset B" + i);
asset.setType("typeB");
assets.add(doPost("/api/asset", asset, Asset.class));
}
for (int i = 0; i < 7; i++) {
Asset asset = new Asset();
asset.setName("My asset C" + i);
asset.setType("typeC");
assets.add(doPost("/api/asset", asset, Asset.class));
}
for (int i = 0; i < 9; i++) {
Asset asset = new Asset();
asset.setName("My asset A" + i);
asset.setType("typeA");
assets.add(doPost("/api/asset", asset, Asset.class));
}
List<EntitySubtype> assetTypes = doGetTyped("/api/asset/types", new TypeReference<List<EntitySubtype>>() {
});
Assert.assertNotNull(assetTypes);
Assert.assertEquals(3, assetTypes.size());
Assert.assertEquals("typeA", assetTypes.get(0).getType());
Assert.assertEquals("typeB", assetTypes.get(1).getType());
Assert.assertEquals("typeC", assetTypes.get(2).getType());
}
use of org.thingsboard.server.common.data.EntitySubtype in project thingsboard by thingsboard.
the class JpaAssetDaoTest method testFindTenantAssetTypesAsync.
@Test
public void testFindTenantAssetTypesAsync() throws ExecutionException, InterruptedException {
UUID assetId1 = UUIDs.timeBased();
UUID assetId2 = UUIDs.timeBased();
UUID tenantId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
UUID customerId1 = UUIDs.timeBased();
UUID customerId2 = UUIDs.timeBased();
saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_1", "TYPE_1");
saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_2", "TYPE_1");
saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_3", "TYPE_2");
saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_4", "TYPE_3");
saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_5", "TYPE_3");
saveAsset(UUIDs.timeBased(), tenantId1, customerId1, "TEST_ASSET_6", "TYPE_3");
saveAsset(UUIDs.timeBased(), tenantId2, customerId2, "TEST_ASSET_7", "TYPE_4");
saveAsset(UUIDs.timeBased(), tenantId2, customerId2, "TEST_ASSET_8", "TYPE_1");
saveAsset(UUIDs.timeBased(), tenantId2, customerId2, "TEST_ASSET_9", "TYPE_1");
List<EntitySubtype> tenant1Types = assetDao.findTenantAssetTypesAsync(tenantId1).get();
assertNotNull(tenant1Types);
List<EntitySubtype> tenant2Types = assetDao.findTenantAssetTypesAsync(tenantId2).get();
assertNotNull(tenant2Types);
assertEquals(3, tenant1Types.size());
assertTrue(tenant1Types.stream().anyMatch(t -> t.getType().equals("TYPE_1")));
assertTrue(tenant1Types.stream().anyMatch(t -> t.getType().equals("TYPE_2")));
assertTrue(tenant1Types.stream().anyMatch(t -> t.getType().equals("TYPE_3")));
assertFalse(tenant1Types.stream().anyMatch(t -> t.getType().equals("TYPE_4")));
assertEquals(2, tenant2Types.size());
assertTrue(tenant2Types.stream().anyMatch(t -> t.getType().equals("TYPE_1")));
assertTrue(tenant2Types.stream().anyMatch(t -> t.getType().equals("TYPE_4")));
assertFalse(tenant2Types.stream().anyMatch(t -> t.getType().equals("TYPE_2")));
assertFalse(tenant2Types.stream().anyMatch(t -> t.getType().equals("TYPE_3")));
}
Aggregations