From d39c13bf2aff5f80029a4b8beb949f1f4a9ed189 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 30 Aug 2019 11:03:10 -0400 Subject: Refactor model entity and repository. Change-Id: I6f06fc46fcedbe1cbb8a8e6f8c30b131680a5b08 Issue-ID: CCSDK-1663 Signed-off-by: Brinda Santh --- .../db/primary/domain/BlueprintModel.kt | 117 +++++++++++++++++++++ .../db/primary/domain/BlueprintModelContent.kt | 98 +++++++++++++++++ .../db/primary/domain/BlueprintModelSearch.kt | 82 +++++++++++++++ .../ControllerBlueprintModelContentRepository.kt | 22 ++++ .../ControllerBlueprintModelRepository.kt | 21 ++++ .../ControllerBlueprintModelSearchRepository.kt | 62 +++++++++++ .../designer/api/BluePrintModelHandler.kt | 59 +++++------ .../designer/api/BlueprintModelController.kt | 2 +- .../load/ControllerBlueprintCatalogServiceImpl.kt | 6 +- .../designer/api/BlueprintModelControllerTest.kt | 2 +- 10 files changed, 435 insertions(+), 36 deletions(-) create mode 100755 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt create mode 100644 ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt (limited to 'ms/blueprintsprocessor') 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 index 000000000..7bc88d8c2 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModel.kt @@ -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 index 000000000..a3a42ff3d --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelContent.kt @@ -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 index 000000000..f00d5cadf --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt @@ -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 + } +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt new file mode 100644 index 000000000..59b82a3da --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelContentRepository.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelContent +import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelContentRepository + +interface ControllerBlueprintModelContentRepository : ModelContentRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt new file mode 100644 index 000000000..c26475b1d --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelRepository.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel +import org.onap.ccsdk.cds.controllerblueprints.db.resources.repository.ModelRepository + +interface ControllerBlueprintModelRepository : ModelRepository diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt new file mode 100644 index 000000000..0e0c5435b --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/ControllerBlueprintModelSearchRepository.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository + +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +/** + * Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ControllerBlueprintModelSearchRepository : JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + fun findById(id: String): BlueprintModelSearch? + + /** + * This is a findAll method + * @return List + */ + override fun findAll(): List + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModelSearch? + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + fun findByTagsContainingIgnoreCase(tags: String): List +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintModelHandler.kt index d4bcd8e94..3a68951db 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintModelHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintModelHandler.kt @@ -18,16 +18,16 @@ 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, diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt index 98f521222..26420cc56 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt @@ -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 diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt index f0252c815..e91f4918c 100755 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ControllerBlueprintCatalogServiceImpl.kt @@ -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 diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt index cd49870ae..877584ed6 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt @@ -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 -- cgit 1.2.3-korg