Search in sources :

Example 1 with EntityCountUpdate

use of org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate in project thingsboard by thingsboard.

the class TbEntityCountSubCtx method update.

@Override
protected void update() {
    int newCount = (int) entityService.countEntitiesByQuery(getTenantId(), getCustomerId(), query);
    if (newCount != result) {
        result = newCount;
        wsService.sendWsMsg(sessionRef.getSessionId(), new EntityCountUpdate(cmdId, result));
    }
}
Also used : EntityCountUpdate(org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate)

Example 2 with EntityCountUpdate

use of org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate in project thingsboard by thingsboard.

the class TbEntityCountSubCtx method fetchData.

@Override
public void fetchData() {
    result = (int) entityService.countEntitiesByQuery(getTenantId(), getCustomerId(), query);
    wsService.sendWsMsg(sessionRef.getSessionId(), new EntityCountUpdate(cmdId, result));
}
Also used : EntityCountUpdate(org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate)

Example 3 with EntityCountUpdate

use of org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate in project thingsboard by thingsboard.

the class BaseWebsocketApiTest method testEntityCountWsCmd.

@Test
public void testEntityCountWsCmd() 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);
    AttributeKvEntry dataPoint1 = new BaseAttributeKvEntry(System.currentTimeMillis(), new LongDataEntry("temperature", 42L));
    sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, Collections.singletonList(dataPoint1));
    DeviceTypeFilter dtf1 = new DeviceTypeFilter();
    dtf1.setDeviceNameFilter("D");
    dtf1.setDeviceType("default");
    EntityCountQuery edq1 = new EntityCountQuery(dtf1, Collections.emptyList());
    EntityCountCmd cmd1 = new EntityCountCmd(1, edq1);
    TelemetryPluginCmdsWrapper wrapper1 = new TelemetryPluginCmdsWrapper();
    wrapper1.setEntityCountCmds(Collections.singletonList(cmd1));
    wsClient.send(mapper.writeValueAsString(wrapper1));
    String msg1 = wsClient.waitForReply();
    EntityCountUpdate update1 = mapper.readValue(msg1, EntityCountUpdate.class);
    Assert.assertEquals(1, update1.getCmdId());
    Assert.assertEquals(1, update1.getCount());
    DeviceTypeFilter dtf2 = new DeviceTypeFilter();
    dtf2.setDeviceNameFilter("D");
    dtf2.setDeviceType("non-existing-device-type");
    EntityCountQuery edq2 = new EntityCountQuery(dtf2, Collections.emptyList());
    EntityCountCmd cmd2 = new EntityCountCmd(2, edq2);
    TelemetryPluginCmdsWrapper wrapper2 = new TelemetryPluginCmdsWrapper();
    wrapper2.setEntityCountCmds(Collections.singletonList(cmd2));
    wsClient.send(mapper.writeValueAsString(wrapper2));
    String msg2 = wsClient.waitForReply();
    EntityCountUpdate update2 = mapper.readValue(msg2, EntityCountUpdate.class);
    Assert.assertEquals(2, update2.getCmdId());
    Assert.assertEquals(0, update2.getCount());
    KeyFilter highTemperatureFilter = new KeyFilter();
    highTemperatureFilter.setKey(new EntityKey(EntityKeyType.ATTRIBUTE, "temperature"));
    NumericFilterPredicate predicate = new NumericFilterPredicate();
    predicate.setValue(FilterPredicateValue.fromDouble(40));
    predicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    highTemperatureFilter.setPredicate(predicate);
    highTemperatureFilter.setValueType(EntityKeyValueType.NUMERIC);
    DeviceTypeFilter dtf3 = new DeviceTypeFilter();
    dtf3.setDeviceNameFilter("D");
    dtf3.setDeviceType("default");
    EntityCountQuery edq3 = new EntityCountQuery(dtf3, Collections.singletonList(highTemperatureFilter));
    EntityCountCmd cmd3 = new EntityCountCmd(3, edq3);
    TelemetryPluginCmdsWrapper wrapper3 = new TelemetryPluginCmdsWrapper();
    wrapper3.setEntityCountCmds(Collections.singletonList(cmd3));
    wsClient.send(mapper.writeValueAsString(wrapper3));
    String msg3 = wsClient.waitForReply();
    EntityCountUpdate update3 = mapper.readValue(msg3, EntityCountUpdate.class);
    Assert.assertEquals(3, update3.getCmdId());
    Assert.assertEquals(1, update3.getCount());
    KeyFilter highTemperatureFilter2 = new KeyFilter();
    highTemperatureFilter2.setKey(new EntityKey(EntityKeyType.ATTRIBUTE, "temperature"));
    NumericFilterPredicate predicate2 = new NumericFilterPredicate();
    predicate2.setValue(FilterPredicateValue.fromDouble(50));
    predicate2.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    highTemperatureFilter2.setPredicate(predicate2);
    highTemperatureFilter2.setValueType(EntityKeyValueType.NUMERIC);
    DeviceTypeFilter dtf4 = new DeviceTypeFilter();
    dtf4.setDeviceNameFilter("D");
    dtf4.setDeviceType("default");
    EntityCountQuery edq4 = new EntityCountQuery(dtf4, Collections.singletonList(highTemperatureFilter2));
    EntityCountCmd cmd4 = new EntityCountCmd(4, edq4);
    TelemetryPluginCmdsWrapper wrapper4 = new TelemetryPluginCmdsWrapper();
    wrapper4.setEntityCountCmds(Collections.singletonList(cmd4));
    wsClient.send(mapper.writeValueAsString(wrapper4));
    String msg4 = wsClient.waitForReply();
    EntityCountUpdate update4 = mapper.readValue(msg4, EntityCountUpdate.class);
    Assert.assertEquals(4, update4.getCmdId());
    Assert.assertEquals(0, update4.getCount());
}
Also used : EntityCountCmd(org.thingsboard.server.service.telemetry.cmd.v2.EntityCountCmd) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) DeviceTypeFilter(org.thingsboard.server.common.data.query.DeviceTypeFilter) EntityKey(org.thingsboard.server.common.data.query.EntityKey) KeyFilter(org.thingsboard.server.common.data.query.KeyFilter) EntityCountUpdate(org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) TelemetryPluginCmdsWrapper(org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper) Test(org.junit.Test)

Aggregations

EntityCountUpdate (org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUpdate)3 Test (org.junit.Test)1 Device (org.thingsboard.server.common.data.Device)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)1 LongDataEntry (org.thingsboard.server.common.data.kv.LongDataEntry)1 DeviceTypeFilter (org.thingsboard.server.common.data.query.DeviceTypeFilter)1 EntityCountQuery (org.thingsboard.server.common.data.query.EntityCountQuery)1 EntityKey (org.thingsboard.server.common.data.query.EntityKey)1 KeyFilter (org.thingsboard.server.common.data.query.KeyFilter)1 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)1 TelemetryPluginCmdsWrapper (org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper)1 EntityCountCmd (org.thingsboard.server.service.telemetry.cmd.v2.EntityCountCmd)1