diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-08-30 13:57:57 -0400 |
---|---|---|
committer | Brinda Santh <brindasanth@in.ibm.com> | 2019-08-30 13:57:57 -0400 |
commit | 9039b516eaa55a08d2f97ef290c17de781e13ae2 (patch) | |
tree | 6cd4052ecea536df45de609032eb01a10d233aa4 /ms/blueprintsprocessor/modules | |
parent | 7bbeeda4e4ff25a073c9d1a8992fe68aaf470e6b (diff) |
Refactor handlers, services to designer api.
Change-Id: I3bc56e14fca332c0c0b661bb7e8a501a2dadbe91
Issue-ID: CCSDK-1663
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules')
37 files changed, 2695 insertions, 12 deletions
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 26420cc56..f67ed25c3 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 @@ -20,6 +20,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.blueprintsprocessor.db.primary.domain.BlueprintModelSearch +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler 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/ControllerBlueprintExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ControllerBlueprintExceptionHandler.kt new file mode 100644 index 000000000..f4dabcded --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ControllerBlueprintExceptionHandler.kt @@ -0,0 +1,57 @@ +/* + * Copyright © 2018-2019 Bell Canada 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.designer.api + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.service.common.ErrorMessage +import org.slf4j.LoggerFactory +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.ExceptionHandler +import org.springframework.web.bind.annotation.RestControllerAdvice + +/** + * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right + * HTTP code status + * + * @author Vinal Patel + * @version 1.0 + */ +@RestControllerAdvice("org.onap.ccsdk.cds.controllerblueprints") +open class ControllerBlueprintExceptionHandler { + + companion object ControllerBlueprintExceptionHandler { + val LOG = LoggerFactory.getLogger(ControllerBlueprintExceptionHandler::class.java) + } + + @ExceptionHandler + fun ControllerBlueprintExceptionHandler(e: BluePrintException): ResponseEntity<ErrorMessage> { + val errorCode = ErrorCode.valueOf(e.code) + val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message") + LOG.error("Error: $errorCode ${e.message}") + return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode)) + } + + @ExceptionHandler + fun ControllerBlueprintExceptionHandler(e: Exception): ResponseEntity<ErrorMessage> { + val errorCode = ErrorCode.GENERIC_FAILURE + val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message") + LOG.error("Error: $errorCode ${e.message}") + return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode)) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt new file mode 100644 index 000000000..4c2ec6aa9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api + +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.springframework.http.MediaType +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping(value = arrayOf("/api/v1/model-type")) +open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) { + + @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking { + modelTypeHandler.getModelTypeByName(name) + } + + @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking { + modelTypeHandler.searchModelTypes(tags) + } + + @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + @ResponseBody + fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking { + modelTypeHandler.getModelTypeByDefinitionType(definitionType) + } + + @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + @ResponseBody + @Throws(BluePrintException::class) + fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking { + modelTypeHandler.saveModel(modelType) + } + + @DeleteMapping(path = arrayOf("/{name}")) + fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking { + modelTypeHandler.deleteByModelName(name) + } +}
\ 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/ResourceDictionaryController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt new file mode 100644 index 000000000..89744dd2f --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt @@ -0,0 +1,69 @@ +/* + * 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.designer.api + +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.http.MediaType +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping(value = ["/api/v1/dictionary"]) +open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) { + + @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking { + resourceDictionaryHandler.getResourceDictionaryByName(name) + } + + @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking { + resourceDictionaryHandler.saveResourceDictionary(dataDictionary) + } + + @DeleteMapping(path = ["/{name}"]) + fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking { + resourceDictionaryHandler.deleteResourceDictionary(name) + } + + @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking { + resourceDictionaryHandler.searchResourceDictionaryByNames(names) + } + + @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking { + resourceDictionaryHandler.searchResourceDictionaryByTags(tags) + + } + + @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking { + resourceDictionaryHandler.getResourceSourceMapping() + } + +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt index b4c658f92..552339be9 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive @@ -28,7 +29,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.stereotype.Service @Service diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt index e018b9d7f..0b64ed503 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition @@ -24,7 +25,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoServ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index acee7c076..723d7bb27 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService @@ -24,7 +25,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnha import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt index 05cfa5a14..efb695b22 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition @@ -27,7 +28,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnha import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt index 62812c0fa..b87cf9c6b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition @@ -25,7 +26,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoServ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt index e4db71904..55eb42f89 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt @@ -25,7 +25,7 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.cds.controllerblueprints.service.ResourceDefinitionRepoService +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt index d3907946e..c018664e4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt @@ -28,8 +28,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeServ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils -import org.onap.ccsdk.cds.controllerblueprints.service.ResourceDefinitionRepoService -import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.springframework.stereotype.Service interface ResourceDefinitionEnhancerService { 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/handler/BluePrintModelHandler.kt index 3a68951db..44b0c4bc8 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/handler/BluePrintModelHandler.kt @@ -16,19 +16,19 @@ * limitations under the License. */ -package org.onap.ccsdk.cds.blueprintsprocessor.designer.api +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler 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.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils 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.utils.BluePrintEnhancerUtils import org.slf4j.LoggerFactory import org.springframework.core.io.ByteArrayResource import org.springframework.core.io.Resource diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt new file mode 100644 index 000000000..034c40774 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt @@ -0,0 +1,122 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler + +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ModelTypeRepository +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.ModelTypeValidator +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service + +@Service +open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository) { + + private val log = LoggerFactory.getLogger(ModelTypeHandler::class.java)!! + + /** + * This is a getModelTypeByName service + * + * @param modelTypeName modelTypeName + * @return ModelType + */ + suspend fun getModelTypeByName(modelTypeName: String): ModelType { + log.info("Searching : $modelTypeName") + check(modelTypeName.isNotBlank()) { "Model Name Information is missing." } + val modelType = modelTypeRepository.findByModelName(modelTypeName) + return if (modelType != null) { + modelType + } else { + throw BluePrintException("couldn't get modelType($modelTypeName)") + } + } + + + /** + * This is a searchModelTypes service + * + * @param tags tags + * @return List<ModelType> + </ModelType> */ + suspend fun searchModelTypes(tags: String): List<ModelType> { + check(tags.isNotBlank()) { "No Search Information provide" } + return modelTypeRepository.findByTagsContainingIgnoreCase(tags) + } + + /** + * This is a saveModel service + * + * @param modelType modelType + * @return ModelType + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + suspend open fun saveModel(modelType: ModelType): ModelType { + lateinit var dbModel: ModelType + ModelTypeValidator.validateModelType(modelType) + val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) + if (dbModelType != null) { + dbModel = dbModelType + dbModel.description = modelType.description + dbModel.definition = modelType.definition + dbModel.definitionType = modelType.definitionType + dbModel.derivedFrom = modelType.derivedFrom + dbModel.tags = modelType.tags + dbModel.version = modelType.version + dbModel.updatedBy = modelType.updatedBy + dbModel = modelTypeRepository.save(dbModel) + } else { + dbModel = modelTypeRepository.save(modelType) + } + return dbModel + } + + + /** + * This is a deleteByModelName service + * + * @param modelName modelName + */ + suspend open fun deleteByModelName(modelName: String) { + check(modelName.isNotBlank()) { "Model Name Information is missing." } + modelTypeRepository.deleteByModelName(modelName) + + } + + /** + * This is a getModelTypeByDefinitionType service + * + * @param definitionType definitionType + * @return List<ModelType> + */ + suspend fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { + check(definitionType.isNotBlank()) { "Model definitionType Information is missing." } + return modelTypeRepository.findByDefinitionType(definitionType) + } + + /** + * This is a getModelTypeByDerivedFrom service + * + * @param derivedFrom derivedFrom + * @return List<ModelType> + */ + suspend fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { + check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } + return modelTypeRepository.findByDerivedFrom(derivedFrom) + } +}
\ 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/handler/ResourceDictionaryHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt new file mode 100644 index 000000000..a7e8f2011 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt @@ -0,0 +1,147 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler + +import com.google.common.base.Preconditions +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.stereotype.Service + +@Service +class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) { + + + /** + * This is a getDataDictionaryByName service + * + * @param name name + * @return DataDictionary + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + suspend fun getResourceDictionaryByName(name: String): ResourceDictionary { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing.") + val resourceDictionaryDb = resourceDictionaryRepository.findByName(name) + return if (resourceDictionaryDb != null) { + resourceDictionaryDb + } else { + throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)) + } + } + + /** + * This is a searchResourceDictionaryByNames service + * + * @param names names + * @return List<ResourceDictionary> + </ResourceDictionary> */ + suspend fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide") + return resourceDictionaryRepository.findByNameIn(names) + } + + /** + * This is a searchResourceDictionaryByTags service + * + * @param tags tags + * @return List<ResourceDictionary> + </ResourceDictionary> */ + suspend fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide") + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags) + } + + /** + * This is a saveDataDictionary service + * + * @param resourceDictionary resourceDictionary + * @return DataDictionary + */ + @Throws(BluePrintException::class) + suspend fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { + var resourceDictionary = resourceDictionary + + val resourceDefinition = resourceDictionary.definition + Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content") + // Validate the Resource Definitions + //TODO( Save Validator) + //validate(resourceDefinition) + + resourceDictionary.tags = resourceDefinition.tags + resourceDefinition.updatedBy = resourceDictionary.updatedBy + // Set the Property Definitions + val propertyDefinition = resourceDefinition.property + resourceDictionary.description = propertyDefinition.description + resourceDictionary.dataType = propertyDefinition.type + if (propertyDefinition.entrySchema != null) { + resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type + } + + validateResourceDictionary(resourceDictionary) + + val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) + if (dbResourceDictionaryData != null) { + val dbResourceDictionary = dbResourceDictionaryData + + dbResourceDictionary.name = resourceDictionary.name + dbResourceDictionary.definition = resourceDictionary.definition + dbResourceDictionary.description = resourceDictionary.description + dbResourceDictionary.tags = resourceDictionary.tags + dbResourceDictionary.updatedBy = resourceDictionary.updatedBy + dbResourceDictionary.dataType = resourceDictionary.dataType + dbResourceDictionary.entrySchema = resourceDictionary.entrySchema + resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary) + } else { + resourceDictionary = resourceDictionaryRepository.save(resourceDictionary) + } + + return resourceDictionary + } + + /** + * This is a deleteResourceDictionary service + * + * @param name name + */ + suspend fun deleteResourceDictionary(name: String) { + check(name.isNotBlank()) { "Resource dictionary name is missing." } + resourceDictionaryRepository.deleteByName(name) + } + + /** + * This is a getResourceSourceMapping service + */ + suspend fun getResourceSourceMapping(): ResourceSourceMapping { + return ResourceSourceMappingFactory.getRegisterSourceMapping() + } + + private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean { + checkNotEmpty(resourceDictionary.name){ "DataDictionary Definition name is missing."} + checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." } + checkNotEmpty(resourceDictionary.description){ "DataDictionary Definition Information is missing."} + checkNotEmpty(resourceDictionary.tags){ "DataDictionary Definition tags is missing."} + checkNotEmpty(resourceDictionary.updatedBy){ "DataDictionary Definition updatedBy is missing."} + return true + } +}
\ 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/load/ModelTypeLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ModelTypeLoadService.kt index 9d1eaff33..1434bccb4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ModelTypeLoadService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ModelTypeLoadService.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope import org.apache.commons.io.FilenameUtils import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.data.* @@ -29,7 +30,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType -import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.io.File diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt index 308c08f82..14dc4473a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt @@ -22,13 +22,13 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary -import org.onap.ccsdk.cds.controllerblueprints.service.handler.ResourceDictionaryHandler import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.io.File diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/BluePrintsReactRepository.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/BluePrintsReactRepository.kt new file mode 100644 index 000000000..78175724f --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/BluePrintsReactRepository.kt @@ -0,0 +1,76 @@ +/* + * 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.designer.api.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.springframework.stereotype.Service +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import reactor.core.scheduler.Schedulers +// TODO("Convert into coroutines") +/** + * ModelTypeReactRepository. + * + * @author Brinda Santh + */ +@Service +open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) { + + fun save(modelType: ModelType): Mono<ModelType> { + return Mono.justOrEmpty(modelTypeRepository.save(modelType)) + } + + fun findByModelName(modelName: String): Mono<ModelType> { + return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName)) + } + + fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> { + return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> { + return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> { + return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionType(definitionType: String): Flux<ModelType> { + return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> { + return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> { + return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByModelName(modelName: String): Mono<Void> { + modelTypeRepository.deleteByModelName(modelName) + return Mono.empty() + } + +}
\ 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/repository/ModelTypeRepository.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeRepository.kt new file mode 100644 index 000000000..82dc89c3e --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeRepository.kt @@ -0,0 +1,85 @@ +/* + * Copyright © 2017-2018 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.designer.api.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import javax.transaction.Transactional + +@Repository +interface ModelTypeRepository : JpaRepository<ModelType, String> { + /** + * This is a findByModelName method + * + * @param modelName Model Name + * @return Optional<ModelType> + */ + fun findByModelName(modelName: String): ModelType? + /** + * This is a findByModelNameIn method + * + * @param modelNames Model Names + * @return List<ModelType> + */ + fun findByModelNameIn(modelNames: List<String>): List<ModelType> + /** + * This is a findByDerivedFrom method + * + * @param derivedFrom Derived From + * @return List<ModelType> + */ + fun findByDerivedFrom(derivedFrom: String): List<ModelType> + /** + * This is a findByDerivedFromIn method + * + * @param derivedFroms Derived Froms + * @return List<ModelType> + */ + fun findByDerivedFromIn(derivedFroms: List<String>): List<ModelType> + + /** + * This is a findByDefinitionType method + * + * @param definitionType Definition Type + * @return List<ModelType> + */ + fun findByDefinitionType(definitionType: String): List<ModelType> + /** + * This is a findByDefinitionTypeIn method + * + * @param definitionTypes Definition Types + * @return List<ModelType> + */ + fun findByDefinitionTypeIn(definitionTypes: List<String>): List<ModelType> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags Tags + * @return Optional<ModelType> + */ + fun findByTagsContainingIgnoreCase(tags: String): List<ModelType> + + /** + * This is a deleteByModelName method + * + * @param modelName ModelName + */ + @Transactional + fun deleteByModelName(modelName: String) +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt new file mode 100644 index 000000000..ccd91b84d --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt @@ -0,0 +1,66 @@ +/* + * 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.designer.api.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + + +/** + * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ResourceDictionaryRepository : JpaRepository<ResourceDictionary, String> { + + + /** + * This is a findByName method + * + * @param name name + * @return Optional<ResourceMapping> + </ResourceMapping> */ + fun findByName(name: String): ResourceDictionary? + + /** + * This is a findByNameIn method + * + * @param names names + * @return Optional<ResourceMapping> + </ResourceMapping> */ + fun findByNameIn(names: List<String>): List<ResourceDictionary> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional<ModelType> + </ModelType> */ + fun findByTagsContainingIgnoreCase(tags: String): List<ResourceDictionary> + + /** + * This is a deleteByName method + * + * @param name name + */ + fun deleteByName(name: String) + + +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/AutoResourceMappingService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/AutoResourceMappingService.kt new file mode 100644 index 000000000..56bd01e11 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/AutoResourceMappingService.kt @@ -0,0 +1,174 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Huawei. + * + * 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.designer.api.service + +import com.google.common.base.Preconditions +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.onap.ccsdk.cds.controllerblueprints.service.model.AutoMapResponse +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.util.* + +@Service +open class AutoResourceMappingService(private val dataDictionaryRepository: ResourceDictionaryRepository) { + + private val log = LoggerFactory.getLogger(AutoResourceMappingService::class.java) + + @Throws(BluePrintException::class) + fun autoMap(resourceAssignments: MutableList<ResourceAssignment>): + AutoMapResponse { + val autoMapResponse = AutoMapResponse() + try { + if (CollectionUtils.isNotEmpty(resourceAssignments)) { + // Create the Dictionary definitions for the ResourceAssignment Names + val dictionaryMap = getDictionaryDefinitions(resourceAssignments) + + for (resourceAssignment in resourceAssignments) { + if (StringUtils.isNotBlank(resourceAssignment.name) + && StringUtils.isBlank(resourceAssignment.dictionaryName)) { + populateDictionaryMapping(dictionaryMap, resourceAssignment) + log.info("Mapped Resource : {}", resourceAssignment) + } + } + } + val dictionaries = getDictionaryDefinitionsList(resourceAssignments) + val resourceAssignmentsFinal = getAllAutoMapResourceAssignments(resourceAssignments) + autoMapResponse.dataDictionaries = dictionaries + autoMapResponse.resourceAssignments = resourceAssignmentsFinal + } catch (e: Exception) { + log.error(String.format("Failed in auto process %s", e.message)) + throw BluePrintException(e, e.message!!) + } + + return autoMapResponse + } + + private fun populateDictionaryMapping(dictionaryMap: Map<String, ResourceDictionary>, resourceAssignment: ResourceAssignment) { + val dbDataDictionary = dictionaryMap[resourceAssignment.name] + if (dbDataDictionary != null && dbDataDictionary.definition != null) { + + val dictionaryDefinition = dbDataDictionary.definition + + if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.name) + && StringUtils.isBlank(resourceAssignment.dictionaryName)) { + + resourceAssignment.dictionaryName = dbDataDictionary.name + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition) + } + } + } + + private fun getDictionaryDefinitions(resourceAssignments: List<ResourceAssignment>): Map<String, ResourceDictionary> { + val dictionaryMap = HashMap<String, ResourceDictionary>() + val names = ArrayList<String>() + for (resourceAssignment in resourceAssignments) { + if (StringUtils.isNotBlank(resourceAssignment.name)) { + names.add(resourceAssignment.name) + } + } + if (CollectionUtils.isNotEmpty(names)) { + + val dictionaries = dataDictionaryRepository.findByNameIn(names) + if (CollectionUtils.isNotEmpty(dictionaries)) { + for (dataDictionary in dictionaries) { + if (StringUtils.isNotBlank(dataDictionary.name)) { + dictionaryMap[dataDictionary.name] = dataDictionary + } + } + } + } + return dictionaryMap + + } + private fun getDictionaryDefinitionsList(resourceAssignments: List<ResourceAssignment>): List<ResourceDictionary>? { + var dictionaries: List<ResourceDictionary>? = null + val names = ArrayList<String>() + for (resourceAssignment in resourceAssignments) { + if (StringUtils.isNotBlank(resourceAssignment.dictionaryName)) { + + if (!names.contains(resourceAssignment.dictionaryName)) { + names.add(resourceAssignment.dictionaryName!!) + } + + if (resourceAssignment.dependencies != null && !resourceAssignment.dependencies!!.isEmpty()) { + val dependencyNames = resourceAssignment.dependencies + for (dependencyName in dependencyNames!!) { + if (StringUtils.isNotBlank(dependencyName) && !names.contains(dependencyName)) { + names.add(dependencyName) + } + } + } + } + } + if (CollectionUtils.isNotEmpty(names)) { + dictionaries = dataDictionaryRepository.findByNameIn(names) + } + return dictionaries + + } + + private fun getAllAutoMapResourceAssignments(resourceAssignments: MutableList<ResourceAssignment>): List<ResourceAssignment> { + var dictionaries: List<ResourceDictionary>? = null + val names = ArrayList<String>() + for (resourceAssignment in resourceAssignments) { + if (StringUtils.isNotBlank(resourceAssignment.dictionaryName)) { + if (resourceAssignment.dependencies != null && !resourceAssignment.dependencies!!.isEmpty()) { + val dependencyNames = resourceAssignment.dependencies + for (dependencyName in dependencyNames!!) { + if (StringUtils.isNotBlank(dependencyName) && !names.contains(dependencyName) + && !checkAssignmentsExists(resourceAssignments, dependencyName)) { + names.add(dependencyName) + } + } + } + } + } + + if (!names.isEmpty()) { + dictionaries = dataDictionaryRepository.findByNameIn(names) + } + if (dictionaries != null) { + for (rscDictionary in dictionaries) { + val dictionaryDefinition = rscDictionary.definition + Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition") + val property = PropertyDefinition() + property.required = true + val resourceAssignment = ResourceAssignment() + resourceAssignment.name = rscDictionary.name + resourceAssignment.dictionaryName = rscDictionary.name + resourceAssignment.version = 0 + resourceAssignment.property = property + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition) + resourceAssignments.add(resourceAssignment) + } + } + return resourceAssignments + } + + + private fun checkAssignmentsExists(resourceAssignmentsWithDepencies: List<ResourceAssignment>, resourceName: String): Boolean { + return resourceAssignmentsWithDepencies.stream().anyMatch { names -> names.name.equals(resourceName, ignoreCase = true) } + } +}
\ 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/service/BluePrintRepoServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/BluePrintRepoServiceImpl.kt new file mode 100644 index 000000000..f8e6163a5 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/BluePrintRepoServiceImpl.kt @@ -0,0 +1,105 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service + +import com.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ModelTypeRepository +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition +import org.springframework.stereotype.Service + +interface ResourceDefinitionRepoService : BluePrintRepoService { + + @Throws(BluePrintException::class) + fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition +} + +@Service +open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRepository, + private val resourceDictionaryRepository: ResourceDictionaryRepository) : ResourceDefinitionRepoService { + + @Throws(BluePrintException::class) + override fun getNodeType(nodeTypeName: String): NodeType { + return getModelType(nodeTypeName, NodeType::class.java) + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName)") + } + + @Throws(BluePrintException::class) + override fun getDataType(dataTypeName: String): DataType { + return getModelType(dataTypeName, DataType::class.java) + ?: throw BluePrintException("couldn't get DataType($dataTypeName)") + } + + @Throws(BluePrintException::class) + override fun getArtifactType(artifactTypeName: String): ArtifactType { + return getModelType(artifactTypeName, ArtifactType::class.java) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName)") + } + + @Throws(BluePrintException::class) + override fun getRelationshipType(relationshipTypeName: String): RelationshipType { + return getModelType(relationshipTypeName, RelationshipType::class.java) + ?: throw BluePrintException("couldn't get RelationshipType($relationshipTypeName)") + } + + @Throws(BluePrintException::class) + override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition { + return getModelType(capabilityDefinitionName, CapabilityDefinition::class.java) + ?: throw BluePrintException("couldn't get CapabilityDefinition($capabilityDefinitionName)") + } + + @Throws(BluePrintException::class) + override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { + val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) + return if (dbResourceDictionary != null) { + dbResourceDictionary.definition + } else { + throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) + } + } + + @Throws(BluePrintException::class) + private fun <T> getModelType(modelName: String, valueClass: Class<T>): T? { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing") + + val modelDefinition = getModelDefinition(modelName) + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)) + + return JacksonUtils.readValue(modelDefinition, valueClass) + } + + @Throws(BluePrintException::class) + private fun getModelDefinition(modelName: String): JsonNode { + val modelDefinition: JsonNode + val modelTypeDb = modelTypeRepository.findByModelName(modelName) + if (modelTypeDb != null) { + modelDefinition = modelTypeDb.definition + } else { + throw BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)) + } + return modelDefinition + } +}
\ 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/utils/BluePrintEnhancerUtils.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtils.kt new file mode 100644 index 000000000..6eab5cd3f --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtils.kt @@ -0,0 +1,164 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.reactive.awaitSingle +import kotlinx.coroutines.withContext +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.springframework.core.io.ByteArrayResource +import org.springframework.core.io.Resource +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.StringUtils +import reactor.core.publisher.Mono +import java.io.File +import java.io.IOException +import java.nio.file.Path +import java.nio.file.Paths +import java.util.* + + +class BluePrintEnhancerUtils { + companion object { + + fun populateDataTypes(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + dataTypeName: String): DataType { + val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) + ?: bluePrintRepoService.getDataType(dataTypeName) + ?: throw BluePrintException("couldn't get DataType($dataTypeName) from repo.") + bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dataType) + return dataType + } + + fun populateRelationshipType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + relationshipName: String): RelationshipType { + + val relationshipType = bluePrintContext.serviceTemplate.relationshipTypes?.get(relationshipName) + ?: bluePrintRepoService.getRelationshipType(relationshipName) + ?: throw BluePrintException("couldn't get RelationshipType($relationshipName) from repo.") + bluePrintContext.serviceTemplate.relationshipTypes?.put(relationshipName, relationshipType) + return relationshipType + } + + + fun populateNodeType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + nodeTypeName: String): NodeType { + + val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName) + ?: bluePrintRepoService.getNodeType(nodeTypeName) + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName) from repo.") + bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) + return nodeType + } + + fun populateArtifactType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + artifactTypeName: String): ArtifactType { + + val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: bluePrintRepoService.getArtifactType(artifactTypeName) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.") + bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) + return artifactType + } + + suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { + // Delete the Directory + targetFile.deleteRecursively() + return filePart.transferTo(targetFile) + .thenReturn(targetFile) + .awaitSingle() + } + + suspend fun extractCompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + //Recreate the Base Directories + normalizedFile(archiveDir).reCreateDirs() + normalizedFile(enhanceDir).reCreateDirs() + val filePartFile = normalizedFile(archiveDir, "cba.zip") + // Copy the File Part to ZIP + return copyFromFilePart(filePart, filePartFile) + } + + suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir) + val deCompressFileName = normalizedPathName(enhanceDir) + return filePartFile.deCompress(deCompressFileName) + } + + suspend fun compressToFilePart(enhanceDir: String, archiveDir: String, + outputFileName:String="enhanced-cba.zip"): ResponseEntity<Resource> { + val compressedFile = normalizedFile(archiveDir, outputFileName) + BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile) + return prepareResourceEntity(compressedFile.name, compressedFile.readBytes()) + } + + suspend fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity<Resource> { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") + .body(ByteArrayResource(file)) + } + + suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) { + deleteDir(archiveLocation) + deleteDir(enhancementLocation) + } + + /** + * This is a saveCBAFile method + * take a [FilePart], transfer it to disk using a Flux of FilePart and return a [Mono] representing the CBA file name + * + * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save + * @return a [Mono] String representing the result of the operation + * @throws (BluePrintException, IOException) BluePrintException, IOException + */ + @Throws(BluePrintException::class, IOException::class) + fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Mono<String> { + + // Normalize file name + val fileName = StringUtils.cleanPath(filePart.filename()) + + // Check if the file's extension is "CBA" + if (StringUtils.getFilenameExtension(fileName) != "zip") { + throw BluePrintException(ErrorCode.INVALID_FILE_EXTENSION.value, "Invalid file extension required ZIP") + } + + // Change file name to match a pattern + val changedFileName = UUID.randomUUID().toString() + ".zip" + //String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); + + // Copy file to the target location (Replacing existing file with the same name) + val targetLocation = targetDirectory.resolve(changedFileName) + + // if a file with the same name already exists in a repository, delete and recreate it + val file = File(targetLocation.toString()) + if (file.exists()) + file.delete() + file.createNewFile() + + return filePart.transferTo(file).thenReturn(changedFileName) + } + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidator.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidator.kt new file mode 100644 index 000000000..7d6644219 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidator.kt @@ -0,0 +1,83 @@ +/* + * Copyright © 2017-2018 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.designer.api.utils + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType + +class ModelTypeValidator { + companion object { + /** + * This is a validateModelTypeDefinition + * + * @param definitionType definitionType + * @param definitionContent definitionContent + * @return boolean + */ + fun validateModelTypeDefinition(definitionType: String, definitionContent: JsonNode): Boolean { + + when (definitionType) { + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE -> { + JacksonUtils.readValue(definitionContent, DataType::class.java) + ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE -> { + JacksonUtils.readValue(definitionContent, NodeType::class.java) + ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE -> { + JacksonUtils.readValue(definitionContent, ArtifactType::class.java) + ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE -> { + JacksonUtils.readValue(definitionContent, CapabilityDefinition::class.java) + ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE -> { + JacksonUtils.readValue(definitionContent, RelationshipType::class.java) + ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent") + } + } + return true + } + + /** + * This is a validateModelType method + * + * @param modelType modelType + * @return boolean + */ + fun validateModelType(modelType: ModelType?): Boolean { + checkNotNull(modelType) { "Model Type Information is missing." } + + val validRootTypes = BluePrintTypes.validModelTypes() + + check(validRootTypes.contains(modelType.definitionType)) { + "Not Valid Model Root Type(${modelType.definitionType}), It should be $validRootTypes" + } + + validateModelTypeDefinition(modelType.definitionType, modelType.definition) + return true + } + } + +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt new file mode 100644 index 000000000..6d3b3da4a --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt @@ -0,0 +1,123 @@ +/* + * 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.designer.api + +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +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.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ModelTypeControllerTest { + + private val log = LoggerFactory.getLogger(ModelTypeControllerTest::class.java)!! + + @Autowired + internal var modelTypeController: ModelTypeController? = null + + private var modelName = "test-datatype" + + @Test + @Commit + @Throws(Exception::class) + fun test01SaveModelType() { + log.info("**************** test01SaveModelType ********************") + + val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json") + var modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + modelType.description = "Definition for Sample Datatype " + modelType.definition = JacksonUtils.jsonNode(content) + modelType.modelName = modelName + modelType.version = "1.0.0" + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.updatedBy = "xxxxxx@xxx.com" + modelType = modelTypeController!!.saveModelType(modelType) + log.info("Saved Mode {}", modelType.toString()) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) + + val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName) + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType) + + // Model Update + modelType.updatedBy = "bs2796@xxx.com" + modelType = modelTypeController!!.saveModelType(modelType) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) + + } + + @Test + @Throws(Exception::class) + fun test02SearchModelTypes() { + log.info("*********************** test02SearchModelTypes ***************************") + + val tags = "test-datatype" + + val dbModelTypes = modelTypeController!!.searchModelTypes(tags) + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty()) + + } + + @Test + @Throws(Exception::class) + fun test03GetModelType() { + log.info("************************* test03GetModelType *********************************") + val dbModelType = modelTypeController!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) + + val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes) + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty()) + } + + @Test + @Commit + @Throws(Exception::class) + fun test04DeleteModelType() { + log.info( + "************************ test03DeleteModelType ***********************") + val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) + + modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt new file mode 100644 index 000000000..893622308 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt @@ -0,0 +1,49 @@ +/* + * 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.designer.api + +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +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.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ResourceDictionaryControllerTest { + + @Autowired + lateinit var resourceDictionaryController: ResourceDictionaryController + + @Test + fun testResourceDictionaryControllerPresence() { + assertNotNull(resourceDictionaryController, "failed to initialise ResourceDictionaryController") + } + +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeServiceTest.kt new file mode 100644 index 000000000..31ae54036 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeServiceTest.kt @@ -0,0 +1,138 @@ +/* + * 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.designer.api.handler + +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +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.designer.api.DesignerApiTestConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner + + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ModelTypeServiceTest { + @Autowired + private val modelTypeHandler: ModelTypeHandler? = null + + internal var modelName = "test-datatype" + + private val log = LoggerFactory.getLogger(ModelTypeServiceTest::class.java) + + @Test + @Commit + @Throws(Exception::class) + fun test01SaveModelType() { + runBlocking { + log.info("**************** test01SaveModelType ********************") + + val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json") + var modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + modelType.description = "Definition for Sample Datatype " + modelType.definition = JacksonUtils.jsonNode(content) + modelType.modelName = modelName + modelType.version = "1.0.0" + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.updatedBy = "xxxxxx@xxx.com" + modelType = modelTypeHandler!!.saveModel(modelType) + log.info("Saved Mode {}", modelType.toString()) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) + + val dbModelType = modelTypeHandler.getModelTypeByName(modelType.modelName) + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType) + + // Model Update + modelType.updatedBy = "bs2796@xxx.com" + modelType = modelTypeHandler.saveModel(modelType) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) + } + + } + + @Test + @Throws(Exception::class) + fun test02SearchModelTypes() { + runBlocking { + log.info("*********************** test02SearchModelTypes ***************************") + + val tags = "test-datatype" + + val dbModelTypes = modelTypeHandler!!.searchModelTypes(tags) + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size > 0) + } + + } + + @Test + @Throws(Exception::class) + fun test03GetModelType() { + runBlocking { + log.info("************************* test03GetModelType *********************************") + val dbModelType = modelTypeHandler!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) + + val dbDatatypeModelTypes = modelTypeHandler.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes) + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size > 0) + + val dbModelTypeByDerivedFroms = modelTypeHandler.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT) + Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms) + Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size > 0) + } + + } + + @Test + @Throws(Exception::class) + fun test04DeleteModelType() { + runBlocking { + log.info( + "************************ test03DeleteModelType ***********************") + val dbResourceMapping = modelTypeHandler!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) + + modelTypeHandler.deleteByModelName(dbResourceMapping.modelName) + } + } + +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/mock/MockFilePart.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/mock/MockFilePart.kt new file mode 100644 index 000000000..3165a6e2f --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/mock/MockFilePart.kt @@ -0,0 +1,53 @@ +/* + * 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.designer.api.mock + +import org.apache.commons.io.FilenameUtils +import org.slf4j.LoggerFactory +import org.springframework.core.io.buffer.DataBuffer +import org.springframework.http.HttpHeaders +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.FileCopyUtils +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.io.File +import java.nio.file.Path + +class MockFilePart(private val fileName: String) : FilePart { + val log = LoggerFactory.getLogger(MockFilePart::class.java)!! + override fun content(): Flux<DataBuffer> { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun headers(): HttpHeaders { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun filename(): String { + return FilenameUtils.getName(fileName) + } + + override fun name(): String { + return FilenameUtils.getBaseName(fileName) + } + + override fun transferTo(path: Path): Mono<Void> { + log.info("Copying file($fileName to ${path}") + FileCopyUtils.copy(File(fileName), path.toFile()) + return Mono.empty() + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepositoryTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepositoryTest.kt new file mode 100644 index 000000000..7adc1c963 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepositoryTest.kt @@ -0,0 +1,110 @@ +/* + * 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.designer.api.repository + +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +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.designer.api.DesignerApiTestConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import java.nio.charset.Charset +import java.util.* + +/** + * ModelTypeReactRepositoryTest. + * + * @author Brinda Santh + */ + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ModelTypeReactRepositoryTest { + + @Autowired + private val modelTypeReactRepository: ModelTypeReactRepository? = null + + internal var modelName = "test-datatype" + + @Test + @Commit + fun test01Save() { + val content = normalizedFile("./src/test/resources/model_type/data_type/datatype-property.json") + .readText(Charset.defaultCharset()) + val modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + modelType.description = "Definition for Sample Datatype " + modelType.definition = JacksonUtils.jsonNode(content) + modelType.modelName = modelName + modelType.version = "1.0.0" + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.updatedBy = "xxxxxx@xxx.com" + + val dbModelType = modelTypeReactRepository!!.save(modelType).block() + Assert.assertNotNull("Failed to get Saved ModelType", dbModelType) + } + + @Test + fun test02Finds() { + val dbFindByModelName = modelTypeReactRepository!!.findByModelName(modelName).block() + Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName) + + val dbFindByDefinitionType = modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block() + Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType) + Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType!!.size > 0) + + val dbFindByDerivedFrom = modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block() + Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom) + Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom!!.size > 0) + + val dbFindByModelNameIn = modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block() + Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn) + Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn!!.size > 0) + + val dbFindByDefinitionTypeIn = modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block() + Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn) + Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn!!.size > 0) + + val dbFindByDerivedFromIn = modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block() + Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn) + Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn!!.size > 0) + } + + @Test + @Commit + fun test03Delete() { + modelTypeReactRepository!!.deleteByModelName(modelName).block() + } + +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepositoryTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepositoryTest.kt new file mode 100644 index 000000000..bbf1751c6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepositoryTest.kt @@ -0,0 +1,99 @@ +/* + * 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.designer.api.repository + +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +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.designer.api.DesignerApiTestConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.transaction.annotation.Transactional + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ResourceDictionaryReactRepositoryTest { + + private val sourceName = "test-source" + + @Autowired + lateinit var resourceDictionaryRepository: ResourceDictionaryRepository + + @Test + @Commit + fun test01Save() { + val resourceDefinition = JacksonUtils + .readValueFromFile("./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json", + ResourceDefinition::class.java) + Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition) + resourceDefinition!!.name = sourceName + + val resourceDictionary = transformResourceDictionary(resourceDefinition) + val dbResourceDictionary = resourceDictionaryRepository.save(resourceDictionary) + Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary) + } + + @Test + fun test02FindByNameReact() { + val dbResourceDictionary = resourceDictionaryRepository.findByName(sourceName) + Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary) + } + + @Test + fun test03FindByNameInReact() { + val dbResourceDictionaries = resourceDictionaryRepository.findByNameIn(arrayListOf(sourceName)) + Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries) + } + + @Test + fun test04FindByTagsContainingIgnoreCaseReact() { + val dbTagsResourceDictionaries = resourceDictionaryRepository.findByTagsContainingIgnoreCase(sourceName) + Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries) + } + + @Test + @Transactional + @Commit + fun test05Delete() { + resourceDictionaryRepository.deleteByName(sourceName) + } + + private fun transformResourceDictionary(resourceDefinition: ResourceDefinition): ResourceDictionary { + val resourceDictionary = ResourceDictionary() + resourceDictionary.name = resourceDefinition.name + resourceDictionary.dataType = resourceDefinition.property.type + resourceDictionary.description = resourceDefinition.property.description + resourceDictionary.tags = resourceDefinition.tags + resourceDictionary.updatedBy = resourceDefinition.updatedBy + resourceDictionary.definition = resourceDefinition + return resourceDictionary + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt new file mode 100644 index 000000000..e34238eb9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt @@ -0,0 +1,66 @@ +/* + * 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.designer.api.utils + +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.mock.MockFilePart +import org.onap.ccsdk.cds.controllerblueprints.core.* +import java.nio.file.Paths +import java.util.* +import kotlin.test.assertTrue + +class BluePrintEnhancerUtilsTest { + + private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + private val blueprintArchivePath: String = "./target/blueprints/archive" + private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" + private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") + + @Before + fun setUp() { + val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() + assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") + val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs() + assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}") + val blueprintFile = Paths.get(blueprintDir).toFile().normalize() + val testZipFile = blueprintFile.compress(zipBlueprintFileName) + assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}") + } + + @After + fun tearDown() { + deleteDir(blueprintArchivePath) + deleteDir(blueprintEnrichmentPath) + } + + @Test + fun testFilePartCompressionNDeCompression() { + val filePart = MockFilePart(zipBlueprintFileName) + + runBlocking { + val enhanceId = UUID.randomUUID().toString() + val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId) + val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId) + BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) + BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) + } + } +} + diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidatorTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidatorTest.kt new file mode 100644 index 000000000..1869acec3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidatorTest.kt @@ -0,0 +1,40 @@ +/* + * Copyright © 2017-2018 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.designer.api.utils + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType + +class ModelTypeValidatorTest { + + @Test(expected = IllegalStateException::class) + @Throws(Exception::class) + fun testvalidateModelType() { + val modelType = ModelType() + modelType.definitionType = "" + modelType.derivedFrom = "" + modelType.description = "" + val definitionContent: JsonNode? = null + modelType.definition = definitionContent + modelType.modelName = "" + modelType.version = "" + modelType.tags = "" + modelType.updatedBy = "" + ModelTypeValidator.validateModelType(modelType) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhance-resource-assignment.json b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhance-resource-assignment.json new file mode 100644 index 000000000..fdf76ab44 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhance-resource-assignment.json @@ -0,0 +1,62 @@ +[ + { + "name": "rs-db-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "sample-db-source", + "dictionary-source": "processor-db", + "dependencies": [ + "input-source" + ] + }, + { + "name": "ra-default-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "sample-default-source", + "dictionary-source": "default", + "dependencies": [] + }, + { + "name": "ra-input-source", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "sample-input-source", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "ra-list-input-source", + "input-param": true, + "property": { + "type": "list", + "required": true, + "entry_schema": { + "type": "string" + } + }, + "dictionary-name": "ra-list-input-source", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "ra-complex-input-source", + "input-param": true, + "property": { + "type": "dt-v4-aggregate", + "required": true + }, + "dictionary-name": "sample-mdsal-source", + "dictionary-source": "sdnc", + "dependencies": [] + } +] diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhance-template.json b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhance-template.json new file mode 100644 index 000000000..3692b7dcd --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhance-template.json @@ -0,0 +1,351 @@ +{ + "metadata": { + "template_author": "Brinda Santh", + "template_name": "enhance-template", + "template_version": "1.0.0", + "template_tags": "brinda, VPE", + "service-type": "Sample Service", + "release": "1806", + "vnf-type": "VPE" + }, + "topology_template": { + "inputs": { + "request-id": { + "required": true, + "type": "string" + }, + "service-instance-id": { + "required": true, + "type": "string" + }, + "scope-type": { + "required": true, + "type": "string" + }, + "action-name": { + "required": true, + "type": "string" + }, + "hostname": { + "required": true, + "type": "string" + } + }, + "node_templates": { + "vpe-netconf-device": { + "capabilities": { + "netconf": { + "properties": { + "login-key": "sdnc", + "login-account": "sndc-local", + "source": "local", + "target-ip-address": { + "get_attribute": [ + "SELF", + "lo0-local-ipv4-address" + ] + }, + "port-number": 22, + "connection-time-out": 30 + } + } + }, + "type": "vnf-netconf-device" + }, + "activate-netconf-component": { + "capabilities": { + "component-node": {} + }, + "requirements": { + "netconf-connection": { + "capability": "netconf", + "node": "vpe-netconf-device", + "relationship": "tosca.relationships.ConnectsTo" + } + }, + "interfaces": { + "NetconfExecutorComponent": { + "operations": { + "process": { + "inputs": { + "action-name": { + "get_input": "action-name" + }, + "template-name": { + "get_input": "template_name" + }, + "template-version": { + "get_input": "template_version" + }, + "resource-type": "vnf-type", + "request-id": { + "get_input": "request-id" + }, + "resource-id": { + "get_input": "hostname" + }, + "execution-script": "execution-script" + }, + "outputs": { + "response-data": { + "get_attribute": [ + "SELF", + "netconf-executor-baseconfig.response-data" + ] + }, + "status": { + "get_attribute": [ + "SELF", + "netconf-executor-baseconfig.status" + ] + } + }, + "implementation": { + "primary": "file://netconf_adaptor/DefaultBaseLicenceConfig.py" + } + } + } + } + }, + "type": "component-netconf-executor" + }, + "resource-assignment-ra-component": { + "capabilities": { + "component-node": {} + }, + "interfaces": { + "ResourceAssignmentComponent": { + "operations": { + "process": { + "inputs": { + "template-names": [ + "base-config-template", + "licence-template" + ], + "action-name": { + "get_input": "action-name" + }, + "template-name": { + "get_input": "template_name" + }, + "template-version": { + "get_input": "template-version" + }, + "resource-type": "vnf-type", + "request-id": { + "get_input": "request-id" + }, + "resource-id": { + "get_input": "hostname" + } + }, + "outputs": { + "resource-assignment-params": "success", + "status": "status" + } + } + } + } + }, + "type": "component-resource-assignment" + }, + "resource-assignment-action": { + "properties": { + "mode": "sync", + "version": "LATEST", + "is-start-flow": false + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "resource-assignment-ra-component", + "relationship": "tosca.relationships.DependsOn" + } + }, + "capabilities": { + "dg-node": {} + }, + "interfaces": { + "CONFIG": { + "operations": { + "ResourceAssignment": { + "inputs": { + "params": [] + } + } + } + } + }, + "type": "dg-resource-assignment" + }, + "activate-action": { + "properties": { + "mode": "sync", + "version": "LATEST", + "is-start-flow": false + }, + "requirements": { + "component-dependency": { + "capability": "component-node", + "node": "activate-netconf-component", + "relationship": "tosca.relationships.DependsOn" + } + }, + "capabilities": { + "dg-node": {} + }, + "interfaces": { + "CONFIG": { + "operations": { + "ActivateNetconf": { + "inputs": { + "params": [] + } + } + } + } + }, + "type": "dg-activate-netconf" + }, + "base-config-template": { + "capabilities": { + "content": { + "properties": { + "content": "db://base-config-template" + } + }, + "mapping": { + "properties": { + "mapping": [ + { + "name": "rs-db-source", + "property": { + "required": true, + "type": "string" + }, + "input-param": false, + "dictionary-name": "sample-db-source", + "dictionary-source": "processor-db", + "dependencies": [ + "hostname" + ], + "version": 0 + }, + { + "name": "mdsal-source", + "property": { + "description": "", + "required": true, + "type": "list", + "entry_schema": { + "type": "dt-v4-aggregate" + } + }, + "input-param": false, + "dictionary-name": "sample-mdsal-source", + "dictionary-source": "sdnc", + "dependencies": [ + "service-instance-id" + ], + "version": 0 + }, + { + "name": "hostname", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "hostname", + "dictionary-source": "input", + "version": 0, + "input-param": false + }, + { + "name": "service", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "service", + "dictionary-source": "input", + "version": 0, + "input-param": false + }, + { + "name": "service-instance-id", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "version": 0, + "input-param": false + } + ] + } + } + }, + "properties": { + "action-names": [ + "resource-assignment-action" + ] + }, + "type": "artifact-config-template" + }, + "licence-template": { + "capabilities": { + "content": { + "properties": { + "content": "db://licence-template" + } + }, + "mapping": { + "properties": { + "mapping": [ + { + "name": "licenses", + "property": { + "required": true, + "type": "list", + "entry_schema": { + "type": "dt-license-key" + } + }, + "input-param": false, + "dictionary-name": "sample-licenses", + "dictionary-source": "sdnc", + "dependencies": [ + "service-instance-id" + ], + "version": 0 + }, + { + "name": "service-instance-id", + "property": { + "required": true, + "type": "string" + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "version": 0, + "input-param": false + } + ] + } + } + }, + "properties": { + "action-names": [ + "resource-assignment-action" + ] + }, + "type": "artifact-config-template" + } + } + }, + "node_types": { + }, + "data_types": { + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhanced-template.json b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhanced-template.json new file mode 100644 index 000000000..d71293259 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/enhance/enhanced-template.json @@ -0,0 +1,327 @@ +{ + "metadata" : { + "template_author" : "Brinda Santh", + "template_name" : "enhance-template", + "template_version" : "1.0.0", + "template_tags" : "brinda, VPE", + "service-type" : "Sample Service", + "release" : "1806", + "vnf-type" : "VPE" + }, + "tosca_definitions_version" : "controller_blueprint_1_0_0", + "artifact_types" : { }, + "data_types" : { + }, + "node_types" : { + }, + "topology_template" : { + "inputs" : { + "request-id" : { + "required" : true, + "type" : "string" + }, + "service-instance-id" : { + "required" : true, + "type" : "string" + }, + "scope-type" : { + "required" : true, + "type" : "string" + }, + "action-name" : { + "required" : true, + "type" : "string" + }, + "hostname" : { + "required" : true, + "type" : "string" + }, + "resource-assignment-request" : { + "description" : "This is Dynamic Data type for the receipe resource-assignment-action.", + "required" : false, + "type" : "dt-resource-assignment-request" + } + }, + "node_templates" : { + "vpe-netconf-device" : { + "type" : "vnf-netconf-device", + "capabilities" : { + "netconf" : { + "properties" : { + "login-key" : "sdnc", + "login-account" : "sndc-local", + "source" : "local", + "target-ip-address" : { + "get_attribute" : [ "SELF", "lo0-local-ipv4-address" ] + }, + "port-number" : 22, + "connection-time-out" : 30 + } + } + } + }, + "activate-netconf-component" : { + "type" : "component-netconf-executor", + "capabilities" : { + "component-node" : { } + }, + "requirements" : { + "netconf-connection" : { + "capability" : "netconf", + "node" : "vpe-netconf-device", + "relationship" : "tosca.relationships.ConnectsTo" + } + }, + "interfaces" : { + "NetconfExecutorComponent" : { + "operations" : { + "process" : { + "implementation" : { + "primary" : "file://netconf_adaptor/DefaultBaseLicenceConfig.py" + }, + "inputs" : { + "action-name" : { + "get_input" : "action-name" + }, + "template-name" : { + "get_input" : "template_name" + }, + "template-version" : { + "get_input" : "template_version" + }, + "resource-type" : "vnf-type", + "request-id" : { + "get_input" : "request-id" + }, + "resource-id" : { + "get_input" : "hostname" + }, + "execution-script" : "execution-script" + }, + "outputs" : { + "response-data" : { + "get_attribute" : [ "SELF", "netconf-executor-baseconfig.response-data" ] + }, + "status" : { + "get_attribute" : [ "SELF", "netconf-executor-baseconfig.status" ] + } + } + } + } + } + } + }, + "resource-assignment-ra-component" : { + "type" : "component-resource-assignment", + "capabilities" : { + "component-node" : { } + }, + "interfaces" : { + "ResourceAssignmentComponent" : { + "operations" : { + "process" : { + "inputs" : { + "template-names" : [ "base-config-template", "licence-template" ], + "action-name" : { + "get_input" : "action-name" + }, + "template-name" : { + "get_input" : "template_name" + }, + "template-version" : { + "get_input" : "template-version" + }, + "resource-type" : "vnf-type", + "request-id" : { + "get_input" : "request-id" + }, + "resource-id" : { + "get_input" : "hostname" + } + }, + "outputs" : { + "resource-assignment-params" : "success", + "status" : "status" + } + } + } + } + } + }, + "resource-assignment-action" : { + "type" : "dg-resource-assignment", + "properties" : { + "mode" : "sync", + "version" : "LATEST", + "is-start-flow" : false + }, + "capabilities" : { + "dg-node" : { } + }, + "requirements" : { + "component-dependency" : { + "capability" : "component-node", + "node" : "resource-assignment-ra-component", + "relationship" : "tosca.relationships.DependsOn" + } + }, + "interfaces" : { + "CONFIG" : { + "operations" : { + "ResourceAssignment" : { + "inputs" : { + "params" : [ ] + } + } + } + } + } + }, + "activate-action" : { + "type" : "dg-activate-netconf", + "properties" : { + "mode" : "sync", + "version" : "LATEST", + "is-start-flow" : false + }, + "capabilities" : { + "dg-node" : { } + }, + "requirements" : { + "component-dependency" : { + "capability" : "component-node", + "node" : "activate-netconf-component", + "relationship" : "tosca.relationships.DependsOn" + } + }, + "interfaces" : { + "CONFIG" : { + "operations" : { + "ActivateNetconf" : { + "inputs" : { + "params" : [ ] + } + } + } + } + } + }, + "base-config-template" : { + "type" : "artifact-config-template", + "properties" : { + "action-names" : [ "resource-assignment-action" ] + }, + "capabilities" : { + "content" : { + "properties" : { + "content" : "db://base-config-template" + } + }, + "mapping" : { + "properties" : { + "mapping" : [ { + "name" : "rs-db-source", + "property" : { + "required" : true, + "type" : "string" + }, + "input-param" : false, + "dictionary-name" : "sample-db-source", + "dictionary-source" : "processor-db", + "dependencies" : [ "hostname" ], + "version" : 0 + }, { + "name" : "mdsal-source", + "property" : { + "description" : "", + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "dt-v4-aggregate" + } + }, + "input-param" : false, + "dictionary-name" : "sample-mdsal-source", + "dictionary-source" : "sdnc", + "dependencies" : [ "service-instance-id" ], + "version" : 0 + }, { + "name" : "hostname", + "property" : { + "required" : true, + "type" : "string" + }, + "dictionary-name" : "hostname", + "dictionary-source" : "input", + "version" : 0, + "input-param" : false + }, { + "name" : "service", + "property" : { + "required" : true, + "type" : "string" + }, + "dictionary-name" : "service", + "dictionary-source" : "input", + "version" : 0, + "input-param" : false + }, { + "name" : "service-instance-id", + "property" : { + "required" : true, + "type" : "string" + }, + "dictionary-name" : "service-instance-id", + "dictionary-source" : "input", + "version" : 0, + "input-param" : false + } ] + } + } + } + }, + "licence-template" : { + "type" : "artifact-config-template", + "properties" : { + "action-names" : [ "resource-assignment-action" ] + }, + "capabilities" : { + "content" : { + "properties" : { + "content" : "db://licence-template" + } + }, + "mapping" : { + "properties" : { + "mapping" : [ { + "name" : "licenses", + "property" : { + "required" : true, + "type" : "list", + "entry_schema" : { + "type" : "dt-license-key" + } + }, + "input-param" : false, + "dictionary-name" : "sample-licenses", + "dictionary-source" : "sdnc", + "dependencies" : [ "service-instance-id" ], + "version" : 0 + }, { + "name" : "service-instance-id", + "property" : { + "required" : true, + "type" : "string" + }, + "dictionary-name" : "service-instance-id", + "dictionary-source" : "input", + "version" : 0, + "input-param" : false + } ] + } + } + } + } + } + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/model_type/data_type/datatype-property.json b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/model_type/data_type/datatype-property.json new file mode 100644 index 000000000..d3ecffd17 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/model_type/data_type/datatype-property.json @@ -0,0 +1,27 @@ +{ + "version": "1.0.0", + "description": "This is Entry point Input Data Type, which is dynamic datatype, The parameter names will be populated during the Design time for each inputs", + "properties": { + "type": { + "required": true, + "type": "string" + }, + "description": { + "required": false, + "type": "string" + }, + "required": { + "required": false, + "type": "boolean" + }, + "default": { + "required": false, + "type": "string" + }, + "entry_schema": { + "required": false, + "type": "string" + } + }, + "derived_from": "tosca.datatypes.Root" +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/resourcedictionary/automap.json b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/resourcedictionary/automap.json new file mode 100644 index 000000000..820c59804 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/resourcedictionary/automap.json @@ -0,0 +1,14 @@ +[ + { + "name": "sample-input-source" + }, + { + "name": "sample-default-source" + }, + { + "name": "sample-db-source" + }, + { + "name": "sample-mdsal-source" + } +]
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/resourcedictionary/default_definition.json b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/resourcedictionary/default_definition.json new file mode 100644 index 000000000..d2fa29918 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/resourcedictionary/default_definition.json @@ -0,0 +1,17 @@ +{ + "name": "ipaddress", + "property": { + "description": "name of the ", + "type": "list", + "entry_schema": { + "type": "dt-v4-aggregate" + } + }, + "updated-by": "Brinda Santh (bs2796)", + "tags": "ipaddress", + "sources": { + "input": { + "type": "source-input" + } + } +}
\ No newline at end of file |