CDS max-occurrence feature
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / db / ResourceResolutionRepository.kt
index 9317a71..5861cf8 100644 (file)
@@ -75,6 +75,29 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin
         @Param("lastN")begin: Int
     ): List<ResourceResolution>
 
+    @Query(
+        value = """
+        SELECT * FROM RESOURCE_RESOLUTION WHERE resource_id = :resourceId
+            AND resource_type =:resourceType AND blueprint_name = :blueprintName
+            AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
+            AND occurrence > (
+                select max(occurrence) - :lastN from RESOURCE_RESOLUTION
+                WHERE resource_id = :resourceId
+                    AND resource_type =:resourceType AND blueprint_name = :blueprintName
+                    AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName)
+                    ORDER BY occurrence DESC, creation_date DESC
+          """,
+        nativeQuery = true
+    )
+    fun findLastNOccurrences(
+        @Param("resourceId")resourceId: String,
+        @Param("resourceType")resourceType: String,
+        @Param("blueprintName")blueprintName: String,
+        @Param("blueprintVersion")blueprintVersion: String,
+        @Param("artifactName")artifactName: String,
+        @Param("lastN")begin: Int
+    ): List<ResourceResolution>
+
     @Query(
         value = """
         SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key