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.*
24 * @author Brinda Santh
26 class BluePrintChainedService {
27 var bpc : BluePrintContext
29 constructor(bpc : BluePrintContext){
33 fun nodeTypeChained(nodeTypeName: String): NodeType {
35 val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName)
36 val attributes = hashMapOf<String, AttributeDefinition>()
37 val properties = hashMapOf<String, PropertyDefinition>()
38 val requirements = hashMapOf<String, RequirementDefinition>()
39 val capabilities = hashMapOf<String, CapabilityDefinition>()
40 val interfaces = hashMapOf<String, InterfaceDefinition>()
41 val artifacts = hashMapOf<String, ArtifactDefinition>()
43 recNodeTypesChained(nodeTypeName).forEach { nodeType ->
45 val subAttributes = bpc.nodeTypeByName(nodeType.id!!).attributes
46 if (subAttributes != null) {
47 attributes.putAll(subAttributes)
50 val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties
51 if (subProperties != null) {
52 properties.putAll(subProperties)
55 val subRequirements = bpc.nodeTypeByName(nodeType.id!!).requirements
56 if (subRequirements != null) {
57 requirements.putAll(subRequirements)
59 val subCapabilities = bpc.nodeTypeByName(nodeType.id!!).capabilities
60 if (subCapabilities != null) {
61 capabilities.putAll(subCapabilities)
63 val subInterfaces = bpc.nodeTypeByName(nodeType.id!!).interfaces
64 if (subInterfaces != null) {
65 interfaces.putAll(subInterfaces)
68 val subArtifacts = bpc.nodeTypeByName(nodeType.id!!).artifacts
69 if (subArtifacts != null) {
70 artifacts.putAll(subArtifacts)
73 nodeType.attributes = attributes
74 nodeType.properties = properties
75 nodeType.requirements = requirements
76 nodeType.capabilities = capabilities
77 nodeType.interfaces = interfaces
78 nodeType.artifacts = artifacts
82 fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap<String, PropertyDefinition>? {
83 val nodeType = bpc.nodeTypeByName(nodeTypeName)
84 val properties = hashMapOf<String, PropertyDefinition>()
86 recNodeTypesChained(nodeTypeName).forEach { nodeType ->
87 val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties
88 if (subProperties != null) {
89 properties.putAll(subProperties)
95 private fun recNodeTypesChained(nodeTypeName: String, nodeTypes: MutableList<NodeType>? = arrayListOf()): MutableList<NodeType> {
96 val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName)
97 nodeType.id = nodeTypeName
98 val derivedFrom: String = nodeType.derivedFrom
99 if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
100 recNodeTypesChained(derivedFrom, nodeTypes)
102 nodeTypes!!.add(nodeType)
106 private fun recDataTypesChained(dataTypeName: String, dataTypes: MutableList<DataType>? = arrayListOf()): MutableList<DataType> {
107 val dataType: DataType = bpc.dataTypeByName(dataTypeName)!!
108 dataType.id = dataTypeName
109 val derivedFrom: String = dataType.derivedFrom
110 if (!BluePrintTypes.rootDataTypes().contains(derivedFrom)) {
111 recDataTypesChained(derivedFrom, dataTypes)
113 dataTypes!!.add(dataType)