Formatting Code base with ktlint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / db / TemplateResolutionService.kt
index c64605e..895bc99 100644 (file)
@@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory
 import org.springframework.dao.DataIntegrityViolationException
 import org.springframework.dao.EmptyResultDataAccessException
 import org.springframework.stereotype.Service
-import java.util.*
+import java.util.UUID
 
 @Service
 class TemplateResolutionService(private val templateResolutionRepository: TemplateResolutionRepository) {
@@ -35,7 +35,8 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
     suspend fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
         bluePrintRuntimeService: BluePrintRuntimeService<*>,
         artifactPrefix: String,
-        resolutionKey: String): String =
+        resolutionKey: String
+    ): String =
         withContext(Dispatchers.IO) {
 
             val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
@@ -43,17 +44,21 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
             val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
             val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
 
-            findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(blueprintName,
+            findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+                blueprintName,
                 blueprintVersion,
                 artifactPrefix,
-                resolutionKey)
+                resolutionKey
+            )
         }
 
-    suspend fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(blueprintName: String,
-                                                                                      blueprintVersion: String,
-                                                                                      artifactPrefix: String,
-                                                                                      resolutionKey: String,
-                                                                                      occurrence: Int = 1): String =
+    suspend fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+        blueprintName: String,
+        blueprintVersion: String,
+        artifactPrefix: String,
+        resolutionKey: String,
+        occurrence: Int = 1
+    ): String =
         withContext(Dispatchers.IO) {
 
             templateResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
@@ -61,15 +66,18 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
                 blueprintName,
                 blueprintVersion,
                 artifactPrefix,
-                occurrence)?.result ?: throw EmptyResultDataAccessException(1)
+                occurrence
+            )?.result ?: throw EmptyResultDataAccessException(1)
         }
 
-    suspend fun findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName(blueprintName: String,
-                                                                                                 blueprintVersion: String,
-                                                                                                 artifactPrefix: String,
-                                                                                                 resourceId: String,
-                                                                                                 resourceType: String,
-                                                                                                 occurrence: Int = 1): String =
+    suspend fun findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName(
+        blueprintName: String,
+        blueprintVersion: String,
+        artifactPrefix: String,
+        resourceId: String,
+        resourceType: String,
+        occurrence: Int = 1
+    ): String =
         withContext(Dispatchers.IO) {
 
             templateResolutionRepository.findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
@@ -78,12 +86,16 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
                 blueprintName,
                 blueprintVersion,
                 artifactPrefix,
-                occurrence)?.result!!
+                occurrence
+            )?.result!!
         }
 
-    suspend fun write(properties: Map<String, Any>,
-                      result: String, bluePrintRuntimeService: BluePrintRuntimeService<*>,
-                      artifactPrefix: String): TemplateResolution = withContext(Dispatchers.IO) {
+    suspend fun write(
+        properties: Map<String, Any>,
+        result: String,
+        bluePrintRuntimeService: BluePrintRuntimeService<*>,
+        artifactPrefix: String
+    ): TemplateResolution = withContext(Dispatchers.IO) {
 
         val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
 
@@ -93,19 +105,28 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
         val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
         val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
         val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
-        write(blueprintName,
+        write(
+            blueprintName,
             blueprintVersion,
             artifactPrefix,
             result,
             occurrence,
             resolutionKey,
             resourceId,
-            resourceType)
+            resourceType
+        )
     }
 
-    suspend fun write(blueprintName: String, blueprintVersion: String, artifactPrefix: String,
-                      template: String, occurrence: Int = 1, resolutionKey: String = "", resourceId: String = "",
-                      resourceType: String = ""): TemplateResolution =
+    suspend fun write(
+        blueprintName: String,
+        blueprintVersion: String,
+        artifactPrefix: String,
+        template: String,
+        occurrence: Int = 1,
+        resolutionKey: String = "",
+        resourceId: String = "",
+        resourceType: String = ""
+    ): TemplateResolution =
         withContext(Dispatchers.IO) {
 
             val resourceResolutionResult = TemplateResolution()
@@ -122,37 +143,49 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
             // Overwrite template resolution-key of resourceId/resourceType already existant
             if (resolutionKey.isNotEmpty()) {
                 templateResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
-                    resolutionKey, blueprintName, blueprintVersion, artifactPrefix, occurrence)?.let {
-                    log.info("Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " +
-                            "artifactName=($artifactPrefix) and resolutionKey=($resolutionKey)")
+                    resolutionKey, blueprintName, blueprintVersion, artifactPrefix, occurrence
+                )?.let {
+                    log.info(
+                        "Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " +
+                                "artifactName=($artifactPrefix) and resolutionKey=($resolutionKey)"
+                    )
                     templateResolutionRepository.deleteByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
                         resolutionKey,
                         blueprintName,
                         blueprintVersion,
                         artifactPrefix,
-                        occurrence)
+                        occurrence
+                    )
                 }
             } else if (resourceId.isNotEmpty() && resourceType.isNotEmpty()) {
                 templateResolutionRepository.findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
-                    resourceId, resourceType, blueprintName, blueprintVersion, artifactPrefix, occurrence)?.let {
-                    log.info("Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " +
-                            "artifactName=($artifactPrefix), resourceId=($resourceId) and resourceType=($resourceType)")
+                    resourceId, resourceType, blueprintName, blueprintVersion, artifactPrefix, occurrence
+                )?.let {
+                    log.info(
+                        "Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " +
+                                "artifactName=($artifactPrefix), resourceId=($resourceId) and resourceType=($resourceType)"
+                    )
                     templateResolutionRepository.deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
                         resourceId,
                         resourceType,
                         blueprintName,
                         blueprintVersion,
                         artifactPrefix,
-                        occurrence)
+                        occurrence
+                    )
                 }
             }
             try {
-                log.info("Writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" +
-                    " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence")
+                log.info(
+                    "Writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" +
+                            " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence"
+                )
                 templateResolutionRepository.saveAndFlush(resourceResolutionResult)
             } catch (ex: DataIntegrityViolationException) {
-                log.error("Error writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" +
-                    " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence error: {}", ex.message)
+                log.error(
+                    "Error writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" +
+                            " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence error: {}", ex.message
+                )
                 throw BluePrintException("Failed to store resource api result.", ex)
             }
         }