summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt20
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt3
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt16
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt33
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt24
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt44
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt7
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt16
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt113
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java56
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java60
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java147
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt12
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt22
16 files changed, 147 insertions, 430 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
index b2f1b727c..cf400fa7a 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
@@ -98,16 +98,9 @@ object BluePrintTypes {
@JvmStatic
fun validPropertyTypes(): List<String> {
val validTypes: MutableList<String> = arrayListOf()
- validTypes.add(BluePrintConstants.DATA_TYPE_STRING)
- validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER)
- validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT)
- validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE)
- validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN)
- validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP)
- validTypes.add(BluePrintConstants.DATA_TYPE_NULL)
- validTypes.add(BluePrintConstants.DATA_TYPE_LIST)
- validTypes.add(BluePrintConstants.DATA_TYPE_MAP)
- validTypes.add(BluePrintConstants.DATA_TYPE_JSON)
+ validTypes.addAll(validPrimitiveTypes())
+ validTypes.addAll(validComplexTypes())
+ validTypes.addAll(validCollectionTypes())
return validTypes
}
@@ -125,6 +118,13 @@ object BluePrintTypes {
}
@JvmStatic
+ fun validComplexTypes(): List<String> {
+ val validTypes: MutableList<String> = arrayListOf()
+ validTypes.add(BluePrintConstants.DATA_TYPE_JSON)
+ return validTypes
+ }
+
+ @JvmStatic
fun validCollectionTypes(): List<String> {
val validTypes: MutableList<String> = arrayListOf()
validTypes.add(BluePrintConstants.DATA_TYPE_LIST)
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
index 80ad3f2a8..c58280732 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
@@ -29,7 +29,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import java.io.File
interface BluePrintRuntimeService<T> {
@@ -234,7 +233,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
} else {
// Assign default value to the Operation
nodeTypeProperty.defaultValue?.let {
- resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!)
+ resolvedValue = nodeTypeProperty.defaultValue!!
}
}
// Set for Return of method
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
index 1bc250053..932f0edce 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
@@ -68,12 +68,14 @@ class JacksonUtils {
}
}
- fun getContent(fileName: String): String = runBlocking {
+ fun getContent(fileName: String): String = getContent(File(fileName))
+
+ fun getContent(file: File): String = runBlocking {
async {
try {
- File(fileName).readText(Charsets.UTF_8)
+ file.readText(Charsets.UTF_8)
} catch (e: Exception) {
- throw BluePrintException("couldn't get file ($fileName) content : ${e.message}")
+ throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}")
}
}.await()
}
@@ -167,17 +169,19 @@ class JacksonUtils {
return getListFromJson(content, valueType)
}
- fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T>? {
+ fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T> {
val objectMapper = jacksonObjectMapper()
val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType)
return objectMapper.readValue(content, mapType)
}
- fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T>? {
- val content: String = getContent(fileName)
+ fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> {
+ val content: String = getContent(file)
return getMapFromJson(content, valueType)
}
+ fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T> = getMapFromFile(File(fileName), valueType)
+
fun <T> getInstanceFromMap(properties: MutableMap<String, JsonNode>, classType: Class<T>): T {
return readValue(getJson(properties), classType)
?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)")
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt
index 4ea5ab5bc..a43bf4571 100644
--- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt
@@ -49,7 +49,7 @@ open class BluePrintArtifactDefinitionValidatorImpl(
paths.add(name)
val type: String = artifactDefinition.type
- log.info("Validation ArtifactDefinition of type {$type}")
+ log.trace("Validation ArtifactDefinition of type {$type}")
// Check Artifact Type
checkValidArtifactType(name, type)
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt
index 84073ff2e..c89857742 100644
--- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt
@@ -19,17 +19,25 @@ package org.onap.ccsdk.apps.controllerblueprints.validation
import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
+import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator
import org.springframework.stereotype.Service
+import java.io.File
import java.util.*
@Service
-open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService {
+open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService,
+ private val resourceDefinitionValidator: ResourceDefinitionValidator)
+ : BluePrintValidatorService {
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDesignTimeValidatorService::class.toString())
@@ -43,9 +51,32 @@ open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidato
bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template",
bluePrintRuntimeService.bluePrintContext().serviceTemplate)
+
+ // Validate Resource Definitions
+ validateResourceDefinitions(bluePrintRuntimeService)
+
if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) {
throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}")
}
return true
}
+
+ private fun validateResourceDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>) {
+ // Validate Resource Dictionary
+ val blueprintBasePath = bluePrintRuntimeService.bluePrintContext().rootPath
+
+ val resourceDefinitionsPath = blueprintBasePath.plus(File.separator)
+ .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator)
+ .plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json")
+
+ val resourceDefinitionFile = File(resourceDefinitionsPath)
+
+ if (resourceDefinitionFile.exists()) {
+ val resourceDefinitionMap = JacksonUtils.getMapFromFile(resourceDefinitionFile, ResourceDefinition::class.java)
+
+ resourceDefinitionMap?.forEach { resourceDefinitionName, resourceDefinition ->
+ resourceDefinitionValidator.validate(bluePrintRuntimeService, resourceDefinitionName, resourceDefinition)
+ }
+ }
+ }
}
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt
new file mode 100644
index 000000000..bad147915
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt
@@ -0,0 +1,24 @@
+/*
+ * 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.apps.controllerblueprints.validation
+
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan
+open class BluePrintValidationConfiguration \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt
index 6fe4fa36e..002dd9fbd 100644
--- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt
@@ -40,7 +40,7 @@ open class ArtifactMappingResourceValidator(private val bluePrintTypeValidatorSe
val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
val file: String = artifactDefinition.file
val completePath = bluePrintContext.rootPath.plus(File.separator).plus(file)
- log.info("Validation artifact-mapping-resource($completePath)")
+ log.trace("Validation artifact-mapping-resource($completePath)")
val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java)
val resourceAssignmentValidationService = ResourceAssignmentValidationServiceImpl()
resourceAssignmentValidationService.validate(resourceAssignment)
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt
new file mode 100644
index 000000000..6975ec619
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt
@@ -0,0 +1,44 @@
+/*
+ * 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.apps.controllerblueprints.validation.extension
+
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidator
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+
+interface ResourceDefinitionValidator : BluePrintValidator<ResourceDefinition>
+
+@Service
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ResourceDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : ResourceDefinitionValidator {
+
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidatorImpl::class.java)
+
+ override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String,
+ resourceDefinition: ResourceDefinition) {
+ log.trace("validating resource definition($name)")
+ resourceDefinition.sources.forEach { name, nodeTemplate ->
+ bluePrintTypeValidatorService.validateNodeTemplate(bluePrintRuntimeService, name, nodeTemplate)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt
index 43c3e0e3e..3fc918e60 100644
--- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.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.
@@ -27,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@@ -35,11 +37,14 @@ class BluePrintDesignTimeValidatorServiceTest {
private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
- private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService)
+ private val resourceDefinitionValidator = mockk<ResourceDefinitionValidator>()
+ private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator)
private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
@Test
fun testValidateOfType() {
+ every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit
+
val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
assertTrue(valid, "failed in blueprint Validation")
}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
index d71fbbf80..b35bca744 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
@@ -23,10 +23,8 @@ import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang3.StringUtils
import org.apache.commons.lang3.text.StrBuilder
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.format
import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
import java.io.Serializable
/**
@@ -53,7 +51,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio
override fun validate(resourceAssignments: List<ResourceAssignment>): Boolean {
try {
- validateSources(resourceAssignments)
validateTemplateNDictionaryKeys(resourceAssignments)
validateCyclicDependency(resourceAssignments)
if (StringUtils.isNotBlank(validationMessage)) {
@@ -65,17 +62,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio
return true
}
- open fun validateSources(resourceAssignments: List<ResourceAssignment>) {
- log.info("validating resource assignment sources")
- // Check the Resource Assignment Source(Dynamic Instance) is valid.
- resourceAssignments.forEach { resourceAssignment ->
- try {
- ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!)
- } catch (e: BluePrintException) {
- validationMessage.appendln(e.message + format(" for resource assignment({})", resourceAssignment.name))
- }
- }
- }
open fun validateTemplateNDictionaryKeys(resourceAssignments: List<ResourceAssignment>) {
@@ -121,7 +107,7 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio
resourceAssignmentMap.map { it.value }.map { resourceAssignment ->
if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
resourceAssignment.dependencies!!.map {
- log.info("Topological Graph link from {} to {}", it, resourceAssignment.name)
+ log.trace("Topological Graph link from {} to {}", it, resourceAssignment.name)
topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment)
}
} else {
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt
deleted file mode 100644
index 9541a7b89..000000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt
+++ /dev/null
@@ -1,113 +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.apps.controllerblueprints.resource.dict.service
-
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
-import com.fasterxml.jackson.databind.JsonNode
-import com.google.common.base.Preconditions
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
-import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
-import org.onap.ccsdk.apps.controllerblueprints.core.format
-import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
-import java.io.Serializable
-
-/**
- * ResourceDefinitionValidationService.
- *
- * @author Brinda Santh
- */
-interface ResourceDefinitionValidationService : Serializable {
-
- @Throws(BluePrintException::class)
- fun validate(resourceDefinition: ResourceDefinition)
-
-}
-
-/**
- * ResourceDefinitionValidationService.
- *
- * @author Brinda Santh
- */
-open class ResourceDefinitionValidationServiceImpl(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService {
-
- private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java)
-
- override fun validate(resourceDefinition: ResourceDefinition) {
- Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition")
- log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name)
-
- resourceDefinition.sources.forEach { name, nodeTemplate ->
- val sourceType = nodeTemplate.type
-
- val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)
-
- // Validate Property Name, expression, values and Data Type
- validateNodeTemplateProperties(nodeTemplate, sourceNodeType)
- }
- }
-
-
- open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) {
- nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) }
- }
-
-
- open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>,
- properties: MutableMap<String, JsonNode>) {
- properties.forEach { propertyName, propertyAssignment ->
- val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName]
- ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName))
- // Check and Validate if Expression Node
- val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)
- if (!expressionData.isExpression) {
- checkPropertyValue(propertyDefinition, propertyName, propertyAssignment)
- } else {
- throw BluePrintException(format("property({}) of expression ({}) is not supported",
- propertyName, propertyAssignment))
- }
- }
- }
-
- open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) {
- val propertyType = propertyDefinition.type
- val isValid: Boolean
-
- if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) {
- isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment)
-
- } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) {
-
- isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment)
- } else {
- bluePrintRepoService.getDataType(propertyType)
- isValid = true
- }
-
- check(isValid) {
- throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})",
- propertyName, propertyType, propertyAssignment))
- }
- }
-} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java
deleted file mode 100644
index 7f040b2e2..000000000
--- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java
+++ /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.apps.controllerblueprints.resource.dict.service;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
-
-public class ResourceDefinitionValidationServiceTest {
- private String basePath = "load/model_type";
- private String dictionaryPath = "load/resource_dictionary";
- private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath);
-
- @Test
- public void testValidateSource() throws Exception {
-
- String inputFileName = dictionaryPath + "/input-source.json";
- testValidate(inputFileName);
-
- String dbFileName = dictionaryPath + "/primary-db-source.json";
- testValidate(dbFileName);
-
- String defaultFileName = dictionaryPath + "/default-source.json";
- testValidate(defaultFileName);
-
- String restFileName = dictionaryPath + "/mdsal-source.json";
- testValidate(restFileName);
- }
-
- private void testValidate(String fileName) throws Exception {
-
- ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class);
- Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition);
-
- ResourceDefinitionValidationService resourceDictionaryValidationService =
- new ResourceDefinitionValidationServiceImpl(bluePrintRepoFileService);
- resourceDictionaryValidationService.validate(resourceDefinition);
- Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition);
- }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java
deleted file mode 100644
index 57330d90f..000000000
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java
+++ /dev/null
@@ -1,60 +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.apps.controllerblueprints.service.validator;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
-
-/**
- * ResourceDictionaryValidator.java Purpose: Provide Validation Service for Model Type Resource
- * Dictionary Validator
- *
- * @author Brinda Santh
- * @version 1.0
- */
-public class ResourceDictionaryValidator {
-
- private ResourceDictionaryValidator() {}
-
- /**
- * This is a validateResourceDictionary method
- *
- * @param resourceDictionary
- * @return boolean
- *
- */
- public static boolean validateResourceDictionary(ResourceDictionary resourceDictionary) {
-
- Preconditions.checkNotNull(resourceDictionary,"ResourceDictionary Information is missing." );
-
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()),
- "DataDictionary Alias Name Information is missing.");
- Preconditions.checkNotNull( resourceDictionary.getDefinition(),
- "DataDictionary Definition Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()),
- "DataDictionary Description Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getTags()),
- "DataDictionary Tags Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getUpdatedBy()),
- "DataDictionary Updated By Information is missing.");
- return true;
-
- }
-
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
deleted file mode 100644
index 5d15e0876..000000000
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.apps.controllerblueprints.service.validator;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator
- *
- * @author Brinda Santh
- * @version 1.0
- */
-
-public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
-
- StringBuilder message = new StringBuilder();
- private Map<String, String> metaData = new HashMap<>();
-
- /**
- * This is a validateServiceTemplate
- *
- * @param serviceTemplateContent serviceTemplateContent
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException {
- if (StringUtils.isNotBlank(serviceTemplateContent)) {
- ServiceTemplate serviceTemplate =
- JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class);
- return validateServiceTemplate(serviceTemplate);
- } else {
- throw new BluePrintException(
- "Service Template Content is (" + serviceTemplateContent + ") not Defined.");
- }
- }
-
- /**
- * This is a validateServiceTemplate
- *
- * @param serviceTemplate serviceTemplate
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- @SuppressWarnings("squid:S00112")
- public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {
- Map<String, Object> properties = new HashMap<>();
- super.validateBlueprint(serviceTemplate, properties);
- return true;
- }
-
- /**
- * This is a getMetaData to get the key information during the
- *
- * @return Map<String , String>
- */
- public Map<String, String> getMetaData() {
- return metaData;
- }
-
- @Override
- public void validateMetadata(@NotNull Map<String, String> metaDataMap) throws BluePrintException {
-
- Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing.");
- super.validateMetadata(metaDataMap);
-
- this.metaData.putAll(serviceTemplate.getMetadata());
- }
-
-
- @Override
- public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- super.validateNodeTemplate(nodeTemplateName, nodeTemplate);
- validateNodeTemplateCustom(nodeTemplateName, nodeTemplate);
-
- }
-
- @Deprecated()
- private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();
-
- if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) {
- List<ResourceAssignment> resourceAssignment = getResourceAssignments(nodeTemplate);
- ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl();
- resourceAssignmentValidationService.validate(resourceAssignment);
- }
- }
-
- private List<ResourceAssignment> getResourceAssignments(@NotNull NodeTemplate nodeTemplate) {
-
- List<ResourceAssignment> resourceAssignment = null;
-
- if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {
-
- CapabilityAssignment capabilityAssignment =
- nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {
- Object mappingObject =
- capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (mappingObject != null) {
- String mappingContent = JacksonUtils.Companion.getJson(mappingObject);
- Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent),
- String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));
-
- resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class);
-
- Preconditions.checkNotNull(resourceAssignment,
- String.format("Failed to get resource assignment info from the content (%s) ", mappingContent));
- }
- }
- }
- return resourceAssignment;
- }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt
index f856b9efe..88589eb7d 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.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.
@@ -24,21 +25,10 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationServiceImpl
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository
import org.springframework.stereotype.Service
-// Resource Dictionary Validation Services
-
-@Service
-class DefaultResourceAssignmentValidationService : ResourceAssignmentValidationServiceImpl()
-
-@Service
-class DefalutResourceDefinitionValidationService(bluePrintRepoService: BluePrintRepoService)
- : ResourceDefinitionValidationServiceImpl(bluePrintRepoService)
-
interface ResourceDefinitionRepoService : BluePrintRepoService {
@Throws(BluePrintException::class)
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
index c24931484..ec7d8aebc 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.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.
@@ -20,17 +21,15 @@ import com.google.common.base.Preconditions
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationService
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository
-import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator
import org.springframework.stereotype.Service
@Service
-class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository,
- private val resourceDictionaryValidationService: ResourceDefinitionValidationService) {
+class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) {
/**
@@ -86,7 +85,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
val resourceDefinition = resourceDictionary.definition
Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content")
// Validate the Resource Definitions
- resourceDictionaryValidationService.validate(resourceDefinition)
+ //TODO( Save Validator)
+ //validate(resourceDefinition)
resourceDictionary.tags = resourceDefinition.tags
resourceDefinition.updatedBy = resourceDictionary.updatedBy
@@ -98,7 +98,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type
}
- ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary)
+ validateResourceDictionary(resourceDictionary)
val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name)
if (dbResourceDictionaryData.isPresent) {
@@ -135,4 +135,14 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
fun getResourceSourceMapping(): ResourceSourceMapping {
return ResourceSourceMappingFactory.getRegisterSourceMapping()
}
+
+ private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean {
+ checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.")
+ checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." }
+ checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.")
+ checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.")
+ checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.")
+ return true
+
+ }
} \ No newline at end of file