Search in sources :

Example 6 with EntitySubtype

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;
}
Also used : Device(org.thingsboard.server.common.data.Device) EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Statement(com.datastax.driver.core.Statement) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype)

Example 7 with EntitySubtype

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;
}
Also used : EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Statement(com.datastax.driver.core.Statement) Asset(org.thingsboard.server.common.data.asset.Asset) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype)

Example 8 with EntitySubtype

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();
            }
        }
    });
}
Also used : java.util(java.util) QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) Function(com.google.common.base.Function) CassandraAbstractSearchTextDao(org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao) Result(com.datastax.driver.mapping.Result) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) NoSqlDao(org.thingsboard.server.dao.util.NoSqlDao) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) AssetEntity(org.thingsboard.server.dao.model.nosql.AssetEntity) ResultSet(com.datastax.driver.core.ResultSet) EntityType(org.thingsboard.server.common.data.EntityType) DaoUtil(org.thingsboard.server.dao.DaoUtil) EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Select(com.datastax.driver.core.querybuilder.Select) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype) Statement(com.datastax.driver.core.Statement) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Nullable(javax.annotation.Nullable) Asset(org.thingsboard.server.common.data.asset.Asset) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Select(com.datastax.driver.core.querybuilder.Select) ResultSet(com.datastax.driver.core.ResultSet) Nullable(javax.annotation.Nullable) Result(com.datastax.driver.mapping.Result)

Example 9 with EntitySubtype

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());
        });
    }
}
Also used : ArrayList(java.util.ArrayList) Asset(org.thingsboard.server.common.data.asset.Asset) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype) Test(org.junit.Test)

Aggregations

EntitySubtype (org.thingsboard.server.common.data.EntitySubtype)9 Asset (org.thingsboard.server.common.data.asset.Asset)5 Statement (com.datastax.driver.core.Statement)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 EntitySubtypeEntity (org.thingsboard.server.dao.model.EntitySubtypeEntity)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Device (org.thingsboard.server.common.data.Device)3 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)3 ResultSet (com.datastax.driver.core.ResultSet)2 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)2 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)2 Select (com.datastax.driver.core.querybuilder.Select)2 Result (com.datastax.driver.mapping.Result)2 Function (com.google.common.base.Function)2 Futures (com.google.common.util.concurrent.Futures)2 java.util (java.util)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 Slf4j (lombok.extern.slf4j.Slf4j)2