Commit 9a749bf720c221267ec427088deb5a68eaef027f
1 parent
ef12b7be
fixed bug with saving similar edges in db
Showing
3 changed files
with
20 additions
and
3 deletions
@@ -23,6 +23,7 @@ import com.google.common.util.concurrent.ListenableFuture; | @@ -23,6 +23,7 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
23 | import com.google.common.util.concurrent.MoreExecutors; | 23 | import com.google.common.util.concurrent.MoreExecutors; |
24 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
25 | import org.apache.commons.codec.binary.Base64; | 25 | import org.apache.commons.codec.binary.Base64; |
26 | +import org.bouncycastle.util.test.FixedSecureRandom; | ||
26 | import org.springframework.beans.factory.annotation.Autowired; | 27 | import org.springframework.beans.factory.annotation.Autowired; |
27 | import org.springframework.cache.Cache; | 28 | import org.springframework.cache.Cache; |
28 | import org.springframework.cache.CacheManager; | 29 | import org.springframework.cache.CacheManager; |
@@ -730,6 +731,11 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -730,6 +731,11 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
730 | throw new DataValidationException("Edge with such name already exists!"); | 731 | throw new DataValidationException("Edge with such name already exists!"); |
731 | } | 732 | } |
732 | ); | 733 | ); |
734 | + edgeDao.findByRoutingKey(edge.getTenantId().getId(), edge.getRoutingKey()).ifPresent( | ||
735 | + d -> { | ||
736 | + throw new DataValidationException("Edge with such routing_key already exists"); | ||
737 | + } | ||
738 | + ); | ||
733 | } | 739 | } |
734 | } | 740 | } |
735 | 741 | ||
@@ -743,13 +749,20 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -743,13 +749,20 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
743 | } | 749 | } |
744 | } | 750 | } |
745 | ); | 751 | ); |
752 | + edgeDao.findByRoutingKey(edge.getTenantId().getId(), edge.getRoutingKey()).ifPresent( | ||
753 | + e -> { | ||
754 | + if (!e.getUuidId().equals(edge.getUuidId())) { | ||
755 | + throw new DataValidationException("Edge with such routing_key already exists!"); | ||
756 | + } | ||
757 | + } | ||
758 | + ); | ||
746 | } | 759 | } |
747 | } | 760 | } |
748 | 761 | ||
749 | @Override | 762 | @Override |
750 | protected void validateDataImpl(TenantId tenantId, Edge edge) { | 763 | protected void validateDataImpl(TenantId tenantId, Edge edge) { |
751 | if (StringUtils.isEmpty(edge.getType())) { | 764 | if (StringUtils.isEmpty(edge.getType())) { |
752 | - throw new DataValidationException("Edge type should be specified!"); | 765 | + throw new DataValidationException("Edge typeshould be specified!"); |
753 | } | 766 | } |
754 | if (StringUtils.isEmpty(edge.getName())) { | 767 | if (StringUtils.isEmpty(edge.getName())) { |
755 | throw new DataValidationException("Edge name should be specified!"); | 768 | throw new DataValidationException("Edge name should be specified!"); |
@@ -266,5 +266,7 @@ CREATE TABLE IF NOT EXISTS edge ( | @@ -266,5 +266,7 @@ CREATE TABLE IF NOT EXISTS edge ( | ||
266 | routing_key varchar(255), | 266 | routing_key varchar(255), |
267 | secret varchar(255), | 267 | secret varchar(255), |
268 | search_text varchar(255), | 268 | search_text varchar(255), |
269 | - tenant_id varchar(31) | 269 | + tenant_id varchar(31), |
270 | + CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name), | ||
271 | + CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key) | ||
270 | ); | 272 | ); |
@@ -266,7 +266,9 @@ CREATE TABLE IF NOT EXISTS edge ( | @@ -266,7 +266,9 @@ CREATE TABLE IF NOT EXISTS edge ( | ||
266 | routing_key varchar(255), | 266 | routing_key varchar(255), |
267 | secret varchar(255), | 267 | secret varchar(255), |
268 | search_text varchar(255), | 268 | search_text varchar(255), |
269 | - tenant_id varchar(31) | 269 | + tenant_id varchar(31), |
270 | + CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name), | ||
271 | + CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key) | ||
270 | ); | 272 | ); |
271 | 273 | ||
272 | CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint) | 274 | CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint) |