Implement BluePrintCatalogService 22/75722/7
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Sat, 12 Jan 2019 20:48:20 +0000 (15:48 -0500)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Fri, 18 Jan 2019 18:56:01 +0000 (13:56 -0500)
Change-Id: Ifcb0d730daec4da747d704c270b72b991e01f474
Issue-ID: CCSDK-908
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
15 files changed:
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties
ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt
ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt
ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt

index 9186635..c99cdf7 100755 (executable)
 
 package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
 
-interface BluePrintCatalogService {
+import org.jetbrains.annotations.NotNull
+import org.jetbrains.annotations.Nullable
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import java.io.File
+import java.nio.file.Path
 
-    /**
-     * Upload the CBA Zip fle to data base and return the Database identifier
-     */
-    fun uploadToDataBase(file: String, validate : Boolean): String
+interface BluePrintCatalogService {
 
     /**
-     * Download the CBA zip file from the data base and place it in a path and return the CBA zip absolute path
+     * Save the CBA to database.
+     * @param blueprintFile Either a directory, or an archive
+     * @param validate whether to validate blueprint content. Default true.
+     * @return The unique blueprint identifier
+     * @throws BluePrintException if process failed
      */
-    fun downloadFromDataBase(name: String, version: String, path: String): String
+    @NotNull
+    @Throws(BluePrintException::class)
+    fun saveToDatabase(@NotNull blueprintFile: File, @Nullable validate: Boolean = true): String
 
     /**
-     * Get the Blueprint from Data Base and Download it under working directory and return the path path
+     * Retrieve the CBA from database either archived or extracted.
+     * @param name Name of the blueprint
+     * @param version Version of the blueprint
+     * @param extract true to extract the content, false for archived content. Default to true
+     * @return Path where CBA is located
+     * @throws BluePrintException if process failed
      */
-    fun prepareBluePrint(name: String, version: String): String
+    @NotNull
+    @Throws(BluePrintException::class)
+    fun getFromDatabase(@NotNull name: String, @NotNull version: String, @Nullable extract: Boolean = true): Path
 
     /**
-     * Get blueprint archive with zip file from Data Base
+     * Delete the CBA from database.
+     * @param name Name of the blueprint
+     * @param version Version of the blueprint
+     * @throws BluePrintException if process failed
      */
-    fun downloadFromDataBase(uuid: String, path: String): String
+    @NotNull
+    @Throws(BluePrintException::class)
+    fun deleteFromDatabase(@NotNull name: String, @NotNull version: String)
 }
\ No newline at end of file
index 89b7f64..dee7ae8 100755 (executable)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.db
 
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
 import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel
 import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelContentRepository
 import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
+import org.slf4j.LoggerFactory
 import org.springframework.dao.DataIntegrityViolationException
 import org.springframework.stereotype.Service
 import java.io.File
 import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
 
 /**
-Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl]
+ * Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl]
  */
 @Service
-class BlueprintProcessorCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
-                                           private val bluePrintValidatorService: BluePrintValidatorService,
+class BlueprintProcessorCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService,
+                                           private val blueprintConfig: BluePrintCoreConfiguration,
                                            private val blueprintModelRepository: BlueprintProcessorModelRepository)
-    : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
-
-    override fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean?) {
-        var valid = false
-        val firstItem = BluePrintArchiveUtils.getFirstItemInDirectory(extractedDirectory)
-        val blueprintBaseDirectory = extractedDirectory.absolutePath + "/" + firstItem
-        // Validate Blueprint
-        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintBaseDirectory)
-
-        // Check Validity of blueprint
-        if (checkValidity!!) {
-            valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
+    : BlueprintCatalogServiceImpl(bluePrintValidatorService) {
+
+    private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString())
+
+    init {
+
+        log.info("BlueprintProcessorCatalogServiceImpl initialized")
+    }
+
+    override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version)
+
+
+    override fun get(name: String, version: String, extract: Boolean): Path? {
+        var path = "${blueprintConfig.archivePath}/$name/$version.zip"
+
+        blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also {
+            it.blueprintModelContent.run {
+                val file = File(path)
+                file.parentFile.mkdirs()
+                file.createNewFile()
+                file.writeBytes(this!!.content!!).let {
+                    if (extract) {
+                        path = "${blueprintConfig.archivePath}/$name/$version"
+                        BluePrintArchiveUtils.deCompress(file, path)
+                    }
+                    return Paths.get(path)
+                }
+            }
         }
+        return null
+    }
 
-        if ((valid && checkValidity!!) || (!valid && !checkValidity!!)) {
-            val metaData = bluePrintRuntimeService.bluePrintContext().metadata!!
-            // FIXME("Check Duplicate for Artifact Name and Artifact Version")
-            val blueprintModel = BlueprintProcessorModel()
-            blueprintModel.id = id
-            blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
-            blueprintModel.published = ApplicationConstants.ACTIVE_N
-            blueprintModel.artifactName = metaData[BluePrintConstants.METADATA_TEMPLATE_NAME]
-            blueprintModel.artifactVersion = metaData[BluePrintConstants.METADATA_TEMPLATE_VERSION]
-            blueprintModel.updatedBy = metaData[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
-            blueprintModel.tags = metaData[BluePrintConstants.METADATA_TEMPLATE_TAGS]
-            blueprintModel.artifactDescription = "Controller Blueprint for ${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
-
-            val blueprintModelContent = BlueprintProcessorModelContent()
-            blueprintModelContent.id = id // For quick access both id's are same.always have one to one mapping.
-            blueprintModelContent.contentType = "CBA_ZIP"
-            blueprintModelContent.name = "${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
-            blueprintModelContent.description = "(${blueprintModel.artifactName}:${blueprintModel.artifactVersion} CBA Zip Content"
-            blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
-
-            // Set the Blueprint Model into blueprintModelContent
-            blueprintModelContent.blueprintModel = blueprintModel
-
-            // Set the Blueprint Model Content into blueprintModel
-            blueprintModel.blueprintModelContent = blueprintModelContent
-
-            try {
-                blueprintModelRepository.saveAndFlush(blueprintModel)
-            } catch (ex: DataIntegrityViolationException) {
-                throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " +
-                        "is already exist in database: ${ex.message}", ex)
+    override fun save(metadata: MutableMap<String, String>, archiveFile: File) {
+        val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
+        val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
+
+        log.isDebugEnabled.apply {
+            blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
+                log.debug("Overwriting blueprint model :$artifactName::$artifactVersion")
             }
         }
+
+        val blueprintModel = BlueprintProcessorModel()
+        blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
+        blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
+        blueprintModel.artifactName = artifactName
+        blueprintModel.artifactVersion = artifactVersion
+        blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
+        blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]
+        blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion"
+
+        val blueprintModelContent = BlueprintProcessorModelContent()
+        blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
+        blueprintModelContent.contentType = "CBA_ZIP"
+        blueprintModelContent.name = "$artifactName:$artifactVersion"
+        blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content"
+        blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
+        blueprintModelContent.blueprintModel = blueprintModel
+
+        blueprintModel.blueprintModelContent = blueprintModelContent
+
+        try {
+            blueprintModelRepository.saveAndFlush(blueprintModel)
+        } catch (ex: DataIntegrityViolationException) {
+            throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " +
+                    "is already exist in database: ${ex.message}", ex)
+        }
     }
 }
\ No newline at end of file
index 00d4830..0935d03 100755 (executable)
@@ -40,13 +40,11 @@ import javax.persistence.TemporalType
 @Table(name = "BLUEPRINT_RUNTIME")
 @Proxy(lazy = false)
 class BlueprintProcessorModel : Serializable {
+
     @Id
-    @Column(name = "config_model_id")
+    @Column(name = "blueprint_runtime_id")
     var id: String? = null
 
-    @Column(name = "artifact_uuid")
-    var artifactUUId: String? = null
-
     @Column(name = "artifact_type")
     var artifactType: String? = null
 
@@ -58,9 +56,6 @@ class BlueprintProcessorModel : Serializable {
     @Column(name = "artifact_description")
     var artifactDescription: String? = null
 
-    @Column(name = "internal_version")
-    var internalVersion: Int? = null
-
     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
     @LastModifiedDate
     @Temporal(TemporalType.TIMESTAMP)
@@ -71,10 +66,6 @@ class BlueprintProcessorModel : Serializable {
     @ApiModelProperty(required = true)
     var artifactName: String? = null
 
-    @Column(name = "published", nullable = false)
-    @ApiModelProperty(required = true)
-    var published: String? = null
-
     @Column(name = "updated_by", nullable = false)
     @ApiModelProperty(required = true)
     var updatedBy: String? = null
@@ -90,4 +81,4 @@ class BlueprintProcessorModel : Serializable {
     companion object {
         private const val serialVersionUID = 1L
     }
-}
\ No newline at end of file
+}
index d012af5..58bf8a3 100644 (file)
@@ -40,7 +40,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener
 class BlueprintProcessorModelContent : Serializable {
 
     @Id
-    @Column(name = "config_model_content_id")
+    @Column(name = "blueprint_content_runtime_id")
     var id: String? = null
 
     @Column(name = "name", nullable = false)
@@ -52,7 +52,7 @@ class BlueprintProcessorModelContent : Serializable {
     var contentType: String? = null
 
     @OneToOne
-    @JoinColumn(name = "config_model_id")
+    @JoinColumn(name = "blueprint_runtime_id")
     var blueprintModel: BlueprintProcessorModel? = null
 
     @Lob
@@ -98,4 +98,4 @@ class BlueprintProcessorModelContent : Serializable {
         private const val serialVersionUID = 1L
     }
 
-}
\ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt
new file mode 100644 (file)
index 0000000..4c95316
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.ccsdk.apps.blueprintsprocessor.db
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import java.io.File
+import java.nio.file.Paths
+import kotlin.test.assertTrue
+
+@RunWith(SpringRunner::class)
+@EnableAutoConfiguration
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class BlueprintProcessorCatalogServiceImplTest {
+
+    @Autowired
+    lateinit var blueprintCatalog: BluePrintCatalogService
+
+    @Test
+    fun `test catalog service`() {
+        val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
+        assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
+
+        blueprintCatalog.saveToDatabase(file)
+
+        blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0")
+
+        blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0")
+
+        File("./src/test/resources/baseconfiguration").deleteRecursively()
+    }
+}
\ No newline at end of file
index 6f10626..3ac7ec3 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
+blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
 blueprintsprocessor.db.primary.username=sa
 blueprintsprocessor.db.primary.password=
 blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
@@ -22,7 +22,6 @@ blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
 blueprintsprocessor.db.primary.hibernateDDLAuto=update
 blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
 blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
-
 # Controller Blueprints Core Configuration
 blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
-blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
\ No newline at end of file
+blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip
new file mode 100644 (file)
index 0000000..a62d4bf
Binary files /dev/null and b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip differ
index 69758ec..56a6393 100644 (file)
@@ -40,10 +40,10 @@ class ExecutionServiceHandler(private val bluePrintCatalogService: BluePrintCata
         val blueprintName = actionIdentifiers.blueprintName
         val blueprintVersion = actionIdentifiers.blueprintVersion
 
-        val basePath = bluePrintCatalogService.prepareBluePrint(blueprintName, blueprintVersion)
+        val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion)
         log.info("blueprint base path $basePath")
 
-        val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath)
+        val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString())
 
         return blueprintDGExecutionService.executeDirectedGraph(blueprintRuntimeService, executionServiceInput)
     }
index 656d92f..e8f25a8 100755 (executable)
@@ -22,6 +22,9 @@ import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExec
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
 import org.springframework.stereotype.Service
+import java.io.File
+import java.nio.file.Path
+import java.nio.file.Paths
 import kotlin.test.assertNotNull
 
 @Service
@@ -38,22 +41,17 @@ class MockBlueprintDGExecutionService : BlueprintDGExecutionService {
 
 @Service
 class MockBluePrintCatalogService : BluePrintCatalogService {
-
-    override fun uploadToDataBase(file: String, validate : Boolean): String {
+    override fun deleteFromDatabase(name: String, version: String) {
         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
     }
 
-    override fun downloadFromDataBase(name: String, version: String, path: String): String {
+    override fun saveToDatabase(blueprintFile: File, validate: Boolean): String {
         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
     }
 
-    override fun prepareBluePrint(name: String, version: String): String {
+    override fun getFromDatabase(name: String, version: String, extract: Boolean): Path {
         assertNotNull(name, "failed to get blueprint Name")
         assertNotNull(version, "failed to get blueprint version")
-        return "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration"
-    }
-
-    override fun downloadFromDataBase(uuid: String, path: String): String {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        return Paths.get("./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
     }
 }
\ No newline at end of file
index 881e3bc..3ba729d 100644 (file)
 
 package org.onap.ccsdk.apps.controllerblueprints.db.resources
 
-import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import java.io.File
+import java.nio.file.Path
+import java.util.*
 import javax.persistence.MappedSuperclass
 
 @MappedSuperclass
-abstract class BlueprintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration) : BluePrintCatalogService {
-
-    override fun uploadToDataBase(file: String, validate: Boolean): String {
-        // The file name provided here is unique as we transform to UUID before storing
-        val blueprintFile = File(file)
-        val fileName = blueprintFile.name
-        val id = BluePrintFileUtils.stripFileExtension(fileName)
-        // If the file is directory
-        if (blueprintFile.isDirectory) {
-
-            val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/$fileName")
-            // zip the directory
-            BluePrintArchiveUtils.compress(blueprintFile, zipFile, true)
+abstract class BlueprintCatalogServiceImpl(private val blueprintValidator: BluePrintValidatorService)
+    : BluePrintCatalogService {
 
-            // Upload to the Data Base
-            saveToDataBase(blueprintFile, id, zipFile)
+    override fun saveToDatabase(blueprintFile: File, validate: Boolean): String {
+        val extractedDirectory: File
+        val archivedDirectory: File
+        val toDeleteDirectory: File
+        val blueprintId = UUID.randomUUID().toString()
 
-            // After Upload to Database delete the zip file
-            zipFile.delete()
+        if (blueprintFile.isDirectory) {
+            extractedDirectory = blueprintFile
+            archivedDirectory = File(":$blueprintFile.zip")
+            toDeleteDirectory = archivedDirectory
 
+            if (!BluePrintArchiveUtils.compress(blueprintFile, archivedDirectory, true)) {
+                throw BluePrintException("Fail to compress blueprint")
+            }
         } else {
-            // If the file is ZIP
-            // unzip the CBA file to validate before store in database
-            val targetDir = "${bluePrintLoadConfiguration.blueprintDeployPath}/$id/"
-            val extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir)
+            val targetDir = "${blueprintFile.parent}/${BluePrintFileUtils.stripFileExtension(blueprintFile.name)}"
 
-            // Upload to the Data Base
-            saveToDataBase(extractedDirectory, id, blueprintFile)
+            extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir)
+            archivedDirectory = blueprintFile
+            toDeleteDirectory = extractedDirectory
+        }
 
-            // After Upload to Database delete the zip file
-            blueprintFile.delete()
-            extractedDirectory.delete()
+        if (validate) {
+            blueprintValidator.validateBluePrints(extractedDirectory.path)
         }
 
-        return id
-    }
+        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, extractedDirectory.path)
+        val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
+        metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
 
-    override fun downloadFromDataBase(name: String, version: String, path: String): String {
-        // If path ends with zip, then compress otherwise download as extracted folder
+        save(metadata, archivedDirectory)
 
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
-    }
+        toDeleteDirectory.deleteRecursively()
 
-    override fun downloadFromDataBase(uuid: String, path: String): String {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        return blueprintId
     }
 
-    override fun prepareBluePrint(name: String, version: String): String {
-        val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version"
-        downloadFromDataBase(name, version, preparedPath)
-        return preparedPath
-    }
+    override fun getFromDatabase(name: String, version: String, extract: Boolean): Path = get(name, version, extract)
+            ?: throw BluePrintException("Could not find blueprint $name:$version from database")
+
+    override fun deleteFromDatabase(name: String, version: String) = delete(name, version)
+
+    abstract fun save(metadata: MutableMap<String, String>, archiveFile: File)
+    abstract fun get(name: String, version: String, extract: Boolean): Path?
+    abstract fun delete(name: String, version: String)
 
-    abstract fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean? = false)
 }
\ No newline at end of file
index 4965677..680f1b2 100644 (file)
@@ -43,25 +43,24 @@ interface ModelContentRepository<T, B> : JpaRepository<B, String> {
      *
      * @param blueprintModel blueprintModel
      * @param contentType contentType
-     * @return Optional<B>
+     * @return B?
      */
-    fun findTopByBlueprintModelAndContentType(blueprintModel: T,
-                                              contentType: String): Optional<B>
+    fun findTopByBlueprintModelAndContentType(blueprintModel: T, contentType: String): B?
 
     /**
      * This is a findByBlueprintModelAndContentType method
      *
      * @param blueprintModel blueprintModel
      * @param contentType contentType
-     * @return Optional<BlueprintModelContent>
+     * @return List<B>
      */
     fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List<B>
 
     /**
      * This is a findByBlueprintModel method
      *
-     * @param blueprintModel B
-     * @return Optional<T>
+     * @param blueprintModel T
+     * @return List<B>
      */
     fun findByBlueprintModel(blueprintModel: T): List<B>
 
@@ -71,15 +70,14 @@ interface ModelContentRepository<T, B> : JpaRepository<B, String> {
      * @param blueprintModel blueprintModel
      * @param contentType contentType
      * @param name name
-     * @return Optional<B>
+     * @return B?
      */
-    fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T,
-                                                  contentType: String, name: String): Optional<B>
+    fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, contentType: String, name: String): B?
 
     /**
      * This is a deleteByMdeleteByBlueprintModelodelName method
      *
-     * @param blueprintModel B
+     * @param blueprintModel T
      */
     fun deleteByBlueprintModel(blueprintModel: T)
 
@@ -90,4 +88,4 @@ interface ModelContentRepository<T, B> : JpaRepository<B, String> {
      */
     override fun deleteById(@NotNull id: String)
 
-}
\ No newline at end of file
+}
index c31f009..e796c36 100644 (file)
 package org.onap.ccsdk.apps.controllerblueprints.db.resources.repository
 
 import org.jetbrains.annotations.NotNull
-import java.util.Optional
 import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.data.repository.NoRepositoryBean
+import java.util.*
+import javax.transaction.Transactional
 
 /**
  * @param <T> Model
@@ -42,23 +43,23 @@ interface ModelRepository<T> : JpaRepository<T, String> {
      *
      * @param artifactName artifactName
      * @param artifactVersion artifactVersion
-     * @return Optional<T>
+     * @return T?
      */
-    fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<T>
+    fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): T?
 
     /**
      * This is a findTopByArtifactNameOrderByArtifactIdDesc method
      *
      * @param artifactName artifactName
-     * @return Optional<T>
+     * @return T?
      */
-    fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): Optional<T>
+    fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): T?
 
     /**
      * This is a findTopByArtifactName method
      *
      * @param artifactName artifactName
-     * @return Optional<T>
+     * @return List<T>
      */
     fun findTopByArtifactName(artifactName: String): List<T>
 
@@ -66,7 +67,7 @@ interface ModelRepository<T> : JpaRepository<T, String> {
      * This is a findByTagsContainingIgnoreCase method
      *
      * @param tags tags
-     * @return Optional<ModelType>
+     * @return List<T>
      */
     fun findByTagsContainingIgnoreCase(tags: String): List<T>
 
@@ -76,6 +77,7 @@ interface ModelRepository<T> : JpaRepository<T, String> {
      * @param artifactName artifactName
      * @param artifactVersion artifactVersion
      */
+    @Transactional
     fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String)
 
     /**
@@ -85,4 +87,4 @@ interface ModelRepository<T> : JpaRepository<T, String> {
      */
     override fun deleteById(@NotNull id: String)
 
-}
+}
\ No newline at end of file
index e80fa8c..3cf144f 100644 (file)
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service;\r
 \r
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
 import org.jetbrains.annotations.NotNull;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants;\r
@@ -41,11 +45,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;\r
 import reactor.core.publisher.Mono;\r
 \r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.util.List;\r
-import java.util.Optional;\r
-\r
 /**\r
  * BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService\r
  *\r
@@ -73,7 +72,7 @@ public class BlueprintModelService {
 \r
     private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo";\r
     private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" +\r
-                                                                    " and version(%s) from repo";\r
+        " and version(%s) from repo";
 \r
     /**\r
      * This is a saveBlueprintModel method\r
@@ -85,15 +84,20 @@ public class BlueprintModelService {
     public Mono<BlueprintModelSearch> saveBlueprintModel(FilePart filePart) throws BluePrintException {\r
         try {\r
             Path cbaLocation = BluePrintFileUtils.Companion\r
-                    .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);\r
+                .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);
             return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> {\r
-                String blueprintId = bluePrintCatalogService\r
-                        .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false);\r
+                String blueprintId = null;
+                try {
+                    blueprintId = bluePrintCatalogService
+                        .saveToDatabase(cbaLocation.toFile(), false);
+                } catch (BluePrintException e) {
+                    // FIXME handle expection
+                }
                 return blueprintModelSearchRepository.findById(blueprintId).get();\r
             });\r
         } catch (IOException e) {\r
             throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(),\r
-                    String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e);\r
+                String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e);
         }\r
     }\r
 \r
@@ -136,15 +140,15 @@ public class BlueprintModelService {
      * @throws BluePrintException BluePrintException\r
      */\r
     public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version)\r
-            throws BluePrintException {\r
+        throws BluePrintException {
         BlueprintModelSearch blueprintModelSearch;\r
         Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository\r
-                .findByArtifactNameAndArtifactVersion(name, version);\r
+            .findByArtifactNameAndArtifactVersion(name, version);
         if (dbBlueprintModel.isPresent()) {\r
             blueprintModelSearch = dbBlueprintModel.get();\r
         } else {\r
             throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(),\r
-                    String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));\r
+                String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));
         }\r
         return blueprintModelSearch;\r
     }\r
@@ -152,19 +156,20 @@ public class BlueprintModelService {
     /**\r
      * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version\r
      *\r
-     * @param name    name\r
+     * @param name name
      * @param version version\r
      * @return ResponseEntity<Resource>\r
      * @throws BluePrintException BluePrintException\r
      */\r
-    public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name, @NotNull String version)\r
-            throws BluePrintException {\r
+    public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name,
+        @NotNull String version)
+        throws BluePrintException {
         BlueprintModel blueprintModel;\r
         try {\r
             blueprintModel = getBlueprintModelByNameAndVersion(name, version);\r
         } catch (BluePrintException e) {\r
             throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +\r
-                    "downloading the CBA file: %s", e.getMessage()), e);\r
+                "downloading the CBA file: %s", e.getMessage()), e);
         }\r
         String fileName = blueprintModel.getId() + ".zip";\r
         byte[] file = blueprintModel.getBlueprintModelContent().getContent();\r
@@ -183,7 +188,7 @@ public class BlueprintModelService {
             blueprintModel = getBlueprintModel(id);\r
         } catch (BluePrintException e) {\r
             throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +\r
-                    "downloading the CBA file: %s", e.getMessage()), e);\r
+                "downloading the CBA file: %s", e.getMessage()), e);
         }\r
         String fileName = blueprintModel.getId() + ".zip";\r
         byte[] file = blueprintModel.getBlueprintModelContent().getContent();\r
@@ -191,15 +196,13 @@ public class BlueprintModelService {
     }\r
 \r
     /**\r
-     *\r
-     * @param (fileName, file)\r
      * @return ResponseEntity<Resource>\r
      */\r
     private ResponseEntity<Resource> prepareResourceEntity(String fileName, byte[] file) {\r
         return ResponseEntity.ok()\r
-                .contentType(MediaType.parseMediaType("text/plain"))\r
-                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")\r
-                .body(new ByteArrayResource(file));\r
+            .contentType(MediaType.parseMediaType("text/plain"))
+            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
+            .body(new ByteArrayResource(file));
     }\r
 \r
     /**\r
@@ -224,22 +227,21 @@ public class BlueprintModelService {
     /**\r
      * This is a getBlueprintModelByNameAndVersion method\r
      *\r
-     * @param name    name\r
+     * @param name name
      * @param version version\r
      * @return BlueprintModel\r
      * @throws BluePrintException BluePrintException\r
      */\r
     private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)\r
-            throws BluePrintException {\r
-        BlueprintModel blueprintModel;\r
-        Optional<BlueprintModel> dbBlueprintModel = blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version);\r
-        if (dbBlueprintModel.isPresent()) {\r
-            blueprintModel = dbBlueprintModel.get();\r
+        throws BluePrintException {
+        BlueprintModel blueprintModel = blueprintModelRepository
+            .findByArtifactNameAndArtifactVersion(name, version);
+        if (blueprintModel != null) {
+            return blueprintModel;
         } else {\r
             String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version);\r
             throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);\r
         }\r
-        return blueprintModel;\r
     }\r
 \r
     /**\r
index d49bcdf..4fd66ed 100644 (file)
@@ -59,7 +59,7 @@ open class BluePrintCatalogLoadService(private val bluePrintCatalogService: Blue
 
     open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) {
         try {
-            bluePrintCatalogService.uploadToDataBase(file.absolutePath, true)
+            bluePrintCatalogService.saveToDatabase(file)
         } catch (e: Exception) {
             errorBuilder.appendln("Couldn't load DataType(${file.name}: ${e.message}")
         }
index 6b367c4..04071dd 100755 (executable)
 package org.onap.ccsdk.apps.controllerblueprints.service.load
 
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository
+import org.slf4j.LoggerFactory
 import org.springframework.dao.DataIntegrityViolationException
 import org.springframework.stereotype.Service
 import java.io.File
 import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
 
 /**
-Similar implementation in [org.onap.ccsdk.apps.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl]
+ * Similar implementation in [org.onap.ccsdk.apps.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl]
  */
 @Service
-class ControllerBlueprintCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
-                                            private val bluePrintValidatorService: BluePrintValidatorService,
+class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService,
+                                            private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
                                             private val blueprintModelRepository: ControllerBlueprintModelRepository)
-    : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
+    : BlueprintCatalogServiceImpl(bluePrintValidatorService) {
 
-    override fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean?) {
-        var valid = false
-        val firstItem = BluePrintArchiveUtils.getFirstItemInDirectory(extractedDirectory)
-        val blueprintBaseDirectory = extractedDirectory.absolutePath + "/" + firstItem
-        // Validate Blueprint
-        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintBaseDirectory)
 
-        // Check Validity of blueprint
-        if (checkValidity!!) {
-            valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
-        }
+    private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString())
 
-        if ((valid && checkValidity!!) || (!valid && !checkValidity!!)) {
-            val metaData = bluePrintRuntimeService.bluePrintContext().metadata!!
-            val blueprintModel = BlueprintModel()
-            blueprintModel.id = id
-            blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
-            blueprintModel.published = ApplicationConstants.ACTIVE_N
-            blueprintModel.artifactName = metaData[BluePrintConstants.METADATA_TEMPLATE_NAME]
-            blueprintModel.artifactVersion = metaData[BluePrintConstants.METADATA_TEMPLATE_VERSION]
-            blueprintModel.updatedBy = metaData[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
-            blueprintModel.tags = metaData[BluePrintConstants.METADATA_TEMPLATE_TAGS]
-            blueprintModel.artifactDescription = "Controller Blueprint for ${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
+    init {
+        log.info("BlueprintProcessorCatalogServiceImpl initialized")
+    }
 
-            val blueprintModelContent = BlueprintModelContent()
-            blueprintModelContent.id = id // For quick access both id's are same.always have one to one mapping.
-            blueprintModelContent.contentType = "CBA_ZIP"
-            blueprintModelContent.name = "${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
-            blueprintModelContent.description = "(${blueprintModel.artifactName}:${blueprintModel.artifactVersion} CBA Zip Content"
-            blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
+    override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version)
 
-            // Set the Blueprint Model into blueprintModelContent
-            blueprintModelContent.blueprintModel = blueprintModel
+    override fun get(name: String, version: String, extract: Boolean): Path? {
+        val path = if (extract) {
+            Paths.get("${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version")
+        } else {
+            Paths.get("${bluePrintLoadConfiguration.blueprintArchivePath}/$name/$version.zip")
+        }
+        blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also {
+            it.blueprintModelContent.run {
+                path.toFile().writeBytes(this!!.content!!).let {
+                    return path
+                }
+            }
+        }
+        return null
+    }
+
+    override fun save(metadata: MutableMap<String, String>, archiveFile: File) {
 
-            // Set the Blueprint Model Content into blueprintModel
-            blueprintModel.blueprintModelContent = blueprintModelContent
+        val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
+        val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
 
-            try {
-                blueprintModelRepository.saveAndFlush(blueprintModel)
-            } catch (ex: DataIntegrityViolationException) {
-                throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " +
-                        "is already exist in database: ${ex.message}", ex)
+        log.isDebugEnabled.apply {
+            blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
+                log.debug("Overwriting blueprint model :$artifactName::$artifactVersion")
             }
         }
+
+        val blueprintModel = BlueprintModel()
+        blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
+        blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
+        blueprintModel.published = ApplicationConstants.ACTIVE_N
+        blueprintModel.artifactName = artifactName
+        blueprintModel.artifactVersion = artifactVersion
+        blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
+        blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS]
+        blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion"
+
+        val blueprintModelContent = BlueprintModelContent()
+        blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
+        blueprintModelContent.contentType = "CBA_ZIP"
+        blueprintModelContent.name = "$artifactName:$artifactVersion"
+        blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content"
+        blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
+        blueprintModelContent.blueprintModel = blueprintModel
+
+        try {
+            blueprintModelRepository.saveAndFlush(blueprintModel)
+        } catch (ex: DataIntegrityViolationException) {
+            throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " +
+                    "is already exist in database: ${ex.message}", ex)
+        }
     }
 }
\ No newline at end of file