Search in sources :

Example 1 with ValuePredicate

use of org.openremote.model.query.filter.ValuePredicate 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));
                }
            }
        }
    };
}
Also used : NULL_LITERAL(org.openremote.model.util.ValueUtil.NULL_LITERAL) Protocol(org.openremote.model.asset.agent.Protocol) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Hex(org.apache.commons.codec.binary.Hex) ValueUtil(org.openremote.model.util.ValueUtil) DYNAMIC_VALUE_PLACEHOLDER(org.openremote.model.asset.agent.Protocol.DYNAMIC_VALUE_PLACEHOLDER) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Level(java.util.logging.Level) ValueUtil.applyValueFilters(org.openremote.model.util.ValueUtil.applyValueFilters) AgentLink(org.openremote.model.asset.agent.AgentLink) Attribute(org.openremote.model.attribute.Attribute) Locale(java.util.Locale) TextUtil(org.openremote.model.util.TextUtil) JsonNodeType(com.fasterxml.jackson.databind.node.JsonNodeType) AttributeState(org.openremote.model.attribute.AttributeState) ValueType(org.openremote.model.value.ValueType) BinaryCodec(org.apache.commons.codec.binary.BinaryCodec) ValuePredicate(org.openremote.model.query.filter.ValuePredicate) Pair(org.openremote.model.util.Pair) Consumer(java.util.function.Consumer) ValueFilter(org.openremote.model.value.ValueFilter) TsIgnore(org.openremote.model.util.TsIgnore) Optional(java.util.Optional) AttributeLink(org.openremote.model.attribute.AttributeLink) AttributeExecuteStatus(org.openremote.model.attribute.AttributeExecuteStatus) AttributeState(org.openremote.model.attribute.AttributeState) ValuePredicate(org.openremote.model.query.filter.ValuePredicate) ValueFilter(org.openremote.model.value.ValueFilter)

Aggregations

JsonNodeType (com.fasterxml.jackson.databind.node.JsonNodeType)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 Level (java.util.logging.Level)1 BinaryCodec (org.apache.commons.codec.binary.BinaryCodec)1 Hex (org.apache.commons.codec.binary.Hex)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 AgentLink (org.openremote.model.asset.agent.AgentLink)1 Protocol (org.openremote.model.asset.agent.Protocol)1 DYNAMIC_VALUE_PLACEHOLDER (org.openremote.model.asset.agent.Protocol.DYNAMIC_VALUE_PLACEHOLDER)1 Attribute (org.openremote.model.attribute.Attribute)1 AttributeExecuteStatus (org.openremote.model.attribute.AttributeExecuteStatus)1 AttributeLink (org.openremote.model.attribute.AttributeLink)1 AttributeState (org.openremote.model.attribute.AttributeState)1 ValuePredicate (org.openremote.model.query.filter.ValuePredicate)1 Pair (org.openremote.model.util.Pair)1