aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/main')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java21
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java10
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java16
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java26
4 files changed, 33 insertions, 40 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 684750c459..f119507214 100644
--- 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
@@ -20,12 +20,11 @@
package org.onap.cps.spi.impl;
-import org.onap.cps.exceptions.CpsNotFoundException;
-import org.onap.cps.exceptions.CpsValidationException;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
import org.onap.cps.spi.entities.Module;
+import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.FragmentRepository;
@@ -51,23 +50,15 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
final String anchorName = anchor.getAnchorName();
try {
final Dataspace dataspace = dataspaceRepository.getByName(anchor.getDataspaceName());
- final Module module =
- moduleRepository.getByDataspaceAndNamespaceAndRevision(dataspace,
- anchor.getNamespace(), anchor.getRevision());
-
- final Fragment fragment = Fragment.builder().xpath(anchorName)
- .anchorName(anchorName)
- .dataspace(dataspace).module(module).build();
+ final Module module = moduleRepository
+ .getByDataspaceAndNamespaceAndRevision(dataspace, anchor.getNamespace(), anchor.getRevision());
+ final Fragment fragment =
+ Fragment.builder().xpath(anchorName).anchorName(anchorName).dataspace(dataspace).module(module).build();
fragmentRepository.save(fragment);
return anchorName;
- } catch (final CpsNotFoundException ex) {
- throw new CpsValidationException("Validation Error",
- "Dataspace and/or Module do not exist.");
} catch (final DataIntegrityViolationException ex) {
- throw new CpsValidationException("Duplication Error",
- String.format("Anchor with name %s already exist in dataspace %s.",
- anchorName, anchor.getDataspaceName()));
+ throw new AnchorAlreadyDefinedException(anchor.getDataspaceName(), anchorName, ex);
}
}
}
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 52f8034575..e63ae5962f 100644
--- 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
@@ -20,9 +20,6 @@
package org.onap.cps.spi.impl;
-import static org.onap.cps.exceptions.CpsExceptionBuilder.duplicateSchemaSetException;
-import static org.onap.cps.exceptions.CpsExceptionBuilder.invalidDataspaceException;
-
import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Map;
@@ -33,6 +30,7 @@ import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.SchemaSet;
import org.onap.cps.spi.entities.YangResource;
+import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.SchemaSetRepository;
import org.onap.cps.spi.repository.YangResourceRepository;
@@ -65,9 +63,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
final Set<String> yangResourcesAsStrings) {
- final Dataspace dataspace = dataspaceRepository.findByName(dataspaceName)
- .orElseThrow(() -> invalidDataspaceException(dataspaceName));
-
+ final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
final Set<YangResource> yangResources = synchronizeYangResources(yangResourcesAsStrings);
final SchemaSet schemaSet = new SchemaSet();
schemaSet.setName(schemaSetName);
@@ -76,7 +72,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
try {
schemaSetRepository.save(schemaSet);
} catch (final DataIntegrityViolationException e) {
- throw duplicateSchemaSetException(dataspaceName, schemaSetName);
+ throw new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, e);
}
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
index 4b649167f3..ce231c9c51 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
@@ -21,8 +21,8 @@ package org.onap.cps.spi.repository;
import java.util.Optional;
import javax.validation.constraints.NotNull;
-import org.onap.cps.exceptions.DataspaceNotFoundException;
import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -32,8 +32,14 @@ public interface DataspaceRepository extends JpaRepository<Dataspace, Integer> {
Optional<Dataspace> findByName(@NotNull String name);
- default Dataspace getByName(@NotNull String name) {
- return findByName(name).orElseThrow(
- () -> new DataspaceNotFoundException("Dataspace " + name + " does not exist."));
+ /**
+ * Get a dataspace by name.
+ * throws a DataspaceNotFoundException if it does not exist
+ *
+ * @param name the name of the dataspace
+ * @return the Dataspace found
+ */
+ default Dataspace getByName(@NotNull final String name) {
+ return findByName(name).orElseThrow(() -> new DataspaceNotFoundException(name));
}
-} \ No newline at end of file
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java
index d3a8bc1f09..cab7e19300 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java
@@ -22,9 +22,9 @@ package org.onap.cps.spi.repository;
import java.util.Optional;
import javax.validation.constraints.NotNull;
-import org.onap.cps.exceptions.CpsNotFoundException;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Module;
+import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -32,24 +32,24 @@ import org.springframework.stereotype.Repository;
public interface ModuleRepository extends JpaRepository<Module, Integer> {
Optional<Module> findByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace,
- @NotNull String namespace,
- @NotNull String revision);
+ @NotNull String namespace,
+ @NotNull String revision);
/**
* This method gets a Module by dataspace, namespace and revision.
*
* @param dataspace the dataspace
* @param namespace the namespace
- * @param revision the revision
+ * @param revision the revision
* @return the Module
- * @throws CpsNotFoundException if Module not found
+ * @throws NotFoundInDataspaceException if Module not found
*/
- default Module getByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace, @NotNull String namespace,
- @NotNull String revision) {
- return findByDataspaceAndNamespaceAndRevision(dataspace, namespace,
- revision)
- .orElseThrow(() -> new CpsNotFoundException("Validation Error", String.format(
- "Module with dataspace %s, revision %s does not exist in namespace %s.",
- dataspace.getName(), revision, namespace)));
+ default Module getByDataspaceAndNamespaceAndRevision(@NotNull final Dataspace dataspace,
+ @NotNull final String namespace,
+ @NotNull final String revision) {
+ return findByDataspaceAndNamespaceAndRevision(dataspace, namespace, revision)
+ .orElseThrow(() -> new NotFoundInDataspaceException("Validation Error", String.format(
+ "Module with dataspace %s, revision %s does not exist in namespace %s.",
+ dataspace.getName(), revision, namespace)));
}
-} \ No newline at end of file
+}