diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/db-lib')
22 files changed, 246 insertions, 149 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml index f444fde66..f11deb44c 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml @@ -32,12 +32,12 @@ <dependencies> <dependency> - <groupId>org.onap.ccsdk.cds.controllerblueprints</groupId> - <artifactId>blueprint-core</artifactId> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>blueprint-core</artifactId> </dependency> <dependency> - <groupId>org.onap.ccsdk.cds.controllerblueprints</groupId> - <artifactId>blueprint-validation</artifactId> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>blueprint-validation</artifactId> </dependency> <dependency> <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt index a7ad921de..0d737f4ca 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt @@ -16,47 +16,62 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice -import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertyService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate +import javax.sql.DataSource @Configuration +@Import( + BluePrintPropertyConfiguration::class, + BluePrintPropertiesService::class, + BluePrintCoreConfiguration::class +) @EnableConfigurationProperties open class BluePrintDBLibConfiguration(private var bluePrintPropertiesService: BluePrintPropertiesService) { @Bean("primary-database-properties") open fun getPrimaryProperties(): PrimaryDataSourceProperties { - return bluePrintPropertiesService.propertyBeanType(DBLibConstants.PREFIX_DB, - PrimaryDataSourceProperties::class.java) + return bluePrintPropertiesService.propertyBeanType( + DBLibConstants.PREFIX_DB, + PrimaryDataSourceProperties::class.java + ) + } + + @Bean("primaryNamedParameterJdbcTemplate") + open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { + return NamedParameterJdbcTemplate(primaryDataSource) } } /** * Exposed Dependency Service by this SSH Lib Module */ -fun BluePrintDependencyService.dbLibPropertyService(): BluePrintDBLibPropertySevice = - instance(BluePrintDBLibPropertySevice::class) +fun BluePrintDependencyService.dbLibPropertyService(): BluePrintDBLibPropertyService = + instance(BluePrintDBLibPropertyService::class) fun BluePrintDependencyService.primaryDBLibGenericService(): BluePrintDBLibGenericService = - instance(PrimaryDBLibGenericService::class) - + instance(PrimaryDBLibGenericService::class) class DBLibConstants { companion object { const val PREFIX_DB: String = "blueprintsprocessor.db" - //list of database + // list of database const val MARIA_DB: String = "maria-db" const val PRIMARY_DB: String = "processor-db" const val MYSQL_DB: String = "mysql-db" const val ORACLE_DB: String = "oracle-db" const val POSTGRES_DB: String = "postgres-db" - //List of database drivers + // List of database drivers const val DRIVER_MARIA_DB = "org.mariadb.jdbc.Driver" const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver" const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver" diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt index fc43ce34d..d4d804857 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibData.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db - open class DBDataSourceProperties { lateinit var url: String lateinit var username: String @@ -24,14 +23,14 @@ open class DBDataSourceProperties { open lateinit var driverClassName: String } -open class PrimaryDataSourceProperties: DBDataSourceProperties() { +open class PrimaryDataSourceProperties : DBDataSourceProperties() { lateinit var hibernateHbm2ddlAuto: String lateinit var hibernateDDLAuto: String lateinit var hibernateNamingStrategy: String lateinit var hibernateDialect: String } -open class MariaDataSourceProperties: DBDataSourceProperties() { +open class MariaDataSourceProperties : DBDataSourceProperties() { lateinit var hibernateHbm2ddlAuto: String lateinit var hibernateDDLAuto: String lateinit var hibernateNamingStrategy: String @@ -40,7 +39,7 @@ open class MariaDataSourceProperties: DBDataSourceProperties() { override var driverClassName = DBLibConstants.DRIVER_MARIA_DB } -open class MySqlDataSourceProperties: DBDataSourceProperties() { +open class MySqlDataSourceProperties : DBDataSourceProperties() { lateinit var hibernateHbm2ddlAuto: String lateinit var hibernateDDLAuto: String lateinit var hibernateNamingStrategy: String diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt index 0f6314685..aeb87fd66 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BluePrintDBLibGenericService.kt @@ -27,8 +27,8 @@ interface BluePrintDBLibGenericService { fun update(sql: String, params: Map<String, Any>): Int } -abstract class AbstractDBLibGenericService(private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate) - : BluePrintDBLibGenericService { +abstract class AbstractDBLibGenericService(private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate) : + BluePrintDBLibGenericService { override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { return namedParameterJdbcTemplate @@ -41,4 +41,4 @@ abstract class AbstractDBLibGenericService(private val namedParameterJdbcTemplat override fun update(sql: String, params: Map<String, Any>): Int { return namedParameterJdbcTemplate.update(sql, params) } -}
\ 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/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/PrimaryDBLibGenericService.kt index 896929fbb..006b7ca45 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/PrimaryDBLibGenericService.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2018 AT&T Intellectual Property. + * Copyright © 2018-2019 AT&T Intellectual Property. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,11 @@ * limitations under the License. */ -package org.onap.ccsdk.cds.blueprintsprocessor.db.primary +package org.onap.ccsdk.cds.blueprintsprocessor.db -import org.onap.ccsdk.cds.blueprintsprocessor.db.AbstractDBLibGenericService import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate import org.springframework.stereotype.Service @Service -open class PrimaryDBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate) - : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) { - -}
\ No newline at end of file +open class PrimaryDBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate) : + AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt index ff53de89f..35baf9314 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt @@ -18,13 +18,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.db.* +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +import org.onap.ccsdk.cds.blueprintsprocessor.db.DBDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.DBLibConstants +import org.onap.ccsdk.cds.blueprintsprocessor.db.MariaDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.MySqlDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.stereotype.Service @Service -class BluePrintDBLibPropertySevice(private var bluePrintPropertiesService: BluePrintPropertiesService) { +class BluePrintDBLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) { fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService { val dBConnetionProperties = dBDataSourceProperties(jsonNode) @@ -101,5 +106,4 @@ class BluePrintDBLibPropertySevice(private var bluePrintPropertiesService: BlueP private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties { return bluePrintPropertiesService.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java) } - -}
\ 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/MariaDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt index 6a0d4a0c5..82895257a 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt @@ -25,6 +25,8 @@ import javax.sql.DataSource class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService { + val log = LoggerFactory.getLogger(MariaDatabaseConfiguration::class.java)!! + override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate { return mariaNamedParameterJdbcTemplate(mariaDataSource()) } @@ -37,8 +39,6 @@ class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDat return mariaNamedParameterJdbcTemplate(mariaDataSource()).update(sql, params) } - val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - fun mariaDataSource(): DataSource { val dataSource = DriverManagerDataSource() dataSource.setDriverClassName(mariaDataSourceProperties.driverClassName) @@ -51,4 +51,4 @@ class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDat fun mariaNamedParameterJdbcTemplate(mariaDataSource: DataSource): NamedParameterJdbcTemplate { return NamedParameterJdbcTemplate(mariaDataSource) } -}
\ 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/MySqlDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt index 3091674f0..49b7ec9eb 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt @@ -50,6 +50,4 @@ class MySqlDatabaseConfiguration(private val mySqlDataSourceProperties: MySqlDat fun mySqlNamedParameterJdbcTemplate(mySqlDataSource: DataSource): NamedParameterJdbcTemplate { return NamedParameterJdbcTemplate(mySqlDataSource) } - - } diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt index 82b77da47..0913a0a58 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt @@ -18,41 +18,23 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties import org.slf4j.LoggerFactory -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration -import org.springframework.data.jpa.repository.config.EnableJpaAuditing -import org.springframework.data.jpa.repository.config.EnableJpaRepositories -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate import org.springframework.jdbc.datasource.DriverManagerDataSource import org.springframework.orm.jpa.JpaTransactionManager import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter import org.springframework.transaction.PlatformTransactionManager -import java.util.* +import java.util.HashMap import javax.sql.DataSource -@Configuration -@ConditionalOnProperty(name = ["blueprintsprocessor.db.primary.defaultConfig"], havingValue = "true", - matchIfMissing = true) -@ComponentScan -@EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.*", - "org.onap.ccsdk.cds.controllerblueprints.*"], - entityManagerFactoryRef = "primaryEntityManager", - transactionManagerRef = "primaryTransactionManager" -) -@EnableJpaAuditing open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) { + private val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! - @Bean("primaryEntityManager") - open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + /** Child class will override with spring bean annotation 'primaryEntityManager' and passing entity [packagesToScan]*/ + open fun primaryEntityManager(vararg packagesToScan: String): LocalContainerEntityManagerFactoryBean { val em = LocalContainerEntityManagerFactoryBean() em.dataSource = primaryDataSource() - em.setPackagesToScan("org.onap.ccsdk.cds.blueprintsprocessor.*", - "org.onap.ccsdk.cds.controllerblueprints.*") + em.setPackagesToScan(*packagesToScan) em.jpaVendorAdapter = HibernateJpaVendorAdapter() val properties = HashMap<String, Any>() properties["hibernate.hbm2ddl.auto"] = primaryDataSourceProperties.hibernateHbm2ddlAuto @@ -61,7 +43,7 @@ open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: return em } - @Bean("primaryDataSource") + /** Child class will override with spring bean annotation 'primaryDataSource' */ open fun primaryDataSource(): DataSource { val dataSource = DriverManagerDataSource() dataSource.setDriverClassName(primaryDataSourceProperties.driverClassName) @@ -71,17 +53,11 @@ open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: return dataSource } - @Bean("primaryTransactionManager") + /** Child class will override with spring bean annotation 'primaryTransactionManager' */ open fun primaryTransactionManager(): PlatformTransactionManager { val transactionManager = JpaTransactionManager() transactionManager.entityManagerFactory = primaryEntityManager().getObject() log.info("Initialised Primary Transaction Manager for url ${primaryDataSourceProperties.url}") return transactionManager } - - @Bean("primaryNamedParameterJdbcTemplate") - open fun primaryNamedParameterJdbcTemplate(primaryDataSource: DataSource): NamedParameterJdbcTemplate { - return NamedParameterJdbcTemplate(primaryDataSource) - } - -}
\ 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 74a611fbb..43bcb6741 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 @@ -22,8 +22,19 @@ 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.* +import java.util.Date +import javax.persistence.CascadeType +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.FetchType +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.OneToOne +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType +import javax.persistence.UniqueConstraint /** * Provide BlueprintModel Entity @@ -37,6 +48,7 @@ import javax.persistence.* @Table(name = "BLUEPRINT_MODEL", uniqueConstraints = [UniqueConstraint(columnNames = ["artifact_name", "artifact_version"])]) @Proxy(lazy = false) class BlueprintModel : Serializable { + @Id @Column(name = "blueprint_model_id") var id: String? = 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 bed6e4e38..a18ae8b1d 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 @@ -21,8 +21,18 @@ import io.swagger.annotations.ApiModelProperty import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.io.Serializable -import java.util.* -import javax.persistence.* +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 /** * Provide Blueprint Model Content Entity @@ -82,8 +92,8 @@ class BlueprintModelContent : Serializable { return false } val blueprintModelContent = o as BlueprintModelContent? - return (id == blueprintModelContent!!.id && name == blueprintModelContent.name - && contentType == blueprintModelContent.contentType) + return (id == blueprintModelContent!!.id && name == blueprintModelContent.name && + contentType == blueprintModelContent.contentType) } override fun hashCode(): Int { @@ -94,5 +104,4 @@ class BlueprintModelContent : Serializable { 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/BlueprintModelSearch.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt index f47124dd0..b1c006793 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt @@ -21,8 +21,14 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.annotation.JsonTypeName import org.springframework.data.annotation.LastModifiedDate import java.io.Serializable -import java.util.* -import javax.persistence.* +import java.util.Date +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType /** * Provide Blueprint Model Search Entity 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 index 7bbfbce79..59ace723a 100644 --- 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 @@ -22,7 +22,7 @@ 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.* +import java.util.Optional /** * @param <T> Model @@ -47,8 +47,8 @@ interface BlueprintModelContentRepository : JpaRepository<BlueprintModelContent, * @param contentType contentType * @return B? */ - fun findTopByBlueprintModelAndContentType(blueprintModel: BlueprintModel, contentType: String) - : BlueprintModelContent? + fun findTopByBlueprintModelAndContentType(blueprintModel: BlueprintModel, contentType: String): + BlueprintModelContent? /** * This is a findByBlueprintModelAndContentType method @@ -57,8 +57,8 @@ interface BlueprintModelContentRepository : JpaRepository<BlueprintModelContent, * @param contentType contentType * @return List<B> */ - fun findByBlueprintModelAndContentType(blueprintModel: BlueprintModel, contentType: String) - : List<BlueprintModelContent> + fun findByBlueprintModelAndContentType(blueprintModel: BlueprintModel, contentType: String): + List<BlueprintModelContent> /** * This is a findByBlueprintModel method @@ -76,8 +76,11 @@ interface BlueprintModelContentRepository : JpaRepository<BlueprintModelContent, * @param name name * @return B? */ - fun findByBlueprintModelAndContentTypeAndName(blueprintModel: BlueprintModel, - contentType: String, name: String): BlueprintModelContent? + fun findByBlueprintModelAndContentTypeAndName( + blueprintModel: BlueprintModel, + contentType: String, + name: String + ): BlueprintModelContent? /** * This is a deleteByMdeleteByBlueprintModelodelName method @@ -92,5 +95,4 @@ interface BlueprintModelContentRepository : JpaRepository<BlueprintModelContent, * @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 index 8ef352852..a7891f6a7 100644 --- 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 @@ -21,7 +21,7 @@ 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 java.util.Optional import javax.transaction.Transactional /** @@ -86,5 +86,4 @@ interface BlueprintModelRepository : JpaRepository<BlueprintModel, String> { * @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 index 5c7a94034..4451283cb 100644 --- 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 @@ -19,7 +19,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch import org.springframework.data.domain.Page -import org.springframework.data.domain.PageRequest import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @@ -77,9 +76,13 @@ interface BlueprintModelSearchRepository : JpaRepository<BlueprintModelSearch, L * @return Optional<BlueprintModelSearch> </BlueprintModelSearch> */ - fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(updatedBy: String, tags: String, artifactName: String, artifactVersion: String, - artifactType: String): List<BlueprintModelSearch> - + fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( + updatedBy: String, + tags: String, + artifactName: String, + artifactVersion: String, + artifactType: String + ): List<BlueprintModelSearch> /** * This is a findby some attributes method @@ -94,10 +97,12 @@ interface BlueprintModelSearchRepository : JpaRepository<BlueprintModelSearch, L * @param pageRequest * @return Page<BlueprintModelSearch> */ - fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(updatedBy: String, tags: String, artifactName: String, artifactVersion: String, - artifactType: String,pageRequest: Pageable): Page<BlueprintModelSearch> - - - - + fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( + updatedBy: String, + tags: String, + artifactName: String, + artifactVersion: String, + artifactType: String, + pageRequest: Pageable + ): Page<BlueprintModelSearch> } diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt index 5700c2a46..9d1826395 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintCatalogServiceImpl.kt @@ -18,10 +18,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.deCompress 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.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.slf4j.LoggerFactory @@ -31,8 +35,9 @@ import javax.persistence.MappedSuperclass @MappedSuperclass abstract class BlueprintCatalogServiceImpl( - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintValidator: BluePrintValidatorService) : BluePrintCatalogService { + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintValidator: BluePrintValidatorService +) : BluePrintCatalogService { private val log = LoggerFactory.getLogger(BlueprintCatalogServiceImpl::class.java)!! @@ -74,14 +79,15 @@ abstract class BlueprintCatalogServiceImpl( 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 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<String, String>, 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/primary/service/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt index 3ba25d8de..0c407ecdf 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/service/BlueprintProcessorCatalogServiceImpl.kt @@ -21,11 +21,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.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.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException 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.deCompress +import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.reCreateNBDirs import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.slf4j.LoggerFactory @@ -33,24 +40,26 @@ import org.springframework.dao.DataIntegrityViolationException import org.springframework.stereotype.Service import java.io.File import java.nio.file.Path -import java.util.* +import java.util.UUID // 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) { +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)) + .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, name, version)) BluePrintCompileCache.cleanClassLoader(cacheKey) log.info("removed cba file name($name), version($version) from cache") // Cleaning Deployed Blueprint @@ -58,16 +67,17 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu log.info("removed cba file name($name), version($version) from deploy location") // Cleaning Data Base blueprintModelRepository - .deleteByArtifactNameAndArtifactVersion(name, version) + .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") + 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})") @@ -91,8 +101,10 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu } } catch (e: Exception) { deleteNBDir(deployFile.absolutePath) - throw BluePrintProcessorException("failed to get get cba file name($name), version($version) from db" + - " : ${e.message}") + throw BluePrintProcessorException( + "failed to get get cba file name($name), version($version) from db" + + " : ${e.message}" + ) } finally { deleteNBDir(cbaFile.parentFile.absolutePath) } @@ -117,7 +129,7 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu log.info("Overwriting blueprint model :$artifactName::$artifactVersion") blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) val deployFile = - normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) + normalizedPathName(bluePrintLoadConfiguration.blueprintDeployPath, artifactName, artifactVersion) val cacheKey = BluePrintFileUtils.compileCacheKey(deployFile) BluePrintCompileCache.cleanClassLoader(cacheKey) @@ -132,7 +144,7 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu 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 + ?: BluePrintConstants.FLAG_N blueprintModel.artifactName = artifactName blueprintModel.artifactVersion = artifactVersion blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]!! @@ -152,8 +164,10 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu 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) + 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 d912d8eae..e86dfab72 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 @@ -43,8 +43,10 @@ import kotlin.test.assertTrue @RunWith(SpringRunner::class) @EnableAutoConfiguration @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor"]) -@ContextConfiguration(classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class, - MockBlueprintProcessorCatalogServiceImpl::class]) +@ContextConfiguration( + classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class, + MockBlueprintProcessorCatalogServiceImpl::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BlueprintProcessorCatalogServiceImplTest { @@ -61,8 +63,10 @@ class BlueprintProcessorCatalogServiceImplTest { @BeforeTest fun setup() { deleteDir("target", "blueprints") - bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime( + blueprintId, + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + ) } @AfterTest @@ -72,9 +76,9 @@ class BlueprintProcessorCatalogServiceImplTest { @Test fun `test catalog service`() { - //TODO: I thing this test function should be remve and replace by the other one. + // TODO: I thing this test function should be remve and replace by the other one. runBlocking { - //FIXME("Create ZIP from test blueprints") + // FIXME("Create ZIP from test blueprints") val file = normalizedFile("./src/test/resources/test-cba.zip") assertTrue(file.exists(), "couldn't get file ${file.absolutePath}") @@ -110,10 +114,14 @@ class BlueprintProcessorCatalogServiceImplTest { blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true) } - assertTrue(File(blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath + - "/baseconfiguration").deleteRecursively(),"Couldn't get blueprint archive " + - "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " + - "from data base.") + assertTrue( + File( + blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath + + "/baseconfiguration" + ).deleteRecursively(), "Couldn't get blueprint archive " + + "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " + + "from data base." + ) } @Test @@ -122,4 +130,4 @@ class BlueprintProcessorCatalogServiceImplTest { blueprintsProcessorCatalogService.delete("baseconfiguration", "1.0.0") } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt new file mode 100644 index 000000000..d8192acfa --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/TestDatabaseConfiguration.kt @@ -0,0 +1,54 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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.PrimaryDatabaseConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.data.jpa.repository.config.EnableJpaAuditing +import org.springframework.data.jpa.repository.config.EnableJpaRepositories +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean +import org.springframework.transaction.PlatformTransactionManager +import javax.sql.DataSource + +@Configuration +@Import(BluePrintDBLibConfiguration::class) +@EnableJpaRepositories( + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.db.primary"], + entityManagerFactoryRef = "primaryEntityManager", + transactionManagerRef = "primaryTransactionManager" +) +@EnableJpaAuditing +open class TestDatabaseConfiguration(primaryDataSourceProperties: PrimaryDataSourceProperties) : + PrimaryDatabaseConfiguration(primaryDataSourceProperties) { + + @Bean("primaryEntityManager") + open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + return primaryEntityManager("org.onap.ccsdk.cds.blueprintsprocessor.db.primary.*") + } + + @Bean("primaryDataSource") + override fun primaryDataSource(): DataSource { + return super.primaryDataSource() + } + + @Bean("primaryTransactionManager") + override fun primaryTransactionManager(): PlatformTransactionManager { + return super.primaryTransactionManager() + } +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt index b98fc0c44..8dcf42668 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt @@ -32,4 +32,4 @@ open class MockBlueprintProcessorCatalogServiceImpl { every { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true return bluePrintValidatorService } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt index 2ab1c5d48..d551fee0d 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfigurationTest.kt @@ -18,13 +18,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.TestDatabaseConfiguration import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @@ -32,11 +27,10 @@ import javax.sql.DataSource import kotlin.test.assertNotNull @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, - BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) +@ContextConfiguration( + classes = [TestDatabaseConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) -@EnableAutoConfiguration class PrimaryDatabaseConfigurationTest { @Autowired @@ -46,4 +40,4 @@ class PrimaryDatabaseConfigurationTest { fun testPrimaryDatabaseConfiguration() { assertNotNull(primaryDataSource, " failed to create primary data source") } -}
\ 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 124e844cb..4345d6e63 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,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -blueprintsprocessor.db.primary.defaultConfig=true blueprintsprocessor.db.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 blueprintsprocessor.db.username=sa |