/*
* 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.
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
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) {
this.bluePrintRuntimeService = bluePrintRuntimeService
this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+ propertyAssignmentValidationUtils = PropertyAssignmentValidationUtils(bluePrintContext)
+
paths.add(name)
val type: String = nodeTemplate.type
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) }
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
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!!)
+ }
}
?: 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 ->
?: 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)
}
}
}
- 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