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));
}
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());
}
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();
}
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();
}
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();
}
Aggregations