use of org.openremote.model.value.ValueFilter in project openremote by openremote.
the class ProtocolUtil method createGenericAttributeMessageConsumer.
public static Consumer<String> createGenericAttributeMessageConsumer(String assetId, Attribute<?> attribute, AgentLink<?> agentLink, Supplier<Long> currentMillisSupplier, Consumer<AttributeState> stateConsumer) {
ValueFilter[] matchFilters = agentLink.getMessageMatchFilters().orElse(null);
ValuePredicate matchPredicate = agentLink.getMessageMatchPredicate().orElse(null);
if (matchPredicate == null) {
return null;
}
return message -> {
if (!TextUtil.isNullOrEmpty(message)) {
Object messageFiltered = applyValueFilters(message, matchFilters);
if (messageFiltered != null) {
if (matchPredicate.asPredicate(currentMillisSupplier).test(messageFiltered)) {
Protocol.LOG.finest("Inbound message meets attribute matching meta so writing state to state consumer for attribute: asssetId=" + assetId + ", attribute=" + attribute.getName());
stateConsumer.accept(new AttributeState(assetId, attribute.getName(), message));
}
}
}
};
}
Aggregations