Commit 6cdb54970435156281e3cdd74195aa08e0977401

Authored by Artem Babak
1 parent 720c89f1

Added ConstraintViolationException for saveEdge

@@ -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;
@@ -172,6 +173,21 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -172,6 +173,21 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
172 public Edge saveEdge(Edge edge) { 173 public Edge saveEdge(Edge edge) {
173 log.trace("Executing saveEdge [{}]", edge); 174 log.trace("Executing saveEdge [{}]", edge);
174 edgeValidator.validate(edge, Edge::getTenantId); 175 edgeValidator.validate(edge, Edge::getTenantId);
  176 + Edge savedEdge;
  177 + if (!sqlDatabaseUsed) {
  178 + savedEdge = edgeDao.save(edge.getTenantId(), edge);
  179 + } else {
  180 + try {
  181 + savedEdge = edgeDao.save(edge.getTenantId(), edge);
  182 + } catch (Exception t) {
  183 + ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
  184 + if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("edge_name_unq_key")) {
  185 + throw new DataValidationException("Edge with such name already exists!");
  186 + } else {
  187 + throw t;
  188 + }
  189 + }
  190 + }
175 return edgeDao.save(edge.getTenantId(), edge); 191 return edgeDao.save(edge.getTenantId(), edge);
176 } 192 }
177 193