summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2020-11-18 16:29:15 +0000
committerniamhcore <niamh.core@est.tech>2020-11-19 09:39:53 +0000
commit181aa2b8d9dd612805cdb5fed749566b171b5a35 (patch)
tree1642a5a945ce24c7ef5fff610fc6a373a0c978a7
parent5a1b4b66b68776e0a13c98d2f41fe39f957fdf4b (diff)
Fix HTTP response for duplicate module
Issue-ID: CPS-80 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I27b83d671a9f235a4e926ebe9897add36080fd6f
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java11
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/CpService.java1
2 files changed, 10 insertions, 2 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java
index a54e506466..03679b3160 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java
@@ -20,12 +20,14 @@
package org.onap.cps.spi.impl;
+import org.onap.cps.exceptions.CpsValidationException;
import org.onap.cps.spi.ModelPersistenceService;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Module;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.ModuleRepository;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;
@Component
@@ -46,6 +48,11 @@ public class ModelPersistenceServiceImpl implements ModelPersistenceService {
}
dataspace.setId(dataspaceRepository.getByName(dataspaceName).getId());
final Module module = new Module(namespace, moduleContent, revision, dataspace);
- moduleRepository.save(module);
+ try {
+ moduleRepository.save(module);
+ } catch (final DataIntegrityViolationException ex) {
+ throw new CpsValidationException("Duplicate Entry",
+ String.format("Module already exist in dataspace %s.", dataspaceName));
+ }
}
-} \ No newline at end of file
+}
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpService.java b/cps-service/src/main/java/org/onap/cps/api/CpService.java
index 6b59949ca0..726ca0f28d 100755
--- a/cps-service/src/main/java/org/onap/cps/api/CpService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpService.java
@@ -51,6 +51,7 @@ public interface CpService {
*
* @param schemaContext the schema context
* @param dataspaceName the dataspace name
+ * @throws CpsValidationException if input data already exists.
*/
void storeSchemaContext(SchemaContext schemaContext, String dataspaceName);