Search in sources :

Example 1 with RelationsQuery

use of org.thingsboard.rule.engine.data.RelationsQuery in project thingsboard by thingsboard.

the class TbGetRelatedAttrNodeConfiguration method defaultConfiguration.

@Override
public TbGetRelatedAttrNodeConfiguration defaultConfiguration() {
    TbGetRelatedAttrNodeConfiguration configuration = new TbGetRelatedAttrNodeConfiguration();
    Map<String, String> attrMapping = new HashMap<>();
    attrMapping.putIfAbsent("temperature", "tempo");
    configuration.setAttrMapping(attrMapping);
    configuration.setTelemetry(false);
    RelationsQuery relationsQuery = new RelationsQuery();
    relationsQuery.setDirection(EntitySearchDirection.FROM);
    relationsQuery.setMaxLevel(1);
    RelationEntityTypeFilter relationEntityTypeFilter = new RelationEntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.emptyList());
    relationsQuery.setFilters(Collections.singletonList(relationEntityTypeFilter));
    configuration.setRelationsQuery(relationsQuery);
    return configuration;
}
Also used : HashMap(java.util.HashMap) RelationsQuery(org.thingsboard.rule.engine.data.RelationsQuery) RelationEntityTypeFilter(org.thingsboard.server.common.data.relation.RelationEntityTypeFilter)

Example 2 with RelationsQuery

use of org.thingsboard.rule.engine.data.RelationsQuery in project thingsboard by thingsboard.

the class TbChangeOriginatorNodeConfiguration method defaultConfiguration.

@Override
public TbChangeOriginatorNodeConfiguration defaultConfiguration() {
    TbChangeOriginatorNodeConfiguration configuration = new TbChangeOriginatorNodeConfiguration();
    configuration.setOriginatorSource(TbChangeOriginatorNode.CUSTOMER_SOURCE);
    RelationsQuery relationsQuery = new RelationsQuery();
    relationsQuery.setDirection(EntitySearchDirection.FROM);
    relationsQuery.setMaxLevel(1);
    RelationEntityTypeFilter relationEntityTypeFilter = new RelationEntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.emptyList());
    relationsQuery.setFilters(Collections.singletonList(relationEntityTypeFilter));
    configuration.setRelationsQuery(relationsQuery);
    return configuration;
}
Also used : RelationsQuery(org.thingsboard.rule.engine.data.RelationsQuery) RelationEntityTypeFilter(org.thingsboard.server.common.data.relation.RelationEntityTypeFilter)

Example 3 with RelationsQuery

use of org.thingsboard.rule.engine.data.RelationsQuery in project thingsboard by thingsboard.

the class EntitiesRelatedEntityIdAsyncLoader method findEntityAsync.

public static ListenableFuture<EntityId> findEntityAsync(TbContext ctx, EntityId originator, RelationsQuery relationsQuery) {
    RelationService relationService = ctx.getRelationService();
    EntityRelationsQuery query = buildQuery(originator, relationsQuery);
    ListenableFuture<List<EntityRelation>> asyncRelation = relationService.findByQuery(ctx.getTenantId(), query);
    if (relationsQuery.getDirection() == EntitySearchDirection.FROM) {
        return Futures.transformAsync(asyncRelation, r -> CollectionUtils.isNotEmpty(r) ? Futures.immediateFuture(r.get(0).getTo()) : Futures.immediateFuture(null), MoreExecutors.directExecutor());
    } else if (relationsQuery.getDirection() == EntitySearchDirection.TO) {
        return Futures.transformAsync(asyncRelation, r -> CollectionUtils.isNotEmpty(r) ? Futures.immediateFuture(r.get(0).getFrom()) : Futures.immediateFuture(null), MoreExecutors.directExecutor());
    }
    return Futures.immediateFailedFuture(new IllegalStateException("Unknown direction"));
}
Also used : RelationService(org.thingsboard.server.dao.relation.RelationService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RelationsQuery(org.thingsboard.rule.engine.data.RelationsQuery) EntitySearchDirection(org.thingsboard.server.common.data.relation.EntitySearchDirection) RelationsSearchParameters(org.thingsboard.server.common.data.relation.RelationsSearchParameters) TbContext(org.thingsboard.rule.engine.api.TbContext) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) RelationService(org.thingsboard.server.dao.relation.RelationService) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) CollectionUtils(org.apache.commons.collections.CollectionUtils) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityRelationsQuery(org.thingsboard.server.common.data.relation.EntityRelationsQuery) EntityRelationsQuery(org.thingsboard.server.common.data.relation.EntityRelationsQuery) List(java.util.List)

Aggregations

RelationsQuery (org.thingsboard.rule.engine.data.RelationsQuery)3 RelationEntityTypeFilter (org.thingsboard.server.common.data.relation.RelationEntityTypeFilter)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 HashMap (java.util.HashMap)1 List (java.util.List)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 TbContext (org.thingsboard.rule.engine.api.TbContext)1 EntityId (org.thingsboard.server.common.data.id.EntityId)1 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)1 EntityRelationsQuery (org.thingsboard.server.common.data.relation.EntityRelationsQuery)1 EntitySearchDirection (org.thingsboard.server.common.data.relation.EntitySearchDirection)1 RelationsSearchParameters (org.thingsboard.server.common.data.relation.RelationsSearchParameters)1 RelationService (org.thingsboard.server.dao.relation.RelationService)1