Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionExtensions.kt
index ab01b15..4774ad5 100644 (file)
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
 
 import kotlinx.coroutines.runBlocking
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
 
-
 /**
  * Register the Resolution module exposed dependency
  */
 fun BluePrintDependencyService.resourceResolutionService(): ResourceResolutionService =
-        instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+    instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
 
+fun BluePrintDependencyService.resourceResolutionDBService(): ResourceResolutionDBService =
+    instance(ResourceResolutionDBService::class.java)
 
-suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB(resolutionKey: String,
-                                                                          artifactName: String): String {
+suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB(
+    resolutionKey: String,
+    artifactName: String
+): String {
     return BluePrintDependencyService.resourceResolutionService()
-            .resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
+        .resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
+}
+
+suspend fun AbstractComponentFunction.storedResourceResolutionsNB(
+    resolutionKey: String,
+    artifactName: String,
+    occurrence: Int = 1
+): List<ResourceResolution> {
+    return BluePrintDependencyService.resourceResolutionDBService()
+        .findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
+            bluePrintRuntimeService,
+            resolutionKey,
+            occurrence,
+            artifactName
+        )
 }
 
 /**
@@ -39,18 +58,18 @@ suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB(resolu
  */
 suspend fun AbstractComponentFunction.contentFromResolvedArtifactNB(artifactPrefix: String): String {
     return BluePrintDependencyService.resourceResolutionService()
-            .resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefix, mapOf())
+        .resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefix, mapOf())
+        .first
 }
 
-
 /**
  * Blocking Methods called from Jython Scripts
  */
 
-fun AbstractComponentFunction.storedContentFromResolvedArtifact(resolutionKey: String, artifactName: String)
-        : String = runBlocking {
-    storedContentFromResolvedArtifactNB(resolutionKey, artifactName)
-}
+fun AbstractComponentFunction.storedContentFromResolvedArtifact(resolutionKey: String, artifactName: String):
+    String = runBlocking {
+        storedContentFromResolvedArtifactNB(resolutionKey, artifactName)
+    }
 
 fun AbstractComponentFunction.contentFromResolvedArtifact(artifactPrefix: String): String = runBlocking {
     contentFromResolvedArtifactNB(artifactPrefix)