CDS max-occurrence feature
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / db / ResourceResolutionDBService.kt
index aa7b61f..bd8f9d2 100644 (file)
@@ -169,6 +169,35 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
         ).groupBy(ResourceResolution::occurrence).toSortedMap(reverseOrder())
     }
 
+    /**
+     * This returns the resolutions of last N 'occurrences'.
+     *
+     * @param blueprintName
+     * @param blueprintVersion
+     * @param artifactPrefix
+     * @param resourceId
+     * @param resourceType
+     * @param lastN
+     */
+    suspend fun findLastNOccurrences(
+        blueprintName: String,
+        blueprintVersion: String,
+        artifactPrefix: String,
+        resourceId: String,
+        resourceType: String,
+        lastN: Int
+    ): Map<Int, List<ResourceResolution>> = withContext(Dispatchers.IO) {
+
+        resourceResolutionRepository.findLastNOccurrences(
+            resourceId,
+            resourceType,
+            blueprintName,
+            blueprintVersion,
+            artifactPrefix,
+            lastN
+        ).groupBy(ResourceResolution::occurrence).toSortedMap(reverseOrder())
+    }
+
     /**
      * This returns the resolutions with 'occurrence' value between begin and end.
      *