Search in sources :

Example 21 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class AbstractCassandraBaseTimeseriesDao method toKvEntry.

public static KvEntry toKvEntry(Row row, String key) {
    KvEntry kvEntry = null;
    String strV = row.get(ModelConstants.STRING_VALUE_COLUMN, String.class);
    if (strV != null) {
        kvEntry = new StringDataEntry(key, strV);
    } else {
        Long longV = row.get(ModelConstants.LONG_VALUE_COLUMN, Long.class);
        if (longV != null) {
            kvEntry = new LongDataEntry(key, longV);
        } else {
            Double doubleV = row.get(ModelConstants.DOUBLE_VALUE_COLUMN, Double.class);
            if (doubleV != null) {
                kvEntry = new DoubleDataEntry(key, doubleV);
            } else {
                Boolean boolV = row.get(ModelConstants.BOOLEAN_VALUE_COLUMN, Boolean.class);
                if (boolV != null) {
                    kvEntry = new BooleanDataEntry(key, boolV);
                } else {
                    String jsonV = row.get(ModelConstants.JSON_VALUE_COLUMN, String.class);
                    if (StringUtils.isNoneEmpty(jsonV)) {
                        kvEntry = new JsonDataEntry(key, jsonV);
                    } else {
                        log.warn("All values in key-value row are nullable ");
                    }
                }
            }
        }
    }
    return kvEntry;
}
Also used : DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) JsonDataEntry(org.thingsboard.server.common.data.kv.JsonDataEntry)

Example 22 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class ApiUsageStateServiceImpl method createDefaultApiUsageState.

@Override
public ApiUsageState createDefaultApiUsageState(TenantId tenantId, EntityId entityId) {
    entityId = Objects.requireNonNullElse(entityId, tenantId);
    log.trace("Executing createDefaultUsageRecord [{}]", entityId);
    validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
    ApiUsageState apiUsageState = new ApiUsageState();
    apiUsageState.setTenantId(tenantId);
    apiUsageState.setEntityId(entityId);
    apiUsageState.setTransportState(ApiUsageStateValue.ENABLED);
    apiUsageState.setReExecState(ApiUsageStateValue.ENABLED);
    apiUsageState.setJsExecState(ApiUsageStateValue.ENABLED);
    apiUsageState.setDbStorageState(ApiUsageStateValue.ENABLED);
    apiUsageState.setSmsExecState(ApiUsageStateValue.ENABLED);
    apiUsageState.setEmailExecState(ApiUsageStateValue.ENABLED);
    apiUsageState.setAlarmExecState(ApiUsageStateValue.ENABLED);
    apiUsageStateValidator.validate(apiUsageState, ApiUsageState::getTenantId);
    ApiUsageState saved = apiUsageStateDao.save(apiUsageState.getTenantId(), apiUsageState);
    List<TsKvEntry> apiUsageStates = new ArrayList<>();
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.TRANSPORT.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.DB.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.RE.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.JS.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.EMAIL.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.SMS.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    apiUsageStates.add(new BasicTsKvEntry(saved.getCreatedTime(), new StringDataEntry(ApiFeature.ALARM.getApiStateKey(), ApiUsageStateValue.ENABLED.name())));
    tsService.save(tenantId, saved.getId(), apiUsageStates, 0L);
    if (entityId.getEntityType() == EntityType.TENANT && !entityId.equals(TenantId.SYS_TENANT_ID)) {
        tenantId = (TenantId) entityId;
        Tenant tenant = tenantDao.findById(tenantId, tenantId.getId());
        TenantProfile tenantProfile = tenantProfileDao.findById(tenantId, tenant.getTenantProfileId().getId());
        TenantProfileConfiguration configuration = tenantProfile.getProfileData().getConfiguration();
        List<TsKvEntry> profileThresholds = new ArrayList<>();
        for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) {
            profileThresholds.add(new BasicTsKvEntry(saved.getCreatedTime(), new LongDataEntry(key.getApiLimitKey(), configuration.getProfileThreshold(key))));
        }
        tsService.save(tenantId, saved.getId(), profileThresholds, 0L);
    }
    return saved;
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Tenant(org.thingsboard.server.common.data.Tenant) TenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.TenantProfileConfiguration) ApiUsageState(org.thingsboard.server.common.data.ApiUsageState) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) ArrayList(java.util.ArrayList) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) TenantProfile(org.thingsboard.server.common.data.TenantProfile) ApiUsageRecordKey(org.thingsboard.server.common.data.ApiUsageRecordKey)

Example 23 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class BaseTimeseriesServiceTest method save.

private TsKvEntry save(DeviceId deviceId, long ts, long value) throws Exception {
    TsKvEntry entry = new BasicTsKvEntry(ts, new LongDataEntry(LONG_KEY, value));
    tsService.save(tenantId, deviceId, entry).get(MAX_TIMEOUT, TimeUnit.SECONDS);
    return entry;
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry)

Example 24 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class BaseEntityServiceTest method saveLongAttribute.

private ListenableFuture<List<Void>> saveLongAttribute(EntityId entityId, String key, long value, String scope) {
    KvEntry attrValue = new LongDataEntry(key, value);
    AttributeKvEntry attr = new BaseAttributeKvEntry(attrValue, 42L);
    return attributesService.save(SYSTEM_TENANT_ID, entityId, scope, Collections.singletonList(attr));
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry)

Aggregations

LongDataEntry (org.thingsboard.server.common.data.kv.LongDataEntry)24 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)16 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)14 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)9 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)9 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Device (org.thingsboard.server.common.data.Device)7 DeviceTypeFilter (org.thingsboard.server.common.data.query.DeviceTypeFilter)7 TelemetryPluginCmdsWrapper (org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper)7 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)6 EntityData (org.thingsboard.server.common.data.query.EntityData)6 EntityDataPageLink (org.thingsboard.server.common.data.query.EntityDataPageLink)6 EntityDataQuery (org.thingsboard.server.common.data.query.EntityDataQuery)6 TsValue (org.thingsboard.server.common.data.query.TsValue)6 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 JsonDataEntry (org.thingsboard.server.common.data.kv.JsonDataEntry)5 EntityKey (org.thingsboard.server.common.data.query.EntityKey)5 ApiUsageRecordKey (org.thingsboard.server.common.data.ApiUsageRecordKey)4