aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-06-21 18:21:42 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2019-06-25 18:39:24 -0400
commitd9e690caf3c1c0b6bb5d55dd21fc75508f267f5d (patch)
tree283de5502a6cef17e30d2bc7116bbc16c1305adf /ms/controllerblueprints/modules
parenta6fae85764a8dfbeba6000a060b8be0f21fb0466 (diff)
Refractor blueprint script dependency
Change-Id: I2e6b4dd278c1a4a3069a44f648129599365909d4 Issue-ID: CCSDK-1428 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintTypeDSLBuilder.kt32
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt47
2 files changed, 75 insertions, 4 deletions
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<String, AttributeDefinition> = 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<ConstraintClause> = mutableListOf()
+ //TODO("Implementation")
+
+ fun validValues(values: List<JsonNode>) {
+ val constraintClause = ConstraintClause()
+ constraintClause.validValues = values.toMutableList()
+ constraints.add(constraintClause)
+ }
+
+ fun build(): MutableList<ConstraintClause> {
+ 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 <reified T> instance(name: String): T {
+ return applicationContext.getBean(name) as? T
+ ?: throw BluePrintProcessorException("failed to get instance($name)")
+ }
+
+ inline fun <reified T> instance(type: Class<T>): T {
+ return applicationContext.getBean(type)
+ ?: throw BluePrintProcessorException("failed to get instance($type)")
+ }
+} \ No newline at end of file