|
|
|
@ -15,7 +15,6 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.dao.edge; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.google.common.base.Function; |
|
|
|
@ -27,6 +26,7 @@ import org.hibernate.exception.ConstraintViolationException; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.event.TransactionalEventListener; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.EntitySubtype; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
@ -46,7 +46,7 @@ import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
|
import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChain; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleNode; |
|
|
|
import org.thingsboard.server.dao.entity.AbstractCachedEntityService; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import org.thingsboard.server.dao.relation.RelationService; |
|
|
|
@ -62,6 +62,7 @@ import java.util.Collections; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static org.thingsboard.server.dao.DaoUtil.toUUIDs; |
|
|
|
@ -78,8 +79,6 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E |
|
|
|
public static final String INCORRECT_CUSTOMER_ID = "Incorrect customerId "; |
|
|
|
public static final String INCORRECT_EDGE_ID = "Incorrect edgeId "; |
|
|
|
|
|
|
|
private static final ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
|
|
|
private static final int DEFAULT_PAGE_SIZE = 1000; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@ -451,16 +450,19 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId) { |
|
|
|
public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId, String tbRuleChainInputNodeClassName) { |
|
|
|
List<RuleChain> edgeRuleChains = findEdgeRuleChains(tenantId, edgeId); |
|
|
|
List<RuleChainId> edgeRuleChainIds = edgeRuleChains.stream().map(IdBased::getId).collect(Collectors.toList()); |
|
|
|
ObjectNode result = mapper.createObjectNode(); |
|
|
|
ObjectNode result = JacksonUtil.OBJECT_MAPPER.createObjectNode(); |
|
|
|
for (RuleChain edgeRuleChain : edgeRuleChains) { |
|
|
|
List<RuleChainConnectionInfo> connectionInfos = |
|
|
|
ruleChainService.loadRuleChainMetaData(edgeRuleChain.getTenantId(), edgeRuleChain.getId()).getRuleChainConnections(); |
|
|
|
if (connectionInfos != null && !connectionInfos.isEmpty()) { |
|
|
|
List<RuleNode> ruleNodes = |
|
|
|
ruleChainService.loadRuleChainMetaData(edgeRuleChain.getTenantId(), edgeRuleChain.getId()).getNodes(); |
|
|
|
if (ruleNodes != null && !ruleNodes.isEmpty()) { |
|
|
|
List<RuleChainId> connectedRuleChains = |
|
|
|
connectionInfos.stream().map(RuleChainConnectionInfo::getTargetRuleChainId).collect(Collectors.toList()); |
|
|
|
ruleNodes.stream() |
|
|
|
.filter(rn -> rn.getType().equals(tbRuleChainInputNodeClassName)) |
|
|
|
.map(rn -> new RuleChainId(UUID.fromString(rn.getConfiguration().get("ruleChainId").asText()))) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
List<String> missingRuleChains = new ArrayList<>(); |
|
|
|
for (RuleChainId connectedRuleChain : connectedRuleChains) { |
|
|
|
if (!edgeRuleChainIds.contains(connectedRuleChain)) { |
|
|
|
@ -469,7 +471,7 @@ public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, E |
|
|
|
} |
|
|
|
} |
|
|
|
if (!missingRuleChains.isEmpty()) { |
|
|
|
ArrayNode array = mapper.createArrayNode(); |
|
|
|
ArrayNode array = JacksonUtil.OBJECT_MAPPER.createArrayNode(); |
|
|
|
for (String missingRuleChain : missingRuleChains) { |
|
|
|
array.add(missingRuleChain); |
|
|
|
} |
|
|
|
|