diff options
Diffstat (limited to 'ms/controllerblueprints/modules')
26 files changed, 709 insertions, 677 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt index b9d80b301..6744b625e 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt @@ -16,10 +16,13 @@ package org.onap.ccsdk.cds.controllerblueprints.core +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.apache.commons.io.FileUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils import java.io.File import java.io.InputStream +import java.nio.charset.Charset import java.nio.file.Path import java.nio.file.Paths @@ -81,3 +84,10 @@ fun normalizedPathName(path: String, vararg more: String?): String { return normalizedPath(path, *more).toString() } +suspend fun File.readNBText(): String = withContext(Dispatchers.IO) { + readText(Charset.defaultCharset()) +} + +suspend fun File.readNBLines(): List<String> = withContext(Dispatchers.IO) { + readLines(Charset.defaultCharset()) +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt index 904983fcd..bc0103958 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,12 +26,12 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBLines import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintImportService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService import java.io.File -import java.nio.charset.Charset import java.util.* class BluePrintMetadataUtils { @@ -39,13 +39,13 @@ class BluePrintMetadataUtils { private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - fun toscaMetaData(basePath: String): ToscaMetaData { + suspend fun toscaMetaData(basePath: String): ToscaMetaData { val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER) .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE) return toscaMetaDataFromMetaFile(toscaMetaPath) } - fun entryDefinitionFile(basePath: String): String { + suspend fun entryDefinitionFile(basePath: String): String { val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER) .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE) return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions @@ -59,7 +59,7 @@ class BluePrintMetadataUtils { fun environmentFileProperties(pathName: String): Properties { val properties = Properties() - val envDir = File(pathName) + val envDir = normalizedFile(pathName) // Verify if the environment directory exists if (envDir.exists() && envDir.isDirectory) { //Find all available environment files @@ -72,9 +72,9 @@ class BluePrintMetadataUtils { return properties } - fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { + private suspend fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { val toscaMetaData = ToscaMetaData() - val lines = normalizedFile(metaFilePath).readLines(Charset.defaultCharset()) + val lines = normalizedFile(metaFilePath).readNBLines() lines.forEach { line -> if (line.contains(":")) { val keyValue = line.split(":") diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt index 85ae359cd..7ac79e2f1 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt @@ -16,15 +16,12 @@ */ package org.onap.ccsdk.cds.controllerblueprints.core.utils -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.node.* import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.apache.commons.io.IOUtils @@ -39,16 +36,18 @@ import java.nio.charset.Charset */ class JacksonUtils { companion object { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) + + val objectMapper = jacksonObjectMapper() + inline fun <reified T : Any> readValue(content: String): T = - jacksonObjectMapper().readValue(content, T::class.java) + objectMapper.readValue(content, T::class.java) fun <T> readValue(content: String, valueType: Class<T>): T? { - return jacksonObjectMapper().readValue(content, valueType) + return objectMapper.readValue(content, valueType) } fun <T> readValue(node: JsonNode, valueType: Class<T>): T? { - return jacksonObjectMapper().treeToValue(node, valueType) + return objectMapper.treeToValue(node, valueType) } fun removeJsonNullNode(node: JsonNode) { @@ -64,16 +63,12 @@ class JacksonUtils { } - fun getContent(fileName: String): String = getContent(normalizedFile(fileName)) - - fun getContent(file: File): String = runBlocking { - async { - try { - file.readText(Charsets.UTF_8) - } catch (e: Exception) { - throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}") - } - }.await() + fun getContent(fileName: String): String = runBlocking { + try { + normalizedFile(fileName).readNBText() + } catch (e: Exception) { + throw BluePrintException("couldn't get file ($fileName) content : ${e.message}") + } } fun getClassPathFileContent(fileName: String): String { @@ -96,11 +91,11 @@ class JacksonUtils { } fun objectNodeFromObject(from: kotlin.Any): ObjectNode { - return jacksonObjectMapper().convertValue(from, ObjectNode::class.java) + return objectMapper.convertValue(from, ObjectNode::class.java) } fun jsonNodeFromObject(from: kotlin.Any): JsonNode { - return jacksonObjectMapper().convertValue(from, JsonNode::class.java) + return objectMapper.convertValue(from, JsonNode::class.java) } fun jsonNodeFromClassPathFile(fileName: String): JsonNode { @@ -171,9 +166,9 @@ class JacksonUtils { return objectMapper.readValue(content, mapType) } - fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> { - val content: String = getContent(file) - return getMapFromJson(content, valueType) + fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> = runBlocking { + val content: String = file.readNBText() + getMapFromJson(content, valueType) } fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T> = getMapFromFile(File(fileName), valueType) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt index 7a1fb6d9e..1a6ccfa17 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.utils +import kotlinx.coroutines.runBlocking import org.junit.Test import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData import kotlin.test.assertEquals @@ -29,15 +30,17 @@ class BluePrintMetadataUtilsTest { @Test fun testToscaMetaData() { - val basePath: String = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - - val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath) - assertNotNull(toscaMetaData, "Missing Tosca Definition Object") - assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") - assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") - assertNotNull(toscaMetaData.createdBy, "Missing Created by") - assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") - assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") + runBlocking { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + + val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath) + assertNotNull(toscaMetaData, "Missing Tosca Definition Object") + assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") + assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") + assertNotNull(toscaMetaData.createdBy, "Missing Created by") + assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") + assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") + } } diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt index 7e70a762d..fb466f7c3 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,14 @@ package org.onap.ccsdk.cds.controllerblueprints.validation import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.validation.utils.PropertyAssignmentValidationUtils 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.format import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTemplateValidator import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintExpressionService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -43,6 +40,7 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext + lateinit var propertyAssignmentValidationUtils: PropertyAssignmentValidationUtils var paths: MutableList<String> = arrayListOf() override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { @@ -51,6 +49,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator this.bluePrintRuntimeService = bluePrintRuntimeService this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + propertyAssignmentValidationUtils = PropertyAssignmentValidationUtils(bluePrintContext) + paths.add(name) val type: String = nodeTemplate.type @@ -58,7 +58,10 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator val nodeType: NodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(type) ?: throw BluePrintException("Failed to get NodeType($type) definition for NodeTemplate($name)") - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } + nodeTemplate.properties?.let { + propertyAssignmentValidationUtils + .validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) + } nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeType, name, nodeTemplate) } nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, name, nodeTemplate) } nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, name, nodeTemplate) } @@ -80,29 +83,6 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator paths.removeAt(paths.lastIndex) } - - @Throws(BluePrintException::class) - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>, - properties: MutableMap<String, JsonNode>) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException("failed to get definition for the property ($propertyName)") - - validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) - - } - } - - @Throws(BluePrintException::class) - open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition, - propertyAssignment: JsonNode) { - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyName, propertyDefinition, propertyAssignment) - } - } - @Throws(BluePrintException::class) open fun validateCapabilityAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { val capabilities = nodeTemplate.capabilities @@ -125,7 +105,10 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator open fun validateCapabilityAssignment(nodeTemplateName: String, capabilityName: String, capabilityDefinition: CapabilityDefinition, capabilityAssignment: CapabilityAssignment) { - capabilityAssignment.properties?.let { validatePropertyAssignments(capabilityDefinition.properties!!, capabilityAssignment.properties!!) } + capabilityAssignment.properties?.let { + propertyAssignmentValidationUtils + .validatePropertyAssignments(capabilityDefinition.properties!!, capabilityAssignment.properties!!) + } } @@ -224,7 +207,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation " + "definition ($operationAssignmentName) property definition($propertyName)") // Check the property values with property definition - validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + propertyAssignmentValidationUtils + .validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) } outputs?.forEach { propertyName, propertyAssignment -> @@ -232,7 +216,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation definition ($operationAssignmentName) " + "output property definition($propertyName)") // Check the property values with property definition - validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + propertyAssignmentValidationUtils + .validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) } } @@ -240,48 +225,6 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator } - open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, propertyAssignment: JsonNode) { - val propertyType = propertyDefinition.type - val isValid: Boolean - - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) - - } else if (BluePrintTypes.validComplexTypes().contains(propertyType)) { - isValid = true - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - - val entrySchemaType = propertyDefinition.entrySchema?.type - ?: throw BluePrintException(format("Failed to get EntrySchema type for the collection property ({})", propertyName)) - - if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) { - checkPropertyDataType(entrySchemaType, propertyName) - } - isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) - } else { - checkPropertyDataType(propertyType, propertyName) - isValid = true - } - - check(isValid) { - throw BluePrintException("property(propertyName) defined of type(propertyType) is not comptable with the value (propertyAssignment)") - } - } - - private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { - - val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) - ?: throw BluePrintException("DataType ($dataTypeName) for the property ($propertyName) not found") - - checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) - - } - - private fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { - check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { - throw BluePrintException("Failed to get DataType($dataTypeName)'s derivedFrom($derivedFrom) definition ") - } - } private fun validateExtension(referencePrefix: String, name: String, nodeTemplate: NodeTemplate) { val customValidator = bluePrintTypeValidatorService diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt index 306203128..a7dbbf846 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -18,6 +19,7 @@ package org.onap.ccsdk.cds.controllerblueprints.validation import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.validation.utils.PropertyAssignmentValidationUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService @@ -45,6 +47,12 @@ open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorServ paths.add(workflowName) paths.joinToString(BluePrintConstants.PATH_DIVIDER) + // Validate Workflow Inputs + validateInputs(workflow) + + // Validate Workflow outputs + validateOutputs(workflow) + // Step Validation Start paths.add("steps") workflow.steps?.forEach { stepName, step -> @@ -69,14 +77,33 @@ open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorServ "definition", paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!) } } - paths.removeAt(paths.lastIndex) + } paths.removeAt(paths.lastIndex) // Step Validation Ends paths.removeAt(paths.lastIndex) + paths.removeAt(paths.lastIndex) + } + + private fun validateInputs(workflow: Workflow) { workflow.inputs?.let { bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.inputs!!) } } + + private fun validateOutputs(workflow: Workflow) { + workflow.outputs?.let { + + bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.outputs!!) + + PropertyAssignmentValidationUtils(bluePrintRuntimeService.bluePrintContext()) + .validatePropertyDefinitionNAssignments(workflow.outputs!!) + } + // Validate Value or Expression + workflow.outputs?.forEach { propertyName, propertyDefinition -> + + } + } + }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/utils/PropertyAssignmentValidationUtils.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/utils/PropertyAssignmentValidationUtils.kt new file mode 100644 index 000000000..35ddc5b6f --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/utils/PropertyAssignmentValidationUtils.kt @@ -0,0 +1,112 @@ +/* + * 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.controllerblueprints.validation.utils + +import com.fasterxml.jackson.databind.JsonNode +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 +import org.onap.ccsdk.cds.controllerblueprints.core.format +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintExpressionService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils + +open class PropertyAssignmentValidationUtils(private val bluePrintContext: BluePrintContext) { + + // Property Definition holds both Definitons and Expression in same construct + open fun validatePropertyDefinitionNAssignments(propertyDefinitions: MutableMap<String, PropertyDefinition>) { + propertyDefinitions.forEach { propertyName, propertyDefinition -> + validatePropertyDefinitionNAssignment(propertyName, propertyDefinition) + } + } + + // Property Definition holds both Definitons and Expression in same construct + open fun validatePropertyDefinitionNAssignment(propertyName: String, propertyDefinition: PropertyDefinition) { + // Check and Validate if Expression Node + checkNotNull(propertyDefinition.value) { + throw BluePrintException("couldn't get 'value' property from PropertyDefinition($propertyName)") + } + val propertyAssignment = propertyDefinition.value!! + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyName, propertyDefinition, propertyAssignment) + } + } + + open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>, + properties: MutableMap<String, JsonNode>) { + properties.forEach { propertyName, propertyAssignment -> + val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] + ?: throw BluePrintException("failed to get definition for the property ($propertyName)") + + validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) + + } + } + + open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition, + propertyAssignment: JsonNode) { + // Check and Validate if Expression Node + val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) + if (!expressionData.isExpression) { + checkPropertyValue(propertyName, propertyDefinition, propertyAssignment) + } + } + + open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, propertyAssignment: JsonNode) { + val propertyType = propertyDefinition.type + val isValid: Boolean + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + + } else if (BluePrintTypes.validComplexTypes().contains(propertyType)) { + isValid = true + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + + val entrySchemaType = propertyDefinition.entrySchema?.type + ?: throw BluePrintException(format("Failed to get EntrySchema type for the collection property ({})", propertyName)) + + if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) { + checkPropertyDataType(entrySchemaType, propertyName) + } + isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) + } else { + checkPropertyDataType(propertyType, propertyName) + isValid = true + } + + check(isValid) { + throw BluePrintException("property(propertyName) defined of type(propertyType) is not comptable with the value (propertyAssignment)") + } + } + + open fun checkPropertyDataType(dataTypeName: String, propertyName: String) { + + val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) + ?: throw BluePrintException("DataType ($dataTypeName) for the property ($propertyName) not found") + + checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) + + } + + open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { + check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { + throw BluePrintException("Failed to get DataType($dataTypeName)'s derivedFrom($derivedFrom) definition ") + } + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java deleted file mode 100644 index 9aeee1771..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.service.repository; - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ControllerBlueprintModelSearchRepository extends JpaRepository<BlueprintModelSearch, Long> { - - /** - * This is a findById method - * - * @param id id - * @return Optional<BlueprintModelSearch> - */ - @NotNull - Optional<BlueprintModelSearch> findById(@NotNull String id); - - /** - * This is a findAll method - * @return List<BlueprintModelSearch> - */ - @Override - List<BlueprintModelSearch> findAll(); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional<AsdcArtifacts> - */ - Optional<BlueprintModelSearch> findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional<BlueprintModelSearch> - */ - List<BlueprintModelSearch> findByTagsContainingIgnoreCase(String tags); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java deleted file mode 100644 index 314ac6a4e..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 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.controllerblueprints.service.repository; - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -/** - * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ResourceDictionaryRepository extends JpaRepository<ResourceDictionary, String> { - - - /** - * This is a findByName method - * - * @param name name - * @return Optional<ResourceMapping> - */ - Optional<ResourceDictionary> findByName(String name); - - /** - * This is a findByNameIn method - * - * @param names names - * @return Optional<ResourceMapping> - */ - List<ResourceDictionary> findByNameIn(List<String> names); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional<ModelType> - */ - List<ResourceDictionary> findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByName method - * - * @param name name - */ - void deleteByName(String name); - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt index 8ede9f208..e1fa1882d 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt @@ -72,8 +72,8 @@ open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRe @Throws(BluePrintException::class) override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) - return if (dbResourceDictionary.isPresent) { - dbResourceDictionary.get().definition + return if (dbResourceDictionary != null) { + dbResourceDictionary.definition } else { throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt index 0509e970e..341d63bf0 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt @@ -1,5 +1,6 @@ /* * 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. @@ -19,6 +20,7 @@ package org.onap.ccsdk.cds.controllerblueprints.service.controller import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler +import kotlinx.coroutines.runBlocking import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -27,30 +29,30 @@ import org.springframework.web.bind.annotation.* 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? { - return modelTypeHandler.getModelTypeByName(name) + 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> { - return modelTypeHandler.searchModelTypes(tags) + 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> { - return modelTypeHandler.getModelTypeByDefinitionType(definitionType) + 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 { - return modelTypeHandler.saveModel(modelType) + fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking { + modelTypeHandler.saveModel(modelType) } @DeleteMapping(path = arrayOf("/{name}")) - fun deleteModelTypeByName(@PathVariable(value = "name") name: String) { + fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking { modelTypeHandler.deleteByModelName(name) } }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt index e21639715..d728fc229 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt @@ -20,6 +20,7 @@ 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.onap.ccsdk.cds.controllerblueprints.service.handler.ResourceDictionaryHandler +import kotlinx.coroutines.runBlocking import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -30,39 +31,39 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary { - return resourceDictionaryHandler.getResourceDictionaryByName(name) + 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 { - return resourceDictionaryHandler.saveResourceDictionary(dataDictionary) + fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking { + resourceDictionaryHandler.saveResourceDictionary(dataDictionary) } @DeleteMapping(path = ["/{name}"]) - fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) { + 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> { - return resourceDictionaryHandler.searchResourceDictionaryByNames(names) + 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> { - return resourceDictionaryHandler.searchResourceDictionaryByTags(tags) + 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 { - return resourceDictionaryHandler.getResourceSourceMapping() + fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking { + resourceDictionaryHandler.getResourceSourceMapping() } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt index 091dfdafc..8379e5032 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -66,11 +67,16 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP // Clean Dynamic Property Field, If present workflow.inputs?.remove(dynamicPropertyName) + // Enrich Workflow Inputs + enhanceWorkflowInputs(name, workflow) + + // Enrich Workflow Outputs + enhanceWorkflowOutputs(name, workflow) + // Enrich Only for Resource Assignment and Dynamic Input Properties if any enhanceStepTargets(name, workflow) - // Enrich Workflow Inputs - enhanceWorkflowInputs(name, workflow) + } open fun enhanceWorkflowInputs(name: String, workflow: Workflow) { @@ -80,6 +86,12 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP } } + open fun enhanceWorkflowOutputs(name: String, workflow: Workflow) { + workflow.outputs?.let { outputs -> + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, outputs) + } + } + private fun enhanceStepTargets(name: String, workflow: Workflow) { // Get the first Step Target NodeTemplate name( It may be Component or DG Node Template) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt index 5c1a1652c..f602437ed 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt @@ -1,5 +1,6 @@ /* * 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. @@ -34,10 +35,15 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @param modelTypeName modelTypeName * @return ModelType */ - fun getModelTypeByName(modelTypeName: String): ModelType? { + suspend fun getModelTypeByName(modelTypeName: String): ModelType { log.info("Searching : $modelTypeName") check(modelTypeName.isNotBlank()) { "Model Name Information is missing." } - return modelTypeRepository.findByModelName(modelTypeName) + val modelType = modelTypeRepository.findByModelName(modelTypeName) + return if (modelType != null) { + modelType + } else { + throw BluePrintException("couldn't get modelType($modelTypeName)") + } } @@ -47,7 +53,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @param tags tags * @return List<ModelType> </ModelType> */ - fun searchModelTypes(tags: String): List<ModelType> { + suspend fun searchModelTypes(tags: String): List<ModelType> { check(tags.isNotBlank()) { "No Search Information provide" } return modelTypeRepository.findByTagsContainingIgnoreCase(tags) } @@ -60,7 +66,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - open fun saveModel(modelType: ModelType): ModelType { + suspend open fun saveModel(modelType: ModelType): ModelType { lateinit var dbModel: ModelType ModelTypeValidator.validateModelType(modelType) val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) @@ -86,7 +92,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param modelName modelName */ - open fun deleteByModelName(modelName: String) { + suspend open fun deleteByModelName(modelName: String) { check(modelName.isNotBlank()) { "Model Name Information is missing." } modelTypeRepository.deleteByModelName(modelName) @@ -97,8 +103,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param definitionType definitionType * @return List<ModelType> - */ - fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { + */ + suspend fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { check(definitionType.isNotBlank()) { "Model definitionType Information is missing." } return modelTypeRepository.findByDefinitionType(definitionType) } @@ -108,8 +114,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param derivedFrom derivedFrom * @return List<ModelType> - */ - fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { + */ + suspend fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } return modelTypeRepository.findByDerivedFrom(derivedFrom) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt index f6e95de2d..df8cffdba 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt @@ -40,11 +40,11 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - fun getResourceDictionaryByName(name: String): ResourceDictionary { + 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.isPresent) { - resourceDictionaryDb.get() + return if (resourceDictionaryDb != null) { + resourceDictionaryDb } else { throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)) } @@ -56,7 +56,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @param names names * @return List<ResourceDictionary> </ResourceDictionary> */ - fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { + suspend fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide") return resourceDictionaryRepository.findByNameIn(names) } @@ -67,7 +67,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @param tags tags * @return List<ResourceDictionary> </ResourceDictionary> */ - fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { + suspend fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide") return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags) } @@ -79,7 +79,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @return DataDictionary */ @Throws(BluePrintException::class) - fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { + suspend fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { var resourceDictionary = resourceDictionary val resourceDefinition = resourceDictionary.definition @@ -101,8 +101,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour validateResourceDictionary(resourceDictionary) val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) - if (dbResourceDictionaryData.isPresent) { - val dbResourceDictionary = dbResourceDictionaryData.get() + if (dbResourceDictionaryData != null) { + val dbResourceDictionary = dbResourceDictionaryData dbResourceDictionary.name = resourceDictionary.name dbResourceDictionary.definition = resourceDictionary.definition @@ -124,7 +124,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * * @param name name */ - fun deleteResourceDictionary(name: String) { + suspend fun deleteResourceDictionary(name: String) { check(name.isNotBlank()) { "Resource dictionary name is missing." } resourceDictionaryRepository.deleteByName(name) } @@ -132,7 +132,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour /** * This is a getResourceSourceMapping service */ - fun getResourceSourceMapping(): ResourceSourceMapping { + suspend fun getResourceSourceMapping(): ResourceSourceMapping { return ResourceSourceMappingFactory.getRegisterSourceMapping() } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt index bffdccda7..eca7ce1bf 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -17,11 +18,8 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking -import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.springframework.stereotype.Service import java.io.File @@ -30,38 +28,28 @@ open class BluePrintCatalogLoadService(private val bluePrintCatalogService: Blue private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java) - open fun loadPathsBluePrintModelCatalog(paths: List<String>) { + open suspend fun loadPathsBluePrintModelCatalog(paths: List<String>) { paths.forEach { loadPathBluePrintModelCatalog(it) } } - open fun loadPathBluePrintModelCatalog(path: String) { + open suspend fun loadPathBluePrintModelCatalog(path: String) { - val files = File(path).listFiles() - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in files) { - deferredResults += async { - loadBluePrintModelCatalog(errorBuilder, file) - } - } - - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } + val files = normalizedFile(path).listFiles() + val errors = mutableListOf<String>() + files.forEach { + loadBluePrintModelCatalog(errors, it) + } + if (!errors.isEmpty()) { + log.error(errors.joinToString("\n")) } } - open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) { + open suspend fun loadBluePrintModelCatalog(errorBuilder: MutableList<String>, file: File) { try { + log.info("loading blueprint cba(${file.absolutePath})") bluePrintCatalogService.saveToDatabase(file) } catch (e: Exception) { - errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}") + errorBuilder.add("Couldn't load BlueprintModel(${file.name}: ${e.message}") } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt index e6f6498df..4a3168d65 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -33,7 +34,7 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: @EventListener(ApplicationReadyEvent::class) - open fun init() { + open fun init() = runBlocking { if (bluePrintLoadConfiguration.loadInitialData) { initModelTypes() initResourceDictionary() @@ -41,23 +42,22 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: } else { log.info("Initial data load is disabled") } + } - open fun initModelTypes() { + open suspend fun initModelTypes() { log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " + "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})") if (bluePrintLoadConfiguration.loadModelType) { val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",") paths?.let { - runBlocking { - modelTypeLoadService.loadPathsModelType(paths) - } + modelTypeLoadService.loadPathsModelType(paths) } } } - open fun initResourceDictionary() { + open suspend fun initResourceDictionary() { log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " + "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") @@ -69,7 +69,7 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: } } - open fun initBluePrintCatalog() { + open suspend fun initBluePrintCatalog() { log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " + "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt index c3533979b..ff87ad465 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -17,18 +18,21 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.* +import kotlinx.coroutines.async +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.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.data.* +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.springframework.stereotype.Service import java.io.File -import java.nio.charset.Charset @Service open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) { @@ -37,65 +41,57 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) private val updateBySystem = "System" open suspend fun loadPathsModelType(modelTypePaths: List<String>) { - modelTypePaths.forEach { runBlocking { loadPathModelType(it) } } + modelTypePaths.forEach { + loadPathModelType(it) + } } /** * Load the Model Type file content from the defined path, Load of sequencing should be maintained. */ - open suspend fun loadPathModelType(modelTypePath: String) = runBlocking { + open suspend fun loadPathModelType(modelTypePath: String) { log.info(" *************************** loadModelType **********************") try { val errorBuilder = StrBuilder() coroutineScope { - val dataTypeFiles = File("$modelTypePath/data_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in dataTypeFiles) deferredResults += async { - loadModelType(file, DataType::class.java, errorBuilder) + val dataTypeFiles = normalizedFile("$modelTypePath", "data_type").listFiles() + val deferred = dataTypeFiles.map { + async { + loadModelType(it, DataType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val artifactTypeFiles = File("$modelTypePath/artifact_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in artifactTypeFiles) deferredResults += async { - loadModelType(file, - ArtifactType::class.java, errorBuilder) + val artifactTypeFiles = normalizedFile("$modelTypePath", "artifact_type").listFiles() + val deferred = artifactTypeFiles.map { + async { + loadModelType(it, ArtifactType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val relationshipTypeFiles = File("$modelTypePath/relationship_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in relationshipTypeFiles) deferredResults += async { - loadModelType(file, - RelationshipType::class.java, errorBuilder) + val relationshipTypeFiles = normalizedFile("$modelTypePath", "relationship_type").listFiles() + val deferred = relationshipTypeFiles.map { + async { + loadModelType(it, RelationshipType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val nodeTypeFiles = File("$modelTypePath/node_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in nodeTypeFiles) deferredResults += async { - loadModelType(file, - NodeType::class.java, errorBuilder) + val nodeTypeFiles = normalizedFile("$modelTypePath", "node_type").listFiles() + val deferred = nodeTypeFiles.map { + async { + loadModelType(it, NodeType::class.java, errorBuilder) + } } - deferredResults.awaitAll() + deferred.awaitAll() } if (!errorBuilder.isEmpty) { @@ -106,11 +102,11 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) } } - private inline fun <reified T> loadModelType(file: File, classType: Class<T>, errorBuilder: StrBuilder) { + private suspend inline fun <reified T> loadModelType(file: File, classType: Class<T>, errorBuilder: StrBuilder) { try { log.trace("Loading ${classType.name} (${file.name})") val dataKey = FilenameUtils.getBaseName(file.name) - val definitionContent = file.readText(Charset.defaultCharset()) + val definitionContent = file.readNBText() val definition = JacksonUtils.readValue(definitionContent, classType) as EntityType //checkNotNull(definition) { "failed to get data type from file : ${file.name}" } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt index e07552592..69b7c643c 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -17,57 +18,56 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking +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.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.springframework.stereotype.Service import java.io.File -import java.nio.charset.Charset @Service open class ResourceDictionaryLoadService(private val resourceDictionaryHandler: ResourceDictionaryHandler) { private val log = EELFManager.getInstance().getLogger(ResourceDictionaryLoadService::class.java) - open fun loadPathsResourceDictionary(paths: List<String>) { - paths.forEach { loadPathResourceDictionary(it) } + open suspend fun loadPathsResourceDictionary(paths: List<String>) { + paths.forEach { + loadPathResourceDictionary(it) + } } - open fun loadPathResourceDictionary(path: String) { + open suspend fun loadPathResourceDictionary(path: String) { log.info(" *************************** loadResourceDictionary **********************") - val files = File(path).listFiles() - - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf<Deferred<Unit>>() + val files = normalizedFile(path).listFiles() + val errorBuilder = StrBuilder() - for (file in files) { - deferredResults += async { - loadResourceDictionary(errorBuilder, file) + coroutineScope() { + val deferred = files.map { + async { + loadResourceDictionary(errorBuilder, it) } } + deferred.awaitAll() + } - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) } + } - private fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { + private suspend fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { try { - log.trace("Loading NodeType(${file.name}") - val definitionContent = file.readText(Charset.defaultCharset()) + log.trace("Loading NodeType(${file.name}}") + val definitionContent = file.readNBText() val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java) if (resourceDefinition != null) { diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt new file mode 100644 index 000000000..bf77af66c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt @@ -0,0 +1,63 @@ +/* + * 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.controllerblueprints.service.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.* + +/** + * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ControllerBlueprintModelSearchRepository : JpaRepository<BlueprintModelSearch, Long> { + + /** + * This is a findById method + * + * @param id id + * @return Optional<BlueprintModelSearch> + </BlueprintModelSearch> */ + fun findById(id: String): Optional<BlueprintModelSearch> + + /** + * This is a findAll method + * @return List<BlueprintModelSearch> + </BlueprintModelSearch> */ + override fun findAll(): List<BlueprintModelSearch> + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional<AsdcArtifacts> + </AsdcArtifacts> */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<BlueprintModelSearch> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional<BlueprintModelSearch> + </BlueprintModelSearch> */ + fun findByTagsContainingIgnoreCase(tags: String): List<BlueprintModelSearch> +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt deleted file mode 100644 index 5758fb7fb..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2018 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.controllerblueprints.service.repository - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary -import org.springframework.stereotype.Service -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import reactor.core.scheduler.Schedulers - -/** - * ResourceDictionaryReactRepository. - * - * @author Brinda Santh - */ -@Service -open class ResourceDictionaryReactRepository(private val resourceDictionaryRepository: ResourceDictionaryRepository) { - - fun save(resourceDictionary: ResourceDictionary): Mono<ResourceDictionary> { - return Mono.justOrEmpty(resourceDictionaryRepository.save(resourceDictionary)) - } - - fun findByName(name: String): Mono<ResourceDictionary> { - return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) - } - - fun findByNameIn(names: List<String>): Flux<ResourceDictionary> { - return Flux.fromIterable(resourceDictionaryRepository.findByNameIn(names)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByTagsContainingIgnoreCase(tags: String): Flux<ResourceDictionary> { - return Flux.fromIterable(resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags)) - .subscribeOn(Schedulers.elastic()) - } - - fun deleteByName(name: String): Mono<Void> { - resourceDictionaryRepository.deleteByName(name) - return Mono.empty() - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt new file mode 100644 index 000000000..b1b633a10 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/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.controllerblueprints.service.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/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java deleted file mode 100644 index 12652c916..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2018 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.controllerblueprints.service; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -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.controllerblueprints.TestApplication; -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.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@RunWith(SpringRunner.class) -@DataJpaTest -@Transactional(propagation = Propagation.NOT_SUPPORTED) -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ModelTypeServiceTest { - private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeServiceTest.class); - @Autowired - private ModelTypeHandler modelTypeHandler; - - String modelName = "test-datatype"; - - @Test - @Commit - public void test01SaveModelType() throws Exception { - log.info("**************** test01SaveModelType ********************"); - - String content = JacksonUtils.Companion.getClassPathFileContent("model_type/data_type/datatype-property.json"); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); - modelType.setDescription("Definition for Sample Datatype "); - modelType.setDefinition(JacksonUtils.Companion.jsonNode(content)); - modelType.setModelName(modelName); - modelType.setVersion("1.0.0"); - modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setUpdatedBy("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.getModelName()); - - ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelType.getModelName()); - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", - dbModelType); - - // Model Update - modelType.setUpdatedBy("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.getUpdatedBy()); - - } - - @Test - public void test02SearchModelTypes() throws Exception { - log.info("*********************** test02SearchModelTypes ***************************"); - - String tags = "test-datatype"; - - List<ModelType> 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 - public void test03GetModelType() throws Exception { - log.info("************************* test03GetModelType *********************************"); - ModelType 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.getModelName()); - - List<ModelType> 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); - - List<ModelType> 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 - public void test04DeleteModelType() throws Exception { - log.info( - "************************ test03DeleteModelType ***********************"); - ModelType 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.getModelName()); - - modelTypeHandler.deleteByModelName(dbResourceMapping.getModelName()); - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java deleted file mode 100644 index 37e0549fa..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.controllerblueprints.service.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.controllerblueprints.TestApplication; -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.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Arrays; -import java.util.List; - -/** - * ResourceDictionaryReactRepositoryTest. - * - * @author Brinda Santh - */ - -@RunWith(SpringRunner.class) -@DataJpaTest -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ResourceDictionaryReactRepositoryTest { - - private String sourceName = "test-source"; - - @Autowired - protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; - - @Test - @Commit - public void test01Save() { - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-primary-db-source.json", ResourceDefinition.class); - Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition); - resourceDefinition.setName(sourceName); - - ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block(); - Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary); - } - - @Test - public void test02FindByNameReact() { - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); - } - - @Test - public void test03FindByNameInReact() { - List<ResourceDictionary> dbResourceDictionaries = - resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); - } - - @Test - public void test04FindByTagsContainingIgnoreCaseReact() { - List<ResourceDictionary> dbTagsResourceDictionaries = - resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); - } - - @Test - @Commit - public void test05Delete() { - resourceDictionaryReactRepository.deleteByName(sourceName).block(); - } - - private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { - ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setName(resourceDefinition.getName()); - resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); - resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); - resourceDictionary.setTags(resourceDefinition.getTags()); - resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); - resourceDictionary.setDefinition(resourceDefinition); - return resourceDictionary; - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.kt new file mode 100644 index 000000000..741431840 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/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.controllerblueprints.service + +import com.att.eelf.configuration.EELFManager +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.controllerblueprints.TestApplication +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.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.transaction.annotation.Propagation +import org.springframework.transaction.annotation.Transactional + + +@RunWith(SpringRunner::class) +@DataJpaTest +@Transactional(propagation = Propagation.NOT_SUPPORTED) +@ContextConfiguration(classes = [TestApplication::class]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ModelTypeServiceTest { + @Autowired + private val modelTypeHandler: ModelTypeHandler? = null + + internal var modelName = "test-datatype" + + private val log = EELFManager.getInstance().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/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepositoryTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepositoryTest.kt new file mode 100644 index 000000000..b35a86b37 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepositoryTest.kt @@ -0,0 +1,94 @@ +/* + * 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.controllerblueprints.service.repository + +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.controllerblueprints.TestApplication +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.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@DataJpaTest +@ContextConfiguration(classes = [TestApplication::class]) +@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-primary-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 + @Commit + fun test05Delete() { + runBlocking { + 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 + } +}
\ No newline at end of file |