Commit 4f6ad3263f24e3f8b2639dd586377b1e25307bb4
1 parent
1ab1a8e0
Added edge_name_unq_key in saveEdge
Showing
1 changed file
with
12 additions
and
1 deletions
@@ -25,6 +25,7 @@ import org.apache.http.HttpHost; | @@ -25,6 +25,7 @@ import org.apache.http.HttpHost; | ||
25 | import org.apache.http.conn.ssl.DefaultHostnameVerifier; | 25 | import org.apache.http.conn.ssl.DefaultHostnameVerifier; |
26 | import org.apache.http.impl.client.CloseableHttpClient; | 26 | import org.apache.http.impl.client.CloseableHttpClient; |
27 | import org.apache.http.impl.client.HttpClients; | 27 | import org.apache.http.impl.client.HttpClients; |
28 | +import org.hibernate.exception.ConstraintViolationException; | ||
28 | import org.springframework.beans.factory.annotation.Autowired; | 29 | import org.springframework.beans.factory.annotation.Autowired; |
29 | import org.springframework.beans.factory.annotation.Value; | 30 | import org.springframework.beans.factory.annotation.Value; |
30 | import org.springframework.cache.Cache; | 31 | import org.springframework.cache.Cache; |
@@ -178,7 +179,17 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | @@ -178,7 +179,17 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic | ||
178 | public Edge saveEdge(Edge edge) { | 179 | public Edge saveEdge(Edge edge) { |
179 | log.trace("Executing saveEdge [{}]", edge); | 180 | log.trace("Executing saveEdge [{}]", edge); |
180 | edgeValidator.validate(edge, Edge::getTenantId); | 181 | edgeValidator.validate(edge, Edge::getTenantId); |
181 | - return edgeDao.save(edge.getTenantId(), edge); | 182 | + try { |
183 | + return edgeDao.save(edge.getTenantId(), edge); | ||
184 | + } catch (Exception t) { | ||
185 | + ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); | ||
186 | + if (e != null && e.getConstraintName() != null | ||
187 | + && e.getConstraintName().equalsIgnoreCase("edge_name_unq_key")) { | ||
188 | + throw new DataValidationException("Edge with such name already exists!"); | ||
189 | + } else { | ||
190 | + throw t; | ||
191 | + } | ||
192 | + } | ||
182 | } | 193 | } |
183 | 194 | ||
184 | @Override | 195 | @Override |