use of org.thingsboard.server.common.data.kv.AttributeKvEntry in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicClientAttributesTest.
@Test
public void basicClientAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("doubleValue == 1.0 && booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
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 basicClientAttributesStressTest.
@Test(timeout = 30000)
public void basicClientAttributesStressTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("doubleValue == 1.0 && booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
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));
for (int i = 0; i < 10000; i++) {
Assert.assertTrue(filter.filter(ruleCtx, null));
}
filter.stop();
}
use of org.thingsboard.server.common.data.kv.AttributeKvEntry in project thingsboard by thingsboard.
the class NashornJsEvaluator method convertListEntries.
public static Bindings convertListEntries(Bindings bindings, String attributesVarName, Collection<AttributeKvEntry> attributes) {
Map<String, Object> attrMap = new HashMap<>();
for (AttributeKvEntry attr : attributes) {
if (!CLIENT_SIDE.equalsIgnoreCase(attr.getKey()) && !SERVER_SIDE.equalsIgnoreCase(attr.getKey()) && !SHARED.equalsIgnoreCase(attr.getKey())) {
bindings.put(attr.getKey(), getValue(attr));
}
attrMap.put(attr.getKey(), getValue(attr));
}
bindings.put(attributesVarName, attrMap);
return bindings;
}
use of org.thingsboard.server.common.data.kv.AttributeKvEntry in project thingsboard by thingsboard.
the class NashornJsEvaluator method updateBindings.
public static Bindings updateBindings(Bindings bindings, UpdateAttributesRequest msg) {
Map<String, Object> attrMap = (Map<String, Object>) bindings.get(CLIENT_SIDE);
for (AttributeKvEntry attr : msg.getAttributes()) {
if (!CLIENT_SIDE.equalsIgnoreCase(attr.getKey()) && !SERVER_SIDE.equalsIgnoreCase(attr.getKey()) && !SHARED.equalsIgnoreCase(attr.getKey())) {
bindings.put(attr.getKey(), getValue(attr));
}
attrMap.put(attr.getKey(), getValue(attr));
}
bindings.put(CLIENT_SIDE, attrMap);
return bindings;
}
use of org.thingsboard.server.common.data.kv.AttributeKvEntry in project thingsboard by thingsboard.
the class DeviceActorMessageProcessor method processAttributesUpdate.
void processAttributesUpdate(ActorContext context, DeviceAttributesEventNotificationMsg msg) {
refreshAttributes(msg);
if (attributeSubscriptions.size() > 0) {
ToDeviceMsg notification = null;
if (msg.isDeleted()) {
List<AttributeKey> sharedKeys = msg.getDeletedKeys().stream().filter(key -> DataConstants.SHARED_SCOPE.equals(key.getScope())).collect(Collectors.toList());
notification = new AttributesUpdateNotification(BasicAttributeKVMsg.fromDeleted(sharedKeys));
} else {
if (DataConstants.SHARED_SCOPE.equals(msg.getScope())) {
List<AttributeKvEntry> attributes = new ArrayList<>(msg.getValues());
if (attributes.size() > 0) {
notification = new AttributesUpdateNotification(BasicAttributeKVMsg.fromShared(attributes));
} else {
logger.debug("[{}] No public server side attributes changed!", deviceId);
}
}
}
if (notification != null) {
ToDeviceMsg finalNotification = notification;
attributeSubscriptions.entrySet().forEach(sub -> {
ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(finalNotification, sub.getKey());
sendMsgToSessionActor(response, sub.getValue().getServer());
});
}
} else {
logger.debug("[{}] No registered attributes subscriptions to process!", deviceId);
}
}
Aggregations