Search in sources :

Example 1 with AttributeKvEntry

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

the class BaseAttributesServiceTest method findAll.

@Test
public void findAll() throws Exception {
    DeviceId deviceId = new DeviceId(UUIDs.timeBased());
    KvEntry attrAOldValue = new StringDataEntry("A", "value1");
    AttributeKvEntry attrAOld = new BaseAttributeKvEntry(attrAOldValue, 42L);
    KvEntry attrANewValue = new StringDataEntry("A", "value2");
    AttributeKvEntry attrANew = new BaseAttributeKvEntry(attrANewValue, 73L);
    KvEntry attrBNewValue = new StringDataEntry("B", "value3");
    AttributeKvEntry attrBNew = new BaseAttributeKvEntry(attrBNewValue, 73L);
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrAOld)).get();
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrANew)).get();
    attributesService.save(deviceId, DataConstants.CLIENT_SCOPE, Collections.singletonList(attrBNew)).get();
    List<AttributeKvEntry> saved = attributesService.findAll(deviceId, DataConstants.CLIENT_SCOPE).get();
    Assert.assertNotNull(saved);
    Assert.assertEquals(2, saved.size());
    Assert.assertEquals(attrANew, saved.get(0));
    Assert.assertEquals(attrBNew, saved.get(1));
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Example 2 with AttributeKvEntry

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

the class TelemetryRuleMsgHandler method handleGetAttributesRequest.

@Override
public void handleGetAttributesRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, GetAttributesRequestRuleToPluginMsg msg) {
    GetAttributesRequest request = msg.getPayload();
    BiPluginCallBack<List<AttributeKvEntry>, List<AttributeKvEntry>> callback = new BiPluginCallBack<List<AttributeKvEntry>, List<AttributeKvEntry>>() {

        @Override
        public void onSuccess(PluginContext ctx, List<AttributeKvEntry> clientAttributes, List<AttributeKvEntry> sharedAttributes) {
            BasicGetAttributesResponse response = BasicGetAttributesResponse.onSuccess(request.getMsgType(), request.getRequestId(), BasicAttributeKVMsg.from(clientAttributes, sharedAttributes));
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, response));
        }

        @Override
        public void onFailure(PluginContext ctx, Exception e) {
            log.error("Failed to process get attributes request", e);
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onError(request.getMsgType(), request.getRequestId(), e)));
        }
    };
    getAttributeKvEntries(ctx, msg.getDeviceId(), DataConstants.CLIENT_SCOPE, request.getClientAttributeNames(), callback.getV1Callback());
    getAttributeKvEntries(ctx, msg.getDeviceId(), DataConstants.SHARED_SCOPE, request.getSharedAttributeNames(), callback.getV2Callback());
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) PluginContext(org.thingsboard.server.extensions.api.plugins.PluginContext) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg)

Example 3 with AttributeKvEntry

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

the class DeviceAttributesFilterTest method basicMissingAttributesTest.

@Test
public void basicMissingAttributesTest() {
    DeviceAttributesFilter filter = new DeviceAttributesFilter();
    filter.init(wrap("((typeof nonExistingVal === 'undefined') || nonExistingVal == true) && booleanValue == false"));
    List<AttributeKvEntry> clientAttributes = new ArrayList<>();
    clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
    DeviceAttributes attributes = new DeviceAttributes(clientAttributes, new ArrayList<>(), new ArrayList<>());
    Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
    Assert.assertTrue(filter.filter(ruleCtx, null));
    filter.stop();
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) DeviceAttributes(org.thingsboard.server.extensions.api.device.DeviceAttributes) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) DeviceMetaData(org.thingsboard.server.extensions.api.device.DeviceMetaData) Test(org.junit.Test)

Example 4 with AttributeKvEntry

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

the class DeviceAttributesFilterTest method basicConflictServerAttributesTest.

@Test
public void basicConflictServerAttributesTest() {
    DeviceAttributesFilter filter = new DeviceAttributesFilter();
    filter.init(wrap("cs.doubleValue == 1.0 && cs.booleanValue == true && ss.doubleValue == 0.0 && ss.booleanValue == false"));
    List<AttributeKvEntry> clientAttributes = new ArrayList<>();
    clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
    clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", true), 42));
    List<AttributeKvEntry> serverAttributes = new ArrayList<>();
    serverAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 0.0), 42));
    serverAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
    DeviceAttributes attributes = new DeviceAttributes(clientAttributes, serverAttributes, new ArrayList<>());
    Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
    Assert.assertTrue(filter.filter(ruleCtx, null));
    filter.stop();
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) DeviceAttributes(org.thingsboard.server.extensions.api.device.DeviceAttributes) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) DeviceMetaData(org.thingsboard.server.extensions.api.device.DeviceMetaData) Test(org.junit.Test)

Example 5 with AttributeKvEntry

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

the class DeviceAttributesFilterTest method basicServerAttributesTest.

@Test
public void basicServerAttributesTest() {
    DeviceAttributesFilter filter = new DeviceAttributesFilter();
    filter.init(wrap("doubleValue == 1.0 && booleanValue == false"));
    List<AttributeKvEntry> serverAttributes = new ArrayList<>();
    serverAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
    serverAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
    DeviceAttributes attributes = new DeviceAttributes(new ArrayList<>(), serverAttributes, new ArrayList<>());
    Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
    Assert.assertTrue(filter.filter(ruleCtx, null));
    filter.stop();
}
Also used : BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) DeviceAttributes(org.thingsboard.server.extensions.api.device.DeviceAttributes) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) DeviceMetaData(org.thingsboard.server.extensions.api.device.DeviceMetaData) Test(org.junit.Test)

Aggregations

AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)16 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)10 DeviceId (org.thingsboard.server.common.data.id.DeviceId)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 DeviceAttributes (org.thingsboard.server.extensions.api.device.DeviceAttributes)5 DeviceMetaData (org.thingsboard.server.extensions.api.device.DeviceMetaData)5 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)4 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)3 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)3 HashMap (java.util.HashMap)2 ActorContext (akka.actor.ActorContext)1 ActorRef (akka.actor.ActorRef)1 LoggingAdapter (akka.event.LoggingAdapter)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 java.util (java.util)1