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.controllerblueprints.core.service
19 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
20 import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.CapabilityDefinition
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.RequirementDefinition
32 * @author Brinda Santh
34 internal class BluePrintChainedService {
36 var bpc: BluePrintContext
38 constructor(bpc: BluePrintContext) {
42 fun nodeTypeChained(nodeTypeName: String): NodeType {
44 val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName)
45 val attributes = hashMapOf<String, AttributeDefinition>()
46 val properties = hashMapOf<String, PropertyDefinition>()
47 val requirements = hashMapOf<String, RequirementDefinition>()
48 val capabilities = hashMapOf<String, CapabilityDefinition>()
49 val interfaces = hashMapOf<String, InterfaceDefinition>()
50 val artifacts = hashMapOf<String, ArtifactDefinition>()
52 recNodeTypesChained(nodeTypeName).forEach { nodeType ->
54 val subAttributes = bpc.nodeTypeByName(nodeType.id!!).attributes
55 if (subAttributes != null) {
56 attributes.putAll(subAttributes)
59 val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties
60 if (subProperties != null) {
61 properties.putAll(subProperties)
64 val subRequirements = bpc.nodeTypeByName(nodeType.id!!).requirements
65 if (subRequirements != null) {
66 requirements.putAll(subRequirements)
68 val subCapabilities = bpc.nodeTypeByName(nodeType.id!!).capabilities
69 if (subCapabilities != null) {
70 capabilities.putAll(subCapabilities)
72 val subInterfaces = bpc.nodeTypeByName(nodeType.id!!).interfaces
73 if (subInterfaces != null) {
74 interfaces.putAll(subInterfaces)
77 val subArtifacts = bpc.nodeTypeByName(nodeType.id!!).artifacts
78 if (subArtifacts != null) {
79 artifacts.putAll(subArtifacts)
82 nodeType.attributes = attributes
83 nodeType.properties = properties
84 nodeType.requirements = requirements
85 nodeType.capabilities = capabilities
86 nodeType.interfaces = interfaces
87 nodeType.artifacts = artifacts
91 fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap<String, PropertyDefinition>? {
92 val nodeType = bpc.nodeTypeByName(nodeTypeName)
93 val properties = hashMapOf<String, PropertyDefinition>()
95 recNodeTypesChained(nodeTypeName).forEach { nodeType ->
96 val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties
97 if (subProperties != null) {
98 properties.putAll(subProperties)
104 private fun recNodeTypesChained(nodeTypeName: String, nodeTypes: MutableList<NodeType>? = arrayListOf()): MutableList<NodeType> {
105 val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName)
106 nodeType.id = nodeTypeName
107 val derivedFrom: String = nodeType.derivedFrom
108 if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
109 recNodeTypesChained(derivedFrom, nodeTypes)
111 nodeTypes!!.add(nodeType)
115 private fun recDataTypesChained(dataTypeName: String, dataTypes: MutableList<DataType>? = arrayListOf()): MutableList<DataType> {
116 val dataType: DataType = bpc.dataTypeByName(dataTypeName)!!
117 dataType.id = dataTypeName
118 val derivedFrom: String = dataType.derivedFrom
119 if (!BluePrintTypes.rootDataTypes().contains(derivedFrom)) {
120 recDataTypesChained(derivedFrom, dataTypes)
122 dataTypes!!.add(dataType)