aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
authorjuhi arora <j.arora@cgi.com>2022-05-19 14:14:17 -0400
committerJUHI ARORA <juhi.arora1@bell.ca>2022-05-24 18:27:15 +0000
commit9500d29a3edceee521d16bb1256974222cf37214 (patch)
tree43bd0151df680c86b631d1cb3d4049704df8fdb4 /ms/blueprintsprocessor/functions/resource-resolution/src/main
parentc3943fbc70105c4ce38d66c7cbe227ddec35d535 (diff)
Extend Template API to retrieve resolutions by occurrence
Add new endpoints - template to get firstN, lastN and by Range (begin, end) of 'occurrence' to get the templates Issue-ID: CCSDK-3666 Change-Id: I242626e826022ed8b70a0abc287560ea634121b7 Signed-off-by: juhi arora <juhi.arora1@bell.ca>
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt65
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt95
2 files changed, 160 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt
index 3df613745..38d61e78d 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt
@@ -42,6 +42,71 @@ interface TemplateResolutionRepository : JpaRepository<TemplateResolution, Strin
): TemplateResolution?
@Query(
+ value = """
+ SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
+ AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
+ AND artifact_name = :artifactName
+ AND occurrence <= :firstN
+ """,
+ nativeQuery = true
+ )
+ fun findFirstNOccurrences(
+ @Param("key")key: String,
+ @Param("blueprintName")blueprintName: String,
+ @Param("blueprintVersion")blueprintVersion: String,
+ @Param("artifactName")artifactName: String,
+ @Param("firstN")begin: Int
+ ): List<TemplateResolution>
+
+ @Query(
+ value = """
+ SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
+ AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
+ AND artifact_name = :artifactName
+ AND occurrence > (
+ select max(occurrence) - :lastN from RESOURCE_RESOLUTION
+ WHERE resolution_key = :key
+ AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
+ AND artifact_name = :artifactName)
+ ORDER BY occurrence DESC, creation_date DESC
+ """,
+ nativeQuery = true
+ )
+ fun findLastNOccurrences(
+ @Param("key")key: String,
+ @Param("blueprintName")blueprintName: String,
+ @Param("blueprintVersion")blueprintVersion: String,
+ @Param("artifactName")artifactName: String,
+ @Param("lastN")begin: Int
+ ): List<TemplateResolution>
+
+ @Query(
+ value = """
+ SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
+ AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
+ AND artifact_name = :artifactName
+ AND occurrence BETWEEN :begin AND :end
+ ORDER BY occurrence DESC, creation_date DESC
+ """,
+ nativeQuery = true
+ )
+ fun findOccurrencesWithinRange(
+ @Param("key")key: String,
+ @Param("blueprintName")blueprintName: String,
+ @Param("blueprintVersion")blueprintVersion: String,
+ @Param("artifactName")artifactName: String,
+ @Param("begin")begin: Int,
+ @Param("end")end: Int
+ ): List<TemplateResolution>
+
+ fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey: String,
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String
+ ): List<TemplateResolution>
+
+ @Query(
"select tr.resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.artifactName = :artifactName and tr.occurrence = :occurrence"
)
fun findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
index 8789ade99..906aedf09 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
@@ -241,4 +241,99 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
throw BluePrintException("Failed to store resource api result.", ex)
}
}
+ /**
+ * This returns the templates of first N 'occurrences'.
+ *
+ * @param blueprintName
+ * @param blueprintVersion
+ * @param artifactPrefix
+ * @param resolutionKey
+ * @param firstN
+ */
+ suspend fun findFirstNOccurrences(
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String,
+ resolutionKey: String,
+ firstN: Int
+ ): Map<Int, List<TemplateResolution>> = withContext(Dispatchers.IO) {
+
+ templateResolutionRepository.findFirstNOccurrences(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix,
+ firstN
+ ).groupBy(TemplateResolution::occurrence).toSortedMap(reverseOrder())
+ }
+
+ /**
+ * This returns the templates of last N 'occurrences'.
+ *
+ * @param blueprintName
+ * @param blueprintVersion
+ * @param artifactPrefix
+ * @param resolutionKey
+ * @param lastN
+ */
+ suspend fun findLastNOccurrences(
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String,
+ resolutionKey: String,
+ lastN: Int
+ ): Map<Int, List<TemplateResolution>> = withContext(Dispatchers.IO) {
+
+ templateResolutionRepository.findLastNOccurrences(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix,
+ lastN
+ ).groupBy(TemplateResolution::occurrence).toSortedMap(reverseOrder())
+ }
+
+ /**
+ * This returns the templates with 'occurrence' value between begin and end.
+ *
+ * @param blueprintName
+ * @param blueprintVersion
+ * @param artifactPrefix
+ * @param resolutionKey
+ * @param begin
+ * @param end
+ */
+ suspend fun findOccurrencesWithinRange(
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String,
+ resolutionKey: String,
+ begin: Int,
+ end: Int
+ ): Map<Int, List<TemplateResolution>> = withContext(Dispatchers.IO) {
+
+ templateResolutionRepository.findOccurrencesWithinRange(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix,
+ begin,
+ end
+ ).groupBy(TemplateResolution::occurrence).toSortedMap(reverseOrder())
+ }
+
+ suspend fun readWithResolutionKey(
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String,
+ resolutionKey: String
+ ): List<TemplateResolution> = withContext(Dispatchers.IO) {
+
+ templateResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix
+ )
+ }
}