From 240f25e7fd15209cf298f640bb856793854fa32f Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 30 Aug 2019 16:51:49 -0400 Subject: Combine Blueprint entities and repositories. Change-Id: I9e8672d6d0252dcf125e27060322ddd2b455aa39 Issue-ID: CCSDK-1663 Signed-off-by: Brinda Santh --- .../db/BlueprintCatalogServiceImpl.kt | 87 ------------ .../db/BlueprintProcessorCatalogServiceImpl.kt | 152 -------------------- .../db/primary/domain/BlueprintModel.kt | 12 +- .../db/primary/domain/BlueprintModelContent.kt | 6 +- .../db/primary/domain/BlueprintProcessorModel.kt | 84 ----------- .../domain/BlueprintProcessorModelContent.kt | 101 -------------- .../repository/BlueprintModelContentRepository.kt | 96 +++++++++++++ .../primary/repository/BlueprintModelRepository.kt | 90 ++++++++++++ .../repository/BlueprintModelSearchRepository.kt | 62 +++++++++ .../BlueprintProcessorModelContentRepository.kt | 21 --- .../BlueprintProcessorModelRepository.kt | 20 --- .../ControllerBlueprintModelContentRepository.kt | 21 --- .../ControllerBlueprintModelRepository.kt | 20 --- .../ControllerBlueprintModelSearchRepository.kt | 62 --------- .../primary/repository/ModelContentRepository.kt | 91 ------------ .../db/primary/repository/ModelRepository.kt | 90 ------------ .../db/service/BlueprintCatalogServiceImpl.kt | 87 ++++++++++++ .../BlueprintProcessorCatalogServiceImpl.kt | 154 +++++++++++++++++++++ .../ControllerBlueprintCatalogServiceImpl.kt | 121 ++++++++++++++++ .../db/BlueprintProcessorCatalogServiceImplTest.kt | 2 + 20 files changed, 621 insertions(+), 758 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt delete mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt delete mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelContentRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt (limited to 'ms/blueprintsprocessor/modules/commons') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt deleted file mode 100644 index 4a1e8f194..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintCatalogServiceImpl.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * Modifications Copyright © 2019 IBM. - * - * 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.cds.blueprintsprocessor.db - -import org.onap.ccsdk.cds.controllerblueprints.core.* -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.slf4j.LoggerFactory -import java.io.File -import java.nio.file.Path -import javax.persistence.MappedSuperclass - -@MappedSuperclass -abstract class BlueprintCatalogServiceImpl( - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintValidator: BluePrintValidatorService) : BluePrintCatalogService { - - private val log = LoggerFactory.getLogger(BlueprintCatalogServiceImpl::class.java)!! - - override suspend fun saveToDatabase(processingId: String, blueprintFile: File, validate: Boolean): String { - - var archiveFile: File? = null - var workingDir: String? = null - - if (blueprintFile.isDirectory) { - log.info("Save processing($processingId) Working Dir(${blueprintFile.absolutePath})") - workingDir = blueprintFile.absolutePath - archiveFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, processingId, "cba.zip") - - if (!BluePrintArchiveUtils.compress(blueprintFile, archiveFile)) { - throw BluePrintException("Fail to compress blueprint") - } - } else { - // Compressed File - log.info("Save processing($processingId) CBA(${blueprintFile.absolutePath})") - workingDir = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, processingId) - archiveFile = blueprintFile - // Decompress the CBA file to working Directory - blueprintFile.deCompress(workingDir) - } - - var valid = BluePrintConstants.FLAG_N - if (validate) { - blueprintValidator.validateBluePrints(workingDir!!) - valid = BluePrintConstants.FLAG_Y - } - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!) - val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId - metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid - - save(metadata, archiveFile) - - return processingId - } - - override suspend fun getFromDatabase(name: String, version: String, extract: Boolean): Path = get(name, version, - extract) - ?: throw BluePrintException("Could not find blueprint $name:$version from database") - - override suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version) - - abstract suspend fun save(metadata: MutableMap, archiveFile: File) - abstract suspend fun get(name: String, version: String, extract: Boolean): Path? - abstract suspend fun delete(name: String, version: String) - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt deleted file mode 100755 index 1509e11f1..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * Modifications Copyright © 2018 IBM. - * - * 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.cds.blueprintsprocessor.db - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository -import org.onap.ccsdk.cds.controllerblueprints.core.* -import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils -import org.slf4j.LoggerFactory -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.stereotype.Service -import java.io.File -import java.nio.file.Path -import java.util.* - -/** - * Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] - */ -@Service("blueprintsProcessorCatalogService") -class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintModelRepository: BlueprintProcessorModelRepository) - : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintRuntimeValidatorService) { - - private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) - - override suspend fun delete(name: String, version: String) { - // Clean blueprint script cache - val cacheKey = BluePrintFileUtils - .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, name, version)) - BluePrintCompileCache.cleanClassLoader(cacheKey) - log.info("removed cba file name($name), version($version) from cache") - // Cleaning Deployed Blueprint - deleteNBDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) - log.info("removed cba file name($name), version($version) from deploy location") - // Cleaning Data Base - blueprintModelRepository - .deleteByArtifactNameAndArtifactVersion(name, version) - log.info("removed cba file name($name), version($version) from database") - } - - - override suspend fun get(name: String, version: String, extract: Boolean): Path? { - - val deployFile = normalizedFile(bluePrintLoadConfiguration.blueprintDeployPath, name, version) - val cbaFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, - UUID.randomUUID().toString(), "cba.zip") - - if (extract && deployFile.exists()) { - log.info("cba file name($name), version($version) already present(${deployFile.absolutePath})") - } else { - deployFile.reCreateNBDirs() - cbaFile.parentFile.reCreateNBDirs() - - try { - log.info("getting cba file name($name), version($version) from db") - blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { - it.blueprintModelContent.run { - - cbaFile.writeBytes(this!!.content!!) - cbaFile.deCompress(deployFile) - log.info("cba file name($name), version($version) saved in (${deployFile.absolutePath})") - } - } - - check(deployFile.exists() && deployFile.list().isNotEmpty()) { - throw BluePrintProcessorException("file check failed") - } - } catch (e: Exception) { - deleteNBDir(deployFile.absolutePath) - throw BluePrintProcessorException("failed to get get cba file name($name), version($version) from db" + - " : ${e.message}") - } finally { - deleteNBDir(cbaFile.parentFile.absolutePath) - } - } - - return if (extract) { - deployFile.toPath() - } else { - cbaFile.toPath() - } - } - - override suspend fun save(metadata: MutableMap, archiveFile: File) { - val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] - val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] - - check(archiveFile.isFile && !archiveFile.isDirectory) { - throw BluePrintException("Not a valid Archive file(${archiveFile.absolutePath})") - } - - blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { - log.info("Overwriting blueprint model :$artifactName::$artifactVersion") - blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) - val deployFile = - normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) - deleteNBDir(deployFile).let { - if (it) log.info("Deleted deployed blueprint model :$artifactName::$artifactVersion") - else log.info("Fail to delete deployed 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 = archiveFile.readBytes() - 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/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt index 7bc88d8c2..17ffd5bac 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt @@ -26,7 +26,7 @@ import java.util.* import javax.persistence.* /** - * Provide Configuration Generator BlueprintModel Entity + * Provide BlueprintModel Entity * * @author Brinda Santh * @version 1.0 @@ -76,7 +76,7 @@ class BlueprintModel : Serializable { @Column(name = "artifact_version", nullable = false) @ApiModelProperty(required = true) - var artifactVersion: String? = null + lateinit var artifactVersion: String @Lob @Column(name = "artifact_description") @@ -93,20 +93,20 @@ class BlueprintModel : Serializable { @Column(name = "artifact_name", nullable = false) @ApiModelProperty(required = true) - var artifactName: String? = null + lateinit var artifactName: String @Column(name = "published", nullable = false) @ApiModelProperty(required = true) - var published: String? = null + lateinit var published: String @Column(name = "updated_by", nullable = false) @ApiModelProperty(required = true) - var updatedBy: String? = null + lateinit var updatedBy: String @Lob @Column(name = "tags", nullable = false) @ApiModelProperty(required = true) - var tags: String? = null + lateinit var tags: String @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL]) var blueprintModelContent: BlueprintModelContent? = null diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt index a3a42ff3d..e0d26a7ae 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt @@ -41,11 +41,11 @@ class BlueprintModelContent : Serializable { @Column(name = "name", nullable = false) @ApiModelProperty(required = true) - var name: String? = null + lateinit var name: String @Column(name = "content_type", nullable = false) @ApiModelProperty(required = true) - var contentType: String? = null + lateinit var contentType: String @OneToOne @JoinColumn(name = "config_model_id") @@ -58,7 +58,7 @@ class BlueprintModelContent : Serializable { @Lob @Column(name = "content", nullable = false) @ApiModelProperty(required = true) - var content: ByteArray? = null + lateinit var content: ByteArray @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt deleted file mode 100755 index c565262db..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 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.cds.blueprintsprocessor.db.primary.domain - -import com.fasterxml.jackson.annotation.JsonFormat -import io.swagger.annotations.ApiModelProperty -import javax.persistence.Entity -import javax.persistence.EntityListeners -import javax.persistence.Table -import org.hibernate.annotations.Proxy -import org.springframework.data.annotation.LastModifiedDate -import org.springframework.data.jpa.domain.support.AuditingEntityListener -import java.io.Serializable -import java.util.* -import javax.persistence.CascadeType -import javax.persistence.Column -import javax.persistence.FetchType -import javax.persistence.Id -import javax.persistence.Lob -import javax.persistence.OneToOne -import javax.persistence.Temporal -import javax.persistence.TemporalType - -@EntityListeners(AuditingEntityListener::class) -@Entity -@Table(name = "BLUEPRINT_RUNTIME") -@Proxy(lazy = false) -class BlueprintProcessorModel : Serializable { - - @Id - @Column(name = "blueprint_runtime_id") - var id: String? = null - - @Column(name = "artifact_type") - var artifactType: String? = null - - @Column(name = "artifact_version", nullable = false) - @ApiModelProperty(required = true) - var artifactVersion: String? = null - - @Lob - @Column(name = "artifact_description") - var artifactDescription: String? = null - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - var createdDate = Date() - - @Column(name = "artifact_name", nullable = false) - @ApiModelProperty(required = true) - var artifactName: String? = null - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required = true) - var updatedBy: String? = null - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required = true) - var tags: String? = null - - @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL]) - var blueprintModelContent: BlueprintProcessorModelContent? = null - - companion object { - private const val serialVersionUID = 1L - } -} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt deleted file mode 100644 index dc02d2fd0..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright © 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.cds.blueprintsprocessor.db.primary.domain - -import com.fasterxml.jackson.annotation.JsonFormat -import io.swagger.annotations.ApiModelProperty -import java.io.Serializable -import java.util.Date -import java.util.Objects -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.EntityListeners -import javax.persistence.Id -import javax.persistence.JoinColumn -import javax.persistence.Lob -import javax.persistence.OneToOne -import javax.persistence.Table -import javax.persistence.Temporal -import javax.persistence.TemporalType -import org.springframework.data.annotation.LastModifiedDate -import org.springframework.data.jpa.domain.support.AuditingEntityListener - -@EntityListeners(AuditingEntityListener::class) -@Entity -@Table(name = "BLUEPRINT_CONTENT_RUNTIME") -class BlueprintProcessorModelContent : Serializable { - - @Id - @Column(name = "blueprint_content_runtime_id") - var id: String? = null - - @Column(name = "name", nullable = false) - @ApiModelProperty(required = true) - var name: String? = null - - @Column(name = "content_type", nullable = false) - @ApiModelProperty(required = true) - var contentType: String? = null - - @OneToOne - @JoinColumn(name = "blueprint_runtime_id") - var blueprintModel: BlueprintProcessorModel? = null - - @Lob - @Column(name = "description") - var description: String? = null - - @Lob - @Column(name = "content", nullable = false) - @ApiModelProperty(required = true) - var content: ByteArray? = null - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "updated_date") - var creationDate = Date() - - override fun toString(): String { - return "[" + "id = " + id + - ", name = " + name + - ", contentType = " + contentType + - "]" - } - - override fun equals(o: Any?): Boolean { - - if (o === this) { - return true - } - if (o !is BlueprintProcessorModelContent) { - return false - } - val blueprintModelContent = o as BlueprintProcessorModelContent? - return (id == blueprintModelContent!!.id && name == blueprintModelContent.name - && contentType == blueprintModelContent.contentType) - } - - override fun hashCode(): Int { - return Objects.hash(id, name, contentType) - } - - companion object { - private const val serialVersionUID = 1L - } - -} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelContentRepository.kt new file mode 100644 index 000000000..7bbfbce79 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelContentRepository.kt @@ -0,0 +1,96 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 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.cds.blueprintsprocessor.db.primary.repository + +import org.jetbrains.annotations.NotNull +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.* + +/** + * @param Model + * @param ModelContent + */ +@Repository +interface BlueprintModelContentRepository : JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + override fun findById(@NotNull id: String): Optional + + /** + * This is a findTopByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return B? + */ + fun findTopByBlueprintModelAndContentType(blueprintModel: BlueprintModel, contentType: String) + : BlueprintModelContent? + + /** + * This is a findByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return List + */ + fun findByBlueprintModelAndContentType(blueprintModel: BlueprintModel, contentType: String) + : List + + /** + * This is a findByBlueprintModel method + * + * @param blueprintModel T + * @return List + */ + fun findByBlueprintModel(blueprintModel: BlueprintModel): List + + /** + * This is a findByBlueprintModelAndContentTypeAndName method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @param name name + * @return B? + */ + fun findByBlueprintModelAndContentTypeAndName(blueprintModel: BlueprintModel, + contentType: String, name: String): BlueprintModelContent? + + /** + * This is a deleteByMdeleteByBlueprintModelodelName method + * + * @param blueprintModel T + */ + fun deleteByBlueprintModel(blueprintModel: BlueprintModel) + + /** + * This is a deleteById method + * + * @param id id + */ + override fun deleteById(@NotNull id: String) + +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt new file mode 100644 index 000000000..8ef352852 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt @@ -0,0 +1,90 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 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.cds.blueprintsprocessor.db.primary.repository + +import org.jetbrains.annotations.NotNull +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.* +import javax.transaction.Transactional + +/** + * @param Model + */ +@Repository +interface BlueprintModelRepository : JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + override fun findById(id: String): Optional + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return T? + */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModel? + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName artifactName + * @return T? + */ + fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): BlueprintModel? + + /** + * This is a findTopByArtifactName method + * + * @param artifactName artifactName + * @return List + */ + fun findTopByArtifactName(artifactName: String): List + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return List + */ + fun findByTagsContainingIgnoreCase(tags: String): List + + /** + * This is a deleteByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + */ + @Transactional + fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String) + + /** + * This is a deleteById method + * + * @param id id + */ + override fun deleteById(@NotNull id: String) + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt new file mode 100644 index 000000000..f5ef0740e --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2019 IBM. + * + * 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.cds.blueprintsprocessor.db.primary.repository + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +/** + * Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface BlueprintModelSearchRepository : JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + fun findById(id: String): BlueprintModelSearch? + + /** + * This is a findAll method + * @return List + */ + override fun findAll(): List + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModelSearch? + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + fun findByTagsContainingIgnoreCase(tags: String): List +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt deleted file mode 100644 index e8cdee397..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.cds.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent - -interface BlueprintProcessorModelContentRepository : ModelContentRepository \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt deleted file mode 100644 index e200184d6..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.cds.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel - -interface BlueprintProcessorModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt deleted file mode 100644 index 3dbaf7b58..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.cds.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent - -interface ControllerBlueprintModelContentRepository : ModelContentRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt deleted file mode 100644 index 4e765cd28..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.cds.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel - -interface ControllerBlueprintModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt deleted file mode 100644 index 0e0c5435b..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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.cds.blueprintsprocessor.db.primary.repository - -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository - -/** - * Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -interface ControllerBlueprintModelSearchRepository : JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - fun findById(id: String): BlueprintModelSearch? - - /** - * This is a findAll method - * @return List - */ - override fun findAll(): List - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional - */ - fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModelSearch? - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional - */ - fun findByTagsContainingIgnoreCase(tags: String): List -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt deleted file mode 100644 index 59f2a20f5..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelContentRepository.kt +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 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.cds.blueprintsprocessor.db.primary.repository - -import org.jetbrains.annotations.NotNull -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.repository.NoRepositoryBean -import java.util.* - -/** - * @param Model - * @param ModelContent - */ -@NoRepositoryBean -interface ModelContentRepository : JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - override fun findById(@NotNull id: String): Optional - - /** - * This is a findTopByBlueprintModelAndContentType method - * - * @param blueprintModel blueprintModel - * @param contentType contentType - * @return B? - */ - fun findTopByBlueprintModelAndContentType(blueprintModel: T, contentType: String): B? - - /** - * This is a findByBlueprintModelAndContentType method - * - * @param blueprintModel blueprintModel - * @param contentType contentType - * @return List - */ - fun findByBlueprintModelAndContentType(blueprintModel: T, contentType: String): List - - /** - * This is a findByBlueprintModel method - * - * @param blueprintModel T - * @return List - */ - fun findByBlueprintModel(blueprintModel: T): List - - /** - * This is a findByBlueprintModelAndContentTypeAndName method - * - * @param blueprintModel blueprintModel - * @param contentType contentType - * @param name name - * @return B? - */ - fun findByBlueprintModelAndContentTypeAndName(blueprintModel: T, contentType: String, name: String): B? - - /** - * This is a deleteByMdeleteByBlueprintModelodelName method - * - * @param blueprintModel T - */ - fun deleteByBlueprintModel(blueprintModel: T) - - /** - * This is a deleteById method - * - * @param id id - */ - override fun deleteById(@NotNull id: String) - -} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt deleted file mode 100644 index 4ad14758c..000000000 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ModelRepository.kt +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 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.cds.blueprintsprocessor.db.primary.repository - -import org.jetbrains.annotations.NotNull -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.repository.NoRepositoryBean -import java.util.* -import javax.transaction.Transactional - -/** - * @param Model - */ -@NoRepositoryBean -interface ModelRepository : JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - override fun findById(@NotNull id: String): Optional - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return T? - */ - fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): T? - - /** - * This is a findTopByArtifactNameOrderByArtifactIdDesc method - * - * @param artifactName artifactName - * @return T? - */ - fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): T? - - /** - * This is a findTopByArtifactName method - * - * @param artifactName artifactName - * @return List - */ - fun findTopByArtifactName(artifactName: String): List - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return List - */ - fun findByTagsContainingIgnoreCase(tags: String): List - - /** - * This is a deleteByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - */ - @Transactional - fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String) - - /** - * This is a deleteById method - * - * @param id id - */ - override fun deleteById(@NotNull id: String) - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt new file mode 100644 index 000000000..aef7c18a2 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintCatalogServiceImpl.kt @@ -0,0 +1,87 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2019 IBM. + * + * 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.cds.blueprintsprocessor.db.service + +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.slf4j.LoggerFactory +import java.io.File +import java.nio.file.Path +import javax.persistence.MappedSuperclass + +@MappedSuperclass +abstract class BlueprintCatalogServiceImpl( + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintValidator: BluePrintValidatorService) : BluePrintCatalogService { + + private val log = LoggerFactory.getLogger(BlueprintCatalogServiceImpl::class.java)!! + + override suspend fun saveToDatabase(processingId: String, blueprintFile: File, validate: Boolean): String { + + var archiveFile: File? = null + var workingDir: String? = null + + if (blueprintFile.isDirectory) { + log.info("Save processing($processingId) Working Dir(${blueprintFile.absolutePath})") + workingDir = blueprintFile.absolutePath + archiveFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, processingId, "cba.zip") + + if (!BluePrintArchiveUtils.compress(blueprintFile, archiveFile)) { + throw BluePrintException("Fail to compress blueprint") + } + } else { + // Compressed File + log.info("Save processing($processingId) CBA(${blueprintFile.absolutePath})") + workingDir = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, processingId) + archiveFile = blueprintFile + // Decompress the CBA file to working Directory + blueprintFile.deCompress(workingDir) + } + + var valid = BluePrintConstants.FLAG_N + if (validate) { + blueprintValidator.validateBluePrints(workingDir!!) + valid = BluePrintConstants.FLAG_Y + } + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(processingId, workingDir!!) + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = processingId + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid + + save(metadata, archiveFile) + + return processingId + } + + override suspend fun getFromDatabase(name: String, version: String, extract: Boolean): Path = get(name, version, + extract) + ?: throw BluePrintException("Could not find blueprint $name:$version from database") + + override suspend fun deleteFromDatabase(name: String, version: String) = delete(name, version) + + abstract suspend fun save(metadata: MutableMap, archiveFile: File) + abstract suspend fun get(name: String, version: String, extract: Boolean): Path? + abstract suspend fun delete(name: String, version: String) + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt new file mode 100755 index 000000000..63c44d209 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/BlueprintProcessorCatalogServiceImpl.kt @@ -0,0 +1,154 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2018 IBM. + * + * 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.cds.blueprintsprocessor.db.service + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import java.io.File +import java.nio.file.Path +import java.util.* +// TODO("Duplicate : Merge BlueprintProcessorCatalogServiceImpl and ControllerBlueprintCatalogServiceImpl") +/** + * Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] + */ +@Service("blueprintsProcessorCatalogService") +class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelRepository: BlueprintModelRepository) + : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintRuntimeValidatorService) { + + private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) + + override suspend fun delete(name: String, version: String) { + // Clean blueprint script cache + val cacheKey = BluePrintFileUtils + .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, name, version)) + BluePrintCompileCache.cleanClassLoader(cacheKey) + log.info("removed cba file name($name), version($version) from cache") + // Cleaning Deployed Blueprint + deleteNBDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + log.info("removed cba file name($name), version($version) from deploy location") + // Cleaning Data Base + blueprintModelRepository + .deleteByArtifactNameAndArtifactVersion(name, version) + log.info("removed cba file name($name), version($version) from database") + } + + + override suspend fun get(name: String, version: String, extract: Boolean): Path? { + + val deployFile = normalizedFile(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + val cbaFile = normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, + UUID.randomUUID().toString(), "cba.zip") + + if (extract && deployFile.exists()) { + log.info("cba file name($name), version($version) already present(${deployFile.absolutePath})") + } else { + deployFile.reCreateNBDirs() + cbaFile.parentFile.reCreateNBDirs() + + try { + log.info("getting cba file name($name), version($version) from db") + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + + cbaFile.writeBytes(this!!.content!!) + cbaFile.deCompress(deployFile) + log.info("cba file name($name), version($version) saved in (${deployFile.absolutePath})") + } + } + + check(deployFile.exists() && deployFile.list().isNotEmpty()) { + throw BluePrintProcessorException("file check failed") + } + } catch (e: Exception) { + deleteNBDir(deployFile.absolutePath) + throw BluePrintProcessorException("failed to get get cba file name($name), version($version) from db" + + " : ${e.message}") + } finally { + deleteNBDir(cbaFile.parentFile.absolutePath) + } + } + + return if (extract) { + deployFile.toPath() + } else { + cbaFile.toPath() + } + } + + override suspend fun save(metadata: MutableMap, archiveFile: File) { + val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] + val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] + + check(archiveFile.isFile && !archiveFile.isDirectory) { + throw BluePrintException("Not a valid Archive file(${archiveFile.absolutePath})") + } + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { + log.info("Overwriting blueprint model :$artifactName::$artifactVersion") + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) + val deployFile = + normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) + deleteNBDir(deployFile).let { + if (it) log.info("Deleted deployed blueprint model :$artifactName::$artifactVersion") + else log.info("Fail to delete deployed 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 = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BluePrintConstants.FLAG_Y + 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 = archiveFile.readBytes() + 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/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt new file mode 100755 index 000000000..66b5d00c4 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/service/ControllerBlueprintCatalogServiceImpl.kt @@ -0,0 +1,121 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2019 IBM. + * + * 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.cds.blueprintsprocessor.db.service + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPath +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.util.* +//TODO("Duplicate : Merge BlueprintProcessorCatalogServiceImpl and ControllerBlueprintCatalogServiceImpl") +/** + * Similar implementation in [org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl] + */ +@Service("controllerBlueprintsCatalogService") +class ControllerBlueprintCatalogServiceImpl(bluePrintDesignTimeValidatorService: BluePrintValidatorService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelRepository: BlueprintModelRepository) + : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration, bluePrintDesignTimeValidatorService) { + + + private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString()) + + init { + log.info("BlueprintProcessorCatalogServiceImpl initialized") + } + + override suspend fun delete(name: String, version: String) { + // Cleaning Deployed Blueprint + deleteDir(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + // Cleaning Data Base + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) + } + + override suspend fun get(name: String, version: String, extract: Boolean): Path? { + val path = if (extract) { + normalizedPath(bluePrintLoadConfiguration.blueprintDeployPath, name, version) + } else { + normalizedPath(bluePrintLoadConfiguration.blueprintArchivePath, UUID.randomUUID().toString(), "cba.zip") + } + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + path.toFile().writeBytes(this!!.content!!).let { + return path + } + } + } + return null + } + + override suspend fun save(metadata: MutableMap, archiveFile: File) { + + val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] + val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] + + check(archiveFile.isFile && !archiveFile.isDirectory) { + throw BluePrintException("Not a valid Archive file(${archiveFile.absolutePath})") + } + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { + log.info("Overwriting blueprint model :$artifactName::$artifactVersion") + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) + } + + val blueprintModel = BlueprintModel() + blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL + blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BluePrintConstants.FLAG_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 + // 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) + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt index 11cd90e7d..8058dc26e 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt @@ -22,6 +22,8 @@ import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.mock.MockBlueprintProcessorCatalogServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.db.service.BlueprintCatalogServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.db.service.BlueprintProcessorCatalogServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -- cgit 1.2.3-korg