Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / handler / BluePrintModelHandler.kt
@@ -30,25 +30,25 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowData
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecRequest
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecResponse
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowsResponse
-import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BlueprintDatabaseLoadService
-import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintEnhancerUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
-import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.config.BlueprintLoadConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BluePrintDatabaseLoadService
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
 import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintCatalogService
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintEnhancerService
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
 import org.onap.ccsdk.cds.controllerblueprints.core.logger
 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
-import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintCompileCache
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
+import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintFileUtils
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
@@ -77,17 +77,17 @@ import java.util.UUID
  */
 
 @Service
-open class BlueprintModelHandler(
-    private val bluePrintDatabaseLoadService: BlueprintDatabaseLoadService,
-    private val blueprintsProcessorCatalogService: BlueprintCatalogService,
-    private val bluePrintLoadConfiguration: BlueprintLoadConfiguration,
+open class BluePrintModelHandler(
+    private val bluePrintDatabaseLoadService: BluePrintDatabaseLoadService,
+    private val blueprintsProcessorCatalogService: BluePrintCatalogService,
+    private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
     private val blueprintModelSearchRepository: BlueprintModelSearchRepository,
     private val blueprintModelRepository: BlueprintModelRepository,
     private val blueprintModelContentRepository: BlueprintModelContentRepository,
-    private val bluePrintEnhancerService: BlueprintEnhancerService
+    private val bluePrintEnhancerService: BluePrintEnhancerService
 ) {
 
-    private val log = logger(BlueprintModelHandler::class)
+    private val log = logger(BluePrintModelHandler::class)
 
     open suspend fun bootstrapBlueprint(bootstrapRequest: BootstrapRequest) {
         log.info(
@@ -102,11 +102,11 @@ open class BlueprintModelHandler(
             bluePrintDatabaseLoadService.initResourceDictionary()
         }
         if (bootstrapRequest.loadCBA) {
-            bluePrintDatabaseLoadService.initBlueprintCatalog()
+            bluePrintDatabaseLoadService.initBluePrintCatalog()
         }
     }
 
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open suspend fun prepareWorkFlowSpec(req: WorkFlowSpecRequest):
         WorkFlowSpecResponse {
             val basePath = blueprintsProcessorCatalogService.getFromDatabase(
@@ -116,7 +116,7 @@ open class BlueprintModelHandler(
             )
             log.info("blueprint base path $basePath")
 
-            val blueprintContext = BlueprintMetadataUtils.getBlueprintContext(basePath.toString())
+            val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(basePath.toString())
             val workFlow = blueprintContext.workflowByName(req.workflowName)
 
             val wfRes = WorkFlowSpecResponse()
@@ -144,7 +144,7 @@ open class BlueprintModelHandler(
             return wfRes
         }
 
-    private fun addPropertyInfo(propName: String, prop: PropertyDefinition, ctx: BlueprintContext, res: WorkFlowSpecResponse) {
+    private fun addPropertyInfo(propName: String, prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
         updatePropertyInfo(propName, prop, ctx, res)
         addDataType(prop.type, ctx, res)
         if (prop.entrySchema != null && prop.entrySchema!!.type != null) {
@@ -152,7 +152,7 @@ open class BlueprintModelHandler(
         }
     }
 
-    private fun updatePropertyInfo(name: String, prop: PropertyDefinition, ctx: BlueprintContext, res: WorkFlowSpecResponse) {
+    private fun updatePropertyInfo(name: String, prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
         if (prop.inputparam == null || prop.inputparam == false) {
             var workflow = ctx.workflowByName(res.workFlowData.workFlowName)
             for ((k, v) in workflow.steps!!) {
@@ -176,7 +176,7 @@ open class BlueprintModelHandler(
         }
     }
 
-    private fun addDataType(name: String, ctx: BlueprintContext, res: WorkFlowSpecResponse) {
+    private fun addDataType(name: String, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
         var data = ctx.dataTypeByName(name)
         if (data != null) {
             res.dataTypes?.put(name, data)
@@ -184,7 +184,7 @@ open class BlueprintModelHandler(
         }
     }
 
-    private fun addParentDataType(data: DataType, ctx: BlueprintContext, res: WorkFlowSpecResponse) {
+    private fun addParentDataType(data: DataType, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
         if (data.properties != null) {
             for ((k, v) in data.properties!!) {
                 addPropertyInfo(k, v, ctx, res)
@@ -192,7 +192,7 @@ open class BlueprintModelHandler(
         }
     }
 
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open suspend fun getWorkflowNames(name: String, version: String): WorkFlowsResponse {
         val basePath = blueprintsProcessorCatalogService.getFromDatabase(
             name, version
@@ -203,7 +203,7 @@ open class BlueprintModelHandler(
         res.blueprintName = name
         res.version = version
 
-        val blueprintContext = BlueprintMetadataUtils.getBlueprintContext(
+        val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(
             basePath.toString()
         )
         if (blueprintContext.workflows() != null) {
@@ -235,9 +235,9 @@ open class BlueprintModelHandler(
      *
      * @param filePart filePart
      * @return Mono<BlueprintModelSearch>
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      </BlueprintModelSearch> */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open suspend fun saveBlueprintModel(filePart: FilePart): BlueprintModelSearch {
         try {
             return upload(filePart, false)
@@ -265,12 +265,12 @@ open class BlueprintModelHandler(
      * @param name name
      * @param version version
      * @return BlueprintModelSearch
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch? {
         return blueprintModelSearchRepository.findByArtifactNameAndArtifactVersion(name, version)
-        /*?: throw BlueprintException(
+        /*?: throw BluePrintException(
             ErrorCode.RESOURCE_NOT_FOUND.value,
             String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)
         )*/
@@ -282,9 +282,9 @@ open class BlueprintModelHandler(
      * @param name name
      * @param version version
      * @return ResponseEntity<Resource>
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      </Resource> */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun downloadBlueprintModelFileByNameAndVersion(
         name: String,
         version: String
@@ -293,7 +293,7 @@ open class BlueprintModelHandler(
             val archiveByteArray = download(name, version)
             val fileName = "${name}_$version.zip"
             return prepareResourceEntity(fileName, archiveByteArray)
-        } catch (e: BlueprintProcessorException) {
+        } catch (e: BluePrintProcessorException) {
             e.http(ErrorCatalogCodes.RESOURCE_NOT_FOUND)
             val errorMsg = "Error while downloading the CBA file by Blueprint Name ($name) and Version ($version)."
             throw e.updateErrorMessage(
@@ -307,14 +307,14 @@ open class BlueprintModelHandler(
      * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource
      *
      * @return ResponseEntity<Resource>
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      </Resource> */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun downloadBlueprintModelFile(id: String): ResponseEntity<Resource> {
         val blueprintModel: BlueprintModel
         try {
             blueprintModel = getBlueprintModel(id)
-        } catch (e: BlueprintException) {
+        } catch (e: BluePrintException) {
             throw httpProcessorException(
                 ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
                 "Error while downloading the CBA file: couldn't get blueprint modelby ID ($id)",
@@ -346,9 +346,9 @@ open class BlueprintModelHandler(
      *
      * @param id id
      * @return BlueprintModel
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun getBlueprintModel(id: String): BlueprintModel {
         val blueprintModel: BlueprintModel
         val dbBlueprintModel = blueprintModelRepository.findById(id)
@@ -367,9 +367,9 @@ open class BlueprintModelHandler(
      * @param name name
      * @param version version
      * @return BlueprintModel
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun getBlueprintModelByNameAndVersion(name: String, version: String): BlueprintModel {
         val blueprintModel = blueprintModelRepository
             .findByArtifactNameAndArtifactVersion(name, version)
@@ -386,9 +386,9 @@ open class BlueprintModelHandler(
      *
      * @param id id
      * @return BlueprintModelSearch
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun getBlueprintModelSearch(id: String): BlueprintModelSearch {
         return blueprintModelSearchRepository.findById(id)
             ?: throw httpProcessorException(
@@ -398,28 +398,28 @@ open class BlueprintModelHandler(
     }
 
     /**
-     * This is a searchBlueprintModelsByKeyWord method to retrieve specific  BlueprintModel in Database
+     * This is a searchBluePrintModelsByKeyWord method to retrieve specific  BlueprintModel in Database
      * where keyword equals updatedBy or tags or artifcat name or artifcat version or artifact type
      * @author Shaaban Ebrahim
      * @param keyWord
      *
      * @return List<BlueprintModelSearch> list of the controller blueprint
      </BlueprintModelSearch> */
-    open fun searchBlueprintModelsByKeyWord(keyWord: String): List<BlueprintModelSearch> {
+    open fun searchBluePrintModelsByKeyWord(keyWord: String): List<BlueprintModelSearch> {
         return blueprintModelSearchRepository.findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(
             keyWord, keyWord, keyWord, keyWord, keyWord
         )
     }
 
     /**
-     * This is a searchBlueprintModelsByKeyWordPagebale method to retrieve specific  BlueprintModel in Database
+     * This is a searchBluePrintModelsByKeyWordPagebale method to retrieve specific  BlueprintModel in Database
      * where keyword equals updatedBy or tags or artifcat name or artifcat version or artifact type and pageable
      * @author Shaaban Ebrahim
      * @param keyWord
      *
      * @return List<BlueprintModelSearch> list of the controller blueprint
      </BlueprintModelSearch> */
-    open fun searchBlueprintModelsByKeyWordPaged(keyWord: String, pageRequest: PageRequest): Page<BlueprintModelSearch> {
+    open fun searchBluePrintModelsByKeyWordPaged(keyWord: String, pageRequest: PageRequest): Page<BlueprintModelSearch> {
         return blueprintModelSearchRepository.findByUpdatedByContainingIgnoreCaseOrTagsContainingIgnoreCaseOrArtifactNameContainingIgnoreCaseOrArtifactVersionContainingIgnoreCaseOrArtifactTypeContainingIgnoreCase(
             keyWord,
             keyWord,
@@ -434,10 +434,10 @@ open class BlueprintModelHandler(
      * This is a deleteBlueprintModel method
      *
      * @param id id
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
     @Transactional
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open fun deleteBlueprintModel(id: String) {
         val dbBlueprintModel = blueprintModelRepository.findById(id)
         if (dbBlueprintModel.isPresent) {
@@ -463,14 +463,14 @@ open class BlueprintModelHandler(
      *
      * @param filePart filePart
      * @return ResponseEntity<Resource>
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity<Resource> {
         try {
             val enhancedByteArray = enrichBlueprintFileSource(filePart)
-            return BlueprintEnhancerUtils.prepareResourceEntity("enhanced-cba.zip", enhancedByteArray)
-        } catch (e: BlueprintProcessorException) {
+            return BluePrintEnhancerUtils.prepareResourceEntity("enhanced-cba.zip", enhancedByteArray)
+        } catch (e: BluePrintProcessorException) {
             e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
             val errorMsg = "Error while enhancing the CBA package."
             throw e.updateErrorMessage(
@@ -491,13 +491,13 @@ open class BlueprintModelHandler(
      *
      * @param filePart filePart
      * @return BlueprintModelSearch
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch {
         try {
             return upload(filePart, true)
-        } catch (e: BlueprintProcessorException) {
+        } catch (e: BluePrintProcessorException) {
             e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
             val errorMsg = "Error in Publishing CBA."
             throw e.updateErrorMessage(
@@ -519,14 +519,14 @@ open class BlueprintModelHandler(
      *
      * @param filePart filePart
      * @return BlueprintModelSearch
-     * @throws BlueprintException BlueprintException
+     * @throws BluePrintException BluePrintException
      */
-    @Throws(BlueprintException::class)
+    @Throws(BluePrintException::class)
     open suspend fun enrichAndPublishBlueprint(filePart: FilePart): BlueprintModelSearch {
         try {
             val enhancedByteArray = enrichBlueprintFileSource(filePart)
             return upload(enhancedByteArray, true)
-        } catch (e: BlueprintProcessorException) {
+        } catch (e: BluePrintProcessorException) {
             e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
             val errorMsg = "Error while enhancing and uploading the CBA package."
             throw e.updateErrorMessage(
@@ -550,8 +550,8 @@ open class BlueprintModelHandler(
         try {
             val compressedFile = normalizedFile(blueprintArchive, "cba.zip")
             when (fileSource) {
-                is FilePart -> BlueprintEnhancerUtils.filePartAsFile(fileSource, compressedFile)
-                is ByteArray -> BlueprintEnhancerUtils.byteArrayAsFile(fileSource, compressedFile)
+                is FilePart -> BluePrintEnhancerUtils.filePartAsFile(fileSource, compressedFile)
+                is ByteArray -> BluePrintEnhancerUtils.byteArrayAsFile(fileSource, compressedFile)
             }
             // Save the Copied file to Database
             val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, validate)
@@ -561,7 +561,7 @@ open class BlueprintModelHandler(
                     ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
                     String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId)
                 )
-        } catch (e: BlueprintException) {
+        } catch (e: BluePrintException) {
             e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
             val errorMsg = "Error in Upload CBA."
             throw e.updateErrorMessage(
@@ -575,9 +575,9 @@ open class BlueprintModelHandler(
             )
         } finally {
             // Clean blueprint script cache
-            val cacheKey = BlueprintFileUtils
+            val cacheKey = BluePrintFileUtils
                 .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId))
-            BlueprintCompileCache.cleanClassLoader(cacheKey)
+            BluePrintCompileCache.cleanClassLoader(cacheKey)
             deleteNBDir(blueprintArchive)
             deleteNBDir(blueprintWorking)
         }
@@ -593,7 +593,7 @@ open class BlueprintModelHandler(
                     ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
                     "Error while downloading the CBA file: couldn't get model content"
                 )
-        } catch (e: BlueprintException) {
+        } catch (e: BluePrintException) {
             e.http(ErrorCatalogCodes.RESOURCE_NOT_FOUND)
             val errorMsg = "Fail to get Blueprint Model content."
             throw e.updateErrorMessage(
@@ -612,16 +612,16 @@ open class BlueprintModelHandler(
         try {
             when (fileSource) {
                 is FilePart ->
-                    BlueprintEnhancerUtils
+                    BluePrintEnhancerUtils
                         .copyFilePartToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir)
                 is ByteArray ->
-                    BlueprintEnhancerUtils
+                    BluePrintEnhancerUtils
                         .copyByteArrayToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir)
             } // Enhance the Blue Prints
             bluePrintEnhancerService.enhance(blueprintWorkingDir)
 
-            return BlueprintEnhancerUtils.compressEnhanceDirAndReturnByteArray(blueprintWorkingDir, blueprintArchive)
-        } catch (e: BlueprintException) {
+            return BluePrintEnhancerUtils.compressEnhanceDirAndReturnByteArray(blueprintWorkingDir, blueprintArchive)
+        } catch (e: BluePrintException) {
             e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
             val errorMsg = "Fail Enriching the CBA."
             throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg)
@@ -631,7 +631,7 @@ open class BlueprintModelHandler(
                 "Error while Enriching the CBA file.", e.errorCauseOrDefault()
             )
         } finally {
-            BlueprintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintWorkingDir)
+            BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintWorkingDir)
         }
     }