|
|
@ -51,6 +51,7 @@ import org.thingsboard.server.common.data.rule.RuleChainUpdateResult; |
|
|
import org.thingsboard.server.common.data.rule.RuleNode; |
|
|
import org.thingsboard.server.common.data.rule.RuleNode; |
|
|
import org.thingsboard.server.common.data.rule.RuleNodeUpdateResult; |
|
|
import org.thingsboard.server.common.data.rule.RuleNodeUpdateResult; |
|
|
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|
|
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|
|
|
|
|
import org.thingsboard.server.dao.entity.EntityCountService; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
import org.thingsboard.server.dao.service.PaginatedRemover; |
|
|
@ -90,6 +91,9 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
|
|
@Autowired |
|
|
@Autowired |
|
|
private RuleNodeDao ruleNodeDao; |
|
|
private RuleNodeDao ruleNodeDao; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private EntityCountService entityCountService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private DataValidator<RuleChain> ruleChainValidator; |
|
|
private DataValidator<RuleChain> ruleChainValidator; |
|
|
|
|
|
|
|
|
@ -98,7 +102,11 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
|
|
public RuleChain saveRuleChain(RuleChain ruleChain) { |
|
|
public RuleChain saveRuleChain(RuleChain ruleChain) { |
|
|
ruleChainValidator.validate(ruleChain, RuleChain::getTenantId); |
|
|
ruleChainValidator.validate(ruleChain, RuleChain::getTenantId); |
|
|
try { |
|
|
try { |
|
|
return ruleChainDao.save(ruleChain.getTenantId(), ruleChain); |
|
|
RuleChain savedRuleChain = ruleChainDao.save(ruleChain.getTenantId(), ruleChain); |
|
|
|
|
|
if (ruleChain.getId() == null) { |
|
|
|
|
|
entityCountService.publishCountEntityEvictEvent(ruleChain.getTenantId(), EntityType.RULE_CHAIN); |
|
|
|
|
|
} |
|
|
|
|
|
return savedRuleChain; |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
checkConstraintViolation(e, "rule_chain_external_id_unq_key", "Rule Chain with such external id already exists!"); |
|
|
checkConstraintViolation(e, "rule_chain_external_id_unq_key", "Rule Chain with such external id already exists!"); |
|
|
throw e; |
|
|
throw e; |
|
|
@ -696,6 +704,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
|
|
|
|
|
|
|
|
private void checkRuleNodesAndDelete(TenantId tenantId, RuleChainId ruleChainId) { |
|
|
private void checkRuleNodesAndDelete(TenantId tenantId, RuleChainId ruleChainId) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
entityCountService.publishCountEntityEvictEvent(tenantId, EntityType.RULE_CHAIN); |
|
|
ruleChainDao.removeById(tenantId, ruleChainId.getId()); |
|
|
ruleChainDao.removeById(tenantId, ruleChainId.getId()); |
|
|
} catch (Exception t) { |
|
|
} catch (Exception t) { |
|
|
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
|
|
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
|
|
@ -737,6 +746,11 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
|
|
return Optional.ofNullable(hasId); |
|
|
return Optional.ofNullable(hasId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public long countByTenantId(TenantId tenantId) { |
|
|
|
|
|
return ruleChainDao.countByTenantId(tenantId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public EntityType getEntityType() { |
|
|
public EntityType getEntityType() { |
|
|
return EntityType.RULE_CHAIN; |
|
|
return EntityType.RULE_CHAIN; |
|
|
|