use of org.thingsboard.server.common.data.EntitySubtype 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.EntitySubtype in project thingsboard by thingsboard.
the class CassandraAssetDao method save.
@Override
public Asset save(Asset domain) {
Asset savedAsset = super.save(domain);
EntitySubtype entitySubtype = new EntitySubtype(savedAsset.getTenantId(), EntityType.ASSET, savedAsset.getType());
EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype);
Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity);
executeWrite(saveStatement);
return savedAsset;
}
use of org.thingsboard.server.common.data.EntitySubtype in project thingsboard by thingsboard.
the class CassandraAssetDao method findTenantAssetTypesAsync.
@Override
public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(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.ASSET));
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 BaseAssetServiceTest method testFindAssetTypesByTenantId.
@Test
public void testFindAssetTypesByTenantId() throws Exception {
List<Asset> assets = new ArrayList<>();
try {
for (int i = 0; i < 3; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setName("My asset B" + i);
asset.setType("typeB");
assets.add(assetService.saveAsset(asset));
}
for (int i = 0; i < 7; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setName("My asset C" + i);
asset.setType("typeC");
assets.add(assetService.saveAsset(asset));
}
for (int i = 0; i < 9; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setName("My asset A" + i);
asset.setType("typeA");
assets.add(assetService.saveAsset(asset));
}
List<EntitySubtype> assetTypes = assetService.findAssetTypesByTenantId(tenantId).get();
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());
} finally {
assets.forEach((asset) -> {
assetService.deleteAsset(asset.getId());
});
}
}
Aggregations