Combine alreadyDefinedException classes
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / impl / CpsDataPersistenceServiceImpl.java
index 7fed534..f4afe3d 100644 (file)
@@ -52,7 +52,6 @@ import org.onap.cps.spi.entities.AnchorEntity;
 import org.onap.cps.spi.entities.DataspaceEntity;
 import org.onap.cps.spi.entities.FragmentEntity;
 import org.onap.cps.spi.exceptions.AlreadyDefinedException;
-import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
 import org.onap.cps.spi.exceptions.ConcurrencyException;
 import org.onap.cps.spi.exceptions.CpsAdminException;
 import org.onap.cps.spi.exceptions.CpsPathException;
@@ -105,12 +104,12 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         for (final Collection<DataNode> newList : newLists) {
             try {
                 addChildrenDataNodes(anchorEntity, parentNodeXpath, newList);
-            } catch (final AlreadyDefinedExceptionBatch e) {
-                failedXpaths.addAll(e.getAlreadyDefinedXpaths());
+            } catch (final AlreadyDefinedException alreadyDefinedException) {
+                failedXpaths.addAll(alreadyDefinedException.getAlreadyDefinedObjectNames());
             }
         }
         if (!failedXpaths.isEmpty()) {
-            throw new AlreadyDefinedExceptionBatch(failedXpaths);
+            throw AlreadyDefinedException.forDataNodes(failedXpaths, anchorEntity.getName());
         }
     }
 
@@ -122,7 +121,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         try {
             fragmentRepository.save(newChildAsFragmentEntity);
         } catch (final DataIntegrityViolationException e) {
-            throw AlreadyDefinedException.forDataNode(newChild.getXpath(), anchorEntity.getName(), e);
+            throw AlreadyDefinedException.forDataNodes(Collections.singletonList(newChild.getXpath()),
+                    anchorEntity.getName());
         }
     }
 
@@ -156,7 +156,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
             }
         }
         if (!failedXpaths.isEmpty()) {
-            throw new AlreadyDefinedExceptionBatch(failedXpaths);
+            throw AlreadyDefinedException.forDataNodes(failedXpaths, anchorEntity.getName());
         }
     }
 
@@ -189,7 +189,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
             }
         }
         if (!failedXpaths.isEmpty()) {
-            throw new AlreadyDefinedExceptionBatch(failedXpaths);
+            throw AlreadyDefinedException.forDataNodes(failedXpaths, anchorEntity.getName());
         }
     }