summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);