2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 Bell Canada.
4 * Modifications Copyright © 2019 IBM.
5 * Modifications Copyright © 2019 Orange.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
22 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel
23 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
24 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelContentRepository
25 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository
26 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelSearchRepository
27 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.BootstrapRequest
28 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiDomains
29 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowData
30 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecRequest
31 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecResponse
32 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowsResponse
33 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BluePrintDatabaseLoadService
34 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
35 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
36 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
37 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
38 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
39 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
40 import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
41 import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
42 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
43 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
44 import org.onap.ccsdk.cds.controllerblueprints.core.logger
45 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
46 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
47 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
48 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
49 import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
50 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
51 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
52 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
53 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
54 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
55 import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault
56 import org.onap.ccsdk.cds.error.catalog.core.utils.errorMessageOrDefault
57 import org.springframework.core.io.ByteArrayResource
58 import org.springframework.core.io.Resource
59 import org.springframework.data.domain.Page
60 import org.springframework.data.domain.PageRequest
61 import org.springframework.data.domain.Pageable
62 import org.springframework.http.HttpHeaders
63 import org.springframework.http.MediaType
64 import org.springframework.http.ResponseEntity
65 import org.springframework.http.codec.multipart.FilePart
66 import org.springframework.stereotype.Service
67 import org.springframework.transaction.annotation.Transactional
69 import java.io.IOException
73 * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest
75 * @author Brinda Santh
80 open class BluePrintModelHandler(
81 private val bluePrintDatabaseLoadService: BluePrintDatabaseLoadService,
82 private val blueprintsProcessorCatalogService: BluePrintCatalogService,
83 private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
84 private val blueprintModelSearchRepository: BlueprintModelSearchRepository,
85 private val blueprintModelRepository: BlueprintModelRepository,
86 private val blueprintModelContentRepository: BlueprintModelContentRepository,
87 private val bluePrintEnhancerService: BluePrintEnhancerService
90 private val log = logger(BluePrintModelHandler::class)
92 open suspend fun bootstrapBlueprint(bootstrapRequest: BootstrapRequest) {
94 "Bootstrap request with type load(${bootstrapRequest.loadModelType}), " +
95 "resource dictionary load(${bootstrapRequest.loadResourceDictionary}) and " +
96 "cba load(${bootstrapRequest.loadCBA})"
98 if (bootstrapRequest.loadModelType) {
99 bluePrintDatabaseLoadService.initModelTypes()
101 if (bootstrapRequest.loadResourceDictionary) {
102 bluePrintDatabaseLoadService.initResourceDictionary()
104 if (bootstrapRequest.loadCBA) {
105 bluePrintDatabaseLoadService.initBluePrintCatalog()
109 @Throws(BluePrintException::class)
110 open suspend fun prepareWorkFlowSpec(req: WorkFlowSpecRequest):
111 WorkFlowSpecResponse {
112 val basePath = blueprintsProcessorCatalogService.getFromDatabase(
117 log.info("blueprint base path $basePath")
119 val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(basePath.toString())
120 val workFlow = blueprintContext.workflowByName(req.workflowName)
122 val wfRes = WorkFlowSpecResponse()
123 wfRes.blueprintName = req.blueprintName
124 wfRes.version = req.version
126 val workFlowData = WorkFlowData()
127 workFlowData.workFlowName = req.workflowName
128 workFlowData.inputs = workFlow.inputs
129 workFlowData.outputs = workFlow.outputs
130 wfRes.workFlowData = workFlowData
132 if (workFlow.inputs != null) {
133 for ((k, v) in workFlow.inputs!!) {
134 addPropertyInfo(k, v, blueprintContext, wfRes)
138 if (workFlow.outputs != null) {
139 for ((k, v) in workFlow.outputs!!) {
140 addPropertyInfo(k, v, blueprintContext, wfRes)
147 private fun addPropertyInfo(propName: String, prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
148 updatePropertyInfo(propName, prop, ctx, res)
149 addDataType(prop.type, ctx, res)
150 if (prop.entrySchema != null && prop.entrySchema!!.type != null) {
151 addDataType(prop.entrySchema!!.type, ctx, res)
155 private fun updatePropertyInfo(name: String, prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
156 if (prop.inputparam == null || prop.inputparam == false) {
157 var workflow = ctx.workflowByName(res.workFlowData.workFlowName)
158 for ((k, v) in workflow.steps!!) {
159 var arts = ctx.nodeTemplateArtifacts(v.target!!)
161 for ((k, v) in arts.entries!!) {
162 if (v.type == "artifact-mapping-resource") {
163 val file: String = v.file
164 val completePath = ctx.rootPath.plus(File.separator).plus(file)
165 val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java)
166 for (res in resourceAssignment) {
167 if (res.name == name && res.inputParameter) {
168 prop.inputparam = true
179 private fun addDataType(name: String, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
180 var data = ctx.dataTypeByName(name)
182 res.dataTypes?.put(name, data)
183 addParentDataType(data, ctx, res)
187 private fun addParentDataType(data: DataType, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
188 if (data.properties != null) {
189 for ((k, v) in data.properties!!) {
190 addPropertyInfo(k, v, ctx, res)
195 @Throws(BluePrintException::class)
196 open suspend fun getWorkflowNames(name: String, version: String): WorkFlowsResponse {
197 val basePath = blueprintsProcessorCatalogService.getFromDatabase(
200 log.info("blueprint base path $basePath")
202 var res = WorkFlowsResponse()
203 res.blueprintName = name
204 res.version = version
206 val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(
209 if (blueprintContext.workflows() != null) {
210 res.workflows = blueprintContext.workflows()!!.keys
216 * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
218 * @return List<BlueprintModelSearch> list of the controller blueprint archives
219 </BlueprintModelSearch> */
220 open fun allBlueprintModel(): List<BlueprintModelSearch> {
221 return blueprintModelSearchRepository.findAll()
225 * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
227 * @return List<BlueprintModelSearch> list of the controller blueprint archives
228 </BlueprintModelSearch> */
229 open fun allBlueprintModel(pageRequest: Pageable): Page<BlueprintModelSearch> {
230 return blueprintModelSearchRepository.findAll(pageRequest)
234 * This is a saveBlueprintModel method
236 * @param filePart filePart
237 * @return Mono<BlueprintModelSearch>
238 * @throws BluePrintException BluePrintException
239 </BlueprintModelSearch> */
240 @Throws(BluePrintException::class)
241 open suspend fun saveBlueprintModel(filePart: FilePart): BlueprintModelSearch {
243 return upload(filePart, false)
244 } catch (e: IOException) {
245 throw httpProcessorException(
246 ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
247 "Error in Save CBA: ${e.message}", e.errorCauseOrDefault()
253 * This is a searchBlueprintModels method
256 * @return List<BlueprintModelSearch>
257 </BlueprintModelSearch> */
258 open fun searchBlueprintModels(tags: String): List<BlueprintModelSearch> {
259 return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags)
263 * This is a getBlueprintModelSearchByNameAndVersion method
266 * @param version version
267 * @return BlueprintModelSearch
268 * @throws BluePrintException BluePrintException
270 @Throws(BluePrintException::class)
271 open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch? {
272 return blueprintModelSearchRepository.findByArtifactNameAndArtifactVersion(name, version)
273 /*?: throw BluePrintException(
274 ErrorCode.RESOURCE_NOT_FOUND.value,
275 String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)
280 * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version
283 * @param version version
284 * @return ResponseEntity<Resource>
285 * @throws BluePrintException BluePrintException
287 @Throws(BluePrintException::class)
288 open fun downloadBlueprintModelFileByNameAndVersion(
291 ): ResponseEntity<Resource> {
293 val archiveByteArray = download(name, version)
294 val fileName = "${name}_$version.zip"
295 return prepareResourceEntity(fileName, archiveByteArray)
296 } catch (e: BluePrintProcessorException) {
297 e.http(ErrorCatalogCodes.RESOURCE_NOT_FOUND)
298 val errorMsg = "Error while downloading the CBA file by Blueprint Name ($name) and Version ($version)."
299 throw e.updateErrorMessage(
300 DesignerApiDomains.DESIGNER_API, errorMsg,
301 "Wrong resource definition or resolution failed."
307 * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource
309 * @return ResponseEntity<Resource>
310 * @throws BluePrintException BluePrintException
312 @Throws(BluePrintException::class)
313 open fun downloadBlueprintModelFile(id: String): ResponseEntity<Resource> {
314 val blueprintModel: BlueprintModel
316 blueprintModel = getBlueprintModel(id)
317 } catch (e: BluePrintException) {
318 throw httpProcessorException(
319 ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
320 "Error while downloading the CBA file: couldn't get blueprint modelby ID ($id)",
321 e.errorCauseOrDefault()
325 val fileName = "${blueprintModel.artifactName}_${blueprintModel.artifactVersion}.zip"
326 val file = blueprintModel.blueprintModelContent?.content
327 ?: throw httpProcessorException(
328 ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
329 "Error while downloading the CBA file: couldn't get model content"
331 return prepareResourceEntity(fileName, file)
335 * @return ResponseEntity<Resource>
337 private fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity<Resource> {
338 return ResponseEntity.ok()
339 .contentType(MediaType.parseMediaType("text/plain"))
340 .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"")
341 .body(ByteArrayResource(file))
345 * This is a getBlueprintModel method
348 * @return BlueprintModel
349 * @throws BluePrintException BluePrintException
351 @Throws(BluePrintException::class)
352 open fun getBlueprintModel(id: String): BlueprintModel {
353 val blueprintModel: BlueprintModel
354 val dbBlueprintModel = blueprintModelRepository.findById(id)
355 if (dbBlueprintModel.isPresent) {
356 blueprintModel = dbBlueprintModel.get()
358 val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
359 throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API, msg)
361 return blueprintModel
365 * This is a getBlueprintModelByNameAndVersion method
368 * @param version version
369 * @return BlueprintModel
370 * @throws BluePrintException BluePrintException
372 @Throws(BluePrintException::class)
373 open fun getBlueprintModelByNameAndVersion(name: String, version: String): BlueprintModel {
374 val blueprintModel = blueprintModelRepository
375 .findByArtifactNameAndArtifactVersion(name, version)
376 if (blueprintModel != null) {
377 return blueprintModel
379 val msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)
380 throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API, msg)
385 * This is a getBlueprintModelSearch method
388 * @return BlueprintModelSearch
389 * @throws BluePrintException BluePrintException
391 @Throws(BluePrintException::class)
392 open fun getBlueprintModelSearch(id: String): BlueprintModelSearch {
393 return blueprintModelSearchRepository.findById(id)
394 ?: throw httpProcessorException(
395 ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
396 String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
401 * This is a searchBluePrintModelsByKeyWord method to retrieve specific BlueprintModel in Database
402 * where keyword equals updatedBy or tags or artifcat name or artifcat version or artifact type
403 * @author Shaaban Ebrahim
406 * @return List<BlueprintModelSearch> list of the controller blueprint
407 </BlueprintModelSearch> */
408 open fun searchBluePrintModelsByKeyWord(keyWord: String): List<BlueprintModelSearch> {
409 return blueprintModelSearchRepository.findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(
410 keyWord, keyWord, keyWord, keyWord, keyWord
415 * This is a searchBluePrintModelsByKeyWordPagebale method to retrieve specific BlueprintModel in Database
416 * where keyword equals updatedBy or tags or artifcat name or artifcat version or artifact type and pageable
417 * @author Shaaban Ebrahim
420 * @return List<BlueprintModelSearch> list of the controller blueprint
421 </BlueprintModelSearch> */
422 open fun searchBluePrintModelsByKeyWordPaged(keyWord: String, pageRequest: PageRequest): Page<BlueprintModelSearch> {
423 return blueprintModelSearchRepository.findByUpdatedByContainingIgnoreCaseOrTagsContainingIgnoreCaseOrArtifactNameContainingIgnoreCaseOrArtifactVersionContainingIgnoreCaseOrArtifactTypeContainingIgnoreCase(
434 * This is a deleteBlueprintModel method
437 * @throws BluePrintException BluePrintException
440 @Throws(BluePrintException::class)
441 open fun deleteBlueprintModel(id: String) {
442 val dbBlueprintModel = blueprintModelRepository.findById(id)
443 if (dbBlueprintModel.isPresent) {
444 blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get())
445 blueprintModelRepository.delete(dbBlueprintModel.get())
447 val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
448 throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API, msg)
452 open suspend fun deleteBlueprintModel(name: String, version: String) {
453 blueprintsProcessorCatalogService.deleteFromDatabase(name, version)
457 * This is a CBA enrichBlueprint method
458 * Save the Zip File in archive location and extract the cba content.
459 * Populate the Enhancement Location
460 * Enhance the CBA content
461 * Compress the Enhanced Content
462 * Return back the the compressed content back to the caller.
464 * @param filePart filePart
465 * @return ResponseEntity<Resource>
466 * @throws BluePrintException BluePrintException
468 @Throws(BluePrintException::class)
469 open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity<Resource> {
471 val enhancedByteArray = enrichBlueprintFileSource(filePart)
472 return BluePrintEnhancerUtils.prepareResourceEntity("enhanced-cba.zip", enhancedByteArray)
473 } catch (e: BluePrintProcessorException) {
474 e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
475 val errorMsg = "Error while enhancing the CBA package."
476 throw e.updateErrorMessage(
477 DesignerApiDomains.DESIGNER_API, errorMsg,
478 "Wrong CBA file provided, please verify and enrich Again."
480 } catch (e: Exception) {
481 throw httpProcessorException(
482 ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
483 "EnrichBlueprint: ${e.message}", e.errorCauseOrDefault()
489 * This is a publishBlueprintModel method to change the status published to YES
490 * NOTE: this method is meant for enriched blueprints only.
492 * @param filePart filePart
493 * @return BlueprintModelSearch
494 * @throws BluePrintException BluePrintException
496 @Throws(BluePrintException::class)
497 open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch {
499 return upload(filePart, true)
500 } catch (e: BluePrintProcessorException) {
501 e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
502 val errorMsg = "Error in Publishing CBA."
503 throw e.updateErrorMessage(
504 DesignerApiDomains.DESIGNER_API, errorMsg,
505 "Wrong CBA provided, please verify and enrich your CBA."
507 } catch (e: Exception) {
508 throw httpProcessorException(
509 ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
510 "Error in Publishing CBA: ${e.message}", e.errorCauseOrDefault()
516 * Enrich and publish the blueprint.
517 * NOTE: this method is meant for the unenriched vs publishBlueprint(filePart)
518 * which is used for enriched blueprints.
520 * @param filePart filePart
521 * @return BlueprintModelSearch
522 * @throws BluePrintException BluePrintException
524 @Throws(BluePrintException::class)
525 open suspend fun enrichAndPublishBlueprint(filePart: FilePart): BlueprintModelSearch {
527 val enhancedByteArray = enrichBlueprintFileSource(filePart)
528 return upload(enhancedByteArray, true)
529 } catch (e: BluePrintProcessorException) {
530 e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
531 val errorMsg = "Error while enhancing and uploading the CBA package."
532 throw e.updateErrorMessage(
533 DesignerApiDomains.DESIGNER_API, errorMsg,
534 "Wrong CBA file provided, please verify the source CBA."
536 } catch (e: Exception) {
537 throw httpProcessorException(
538 ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
539 "EnrichBlueprint: ${e.message}", e.errorCauseOrDefault()
544 /** Common CBA Save and Publish function for RestController and GRPC Handler, the [fileSource] may be
545 * byteArray or File Part type.*/
546 open suspend fun upload(fileSource: Any, validate: Boolean): BlueprintModelSearch {
547 val saveId = UUID.randomUUID().toString()
548 val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, saveId)
549 val blueprintWorking = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId)
551 val compressedFile = normalizedFile(blueprintArchive, "cba.zip")
553 is FilePart -> BluePrintEnhancerUtils.filePartAsFile(fileSource, compressedFile)
554 is ByteArray -> BluePrintEnhancerUtils.byteArrayAsFile(fileSource, compressedFile)
556 // Save the Copied file to Database
557 val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, validate)
559 return blueprintModelSearchRepository.findById(blueprintId)
560 ?: throw httpProcessorException(
561 ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
562 String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId)
564 } catch (e: BluePrintException) {
565 e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
566 val errorMsg = "Error in Upload CBA."
567 throw e.updateErrorMessage(
568 DesignerApiDomains.DESIGNER_API, errorMsg,
569 "Wrong enriched CBA."
571 } catch (e: IOException) {
572 throw httpProcessorException(
573 ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
574 "Error in Upload CBA: ${e.errorMessageOrDefault()}", e.errorCauseOrDefault()
577 // Clean blueprint script cache
578 val cacheKey = BluePrintFileUtils
579 .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId))
580 BluePrintCompileCache.cleanClassLoader(cacheKey)
581 deleteNBDir(blueprintArchive)
582 deleteNBDir(blueprintWorking)
586 /** Common CBA download function for RestController and GRPC Handler, the [fileSource] may be
587 * byteArray or File Part type.*/
588 open fun download(name: String, version: String): ByteArray {
590 val blueprintModel = getBlueprintModelByNameAndVersion(name, version)
591 return blueprintModel.blueprintModelContent?.content
592 ?: throw httpProcessorException(
593 ErrorCatalogCodes.RESOURCE_NOT_FOUND, DesignerApiDomains.DESIGNER_API,
594 "Error while downloading the CBA file: couldn't get model content"
596 } catch (e: BluePrintException) {
597 e.http(ErrorCatalogCodes.RESOURCE_NOT_FOUND)
598 val errorMsg = "Fail to get Blueprint Model content."
599 throw e.updateErrorMessage(
600 DesignerApiDomains.DESIGNER_API, errorMsg,
601 "Wrong name and version was provide."
606 /** Common CBA Enrich function for RestController and GRPC Handler, the [fileSource] may be
607 * byteArray or File Part type.*/
608 open suspend fun enrichBlueprintFileSource(fileSource: Any): ByteArray {
609 val enhanceId = UUID.randomUUID().toString()
610 val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, enhanceId)
611 val blueprintWorkingDir = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, enhanceId)
615 BluePrintEnhancerUtils
616 .copyFilePartToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir)
618 BluePrintEnhancerUtils
619 .copyByteArrayToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir)
620 } // Enhance the Blue Prints
621 bluePrintEnhancerService.enhance(blueprintWorkingDir)
623 return BluePrintEnhancerUtils.compressEnhanceDirAndReturnByteArray(blueprintWorkingDir, blueprintArchive)
624 } catch (e: BluePrintException) {
625 e.http(ErrorCatalogCodes.IO_FILE_INTERRUPT)
626 val errorMsg = "Fail Enriching the CBA."
627 throw e.updateErrorMessage(DesignerApiDomains.DESIGNER_API, errorMsg)
628 } catch (e: IOException) {
629 throw httpProcessorException(
630 ErrorCatalogCodes.IO_FILE_INTERRUPT, DesignerApiDomains.DESIGNER_API,
631 "Error while Enriching the CBA file.", e.errorCauseOrDefault()
634 BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintWorkingDir)
640 private const val BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo"
641 private const val BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + " and version(%s) from repo"