aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-03-15 15:54:12 +0000
committerniamhcore <niamh.core@est.tech>2021-03-31 13:30:09 +0100
commit22bcf714b12e21352c1b90ba72ffc65b0cf5d6e7 (patch)
tree81cb5544bf317f264a7677c6ce614cf88ec16c1d /cps-ri/src/main/java
parent4663fd3a91ddee17393d6e4b1452213208ba5243 (diff)
Internal Server Error when creating the same data node twice
Drop back to honolulu This change adds a generic exception handler class for a already defined object and handles a JsonSyntaxException. Issue-ID: CPS-290 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: Ie645237b5dd5b8e2b1d074c5613e7da560f57484
Diffstat (limited to 'cps-ri/src/main/java')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java7
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java10
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java4
3 files changed, 13 insertions, 8 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
index ddbfeb2283..1b8f1968bc 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
@@ -27,8 +27,7 @@ import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.SchemaSetEntity;
-import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
-import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.repository.AnchorRepository;
import org.onap.cps.spi.repository.DataspaceRepository;
@@ -54,7 +53,7 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
try {
dataspaceRepository.save(new DataspaceEntity(dataspaceName));
} catch (final DataIntegrityViolationException e) {
- throw new DataspaceAlreadyDefinedException(dataspaceName, e);
+ throw AlreadyDefinedException.forDataspace(dataspaceName, e);
}
}
@@ -71,7 +70,7 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
try {
anchorRepository.save(anchorEntity);
} catch (final DataIntegrityViolationException e) {
- throw new AnchorAlreadyDefinedException(dataspaceName, anchorName, e);
+ throw AlreadyDefinedException.forAnchor(anchorName, dataspaceName, e);
}
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index 4cfa78b3e3..26aa4ac0bd 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -36,6 +36,7 @@ import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.FragmentEntity;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.spi.query.CpsPathQuery;
@@ -44,6 +45,7 @@ import org.onap.cps.spi.repository.AnchorRepository;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.FragmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
@Service
@@ -76,7 +78,11 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
final FragmentEntity fragmentEntity = convertToFragmentWithAllDescendants(dataspaceEntity, anchorEntity,
dataNode);
- fragmentRepository.save(fragmentEntity);
+ try {
+ fragmentRepository.save(fragmentEntity);
+ } catch (final DataIntegrityViolationException exception) {
+ throw AlreadyDefinedException.forDataNode(dataNode.getXpath(), anchorName, exception);
+ }
}
/**
@@ -139,7 +145,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
.getLeafName(), cpsPathQuery.getLeafValue());
} else {
fragmentEntities = fragmentRepository
- .getByAnchorAndEndsWithXpath(anchorEntity.getId(), cpsPathQuery.getEndsWith());
+ .getByAnchorAndEndsWithXpath(anchorEntity.getId(), cpsPathQuery.getEndsWith());
}
return fragmentEntities.stream()
.map(fragmentEntity -> toDataNode(fragmentEntity, fetchDescendantsOption))
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
index b28beb42c9..51d5f5754a 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -35,7 +35,7 @@ import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.SchemaSetEntity;
import org.onap.cps.spi.entities.YangResourceEntity;
-import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.SchemaSetInUseException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.repository.AnchorRepository;
@@ -83,7 +83,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
try {
schemaSetRepository.save(schemaSetEntity);
} catch (final DataIntegrityViolationException e) {
- throw new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, e);
+ throw AlreadyDefinedException.forSchemaSet(schemaSetName, dataspaceName, e);
}
}