summaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-12-10 16:49:53 +0000
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-12-10 16:55:54 +0000
commite182a6b6cb4a87b4f461adf83fe60a65948fc230 (patch)
tree1a8dbc71794cf742e5f9dd2ce6346c308cc1afc4 /cps-ri
parenta66dd4e82e8ef5b2cfe956a9a88a90154889635a (diff)
Retrieve All anchors for a given Dataspace
Issue-ID: CPS-8 Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca> Change-Id: Idb2e4f83d390f078345e556d89781e0bf4a9a41f
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/pom.xml4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java13
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java11
3 files changed, 28 insertions, 0 deletions
diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml
index b5fe933818..89b19d5ffa 100644
--- a/cps-ri/pom.xml
+++ b/cps-ri/pom.xml
@@ -36,6 +36,10 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.modelmapper</groupId>
+ <artifactId>modelmapper</artifactId>
+ </dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
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 f119507214..48e7303593 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
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,10 @@
package org.onap.cps.spi.impl;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import org.modelmapper.ModelMapper;
+import org.modelmapper.TypeToken;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
@@ -61,4 +66,12 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
throw new AnchorAlreadyDefinedException(anchor.getDataspaceName(), anchorName, ex);
}
}
+
+ @Override
+ public Collection<Anchor> getAnchors(final String dataspaceName) {
+ final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
+ final Collection<Fragment> fragments = fragmentRepository.findFragmentsThatAreAnchorsByDataspace(dataspace);
+ final Type anchorListType = new TypeToken<Collection<Anchor>>() {}.getType();
+ return new ModelMapper().map(fragments, anchorListType);
+ }
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
index ba83f15881..7ae7c13b73 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +21,20 @@
package org.onap.cps.spi.repository;
+import java.util.Collection;
+import org.onap.cps.spi.entities.Dataspace;
import org.onap.cps.spi.entities.Fragment;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface FragmentRepository extends JpaRepository<Fragment, Integer> {
+
+ default Collection<Fragment> findFragmentsThatAreAnchorsByDataspace(Dataspace dataspace) {
+ return findFragmentsByDataspaceAndParentFragmentIsNull(dataspace);
+ }
+
+ Collection<Fragment> findFragmentsByDataspaceAndParentFragmentIsNull(Dataspace dataspace);
} \ No newline at end of file