summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/main/java')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java11
1 files changed, 9 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
+}