Commit c24cf599804bbb2785c77f960a0183ca3780f61d
Committed by
GitHub
Merge pull request #68 from deaflynx/develop/3.3-edge
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 | 25 | import org.apache.http.conn.ssl.DefaultHostnameVerifier; |
26 | 26 | import org.apache.http.impl.client.CloseableHttpClient; |
27 | 27 | import org.apache.http.impl.client.HttpClients; |
28 | +import org.hibernate.exception.ConstraintViolationException; | |
28 | 29 | import org.springframework.beans.factory.annotation.Autowired; |
29 | 30 | import org.springframework.beans.factory.annotation.Value; |
30 | 31 | import org.springframework.cache.Cache; |
... | ... | @@ -178,7 +179,17 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic |
178 | 179 | public Edge saveEdge(Edge edge) { |
179 | 180 | log.trace("Executing saveEdge [{}]", edge); |
180 | 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 | 195 | @Override | ... | ... |