Search in sources :

Example 1 with ComplexFilterPredicate

use of org.thingsboard.server.common.data.query.ComplexFilterPredicate in project thingsboard by thingsboard.

the class ProfileState method addDynamicValuesRecursively.

private void addDynamicValuesRecursively(KeyFilterPredicate predicate, Set<AlarmConditionFilterKey> entityKeys, Set<AlarmConditionFilterKey> ruleKeys) {
    switch(predicate.getType()) {
        case STRING:
        case NUMERIC:
        case BOOLEAN:
            DynamicValue value = ((SimpleKeyFilterPredicate) predicate).getValue().getDynamicValue();
            if (value != null && (value.getSourceType() == DynamicValueSourceType.CURRENT_TENANT || value.getSourceType() == DynamicValueSourceType.CURRENT_CUSTOMER || value.getSourceType() == DynamicValueSourceType.CURRENT_DEVICE)) {
                AlarmConditionFilterKey entityKey = new AlarmConditionFilterKey(AlarmConditionKeyType.ATTRIBUTE, value.getSourceAttribute());
                entityKeys.add(entityKey);
                ruleKeys.add(entityKey);
            }
            break;
        case COMPLEX:
            for (KeyFilterPredicate child : ((ComplexFilterPredicate) predicate).getPredicates()) {
                addDynamicValuesRecursively(child, entityKeys, ruleKeys);
            }
            break;
    }
}
Also used : ComplexFilterPredicate(org.thingsboard.server.common.data.query.ComplexFilterPredicate) KeyFilterPredicate(org.thingsboard.server.common.data.query.KeyFilterPredicate) SimpleKeyFilterPredicate(org.thingsboard.server.common.data.query.SimpleKeyFilterPredicate) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue)

Example 2 with ComplexFilterPredicate

use of org.thingsboard.server.common.data.query.ComplexFilterPredicate in project thingsboard by thingsboard.

the class TbAbstractSubCtx method registerDynamicValues.

@SuppressWarnings("unchecked")
private void registerDynamicValues(KeyFilterPredicate predicate) {
    switch(predicate.getType()) {
        case STRING:
        case NUMERIC:
        case BOOLEAN:
            Optional<DynamicValue> value = getDynamicValueFromSimplePredicate((SimpleKeyFilterPredicate) predicate);
            if (value.isPresent()) {
                DynamicValue dynamicValue = value.get();
                DynamicValueKey key = new DynamicValueKey(predicate.getType(), dynamicValue.getSourceType(), dynamicValue.getSourceAttribute());
                dynamicValues.computeIfAbsent(key, tmp -> new ArrayList<>()).add(dynamicValue);
            }
            break;
        case COMPLEX:
            ((ComplexFilterPredicate) predicate).getPredicates().forEach(this::registerDynamicValues);
    }
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Setter(lombok.Setter) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue) ScheduledFuture(java.util.concurrent.ScheduledFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Getter(lombok.Getter) TsValue(org.thingsboard.server.common.data.query.TsValue) FilterPredicateType(org.thingsboard.server.common.data.query.FilterPredicateType) HashMap(java.util.HashMap) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) DynamicValueSourceType(org.thingsboard.server.common.data.query.DynamicValueSourceType) KeyFilter(org.thingsboard.server.common.data.query.KeyFilter) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) KeyFilterPredicate(org.thingsboard.server.common.data.query.KeyFilterPredicate) Map(java.util.Map) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityService(org.thingsboard.server.dao.entity.EntityService) AttributesService(org.thingsboard.server.dao.attributes.AttributesService) ComplexFilterPredicate(org.thingsboard.server.common.data.query.ComplexFilterPredicate) EntityKeyType(org.thingsboard.server.common.data.query.EntityKeyType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TelemetryWebSocketSessionRef(org.thingsboard.server.service.telemetry.TelemetryWebSocketSessionRef) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) UserId(org.thingsboard.server.common.data.id.UserId) List(java.util.List) SimpleKeyFilterPredicate(org.thingsboard.server.common.data.query.SimpleKeyFilterPredicate) Data(lombok.Data) Optional(java.util.Optional) TelemetrySubscriptionUpdate(org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate) TelemetryWebSocketService(org.thingsboard.server.service.telemetry.TelemetryWebSocketService) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ArrayList(java.util.ArrayList) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue)

Aggregations

ComplexFilterPredicate (org.thingsboard.server.common.data.query.ComplexFilterPredicate)2 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)2 KeyFilterPredicate (org.thingsboard.server.common.data.query.KeyFilterPredicate)2 SimpleKeyFilterPredicate (org.thingsboard.server.common.data.query.SimpleKeyFilterPredicate)2 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Data (lombok.Data)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 Slf4j (lombok.extern.slf4j.Slf4j)1