Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / service / BlueprintChainedService.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.core.service
18
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
28
29 /**
30  *
31  *
32  * @author Brinda Santh
33  */
34 internal class BlueprintChainedService {
35
36     var bpc: BlueprintContext
37
38     constructor(bpc: BlueprintContext) {
39         this.bpc = bpc
40     }
41
42     fun nodeTypeChained(nodeTypeName: String): NodeType {
43
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>()
51
52         recNodeTypesChained(nodeTypeName).forEach { nodeType ->
53
54             val subAttributes = bpc.nodeTypeByName(nodeType.id!!).attributes
55             if (subAttributes != null) {
56                 attributes.putAll(subAttributes)
57             }
58
59             val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties
60             if (subProperties != null) {
61                 properties.putAll(subProperties)
62             }
63
64             val subRequirements = bpc.nodeTypeByName(nodeType.id!!).requirements
65             if (subRequirements != null) {
66                 requirements.putAll(subRequirements)
67             }
68             val subCapabilities = bpc.nodeTypeByName(nodeType.id!!).capabilities
69             if (subCapabilities != null) {
70                 capabilities.putAll(subCapabilities)
71             }
72             val subInterfaces = bpc.nodeTypeByName(nodeType.id!!).interfaces
73             if (subInterfaces != null) {
74                 interfaces.putAll(subInterfaces)
75             }
76
77             val subArtifacts = bpc.nodeTypeByName(nodeType.id!!).artifacts
78             if (subArtifacts != null) {
79                 artifacts.putAll(subArtifacts)
80             }
81         }
82         nodeType.attributes = attributes
83         nodeType.properties = properties
84         nodeType.requirements = requirements
85         nodeType.capabilities = capabilities
86         nodeType.interfaces = interfaces
87         nodeType.artifacts = artifacts
88         return nodeType
89     }
90
91     fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap<String, PropertyDefinition>? {
92         val nodeType = bpc.nodeTypeByName(nodeTypeName)
93         val properties = hashMapOf<String, PropertyDefinition>()
94
95         recNodeTypesChained(nodeTypeName).forEach { nodeType ->
96             val subProperties = bpc.nodeTypeByName(nodeType.id!!).properties
97             if (subProperties != null) {
98                 properties.putAll(subProperties)
99             }
100         }
101         return properties
102     }
103
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)
110         }
111         nodeTypes!!.add(nodeType)
112         return nodeTypes
113     }
114
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)
121         }
122         dataTypes!!.add(dataType)
123         return dataTypes
124     }
125 }