Commit 138a0ba5813a253a12ecab5a3cbdfbcf0576d1f7
Committed by
GitHub
Merge pull request #11 from BohdanSmetanyuk/bug/similar_edges_in_db
fixed bug with saving similar edges in db
Showing
3 changed files
with
18 additions
and
7 deletions
... | ... | @@ -32,14 +32,12 @@ import org.springframework.stereotype.Service; |
32 | 32 | import org.springframework.util.StringUtils; |
33 | 33 | import org.thingsboard.server.common.data.Customer; |
34 | 34 | import org.thingsboard.server.common.data.Dashboard; |
35 | -import org.thingsboard.server.common.data.DashboardInfo; | |
36 | 35 | import org.thingsboard.server.common.data.DataConstants; |
37 | 36 | import org.thingsboard.server.common.data.Device; |
38 | 37 | import org.thingsboard.server.common.data.EntitySubtype; |
39 | 38 | import org.thingsboard.server.common.data.EntityType; |
40 | 39 | import org.thingsboard.server.common.data.EntityView; |
41 | 40 | import org.thingsboard.server.common.data.Event; |
42 | -import org.thingsboard.server.common.data.ShortEdgeInfo; | |
43 | 41 | import org.thingsboard.server.common.data.Tenant; |
44 | 42 | import org.thingsboard.server.common.data.alarm.Alarm; |
45 | 43 | import org.thingsboard.server.common.data.asset.Asset; |
... | ... | @@ -47,13 +45,10 @@ import org.thingsboard.server.common.data.edge.Edge; |
47 | 45 | import org.thingsboard.server.common.data.edge.EdgeQueueEntityType; |
48 | 46 | import org.thingsboard.server.common.data.edge.EdgeQueueEntry; |
49 | 47 | import org.thingsboard.server.common.data.edge.EdgeSearchQuery; |
50 | -import org.thingsboard.server.common.data.id.AssetId; | |
51 | 48 | import org.thingsboard.server.common.data.id.CustomerId; |
52 | 49 | import org.thingsboard.server.common.data.id.DashboardId; |
53 | -import org.thingsboard.server.common.data.id.DeviceId; | |
54 | 50 | import org.thingsboard.server.common.data.id.EdgeId; |
55 | 51 | import org.thingsboard.server.common.data.id.EntityId; |
56 | -import org.thingsboard.server.common.data.id.EntityViewId; | |
57 | 52 | import org.thingsboard.server.common.data.id.RuleChainId; |
58 | 53 | import org.thingsboard.server.common.data.id.TenantId; |
59 | 54 | import org.thingsboard.server.common.data.page.TextPageData; |
... | ... | @@ -730,6 +725,11 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic |
730 | 725 | throw new DataValidationException("Edge with such name already exists!"); |
731 | 726 | } |
732 | 727 | ); |
728 | + edgeDao.findByRoutingKey(edge.getTenantId().getId(), edge.getRoutingKey()).ifPresent( | |
729 | + d -> { | |
730 | + throw new DataValidationException("Edge with such routing_key already exists"); | |
731 | + } | |
732 | + ); | |
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
... | ... | @@ -743,6 +743,13 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic |
743 | 743 | } |
744 | 744 | } |
745 | 745 | ); |
746 | + edgeDao.findByRoutingKey(edge.getTenantId().getId(), edge.getRoutingKey()).ifPresent( | |
747 | + e -> { | |
748 | + if (!e.getUuidId().equals(edge.getUuidId())) { | |
749 | + throw new DataValidationException("Edge with such routing_key already exists!"); | |
750 | + } | |
751 | + } | |
752 | + ); | |
746 | 753 | } |
747 | 754 | } |
748 | 755 | ... | ... |
... | ... | @@ -266,5 +266,7 @@ CREATE TABLE IF NOT EXISTS edge ( |
266 | 266 | routing_key varchar(255), |
267 | 267 | secret varchar(255), |
268 | 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 | 266 | routing_key varchar(255), |
267 | 267 | secret varchar(255), |
268 | 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 | 274 | CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint) | ... | ... |