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 --- .../designer/api/BluePrintModelHandler.kt | 59 ++++++++++------------ .../designer/api/BlueprintModelController.kt | 2 +- .../load/ControllerBlueprintCatalogServiceImpl.kt | 6 +-- .../designer/api/BlueprintModelControllerTest.kt | 2 +- 4 files changed, 33 insertions(+), 36 deletions(-) (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src') 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