A constraint clause defines an operation along with one or more compatible values that can be used to define a constraint on a property or parameter’s allowed values when it is defined in a TOSCA Service Template or one of its entities.
*/
class ConstraintClause {
- @get:JsonProperty("equal")
var equal: JsonNode? = null
@get:JsonProperty("greater_than")
- var greaterThan: Any? = null
+ var greaterThan: JsonNode? = null
@get:JsonProperty("greater_or_equal")
- var greaterOrEqual: Any? = null
+ var greaterOrEqual: JsonNode? = null
@get:JsonProperty("less_than")
- var lessThan: Any? = null
+ var lessThan: JsonNode? = null
@get:JsonProperty("less_or_equal")
- var lessOrEqual: Any? = null
+ var lessOrEqual: JsonNode? = null
@get:JsonProperty("in_range")
- var inRange: Any? = null
+ var inRange: MutableList<JsonNode>? = null
@get:JsonProperty("valid_values")
var validValues: MutableList<JsonNode>? = null
- @get:JsonProperty("length")
- var length: Any? = null
+ var length: JsonNode? = null
@get:JsonProperty("min_length")
- var minLength: Any? = null
+ var minLength: JsonNode? = null
@get:JsonProperty("max_length")
- var maxLength: Any? = null
+ var maxLength: JsonNode? = null
var pattern: String? = null
var schema: String? = null
}
var constraints: MutableList<ConstraintClause>? = null
@get:JsonProperty("entry_schema")
var entrySchema: EntrySchema? = null
+ @get:JsonProperty("external-schema")
+ var externalSchema: String? = null
+ var metadata: MutableMap<String, String>? = null
// Mainly used in Workflow Outputs
@get:ApiModelProperty(notes = "Property Value, It may be Expression or Json type values")
var value: JsonNode? = null
class RelationshipType : EntityType() {
var interfaces: MutableMap<String, InterfaceDefinition>? = null
@get:JsonProperty("valid_target_types")
- var validTargetTypes: ArrayList<String>? = null
+ var validTargetTypes: MutableList<String>? = null
}
/*
private val type: String,
private val description: String? = "") {
private var nodeTemplate: NodeTemplate = NodeTemplate()
+ private var properties: MutableMap<String, JsonNode>? = null
private var interfaces: MutableMap<String, InterfaceAssignment>? = null
private var artifacts: MutableMap<String, ArtifactDefinition>? = null
private var capabilities: MutableMap<String, CapabilityAssignment>? = null
private var requirements: MutableMap<String, RequirementAssignment>? = null
+ fun properties(block: PropertiesAssignmentBuilder.() -> Unit) {
+ if (properties == null)
+ properties = hashMapOf()
+ properties = PropertiesAssignmentBuilder().apply(block).build()
+ }
+
fun operation(interfaceName: String, description: String? = "",
block: OperationAssignmentBuilder.() -> Unit) {
if (interfaces == null)
nodeTemplate.id = id
nodeTemplate.type = type
nodeTemplate.description = description
+ nodeTemplate.properties = properties
nodeTemplate.interfaces = interfaces
nodeTemplate.artifacts = artifacts
nodeTemplate.capabilities = capabilities
class ArtifactDefinitionBuilder(private val id: String, private val type: String, private val file: String) {
private var artifactDefinition: ArtifactDefinition = ArtifactDefinition()
- // TODO()
+ private var properties: MutableMap<String, JsonNode>? = null
+
+ fun repository(repository: String) {
+ artifactDefinition.repository = repository
+ }
+
+ fun deployPath(deployPath: String) {
+ artifactDefinition.deployPath = deployPath
+ }
+
+ fun properties(block: PropertiesAssignmentBuilder.() -> Unit) {
+ if (properties == null)
+ properties = hashMapOf()
+ properties = PropertiesAssignmentBuilder().apply(block).build()
+ }
fun build(): ArtifactDefinition {
artifactDefinition.id = id
artifactDefinition.type = type
artifactDefinition.file = file
+ artifactDefinition.properties = properties
return artifactDefinition
}
}
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 com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.cds.controllerblueprints.core.*
import org.onap.ccsdk.cds.controllerblueprints.core.data.*
class PolicyTypeBuilder(id: String, version: String, derivedFrom: String,
description: String?) : EntityTypeBuilder(id, version, derivedFrom, description) {
private var policyType = PolicyType()
- // TODO()
+
+ fun targets(targetsStr: String) {
+ val arrayNode = targetsStr.jsonAsJsonType() as ArrayNode
+ targets(arrayNode.asListOfString())
+ }
+
+ fun targets(target: List<String>) {
+ policyType.targets = target.toMutableList()
+ }
+
fun build(): PolicyType {
buildEntityType(policyType)
return policyType
: EntityTypeBuilder(id, version, derivedFrom, description) {
private var relationshipType = RelationshipType()
- // TODO()
+
+ fun validTargetTypes(validTargetTypesStr: String) {
+ val arrayNode = validTargetTypesStr.jsonAsJsonType() as ArrayNode
+ validTargetTypes(arrayNode.asListOfString())
+ }
+
+ fun validTargetTypes(validTargetTypes: List<String>) {
+ relationshipType.validTargetTypes = validTargetTypes.toMutableList()
+ }
+
fun build(): RelationshipType {
buildEntityType(relationshipType)
relationshipType.id = id
class DataTypeBuilder(id: String, version: String, derivedFrom: String,
description: String?) : EntityTypeBuilder(id, version, derivedFrom, description) {
private var dataType = DataType()
- // TODO()
+
+ fun constrain(block: ConstraintClauseBuilder.() -> Unit) {
+ if (dataType.constraints == null) {
+ dataType.constraints = mutableListOf()
+ }
+ val constraintClause = ConstraintClauseBuilder().apply(block).build()
+ dataType.constraints!!.add(constraintClause)
+ }
+
fun build(): DataType {
buildEntityType(dataType)
return dataType
}
}
-class AttributesDefinitionBuilder {
- private val attributes: MutableMap<String, AttributeDefinition> = hashMapOf()
-
- fun attribute(id: String, attribute: AttributeDefinition) {
- attributes[id] = attribute
- }
-
- fun attribute(id: String, type: String?, required: Boolean?, description: String?) {
- val attribute = AttributeDefinitionBuilder(id, type, required, description).build()
- attributes[id] = attribute
- }
-
- 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
- }
-
- fun build(): MutableMap<String, AttributeDefinition> {
- return attributes
- }
-}
-
class AttributeDefinitionBuilder(private val id: String,
private val type: String? = BluePrintConstants.DATA_TYPE_STRING,
private val required: Boolean? = false,
attributeDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build()
}
- // TODO("Constrains")
+ fun constrain(block: ConstraintClauseBuilder.() -> Unit) {
+ if (attributeDefinition.constraints == null) {
+ attributeDefinition.constraints = mutableListOf()
+ }
+ val constraintClause = ConstraintClauseBuilder().apply(block).build()
+ attributeDefinition.constraints!!.add(constraintClause)
+ }
+
+ fun defaultValue(defaultValue: Any) {
+ defaultValue(defaultValue.asJsonType())
+ }
fun defaultValue(defaultValue: JsonNode) {
attributeDefinition.defaultValue = defaultValue
propertyDefinition.entrySchema = EntrySchemaBuilder(entrySchemaType).apply(block).build()
}
- fun constrains(block: ConstraintClauseBuilder.() -> Unit) {
- propertyDefinition.constraints = ConstraintClauseBuilder().apply(block).build()
+ fun constrain(block: ConstraintClauseBuilder.() -> Unit) {
+ if (propertyDefinition.constraints == null) {
+ propertyDefinition.constraints = mutableListOf()
+ }
+ val constraintClause = ConstraintClauseBuilder().apply(block).build()
+ propertyDefinition.constraints!!.add(constraintClause)
}
fun defaultValue(defaultValue: Any) {
}
}
-class ConstraintClauseBuilder {
- private val constraints: MutableList<ConstraintClause> = mutableListOf()
- //TODO("Implementation")
+class ConstraintsClauseBuilder {
+ val constraints: MutableList<ConstraintClause> = mutableListOf()
- fun validValues(values: List<JsonNode>) {
- val constraintClause = ConstraintClause()
- constraintClause.validValues = values.toMutableList()
+ fun constrain(block: ConstraintClauseBuilder.() -> Unit) {
+ val constraintClause = ConstraintClauseBuilder().apply(block).build()
constraints.add(constraintClause)
}
}
}
+class ConstraintClauseBuilder {
+ private val constraintClause = ConstraintClause()
+
+ fun equal(equal: Any) = equal(equal.asJsonType())
+
+ fun equal(equal: JsonNode) {
+ constraintClause.equal = equal
+ }
+
+ fun greaterOrEqual(greaterOrEqual: Any) {
+ constraintClause.greaterOrEqual = greaterOrEqual.asJsonPrimitive()
+ }
+
+ fun greaterThan(greaterThan: Any) {
+ constraintClause.greaterThan = greaterThan.asJsonPrimitive()
+ }
+
+ fun lessOrEqual(lessOrEqual: Any) {
+ constraintClause.lessOrEqual = lessOrEqual.asJsonPrimitive()
+ }
+
+ fun lessThan(lessThan: Any) {
+ constraintClause.lessThan = lessThan.asJsonPrimitive()
+ }
+
+ fun inRange(inRangeStr: String) = inRange(inRangeStr.jsonAsJsonType() as ArrayNode)
+
+ fun inRange(inRangeNode: ArrayNode) {
+ constraintClause.inRange = inRangeNode.toMutableList()
+ }
+
+ fun validValues(validValuesStr: String) = validValues(validValuesStr.jsonAsJsonType() as ArrayNode)
+
+ fun validValues(validValuesNode: ArrayNode) = validValues(validValuesNode.toMutableList())
+
+ fun validValues(validValues: List<JsonNode>) {
+ constraintClause.validValues = validValues.toMutableList()
+ }
+
+ fun length(length: Any) {
+ constraintClause.length = length.asJsonPrimitive()
+ }
+
+ fun minLength(minLength: Any) {
+ constraintClause.minLength = minLength.asJsonPrimitive()
+ }
+
+ fun maxLength(maxLength: Any) {
+ constraintClause.maxLength = maxLength.asJsonPrimitive()
+ }
+
+ fun pattern(pattern: String) {
+ constraintClause.pattern = pattern
+ }
+
+ fun schema(schema: String) {
+ constraintClause.schema = schema
+ }
+
+ fun build(): ConstraintClause {
+ return constraintClause
+ }
+}
+
class EntrySchemaBuilder(private val type: String) {
private var entrySchema: EntrySchema = EntrySchema()
+ fun constrain(block: ConstraintClauseBuilder.() -> Unit) {
+ if (entrySchema.constraints == null) {
+ entrySchema.constraints = mutableListOf()
+ }
+ val constraintClause = ConstraintClauseBuilder().apply(block).build()
+ entrySchema.constraints!!.add(constraintClause)
+ }
+
fun build(): EntrySchema {
entrySchema.type = type
return entrySchema