diff options
author | niamhcore <niamh.core@est.tech> | 2020-11-18 16:29:15 +0000 |
---|---|---|
committer | niamhcore <niamh.core@est.tech> | 2020-11-19 09:39:53 +0000 |
commit | 181aa2b8d9dd612805cdb5fed749566b171b5a35 (patch) | |
tree | 1642a5a945ce24c7ef5fff610fc6a373a0c978a7 /cps-ri/src/main/java/org/onap | |
parent | 5a1b4b66b68776e0a13c98d2f41fe39f957fdf4b (diff) |
Fix HTTP response for duplicate module
Issue-ID: CPS-80
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: I27b83d671a9f235a4e926ebe9897add36080fd6f
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-rwxr-xr-x | cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java | 11 |
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 +} |