From d9e690caf3c1c0b6bb5d55dd21fc75508f267f5d Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Fri, 21 Jun 2019 18:21:42 -0400 Subject: Refractor blueprint script dependency Change-Id: I2e6b4dd278c1a4a3069a44f648129599365909d4 Issue-ID: CCSDK-1428 Signed-off-by: Brinda Santh --- .../core/dsl/BluePrintTypeDSLBuilder.kt | 32 +++++++++++++-- .../core/service/BluePrintDependencyService.kt | 47 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt (limited to 'ms/controllerblueprints/modules/blueprint-core/src') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt index 07cc20ebd..0f011948d 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.dsl import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.* @@ -266,16 +267,16 @@ class OperationDefinitionBuilder(private val id: String, class AttributesDefinitionBuilder { private val attributes: MutableMap = hashMapOf() - fun property(id: String, attribute: AttributeDefinition) { + fun attribute(id: String, attribute: AttributeDefinition) { attributes[id] = attribute } - fun property(id: String, type: String?, required: Boolean?, description: String?) { + fun attribute(id: String, type: String?, required: Boolean?, description: String?) { val attribute = AttributeDefinitionBuilder(id, type, required, description).build() attributes[id] = attribute } - fun property(id: String, type: String?, required: Boolean?, description: String?, + fun attribute(id: String, type: String?, required: Boolean?, description: String?, block: AttributeDefinitionBuilder.() -> Unit) { val attribute = AttributeDefinitionBuilder(id, type, required, description).apply(block).build() attributes[id] = attribute @@ -353,7 +354,14 @@ class PropertyDefinitionBuilder(private val id: String, fun entrySchema(entrySchemaType: String, block: EntrySchemaBuilder.() -> Unit) { propertyDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build() } - // TODO("Constrains") + + fun constrains(block: ConstraintClauseBuilder.() -> Unit) { + propertyDefinition.constraints = ConstraintClauseBuilder().apply(block).build() + } + + fun defaultValue(defaultValue: Any) { + defaultValue(defaultValue.asJsonType()) + } fun defaultValue(defaultValue: JsonNode) { propertyDefinition.defaultValue = defaultValue @@ -372,6 +380,22 @@ class PropertyDefinitionBuilder(private val id: String, } } +class ConstraintClauseBuilder { + private val constraints: MutableList = mutableListOf() + //TODO("Implementation") + + fun validValues(values: List) { + val constraintClause = ConstraintClause() + constraintClause.validValues = values.toMutableList() + constraints.add(constraintClause) + } + + fun build(): MutableList { + return constraints + } +} + + class EntrySchemaBuilder(private val type: String) { private var entrySchema: EntrySchema = EntrySchema() diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt new file mode 100644 index 000000000..fdaf25c15 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt @@ -0,0 +1,47 @@ +/* + * 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.core.service + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.springframework.context.ApplicationContext + +/** + * Generic Bluepring Dependency Service, which will be used mainly in scripts. + * This will be initialised only once during the Application startup. + * Function modules, shall add their own dependency function names as an extension function. + * + * @author Brinda Santh + */ + +object BluePrintDependencyService { + + lateinit var applicationContext: ApplicationContext + + fun inject(applicationContext: ApplicationContext) { + BluePrintDependencyService.applicationContext = applicationContext + } + + inline fun instance(name: String): T { + return applicationContext.getBean(name) as? T + ?: throw BluePrintProcessorException("failed to get instance($name)") + } + + inline fun instance(type: Class): T { + return applicationContext.getBean(type) + ?: throw BluePrintProcessorException("failed to get instance($type)") + } +} \ No newline at end of file -- cgit 1.2.3-korg