Refactor model entity and repository. 91/94691/1
authorBrinda Santh <brindasanth@in.ibm.com>
Fri, 30 Aug 2019 15:03:10 +0000 (11:03 -0400)
committerBrinda Santh <brindasanth@in.ibm.com>
Fri, 30 Aug 2019 15:03:10 +0000 (11:03 -0400)
Change-Id: I6f06fc46fcedbe1cbb8a8e6f8c30b131680a5b08
Issue-ID: CCSDK-1663
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
13 files changed:
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt [new file with mode: 0755]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt [moved from ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt with 77% similarity]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt [moved from ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt with 83% similarity]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt [moved from ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt with 81% similarity]
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintModelHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java [deleted file]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java [deleted file]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java [deleted 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
new file mode 100755 (executable)
index 0000000..7bc88d8
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ *  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.domain
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import io.swagger.annotations.ApiModelProperty
+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.*
+
+/**
+ *  Provide Configuration Generator BlueprintModel Entity
+ *
+ * @author Brinda Santh
+ * @version 1.0
+ */
+
+@EntityListeners(AuditingEntityListener::class)
+@Entity
+@Table(name = "CONFIG_MODEL", uniqueConstraints = [UniqueConstraint(columnNames = ["artifact_name", "artifact_version"])])
+@Proxy(lazy = false)
+class BlueprintModel : Serializable {
+    @Id
+    @Column(name = "config_model_id")
+    var id: String? = null
+
+    @Column(name = "service_uuid")
+    var serviceUUID: String? = null
+
+    @Column(name = "distribution_id")
+    var distributionId: String? = null
+
+    @Column(name = "service_name")
+    var serviceName: String? = null
+
+    @Column(name = "service_description")
+    var serviceDescription: String? = null
+
+    @Column(name = "resource_uuid")
+    var resourceUUID: String? = null
+
+    @Column(name = "resource_instance_name")
+    var resourceInstanceName: String? = null
+
+    @Column(name = "resource_name")
+    var resourceName: String? = null
+
+    @Column(name = "resource_version")
+    var resourceVersion: String? = null
+
+    @Column(name = "resource_type")
+    var resourceType: String? = null
+
+    @Column(name = "artifact_uuid")
+    var artifactUUId: 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
+
+    @Column(name = "internal_version")
+    var internalVersion: Int? = null
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+    @LastModifiedDate
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "creation_date")
+    var createdDate = Date()
+
+    @Column(name = "artifact_name", nullable = false)
+    @ApiModelProperty(required = true)
+    var artifactName: String? = null
+
+    @Column(name = "published", nullable = false)
+    @ApiModelProperty(required = true)
+    var published: String? = null
+
+    @Column(name = "updated_by", nullable = false)
+    @ApiModelProperty(required = true)
+    var updatedBy: String? = null
+
+    @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: BlueprintModelContent? = 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/BlueprintModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt
new file mode 100644 (file)
index 0000000..a3a42ff
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ *  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.domain
+
+import com.fasterxml.jackson.annotation.JsonFormat
+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.*
+
+/**
+ * Provide Blueprint Model Content Entity
+ *
+ * @author Brinda Santh
+ * @version 1.0
+ */
+@EntityListeners(AuditingEntityListener::class)
+@Entity
+@Table(name = "CONFIG_MODEL_CONTENT")
+class BlueprintModelContent : Serializable {
+
+    @Id
+    @Column(name = "config_model_content_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 = "config_model_id")
+    var blueprintModel: BlueprintModel? = 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 BlueprintModelContent) {
+            return false
+        }
+        val blueprintModelContent = o as BlueprintModelContent?
+        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/domain/BlueprintModelSearch.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt
new file mode 100644 (file)
index 0000000..f00d5ca
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ *  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.domain
+
+import com.fasterxml.jackson.annotation.JsonFormat
+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.*
+
+/**
+ * Provide Blueprint Model Search Entity
+ *
+ * @author Brinda Santh
+ * @version 1.0
+ */
+
+@Entity
+@Table(name = "CONFIG_MODEL")
+@JsonTypeName("blueprintModel")
+@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
+class BlueprintModelSearch : Serializable {
+
+    @Id
+    @Column(name = "config_model_id")
+    var id: String? = null
+
+    @Column(name = "artifact_uuid")
+    var artifactUUId: String? = null
+
+    @Column(name = "artifact_type")
+    var artifactType: String? = null
+
+    @Column(name = "artifact_version", nullable = false)
+    var artifactVersion: String? = null
+
+    @Lob
+    @Column(name = "artifact_description")
+    var artifactDescription: String? = null
+
+    @Column(name = "internal_version")
+    var internalVersion: Int? = null
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+    @LastModifiedDate
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "creation_date")
+    var createdDate = Date()
+
+    @Column(name = "artifact_name", nullable = false)
+    var artifactName: String? = null
+
+    @Column(name = "published", nullable = false)
+    var published: String? = null
+
+    @Column(name = "updated_by", nullable = false)
+    var updatedBy: String? = null
+
+    @Lob
+    @Column(name = "tags", nullable = false)
+    var tags: String? = null
+
+    companion object {
+        const val serialversionuid = 1L
+    }
+}
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.ccsdk.cds.controllerblueprints.service.repository
+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
 import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelContentRepository
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent
 
 interface ControllerBlueprintModelContentRepository : ModelContentRepository<BlueprintModel, BlueprintModelContent>
@@ -13,9 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.ccsdk.cds.controllerblueprints.service.repository
+package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository
 
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel
 import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelRepository
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel
 
 interface ControllerBlueprintModelRepository : ModelRepository<BlueprintModel>
  *  limitations under the License.
  */
 
-package org.onap.ccsdk.cds.controllerblueprints.service.repository
+package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository
 
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
 import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.stereotype.Repository
-import java.util.*
 
 /**
- * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository
+ * Provide Configuration Generator AsdcArtifactsRepository
  *
  * @author Brinda Santh
  * @version 1.0
@@ -36,7 +35,7 @@ interface ControllerBlueprintModelSearchRepository : JpaRepository<BlueprintMode
      * @param id id
      * @return Optional<BlueprintModelSearch>
     </BlueprintModelSearch> */
-    fun findById(id: String): Optional<BlueprintModelSearch>
+    fun findById(id: String): BlueprintModelSearch?
 
     /**
      * This is a findAll method
@@ -51,7 +50,7 @@ interface ControllerBlueprintModelSearchRepository : JpaRepository<BlueprintMode
      * @param artifactVersion artifactVersion
      * @return Optional<AsdcArtifacts>
     </AsdcArtifacts> */
-    fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<BlueprintModelSearch>
+    fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModelSearch?
 
     /**
      * This is a findByTagsContainingIgnoreCase method
index d4bcd8e..3a68951 100644 (file)
 
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
 
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.ControllerBlueprintModelContentRepository
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.ControllerBlueprintModelRepository
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.ControllerBlueprintModelSearchRepository
 import org.onap.ccsdk.cds.controllerblueprints.core.*
 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.BluePrintCatalogService
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch
-import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository
-import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelRepository
-import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository
 import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils
 import org.slf4j.LoggerFactory
 import org.springframework.core.io.ByteArrayResource
@@ -88,7 +88,10 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
             // Save the Copied file to Database
             val blueprintId = controllerBlueprintsCatalogService.saveToDatabase(saveId, deCompressedFile, false)
             // Check and Return the Saved File
-            val blueprintModelSearch = blueprintModelSearchRepository.findById(blueprintId).get()
+            val blueprintModelSearch = blueprintModelSearchRepository.findById(blueprintId)
+                    ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                            String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId))
+
             log.info("Save($saveId) successful for blueprint(${blueprintModelSearch.artifactName}) " +
                     "version(${blueprintModelSearch.artifactVersion})")
             return blueprintModelSearch
@@ -121,16 +124,10 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
      */
     @Throws(BluePrintException::class)
     open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch {
-        val blueprintModelSearch: BlueprintModelSearch
-        val dbBlueprintModel = blueprintModelSearchRepository
-                .findByArtifactNameAndArtifactVersion(name, version)
-        if (dbBlueprintModel.isPresent) {
-            blueprintModelSearch = dbBlueprintModel.get()
-        } else {
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
-                    String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version))
-        }
-        return blueprintModelSearch
+        return blueprintModelSearchRepository.findByArtifactNameAndArtifactVersion(name, version)
+                ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                        String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version))
+
     }
 
     /**
@@ -148,11 +145,14 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
         try {
             blueprintModel = getBlueprintModelByNameAndVersion(name, version)
         } catch (e: BluePrintException) {
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e)
+            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                    String.format("Error while " + "downloading the CBA file: %s", e.message), e)
         }
 
         val fileName = blueprintModel.id + ".zip"
-        val file = blueprintModel.blueprintModelContent.content
+        val file = blueprintModel.blueprintModelContent?.content
+                ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                        String.format("Error while downloading the CBA file: couldn't get model content"))
         return prepareResourceEntity(fileName, file)
     }
 
@@ -172,7 +172,9 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
         }
 
         val fileName = blueprintModel.id + ".zip"
-        val file = blueprintModel.blueprintModelContent.content
+        val file = blueprintModel.blueprintModelContent?.content
+                ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                        String.format("Error while downloading the CBA file: couldn't get model content"))
         return prepareResourceEntity(fileName, file)
     }
 
@@ -235,16 +237,9 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
      */
     @Throws(BluePrintException::class)
     open fun getBlueprintModelSearch(id: String): BlueprintModelSearch {
-        val blueprintModelSearch: BlueprintModelSearch
-        val dbBlueprintModel = blueprintModelSearchRepository.findById(id)
-        if (dbBlueprintModel.isPresent) {
-            blueprintModelSearch = dbBlueprintModel.get()
-        } else {
-            val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
-            throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
-        }
-
-        return blueprintModelSearch
+        return blueprintModelSearchRepository.findById(id)
+                ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                        String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id))
     }
 
     /**
@@ -257,7 +252,7 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
     @Throws(BluePrintException::class)
     open fun deleteBlueprintModel(id: String) {
         val dbBlueprintModel = blueprintModelRepository.findById(id)
-        if (dbBlueprintModel.isPresent) {
+        if (dbBlueprintModel != null && dbBlueprintModel.isPresent) {
             blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get())
             blueprintModelRepository.delete(dbBlueprintModel.get())
         } else {
@@ -317,7 +312,9 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
 
             val blueprintId = controllerBlueprintsCatalogService.saveToDatabase(publishId, compressedFilePart, true)
 
-            return blueprintModelSearchRepository.findById(blueprintId).get()
+            return blueprintModelSearchRepository.findById(blueprintId)
+                    ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
+                            String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId))
 
         } catch (e: Exception) {
             throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
index 98f5212..26420cc 100644 (file)
@@ -19,7 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
 
 import kotlinx.coroutines.runBlocking
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
 import org.springframework.core.io.Resource
 import org.springframework.http.MediaType
 import org.springframework.http.ResponseEntity
index f0252c8..e91f491 100755 (executable)
@@ -27,9 +27,9 @@ 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.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent
-import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelRepository
+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.ControllerBlueprintModelRepository
 import org.slf4j.LoggerFactory
 import org.springframework.dao.DataIntegrityViolationException
 import org.springframework.stereotype.Service
index cd49870..877584e 100644 (file)
@@ -29,9 +29,9 @@ import org.junit.runners.MethodSorters
 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
 import org.onap.ccsdk.cds.controllerblueprints.core.*
 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
-import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java
deleted file mode 100755 (executable)
index 916e94b..0000000
+++ /dev/null
@@ -1,285 +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.controllerblueprints.service.domain;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import io.swagger.annotations.ApiModelProperty;
-import org.hibernate.annotations.Proxy;
-import org.springframework.data.annotation.LastModifiedDate;
-import org.springframework.data.jpa.domain.support.AuditingEntityListener;
-
-import javax.persistence.*;
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * BlueprintModel.java Purpose: Provide Configuration Generator BlueprintModel Entity
- *
- * @author Brinda Santh
- * @version 1.0
- */
-
-@EntityListeners({AuditingEntityListener.class})
-@Entity
-@Table(name = "CONFIG_MODEL", uniqueConstraints=@UniqueConstraint(columnNames={"artifact_name","artifact_version"}))
-@Proxy(lazy=false)
-public class BlueprintModel implements Serializable {
-    private static final long serialVersionUID = 1L;
-    @Id
-    @Column(name = "config_model_id")
-    private String id;
-
-    @Column(name = "service_uuid")
-    private String serviceUUID;
-
-    @Column(name = "distribution_id")
-    private String distributionId;
-
-    @Column(name = "service_name")
-    private String serviceName;
-
-    @Column(name = "service_description")
-    private String serviceDescription;
-
-    @Column(name = "resource_uuid")
-    private String resourceUUID;
-
-    @Column(name = "resource_instance_name")
-    private String resourceInstanceName;
-
-    @Column(name = "resource_name")
-    private String resourceName;
-
-    @Column(name = "resource_version")
-    private String resourceVersion;
-
-    @Column(name = "resource_type")
-    private String resourceType;
-
-    @Column(name = "artifact_uuid")
-    private String artifactUUId;
-
-    @Column(name = "artifact_type")
-    private String artifactType;
-
-    @Column(name = "artifact_version", nullable = false)
-    @ApiModelProperty(required=true)
-    private String artifactVersion;
-
-    @Lob
-    @Column(name = "artifact_description")
-    private String artifactDescription;
-
-    @Column(name = "internal_version")
-    private Integer internalVersion;
-
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    @LastModifiedDate
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "creation_date")
-    private Date createdDate = new Date();
-
-    @Column(name = "artifact_name", nullable = false)
-    @ApiModelProperty(required=true)
-    private String artifactName;
-
-    @Column(name = "published", nullable = false)
-    @ApiModelProperty(required=true)
-    private String published;
-
-    @Column(name = "updated_by", nullable = false)
-    @ApiModelProperty(required=true)
-    private String updatedBy;
-
-    @Lob
-    @Column(name = "tags", nullable = false)
-    @ApiModelProperty(required=true)
-    private String tags;
-
-    @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL)
-    private org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent blueprintModelContent;
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getServiceUUID() {
-        return serviceUUID;
-    }
-
-    public void setServiceUUID(String serviceUUID) {
-        this.serviceUUID = serviceUUID;
-    }
-
-    public String getDistributionId() {
-        return distributionId;
-    }
-
-    public void setDistributionId(String distributionId) {
-        this.distributionId = distributionId;
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    public void setServiceName(String serviceName) {
-        this.serviceName = serviceName;
-    }
-
-    public String getServiceDescription() {
-        return serviceDescription;
-    }
-
-    public void setServiceDescription(String serviceDescription) {
-        this.serviceDescription = serviceDescription;
-    }
-
-    public String getResourceUUID() {
-        return resourceUUID;
-    }
-
-    public void setResourceUUID(String resourceUUID) {
-        this.resourceUUID = resourceUUID;
-    }
-
-    public String getResourceInstanceName() {
-        return resourceInstanceName;
-    }
-
-    public void setResourceInstanceName(String resourceInstanceName) {
-        this.resourceInstanceName = resourceInstanceName;
-    }
-
-    public String getResourceName() {
-        return resourceName;
-    }
-
-    public void setResourceName(String resourceName) {
-        this.resourceName = resourceName;
-    }
-
-    public String getResourceVersion() {
-        return resourceVersion;
-    }
-
-    public void setResourceVersion(String resourceVersion) {
-        this.resourceVersion = resourceVersion;
-    }
-
-    public String getResourceType() {
-        return resourceType;
-    }
-
-    public void setResourceType(String resourceType) {
-        this.resourceType = resourceType;
-    }
-
-    public String getArtifactUUId() {
-        return artifactUUId;
-    }
-
-    public void setArtifactUUId(String artifactUUId) {
-        this.artifactUUId = artifactUUId;
-    }
-
-    public String getArtifactType() {
-        return artifactType;
-    }
-
-    public void setArtifactType(String artifactType) {
-        this.artifactType = artifactType;
-    }
-
-    public String getArtifactVersion() {
-        return artifactVersion;
-    }
-
-    public void setArtifactVersion(String artifactVersion) {
-        this.artifactVersion = artifactVersion;
-    }
-
-    public String getArtifactDescription() {
-        return artifactDescription;
-    }
-
-    public void setArtifactDescription(String artifactDescription) {
-        this.artifactDescription = artifactDescription;
-    }
-
-    public Integer getInternalVersion() {
-        return internalVersion;
-    }
-
-    public void setInternalVersion(Integer internalVersion) {
-        this.internalVersion = internalVersion;
-    }
-
-    public Date getCreatedDate() {
-        return createdDate;
-    }
-
-    public void setCreatedDate(Date createdDate) {
-        this.createdDate = createdDate;
-    }
-
-    public String getArtifactName() {
-        return artifactName;
-    }
-
-    public void setArtifactName(String artifactName) {
-        this.artifactName = artifactName;
-    }
-
-    public String getPublished() {
-        return published;
-    }
-
-    public void setPublished(String published) {
-        this.published = published;
-    }
-
-    public String getUpdatedBy() {
-        return updatedBy;
-    }
-
-    public void setUpdatedBy(String updatedBy) {
-        this.updatedBy = updatedBy;
-    }
-
-    public String getTags() {
-        return tags;
-    }
-
-    public void setTags(String tags) {
-        this.tags = tags;
-    }
-
-    public org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent getBlueprintModelContent() {
-        return blueprintModelContent;
-    }
-
-    public void setBlueprintModelContent(
-        org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent blueprintModelContent) {
-        this.blueprintModelContent = blueprintModelContent;
-    }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java
deleted file mode 100644 (file)
index 20a1fdc..0000000
+++ /dev/null
@@ -1,170 +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.controllerblueprints.service.domain;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import io.swagger.annotations.ApiModelProperty;
-import org.springframework.data.annotation.LastModifiedDate;
-import org.springframework.data.jpa.domain.support.AuditingEntityListener;
-
-import javax.persistence.*;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.Objects;
-
-/**
- * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity
- *
- * @author Brinda Santh
- * @version 1.0
- */
-@EntityListeners({AuditingEntityListener.class})
-@Entity
-@Table(name = "CONFIG_MODEL_CONTENT")
-public class BlueprintModelContent implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @Id
-    @Column(name = "config_model_content_id")
-    private String id;
-
-    @Column(name = "name", nullable = false)
-    @ApiModelProperty(required=true)
-    private String name;
-
-    @Column(name = "content_type", nullable = false)
-    @ApiModelProperty(required=true)
-    private String contentType;
-
-    @OneToOne
-    @JoinColumn(name = "config_model_id")
-    private BlueprintModel blueprintModel;
-
-    @Lob
-    @Column(name = "description")
-    private String description;
-
-    @Lob
-    @Column(name = "content", nullable = false)
-    @ApiModelProperty(required=true)
-    private byte[]  content;
-
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    @LastModifiedDate
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "updated_date")
-    private Date creationDate = new Date();
-
-    @Override
-    public String toString() {
-        return "[" + "id = " + id +
-                ", name = " + name +
-                ", contentType = " + contentType +
-                "]";
-    }
-
-    @Override
-    public boolean equals(Object o) {
-
-        if (o == this) {
-            return true;
-        }
-        if (!(o instanceof BlueprintModelContent)) {
-            return false;
-        }
-        BlueprintModelContent blueprintModelContent = (BlueprintModelContent) o;
-        return Objects.equals(id, blueprintModelContent.id) && Objects.equals(name, blueprintModelContent.name)
-                && Objects.equals(contentType, blueprintModelContent.contentType);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(id, name, contentType);
-    }
-
-    public String getId() {
-        return id;
-    }
-
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-
-    public String getName() {
-        return name;
-    }
-
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-
-    public String getContentType() {
-        return contentType;
-    }
-
-
-    public void setContentType(String contentType) {
-        this.contentType = contentType;
-    }
-
-
-    public BlueprintModel getBlueprintModel() {
-        return blueprintModel;
-    }
-
-
-    public void setBlueprintModel(BlueprintModel blueprintModel) {
-        this.blueprintModel = blueprintModel;
-    }
-
-
-    public String getDescription() {
-        return description;
-    }
-
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
-
-    public byte[] getContent() {
-        return content;
-    }
-
-
-    public void setContent(byte[] content) {
-        this.content = content;
-    }
-
-
-    public Date getCreationDate() {
-        return creationDate;
-    }
-
-
-    public void setCreationDate(Date creationDate) {
-        this.creationDate = creationDate;
-    }
-
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java
deleted file mode 100644 (file)
index 5c351bc..0000000
+++ /dev/null
@@ -1,166 +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.controllerblueprints.service.domain;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeName;
-import org.springframework.data.annotation.LastModifiedDate;
-
-import javax.persistence.*;
-import java.io.Serializable;
-import java.util.Date;
-
-@Entity
-@Table(name = "CONFIG_MODEL")
-@JsonTypeName("blueprintModel")
-@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME)
-public class BlueprintModelSearch implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    @Id
-    @Column(name = "config_model_id")
-    private String id;
-
-    @Column(name = "artifact_uuid")
-    private String artifactUUId;
-
-    @Column(name = "artifact_type")
-    private String artifactType;
-
-    @Column(name = "artifact_version", nullable = false)
-    private String artifactVersion;
-
-    @Lob
-    @Column(name = "artifact_description")
-    private String artifactDescription;
-
-    @Column(name = "internal_version")
-    private Integer internalVersion;
-
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    @LastModifiedDate
-    @Temporal(TemporalType.TIMESTAMP)
-    @Column(name = "creation_date")
-    private Date createdDate = new Date();
-
-    @Column(name = "artifact_name", nullable = false)
-    private String artifactName;
-
-    @Column(name = "published", nullable = false)
-    private String published;
-
-    @Column(name = "updated_by", nullable = false)
-    private String updatedBy;
-
-    @Lob
-    @Column(name = "tags", nullable = false)
-    private String tags;
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getArtifactUUId() {
-        return artifactUUId;
-    }
-
-    public void setArtifactUUId(String artifactUUId) {
-        this.artifactUUId = artifactUUId;
-    }
-
-    public String getArtifactType() {
-        return artifactType;
-    }
-
-    public void setArtifactType(String artifactType) {
-        this.artifactType = artifactType;
-    }
-
-    public String getArtifactVersion() {
-        return artifactVersion;
-    }
-
-    public void setArtifactVersion(String artifactVersion) {
-        this.artifactVersion = artifactVersion;
-    }
-
-    public String getArtifactDescription() {
-        return artifactDescription;
-    }
-
-    public void setArtifactDescription(String artifactDescription) {
-        this.artifactDescription = artifactDescription;
-    }
-
-    public Integer getInternalVersion() {
-        return internalVersion;
-    }
-
-    public void setInternalVersion(Integer internalVersion) {
-        this.internalVersion = internalVersion;
-    }
-
-    public Date getCreatedDate() {
-        return createdDate;
-    }
-
-    public void setCreatedDate(Date createdDate) {
-        this.createdDate = createdDate;
-    }
-
-    public String getArtifactName() {
-        return artifactName;
-    }
-
-    public void setArtifactName(String artifactName) {
-        this.artifactName = artifactName;
-    }
-
-    public String getPublished() {
-        return published;
-    }
-
-    public void setPublished(String published) {
-        this.published = published;
-    }
-
-    public String getUpdatedBy() {
-        return updatedBy;
-    }
-
-    public void setUpdatedBy(String updatedBy) {
-        this.updatedBy = updatedBy;
-    }
-
-    public String getTags() {
-        return tags;
-    }
-
-    public void setTags(String tags) {
-        this.tags = tags;
-    }
-
-    public static long getSerialversionuid() {
-        return serialVersionUID;
-    }
-}