aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorKuldip Rai <kuldip.rai@bell.ca>2022-03-16 14:26:30 +0000
committerkuldipr <kuldip.rai@amdocs.com>2022-05-19 11:52:25 -0400
commita1142669cd10f47d8178230500012e6421722c30 (patch)
treeb54242da6f068e2e1a940c96cb77b768df3166ab /ms/blueprintsprocessor/functions
parentc3943fbc70105c4ce38d66c7cbe227ddec35d535 (diff)
Resource endpoint should support occurrences
The getOneFromResolutionKey endpoint would fail if there are multiple occurrences for a resource. Instead it should return the last occurrence. Issue-ID: CCSDK-3664 Signed-off-by: kuldipr <kuldip.rai@amdocs.com> Change-Id: I1468c41c164f64931ce719f9908b935baae6e1a4
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt18
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt9
3 files changed, 19 insertions, 10 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
index 5958c7899..bfe9da35c 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
@@ -90,7 +90,7 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
artifactPrefix: String,
resolutionKey: String,
name: String
- ): ResourceResolution = withContext(Dispatchers.IO) {
+ ): ResourceResolution? = withContext(Dispatchers.IO) {
resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
resolutionKey,
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
index c2d630e5e..6e0ed3a4b 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
@@ -16,19 +16,25 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
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
import javax.transaction.Transactional
@Repository
interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> {
+ @Query(
+ value = "SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName AND name = :name ORDER BY occurrence DESC, creation_date DESC LIMIT 1",
+ nativeQuery = true
+ )
fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
- key: String,
- blueprintName: String?,
- blueprintVersion: String?,
- artifactName: String,
- name: String
- ): ResourceResolution
+ @Param("key")key: String,
+ @Param("blueprintName")blueprintName: String,
+ @Param("blueprintVersion")blueprintVersion: String,
+ @Param("artifactName")artifactName: String,
+ @Param("name")name: String
+ ): ResourceResolution?
fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
resolutionKey: String,
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
index fa59876a9..635ce0e38 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
@@ -30,6 +30,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRunt
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.springframework.dao.EmptyResultDataAccessException
import kotlin.test.assertEquals
+import kotlin.test.assertNotEquals
open class ResourceResolutionDBServiceTest {
@@ -158,9 +159,11 @@ open class ResourceResolutionDBServiceTest {
resourceResolutionDBService.readValue(
blueprintName, blueprintVersion, artifactPrefix, resolutionKey, "bob"
)
-
- assertEquals(rr.name, res.name)
- assertEquals(rr.value, res.value)
+ assertNotEquals(res, null, "resource resolution failed")
+ if (res != null) {
+ assertEquals(rr.name, res.name)
+ assertEquals(rr.value, res.value)
+ }
}
}