package org.onap.ccsdk.cds.controllerblueprints.validation
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
+import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes
import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition
import org.onap.ccsdk.cds.controllerblueprints.core.format
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionValidator
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintAttributeDefinitionValidator
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintTypeValidatorService
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
@Service("default-attribute-definition-validator")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class BluePrintAttributeDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) :
- BluePrintAttributeDefinitionValidator {
+open class BlueprintAttributeDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BlueprintTypeValidatorService) :
+ BlueprintAttributeDefinitionValidator {
- private val log = LoggerFactory.getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
+ private val log = LoggerFactory.getLogger(BlueprintServiceTemplateValidatorImpl::class.toString())
- lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
+ lateinit var bluePrintRuntimeService: BlueprintRuntimeService<*>
override fun validate(
- bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ bluePrintRuntimeService: BlueprintRuntimeService<*>,
name: String,
attributeDefinition: AttributeDefinition
) {
val dataType: String = attributeDefinition.type
when {
- BluePrintTypes.validPrimitiveTypes().contains(dataType) -> {
+ BlueprintTypes.validPrimitiveTypes().contains(dataType) -> {
// Do Nothing
}
- BluePrintTypes.validComplexTypes().contains(dataType) -> {
+ BlueprintTypes.validComplexTypes().contains(dataType) -> {
// Do Nothing
}
- BluePrintTypes.validCollectionTypes().contains(dataType) -> {
+ BlueprintTypes.validCollectionTypes().contains(dataType) -> {
val entrySchemaType: String = attributeDefinition.entrySchema?.type
- ?: throw BluePrintException("Entry schema for DataType ($dataType) for the property ($name) not found")
+ ?: throw BlueprintException("Entry schema for DataType ($dataType) for the property ($name) not found")
checkPrimitiveOrComplex(entrySchemaType, name)
}
else -> checkPropertyDataType(dataType, name)
}
private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean {
- if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) {
+ if (BlueprintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) {
return true
} else {
- throw BluePrintException("DataType($dataType) for the attribute($propertyName) is not valid")
+ throw BlueprintException("DataType($dataType) for the attribute($propertyName) is not valid")
}
}
private fun checkPropertyDataType(dataTypeName: String, propertyName: String) {
val dataType = bluePrintRuntimeService.bluePrintContext().serviceTemplate.dataTypes?.get(dataTypeName)
- ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName))
+ ?: throw BlueprintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName))
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 ")
+ check(BlueprintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) {
+ throw BlueprintException("Failed to get DataType($dataTypeName)'s derivedFrom($derivedFrom) definition ")
}
}
}