diff options
author | Dan Timoney <dtimoney@att.com> | 2019-01-19 01:04:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-01-19 01:04:20 +0000 |
commit | 6e508791783a0150cedab6f9275c55ca936bd16e (patch) | |
tree | b8cd395f404dd612100b05547c2b88ed5198c2f5 | |
parent | e03e5b5c4222f492bb02c231b3f2e65c1bb6690e (diff) | |
parent | 125b60f22593467dd633c19a296b92ddcb4b260b (diff) |
Merge "Implement BluePrintCatalogService"
15 files changed, 322 insertions, 223 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt index 9186635e..c99cdf74 100755 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt @@ -16,25 +16,44 @@ 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 diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt index 89b7f649..dee7ae86 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt @@ -17,77 +17,98 @@ 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 diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt index 00d4830e..0935d038 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt @@ -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 +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt index d012af58..58bf8a33 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt @@ -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 index 00000000..4c953163 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt @@ -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 diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties index 6f10626e..3ac7ec38 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties @@ -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 Binary files differnew file mode 100644 index 00000000..a62d4bfb --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 69758ecf..56a6393a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -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) } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt index 656d92f1..e8f25a89 100755 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt @@ -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 diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt index 881e3bc4..3ba729d1 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt @@ -17,66 +17,66 @@ 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 diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt index 4965677e..680f1b2c 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelContentRepository.kt @@ -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 +} diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt index c31f009a..e796c366 100644 --- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt +++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/repository/ModelRepository.kt @@ -18,9 +18,10 @@ 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 diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java index e80fa8cd..3cf144f1 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java @@ -17,6 +17,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service;
+import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; import org.jetbrains.annotations.NotNull;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants;
@@ -41,11 +45,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Mono;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Optional;
-
/**
* BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService
*
@@ -73,7 +72,7 @@ public class BlueprintModelService { private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo";
private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" +
- " and version(%s) from repo";
+ " and version(%s) from repo"; /**
* This is a saveBlueprintModel method
@@ -85,15 +84,20 @@ public class BlueprintModelService { public Mono<BlueprintModelSearch> saveBlueprintModel(FilePart filePart) throws BluePrintException {
try {
Path cbaLocation = BluePrintFileUtils.Companion
- .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath);
+ .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> {
- String blueprintId = bluePrintCatalogService
- .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false);
+ String blueprintId = null; + try { + blueprintId = bluePrintCatalogService + .saveToDatabase(cbaLocation.toFile(), false); + } catch (BluePrintException e) { + // FIXME handle expection + } return blueprintModelSearchRepository.findById(blueprintId).get();
});
} catch (IOException e) {
throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(),
- String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e);
+ String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e); }
}
@@ -136,15 +140,15 @@ public class BlueprintModelService { * @throws BluePrintException BluePrintException
*/
public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version)
- throws BluePrintException {
+ throws BluePrintException { BlueprintModelSearch blueprintModelSearch;
Optional<BlueprintModelSearch> dbBlueprintModel = blueprintModelSearchRepository
- .findByArtifactNameAndArtifactVersion(name, version);
+ .findByArtifactNameAndArtifactVersion(name, version); if (dbBlueprintModel.isPresent()) {
blueprintModelSearch = dbBlueprintModel.get();
} else {
throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(),
- String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version));
+ String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); }
return blueprintModelSearch;
}
@@ -152,19 +156,20 @@ public class BlueprintModelService { /**
* This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version
*
- * @param name name
+ * @param name name * @param version version
* @return ResponseEntity<Resource>
* @throws BluePrintException BluePrintException
*/
- public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name, @NotNull String version)
- throws BluePrintException {
+ public ResponseEntity<Resource> downloadBlueprintModelFileByNameAndVersion(@NotNull String name, + @NotNull String version) + throws BluePrintException { BlueprintModel blueprintModel;
try {
blueprintModel = getBlueprintModelByNameAndVersion(name, version);
} catch (BluePrintException e) {
throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +
- "downloading the CBA file: %s", e.getMessage()), e);
+ "downloading the CBA file: %s", e.getMessage()), e); }
String fileName = blueprintModel.getId() + ".zip";
byte[] file = blueprintModel.getBlueprintModelContent().getContent();
@@ -183,7 +188,7 @@ public class BlueprintModelService { blueprintModel = getBlueprintModel(id);
} catch (BluePrintException e) {
throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " +
- "downloading the CBA file: %s", e.getMessage()), e);
+ "downloading the CBA file: %s", e.getMessage()), e); }
String fileName = blueprintModel.getId() + ".zip";
byte[] file = blueprintModel.getBlueprintModelContent().getContent();
@@ -191,15 +196,13 @@ public class BlueprintModelService { }
/**
- *
- * @param (fileName, file)
* @return ResponseEntity<Resource>
*/
private ResponseEntity<Resource> prepareResourceEntity(String fileName, byte[] file) {
return ResponseEntity.ok()
- .contentType(MediaType.parseMediaType("text/plain"))
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
- .body(new ByteArrayResource(file));
+ .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") + .body(new ByteArrayResource(file)); }
/**
@@ -224,22 +227,21 @@ public class BlueprintModelService { /**
* This is a getBlueprintModelByNameAndVersion method
*
- * @param name name
+ * @param name name * @param version version
* @return BlueprintModel
* @throws BluePrintException BluePrintException
*/
private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version)
- throws BluePrintException {
- BlueprintModel blueprintModel;
- Optional<BlueprintModel> dbBlueprintModel = blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version);
- if (dbBlueprintModel.isPresent()) {
- blueprintModel = dbBlueprintModel.get();
+ throws BluePrintException { + BlueprintModel blueprintModel = blueprintModelRepository + .findByArtifactNameAndArtifactVersion(name, version); + if (blueprintModel != null) { + return blueprintModel; } else {
String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version);
throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg);
}
- return blueprintModel;
}
/**
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt index d49bcdff..4fd66ed5 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt @@ -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}") } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt index 6b367c4d..04071dd2 100755 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt @@ -18,74 +18,91 @@ 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 |