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(private val bluePrintRepoService: BluePrintRepoService,
38 private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTypeEnhancer {
40 private val log= logger(BluePrintNodeTypeEnhancerImpl::class)
42 lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
43 lateinit var bluePrintContext: BluePrintContext
46 override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
47 this.bluePrintRuntimeService = bluePrintRuntimeService
48 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)
69 enrichNodeTypeCapabilityProperties(name, nodeType)
72 enrichNodeTypeInterfaces(name, nodeType)
76 open fun enrichNodeTypeAttributes(nodeTypeName: String, nodeType: NodeType) {
77 nodeType.attributes?.let {
78 bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!)
82 open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
83 nodeType.properties?.let {
84 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!)
88 open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) {
90 nodeType.requirements?.forEach { requirementName, requirementDefinition ->
91 // Populate Requirement Node
92 requirementDefinition.node?.let { requirementNodeTypeName ->
93 // Get Requirement NodeType from Repo and Update Service Template
94 val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext,
95 bluePrintRepoService, requirementNodeTypeName)
97 enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType)
99 // Enhance Relationship Type
100 val relationShipTypeName = requirementDefinition.relationship
101 ?: throw BluePrintException("couldn't get relationship name for the NodeType($nodeTypeName) " +
102 "Requirement($requirementName)")
103 enrichRelationShipType(relationShipTypeName)
108 open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {
109 nodeType.capabilities?.forEach { _, capabilityDefinition ->
110 capabilityDefinition.properties?.let { properties ->
111 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties)
116 open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) {
117 nodeType.interfaces?.forEach { interfaceName, interfaceObj ->
118 // Populate Node type Interface Operation
119 log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName)
120 populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj)
125 open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) {
127 interfaceObj.operations?.forEach { operationName, operation ->
128 enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation)
129 enrichNodeTypeInterfaceOperationOutputs(nodeTypeName, operationName, operation)
133 open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
134 operation.inputs?.let { inputs ->
135 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
139 open fun enrichNodeTypeInterfaceOperationOutputs(nodeTypeName: String, operationName: String,
140 operation: OperationDefinition) {
141 operation.outputs?.let { inputs ->
142 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
147 * Get the Relationship Type from database and add to Blueprint Context
149 open fun enrichRelationShipType(relationshipName: String) {
150 BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, relationshipName)