|
|
|
@ -15,9 +15,6 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.dao.sql.rule; |
|
|
|
|
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import com.google.common.util.concurrent.MoreExecutors; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.repository.CrudRepository; |
|
|
|
@ -25,19 +22,13 @@ import org.springframework.stereotype.Component; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChain; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChainType; |
|
|
|
import org.thingsboard.server.dao.DaoUtil; |
|
|
|
import org.thingsboard.server.dao.model.sql.RuleChainEntity; |
|
|
|
import org.thingsboard.server.dao.relation.RelationDao; |
|
|
|
import org.thingsboard.server.dao.rule.RuleChainDao; |
|
|
|
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@ -48,9 +39,6 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R |
|
|
|
@Autowired |
|
|
|
private RuleChainRepository ruleChainRepository; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RelationDao relationDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected Class<RuleChainEntity> getEntityClass() { |
|
|
|
return RuleChainEntity.class; |
|
|
|
@ -91,7 +79,6 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R |
|
|
|
@Override |
|
|
|
public PageData<RuleChain> findRuleChainsByTenantIdAndEdgeId(UUID tenantId, UUID edgeId, PageLink pageLink) { |
|
|
|
log.debug("Try to find rule chains by tenantId [{}], edgeId [{}] and pageLink [{}]", tenantId, edgeId, pageLink); |
|
|
|
|
|
|
|
return DaoUtil.toPageData(ruleChainRepository |
|
|
|
.findByTenantIdAndEdgeId( |
|
|
|
tenantId, |
|
|
|
@ -101,21 +88,13 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ListenableFuture<List<RuleChain>> findAutoAssignToEdgeRuleChainsByTenantId(UUID tenantId) { |
|
|
|
public PageData<RuleChain> findAutoAssignToEdgeRuleChainsByTenantId(UUID tenantId, PageLink pageLink) { |
|
|
|
log.debug("Try to find auto assign to edge rule chains by tenantId [{}]", tenantId); |
|
|
|
ListenableFuture<List<EntityRelation>> relations = |
|
|
|
relationDao.findAllByFromAndType(new TenantId(tenantId), new TenantId(tenantId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE_AUTO_ASSIGN_RULE_CHAIN); |
|
|
|
return Futures.transformAsync(relations, input -> { |
|
|
|
if (input != null && !input.isEmpty()) { |
|
|
|
List<ListenableFuture<RuleChain>> ruleChainsFutures = new ArrayList<>(input.size()); |
|
|
|
for (EntityRelation relation : input) { |
|
|
|
ruleChainsFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId())); |
|
|
|
} |
|
|
|
return Futures.successfulAsList(ruleChainsFutures); |
|
|
|
} else { |
|
|
|
return Futures.immediateFuture(Collections.emptyList()); |
|
|
|
} |
|
|
|
}, MoreExecutors.directExecutor()); |
|
|
|
return DaoUtil.toPageData(ruleChainRepository |
|
|
|
.findAutoAssignByTenantId( |
|
|
|
tenantId, |
|
|
|
Objects.toString(pageLink.getTextSearch(), ""), |
|
|
|
DaoUtil.toPageable(pageLink))); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|