Search in sources :

Example 11 with EntityKey

use of org.thingsboard.server.common.data.query.EntityKey in project thingsboard by thingsboard.

the class BaseWebsocketApiTest method testEntityDataLatestAttrTypesWsCmd.

@Test
public void testEntityDataLatestAttrTypesWsCmd() throws Exception {
    Device device = new Device();
    device.setName("Device");
    device.setType("default");
    device.setLabel("testLabel" + (int) (Math.random() * 1000));
    device = doPost("/api/device", device, Device.class);
    long now = System.currentTimeMillis();
    DeviceTypeFilter dtf = new DeviceTypeFilter();
    dtf.setDeviceNameFilter("D");
    dtf.setDeviceType("default");
    EntityDataQuery edq = new EntityDataQuery(dtf, new EntityDataPageLink(1, 0, null, null), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    LatestValueCmd latestCmd = new LatestValueCmd();
    List<EntityKey> keys = new ArrayList<>();
    keys.add(new EntityKey(EntityKeyType.SERVER_ATTRIBUTE, "serverAttributeKey"));
    keys.add(new EntityKey(EntityKeyType.CLIENT_ATTRIBUTE, "clientAttributeKey"));
    keys.add(new EntityKey(EntityKeyType.SHARED_ATTRIBUTE, "sharedAttributeKey"));
    keys.add(new EntityKey(EntityKeyType.ATTRIBUTE, "anyAttributeKey"));
    latestCmd.setKeys(keys);
    EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
    TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
    wrapper.setEntityDataCmds(Collections.singletonList(cmd));
    wsClient.send(mapper.writeValueAsString(wrapper));
    String msg = wsClient.waitForReply();
    EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    PageData<EntityData> pageData = update.getData();
    Assert.assertNotNull(pageData);
    Assert.assertEquals(1, pageData.getData().size());
    Assert.assertEquals(device.getId(), pageData.getData().get(0).getEntityId());
    Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey"));
    Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey").getTs());
    Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey").getValue());
    Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey"));
    Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey").getTs());
    Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey").getValue());
    Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey"));
    Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey").getTs());
    Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey").getValue());
    Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey"));
    Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey").getTs());
    Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey").getValue());
    wsClient.registerWaitForUpdate();
    AttributeKvEntry dataPoint1 = new BaseAttributeKvEntry(now - TimeUnit.MINUTES.toMillis(1), new LongDataEntry("serverAttributeKey", 42L));
    List<AttributeKvEntry> tsData = Arrays.asList(dataPoint1);
    Thread.sleep(100);
    sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, tsData);
    msg = wsClient.waitForUpdate();
    Assert.assertNotNull(msg);
    update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    List<EntityData> eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE));
    TsValue attrValue = eData.get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey");
    Assert.assertEquals(new TsValue(dataPoint1.getLastUpdateTs(), dataPoint1.getValueAsString()), attrValue);
    // Sending update from the past, while latest value has new timestamp;
    wsClient.registerWaitForUpdate();
    sendAttributes(device, TbAttributeSubscriptionScope.SHARED_SCOPE, Arrays.asList(dataPoint1));
    msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
    Assert.assertNull(msg);
    // Sending duplicate update again
    wsClient.registerWaitForUpdate();
    sendAttributes(device, TbAttributeSubscriptionScope.CLIENT_SCOPE, Arrays.asList(dataPoint1));
    msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
    Assert.assertNull(msg);
    // Sending update from the past, while latest value has new timestamp;
    wsClient.registerWaitForUpdate();
    AttributeKvEntry dataPoint2 = new BaseAttributeKvEntry(now, new LongDataEntry("sharedAttributeKey", 42L));
    sendAttributes(device, TbAttributeSubscriptionScope.SHARED_SCOPE, Arrays.asList(dataPoint2));
    msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
    update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE));
    attrValue = eData.get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey");
    Assert.assertEquals(new TsValue(dataPoint2.getLastUpdateTs(), dataPoint2.getValueAsString()), attrValue);
    wsClient.registerWaitForUpdate();
    AttributeKvEntry dataPoint3 = new BaseAttributeKvEntry(now, new LongDataEntry("clientAttributeKey", 42L));
    sendAttributes(device, TbAttributeSubscriptionScope.CLIENT_SCOPE, Arrays.asList(dataPoint3));
    msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
    update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE));
    attrValue = eData.get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey");
    Assert.assertEquals(new TsValue(dataPoint3.getLastUpdateTs(), dataPoint3.getValueAsString()), attrValue);
    wsClient.registerWaitForUpdate();
    AttributeKvEntry dataPoint4 = new BaseAttributeKvEntry(now, new LongDataEntry("anyAttributeKey", 42L));
    sendAttributes(device, TbAttributeSubscriptionScope.CLIENT_SCOPE, Arrays.asList(dataPoint4));
    msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
    update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE));
    attrValue = eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey");
    Assert.assertEquals(new TsValue(dataPoint4.getLastUpdateTs(), dataPoint4.getValueAsString()), attrValue);
    wsClient.registerWaitForUpdate();
    AttributeKvEntry dataPoint5 = new BaseAttributeKvEntry(now, new LongDataEntry("anyAttributeKey", 43L));
    sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, Arrays.asList(dataPoint5));
    msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
    update = mapper.readValue(msg, EntityDataUpdate.class);
    Assert.assertEquals(1, update.getCmdId());
    eData = update.getUpdate();
    Assert.assertNotNull(eData);
    Assert.assertEquals(1, eData.size());
    Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
    Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE));
    attrValue = eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey");
    Assert.assertEquals(new TsValue(dataPoint5.getLastUpdateTs(), dataPoint5.getValueAsString()), attrValue);
}
Also used : TsValue(org.thingsboard.server.common.data.query.TsValue) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) Device(org.thingsboard.server.common.data.Device) DeviceTypeFilter(org.thingsboard.server.common.data.query.DeviceTypeFilter) EntityDataPageLink(org.thingsboard.server.common.data.query.EntityDataPageLink) ArrayList(java.util.ArrayList) EntityData(org.thingsboard.server.common.data.query.EntityData) EntityDataUpdate(org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate) EntityKey(org.thingsboard.server.common.data.query.EntityKey) EntityDataQuery(org.thingsboard.server.common.data.query.EntityDataQuery) LatestValueCmd(org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd) EntityDataCmd(org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) TelemetryPluginCmdsWrapper(org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper) Test(org.junit.Test)

Example 12 with EntityKey

use of org.thingsboard.server.common.data.query.EntityKey in project thingsboard by thingsboard.

the class BaseAlarmServiceTest method testFindPropagatedToOwnerAndTenantAlarm.

@Test
public void testFindPropagatedToOwnerAndTenantAlarm() {
    Customer customer = new Customer();
    customer.setTitle("TestCustomer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    Device device = new Device();
    device.setName("TestTenantDevice");
    device.setType("default");
    device.setTenantId(tenantId);
    device.setCustomerId(customer.getId());
    device = deviceService.saveDevice(device);
    long ts = System.currentTimeMillis();
    Alarm tenantAlarm = Alarm.builder().tenantId(tenantId).originator(device.getId()).type("Propagated To Tenant").propagateToTenant(true).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
    tenantAlarm = result.getAlarm();
    Alarm customerAlarm = Alarm.builder().tenantId(tenantId).originator(device.getId()).type("Propagated to Customer").propagate(false).propagateToOwner(true).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    result = alarmService.createOrUpdateAlarm(customerAlarm);
    customerAlarm = result.getAlarm();
    AlarmDataPageLink pageLink = new AlarmDataPageLink();
    pageLink.setPage(0);
    pageLink.setPageSize(10);
    pageLink.setSortOrder(new EntityDataSortOrder(new EntityKey(EntityKeyType.ALARM_FIELD, "createdTime")));
    pageLink.setStartTs(0L);
    pageLink.setEndTs(System.currentTimeMillis());
    pageLink.setSearchPropagatedAlarms(true);
    pageLink.setSeverityList(Arrays.asList(AlarmSeverity.CRITICAL, AlarmSeverity.WARNING));
    pageLink.setStatusList(Arrays.asList(AlarmSearchStatus.ACTIVE));
    // TEST that propagated alarms are visible on the asset level.
    PageData<AlarmData> tenantAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(tenantId));
    Assert.assertEquals(1, tenantAlarms.getData().size());
    Assert.assertEquals(tenantAlarm, tenantAlarms.getData().get(0));
    // TEST that propagated alarms are visible on the asset level.
    PageData<AlarmData> customerAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(customer.getId()));
    Assert.assertEquals(1, customerAlarms.getData().size());
    Assert.assertEquals(customerAlarm, customerAlarms.getData().get(0));
}
Also used : EntityKey(org.thingsboard.server.common.data.query.EntityKey) Customer(org.thingsboard.server.common.data.Customer) Device(org.thingsboard.server.common.data.Device) Alarm(org.thingsboard.server.common.data.alarm.Alarm) EntityDataSortOrder(org.thingsboard.server.common.data.query.EntityDataSortOrder) AlarmOperationResult(org.thingsboard.server.dao.alarm.AlarmOperationResult) AlarmDataPageLink(org.thingsboard.server.common.data.query.AlarmDataPageLink) AlarmData(org.thingsboard.server.common.data.query.AlarmData) Test(org.junit.Test)

Example 13 with EntityKey

use of org.thingsboard.server.common.data.query.EntityKey in project thingsboard by thingsboard.

the class BaseAlarmServiceTest method testFindPropagatedCustomerAssetAlarm.

@Test
public void testFindPropagatedCustomerAssetAlarm() throws ExecutionException, InterruptedException {
    Customer customer = new Customer();
    customer.setTitle("TestCustomer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    Device tenantDevice = new Device();
    tenantDevice.setName("TestTenantDevice");
    tenantDevice.setType("default");
    tenantDevice.setTenantId(tenantId);
    tenantDevice = deviceService.saveDevice(tenantDevice);
    Asset customerAsset = new Asset();
    customerAsset.setName("TestCustomerDevice");
    customerAsset.setType("default");
    customerAsset.setTenantId(tenantId);
    customerAsset.setCustomerId(customer.getId());
    customerAsset = assetService.saveAsset(customerAsset);
    EntityRelation relation = new EntityRelation();
    relation.setFrom(customerAsset.getId());
    relation.setTo(tenantDevice.getId());
    relation.setAdditionalInfo(JacksonUtil.newObjectNode());
    relation.setType("Contains");
    relation.setTypeGroup(RelationTypeGroup.COMMON);
    relationService.saveRelation(tenantId, relation);
    long ts = System.currentTimeMillis();
    Alarm tenantAlarm = Alarm.builder().tenantId(tenantId).originator(tenantDevice.getId()).type("Not Propagated").propagate(false).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    AlarmOperationResult result = alarmService.createOrUpdateAlarm(tenantAlarm);
    tenantAlarm = result.getAlarm();
    Alarm customerAlarm = Alarm.builder().tenantId(tenantId).originator(tenantDevice.getId()).type("Propagated").propagate(true).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
    result = alarmService.createOrUpdateAlarm(customerAlarm);
    customerAlarm = result.getAlarm();
    AlarmDataPageLink pageLink = new AlarmDataPageLink();
    pageLink.setPage(0);
    pageLink.setPageSize(10);
    pageLink.setSortOrder(new EntityDataSortOrder(new EntityKey(EntityKeyType.ALARM_FIELD, "createdTime")));
    pageLink.setStartTs(0L);
    pageLink.setEndTs(System.currentTimeMillis());
    pageLink.setSearchPropagatedAlarms(true);
    pageLink.setSeverityList(Arrays.asList(AlarmSeverity.CRITICAL, AlarmSeverity.WARNING));
    pageLink.setStatusList(Arrays.asList(AlarmSearchStatus.ACTIVE));
    // TEST that propagated alarms are visible on the asset level.
    PageData<AlarmData> customerAlarms = alarmService.findAlarmDataByQueryForEntities(tenantId, toQuery(pageLink), Collections.singletonList(customerAsset.getId()));
    Assert.assertEquals(1, customerAlarms.getData().size());
    Assert.assertEquals(customerAlarm, customerAlarms.getData().get(0));
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) EntityKey(org.thingsboard.server.common.data.query.EntityKey) Customer(org.thingsboard.server.common.data.Customer) Device(org.thingsboard.server.common.data.Device) Alarm(org.thingsboard.server.common.data.alarm.Alarm) EntityDataSortOrder(org.thingsboard.server.common.data.query.EntityDataSortOrder) Asset(org.thingsboard.server.common.data.asset.Asset) AlarmOperationResult(org.thingsboard.server.dao.alarm.AlarmOperationResult) AlarmDataPageLink(org.thingsboard.server.common.data.query.AlarmDataPageLink) AlarmData(org.thingsboard.server.common.data.query.AlarmData) Test(org.junit.Test)

Example 14 with EntityKey

use of org.thingsboard.server.common.data.query.EntityKey in project thingsboard by thingsboard.

the class BaseEntityServiceTest method doTestHierarchicalFindEntityDataWithAttributesByQuery.

private void doTestHierarchicalFindEntityDataWithAttributesByQuery(final int maxLevel, final boolean fetchLastLevelOnly) throws ExecutionException, InterruptedException {
    List<Asset> assets = new ArrayList<>();
    List<Device> devices = new ArrayList<>();
    List<Long> temperatures = new ArrayList<>();
    List<Long> highTemperatures = new ArrayList<>();
    createTestHierarchy(tenantId, assets, devices, new ArrayList<>(), new ArrayList<>(), temperatures, highTemperatures);
    List<ListenableFuture<List<Void>>> attributeFutures = new ArrayList<>();
    for (int i = 0; i < devices.size(); i++) {
        Device device = devices.get(i);
        attributeFutures.add(saveLongAttribute(device.getId(), "temperature", temperatures.get(i), DataConstants.CLIENT_SCOPE));
    }
    Futures.successfulAsList(attributeFutures).get();
    RelationsQueryFilter filter = new RelationsQueryFilter();
    filter.setRootEntity(tenantId);
    filter.setDirection(EntitySearchDirection.FROM);
    filter.setFilters(Collections.singletonList(new RelationEntityTypeFilter("Contains", Collections.singletonList(EntityType.DEVICE))));
    filter.setMaxLevel(maxLevel);
    filter.setFetchLastLevelOnly(fetchLastLevelOnly);
    EntityDataSortOrder sortOrder = new EntityDataSortOrder(new EntityKey(EntityKeyType.ENTITY_FIELD, "createdTime"), EntityDataSortOrder.Direction.ASC);
    EntityDataPageLink pageLink = new EntityDataPageLink(10, 0, null, sortOrder);
    List<EntityKey> entityFields = Collections.singletonList(new EntityKey(EntityKeyType.ENTITY_FIELD, "name"));
    List<EntityKey> latestValues = Collections.singletonList(new EntityKey(EntityKeyType.ATTRIBUTE, "temperature"));
    EntityDataQuery query = new EntityDataQuery(filter, pageLink, entityFields, latestValues, null);
    PageData<EntityData> data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query);
    List<EntityData> loadedEntities = new ArrayList<>(data.getData());
    while (data.hasNext()) {
        query = query.next();
        data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query);
        loadedEntities.addAll(data.getData());
    }
    Assert.assertEquals(25, loadedEntities.size());
    List<String> loadedTemperatures = loadedEntities.stream().map(entityData -> entityData.getLatest().get(EntityKeyType.ATTRIBUTE).get("temperature").getValue()).collect(Collectors.toList());
    List<String> deviceTemperatures = temperatures.stream().map(aLong -> Long.toString(aLong)).collect(Collectors.toList());
    Assert.assertEquals(deviceTemperatures, loadedTemperatures);
    pageLink = new EntityDataPageLink(10, 0, null, sortOrder);
    KeyFilter highTemperatureFilter = new KeyFilter();
    highTemperatureFilter.setKey(new EntityKey(EntityKeyType.ATTRIBUTE, "temperature"));
    NumericFilterPredicate predicate = new NumericFilterPredicate();
    predicate.setValue(FilterPredicateValue.fromDouble(45));
    predicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    highTemperatureFilter.setPredicate(predicate);
    List<KeyFilter> keyFilters = Collections.singletonList(highTemperatureFilter);
    query = new EntityDataQuery(filter, pageLink, entityFields, latestValues, keyFilters);
    data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query);
    loadedEntities = new ArrayList<>(data.getData());
    while (data.hasNext()) {
        query = query.next();
        data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query);
        loadedEntities.addAll(data.getData());
    }
    Assert.assertEquals(highTemperatures.size(), loadedEntities.size());
    List<String> loadedHighTemperatures = loadedEntities.stream().map(entityData -> entityData.getLatest().get(EntityKeyType.ATTRIBUTE).get("temperature").getValue()).collect(Collectors.toList());
    List<String> deviceHighTemperatures = highTemperatures.stream().map(aLong -> Long.toString(aLong)).collect(Collectors.toList());
    Assert.assertEquals(deviceHighTemperatures, loadedHighTemperatures);
    deviceService.deleteDevicesByTenantId(tenantId);
}
Also used : Arrays(java.util.Arrays) Edge(org.thingsboard.server.common.data.edge.Edge) EntitySearchDirection(org.thingsboard.server.common.data.relation.EntitySearchDirection) Autowired(org.springframework.beans.factory.annotation.Autowired) Random(java.util.Random) StringUtils(org.apache.commons.lang3.StringUtils) KeyFilter(org.thingsboard.server.common.data.query.KeyFilter) TenantId(org.thingsboard.server.common.data.id.TenantId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) IdBased(org.thingsboard.server.common.data.id.IdBased) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) StringFilterPredicate(org.thingsboard.server.common.data.query.StringFilterPredicate) EntityListFilter(org.thingsboard.server.common.data.query.EntityListFilter) After(org.junit.After) RelationsQueryFilter(org.thingsboard.server.common.data.query.RelationsQueryFilter) Map(java.util.Map) EntityType(org.thingsboard.server.common.data.EntityType) AttributesService(org.thingsboard.server.dao.attributes.AttributesService) EdgeId(org.thingsboard.server.common.data.id.EdgeId) DeviceTypeFilter(org.thingsboard.server.common.data.query.DeviceTypeFilter) DeviceId(org.thingsboard.server.common.data.id.DeviceId) EntityKeyType(org.thingsboard.server.common.data.query.EntityKeyType) RelationRepository(org.thingsboard.server.dao.sql.relation.RelationRepository) TimeseriesService(org.thingsboard.server.dao.timeseries.TimeseriesService) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) AssetSearchQueryFilter(org.thingsboard.server.common.data.query.AssetSearchQueryFilter) Stream(java.util.stream.Stream) RelationEntityTypeFilter(org.thingsboard.server.common.data.relation.RelationEntityTypeFilter) StringOperation(org.thingsboard.server.common.data.query.StringFilterPredicate.StringOperation) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) CustomerId(org.thingsboard.server.common.data.id.CustomerId) RandomUtils(org.apache.commons.lang3.RandomUtils) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Device(org.thingsboard.server.common.data.Device) Tenant(org.thingsboard.server.common.data.Tenant) HashMap(java.util.HashMap) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) DeviceSearchQueryFilter(org.thingsboard.server.common.data.query.DeviceSearchQueryFilter) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TsKvEntity(org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityDataPageLink(org.thingsboard.server.common.data.query.EntityDataPageLink) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) EdgeTypeFilter(org.thingsboard.server.common.data.query.EdgeTypeFilter) EntityKey(org.thingsboard.server.common.data.query.EntityKey) DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) Before(org.junit.Before) DataConstants(org.thingsboard.server.common.data.DataConstants) EntityData(org.thingsboard.server.common.data.query.EntityData) FilterPredicateValue(org.thingsboard.server.common.data.query.FilterPredicateValue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) EdgeSearchQueryFilter(org.thingsboard.server.common.data.query.EdgeSearchQueryFilter) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) EntityDataSortOrder(org.thingsboard.server.common.data.query.EntityDataSortOrder) EntityDataQuery(org.thingsboard.server.common.data.query.EntityDataQuery) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) PageData(org.thingsboard.server.common.data.page.PageData) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) Assert(org.junit.Assert) Comparator(java.util.Comparator) Collections(java.util.Collections) ResultSetExtractor(org.springframework.jdbc.core.ResultSetExtractor) Assert.assertEquals(org.junit.Assert.assertEquals) Asset(org.thingsboard.server.common.data.asset.Asset) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) ArrayList(java.util.ArrayList) RelationsQueryFilter(org.thingsboard.server.common.data.query.RelationsQueryFilter) EntityKey(org.thingsboard.server.common.data.query.EntityKey) EntityDataSortOrder(org.thingsboard.server.common.data.query.EntityDataSortOrder) Asset(org.thingsboard.server.common.data.asset.Asset) RelationEntityTypeFilter(org.thingsboard.server.common.data.relation.RelationEntityTypeFilter) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) EntityDataPageLink(org.thingsboard.server.common.data.query.EntityDataPageLink) EntityData(org.thingsboard.server.common.data.query.EntityData) CustomerId(org.thingsboard.server.common.data.id.CustomerId) EntityDataQuery(org.thingsboard.server.common.data.query.EntityDataQuery) KeyFilter(org.thingsboard.server.common.data.query.KeyFilter) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 15 with EntityKey

use of org.thingsboard.server.common.data.query.EntityKey in project thingsboard by thingsboard.

the class BaseEntityServiceTest method createStringKeyFilters.

private List<KeyFilter> createStringKeyFilters(String key, EntityKeyType keyType, StringFilterPredicate.StringOperation operation, String value) {
    KeyFilter filter = new KeyFilter();
    filter.setKey(new EntityKey(keyType, key));
    StringFilterPredicate predicate = new StringFilterPredicate();
    predicate.setValue(FilterPredicateValue.fromString(value));
    predicate.setOperation(operation);
    predicate.setIgnoreCase(true);
    filter.setPredicate(predicate);
    return Collections.singletonList(filter);
}
Also used : EntityKey(org.thingsboard.server.common.data.query.EntityKey) KeyFilter(org.thingsboard.server.common.data.query.KeyFilter) StringFilterPredicate(org.thingsboard.server.common.data.query.StringFilterPredicate)

Aggregations

EntityKey (org.thingsboard.server.common.data.query.EntityKey)36 EntityDataQuery (org.thingsboard.server.common.data.query.EntityDataQuery)24 EntityData (org.thingsboard.server.common.data.query.EntityData)23 Test (org.junit.Test)22 Device (org.thingsboard.server.common.data.Device)22 EntityDataPageLink (org.thingsboard.server.common.data.query.EntityDataPageLink)22 ArrayList (java.util.ArrayList)21 EntityDataSortOrder (org.thingsboard.server.common.data.query.EntityDataSortOrder)21 List (java.util.List)19 DeviceTypeFilter (org.thingsboard.server.common.data.query.DeviceTypeFilter)19 EntityKeyType (org.thingsboard.server.common.data.query.EntityKeyType)19 KeyFilter (org.thingsboard.server.common.data.query.KeyFilter)19 HashMap (java.util.HashMap)16 Map (java.util.Map)16 Collectors (java.util.stream.Collectors)16 EntityId (org.thingsboard.server.common.data.id.EntityId)15 LongDataEntry (org.thingsboard.server.common.data.kv.LongDataEntry)15 PageData (org.thingsboard.server.common.data.page.PageData)15 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)15 EntityType (org.thingsboard.server.common.data.EntityType)14