aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-12 15:48:20 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-18 13:56:01 -0500
commit125b60f22593467dd633c19a296b92ddcb4b260b (patch)
tree8c279361132219433e496eea5edf60ec25249072 /ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org
parent78702c12bd0b6cb8ec0fd621f27fa61c9a017fbe (diff)
Implement BluePrintCatalogService
Change-Id: Ifcb0d730daec4da747d704c270b72b991e01f474 Issue-ID: CCSDK-908 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org')
-rwxr-xr-xms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt119
-rwxr-xr-xms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt15
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt6
3 files changed, 76 insertions, 64 deletions
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
+}