2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer
19 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationDefinition
25 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
28 import org.onap.ccsdk.cds.controllerblueprints.core.logger
29 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
30 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
31 import org.springframework.beans.factory.config.ConfigurableBeanFactory
32 import org.springframework.context.annotation.Scope
33 import org.springframework.stereotype.Service
36 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
37 open class BluePrintNodeTypeEnhancerImpl(
38 private val bluePrintRepoService: BluePrintRepoService,
39 private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService
40 ) : BluePrintNodeTypeEnhancer {
42 private val log = logger(BluePrintNodeTypeEnhancerImpl::class)
44 lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
45 lateinit var bluePrintContext: BluePrintContext
47 override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
48 this.bluePrintRuntimeService = bluePrintRuntimeService
49 this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
51 val derivedFrom = nodeType.derivedFrom
53 if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
54 val derivedFromNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, name)
56 enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType)
59 // NodeType Attribute Definitions
60 enrichNodeTypeAttributes(name, nodeType)
62 // NodeType Property Definitions
63 enrichNodeTypeProperties(name, nodeType)
65 // NodeType Requirement
66 enrichNodeTypeRequirements(name, nodeType)
68 // NodeType Capability
69 enrichNodeTypeCapabilityProperties(name, nodeType)
72 enrichNodeTypeInterfaces(name, nodeType)
75 open fun enrichNodeTypeAttributes(nodeTypeName: String, nodeType: NodeType) {
76 nodeType.attributes?.let {
77 bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!)
81 open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
82 nodeType.properties?.let {
83 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!)
87 open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) {
89 nodeType.requirements?.forEach { requirementName, requirementDefinition ->
90 // Populate Requirement Node
91 requirementDefinition.node?.let { requirementNodeTypeName ->
92 // Get Requirement NodeType from Repo and Update Service Template
93 val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(
95 bluePrintRepoService, requirementNodeTypeName
98 enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType)
100 // Enhance Relationship Type
101 val relationShipTypeName = requirementDefinition.relationship
102 ?: throw BluePrintException(
103 "couldn't get relationship name for the NodeType($nodeTypeName) " +
104 "Requirement($requirementName)"
106 enrichRelationShipType(relationShipTypeName)
111 open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {
112 nodeType.capabilities?.forEach { _, capabilityDefinition ->
113 capabilityDefinition.properties?.let { properties ->
114 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties)
119 open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) {
120 nodeType.interfaces?.forEach { interfaceName, interfaceObj ->
121 // Populate Node type Interface Operation
122 log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName)
123 populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj)
127 open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) {
129 interfaceObj.operations?.forEach { operationName, operation ->
130 enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation)
131 enrichNodeTypeInterfaceOperationOutputs(nodeTypeName, operationName, operation)
135 open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
136 operation.inputs?.let { inputs ->
137 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
141 open fun enrichNodeTypeInterfaceOperationOutputs(
142 nodeTypeName: String,
143 operationName: String,
144 operation: OperationDefinition
146 operation.outputs?.let { inputs ->
147 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
152 * Get the Relationship Type from database and add to Blueprint Context
154 open fun enrichRelationShipType(relationshipName: String) {
155 BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, relationshipName)