Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / execution-service / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / execution / ComponentFunctionScriptingService.kt
index 49a2c62..b798f00 100644 (file)
 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution
 
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintScriptsService
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintScriptsService
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
-import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintScriptsServiceImpl
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
 import org.slf4j.LoggerFactory
 import org.springframework.context.ApplicationContext
 import org.springframework.stereotype.Service
 
 @Service
-class ComponentFunctionScriptingService(private val applicationContext: ApplicationContext,
-                                        private val blueprintJythonService: BlueprintJythonService) {
+class ComponentFunctionScriptingService(
+    private val applicationContext: ApplicationContext,
+    private val blueprintJythonService: BlueprintJythonService
+) {
 
     private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java)
 
-    suspend fun <T : AbstractScriptComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction,
-                                                                     scriptType: String,
-                                                                     scriptClassReference: String,
-                                                                     instanceDependencies: List<String>): T {
+    suspend fun <T : AbstractScriptComponentFunction> scriptInstance(
+        componentFunction: AbstractComponentFunction,
+        scriptType: String,
+        scriptClassReference: String,
+        instanceDependencies: List<String>
+    ): T {
 
-        log.info("creating component function of script type($scriptType), reference name($scriptClassReference) and " +
-                "instanceDependencies($instanceDependencies)")
+        log.info(
+            "creating component function of script type($scriptType), reference name($scriptClassReference) and " +
+                "instanceDependencies($instanceDependencies)"
+        )
 
-        val scriptComponent: T = scriptInstance(componentFunction.bluePrintRuntimeService.bluePrintContext(),
-                scriptType, scriptClassReference)
+        val scriptComponent: T = scriptInstance(
+            componentFunction.bluePrintRuntimeService.bluePrintContext(),
+            scriptType, scriptClassReference
+        )
 
         checkNotNull(scriptComponent) { "failed to initialize script component" }
 
@@ -54,38 +62,43 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat
         scriptComponent.operationName = componentFunction.operationName
         scriptComponent.nodeTemplateName = componentFunction.nodeTemplateName
         scriptComponent.operationInputs = componentFunction.operationInputs
+        scriptComponent.executionServiceInput = componentFunction.executionServiceInput
         scriptComponent.scriptType = scriptType
 
         // Populate Instance Properties
         instanceDependencies.forEach { instanceDependency ->
             scriptComponent.functionDependencyInstances[instanceDependency] = applicationContext
-                    .getBean(instanceDependency)
+                .getBean(instanceDependency)
         }
         return scriptComponent
     }
 
-
-    suspend fun <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String,
-                                                                 scriptClassReference: String): T {
+    suspend fun <T : BlueprintFunctionNode<*, *>> scriptInstance(
+        bluePrintContext: BlueprintContext,
+        scriptType: String,
+        scriptClassReference: String
+    ): T {
         var scriptComponent: T? = null
 
         when (scriptType) {
-            BluePrintConstants.SCRIPT_INTERNAL -> {
-                val bluePrintScriptsService: BluePrintScriptsService = BluePrintScriptsServiceImpl()
+            BlueprintConstants.SCRIPT_INTERNAL -> {
+                val bluePrintScriptsService: BlueprintScriptsService = BlueprintScriptsServiceImpl()
                 scriptComponent = bluePrintScriptsService.scriptInstance<T>(scriptClassReference)
             }
-            BluePrintConstants.SCRIPT_KOTLIN -> {
-                val bluePrintScriptsService: BluePrintScriptsService = BluePrintScriptsServiceImpl()
-                scriptComponent = bluePrintScriptsService.scriptInstance<T>(bluePrintContext, scriptClassReference, false)
+            BlueprintConstants.SCRIPT_KOTLIN -> {
+                val bluePrintScriptsService: BlueprintScriptsService = BlueprintScriptsServiceImpl()
+                scriptComponent = bluePrintScriptsService.scriptInstance<T>(
+                    bluePrintContext.rootPath,
+                    bluePrintContext.name(), bluePrintContext.version(), scriptClassReference, false
+                )
             }
-            BluePrintConstants.SCRIPT_JYTHON -> {
+            BlueprintConstants.SCRIPT_JYTHON -> {
                 scriptComponent = blueprintJythonService.jythonComponentInstance(bluePrintContext, scriptClassReference) as T
             }
             else -> {
-                throw BluePrintProcessorException("script type($scriptType) is not supported")
+                throw BlueprintProcessorException("script type($scriptType) is not supported")
             }
         }
         return scriptComponent
     }
-
-}
\ No newline at end of file
+}