Commit 053d265430ce87a11163de2f2d11ae614771de02

Authored by Volodymyr Babak
2 parents 96dfc069 c24cf599

Merge branch 'develop/3.3-edge' of github.com:volodymyr-babak/thingsboard into develop/3.3-edge

... ... @@ -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
... ...