06517634272b4fc7dd5607e409404ee78bf97342
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
18 \r
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes\r
20 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
21 /**\r
22  *\r
23  *\r
24  * @author Brinda Santh\r
25  */\r
26 class BluePrintChainedService {\r
27     var bpc : BluePrintContext\r
28 \r
29     constructor(bpc : BluePrintContext){\r
30         this.bpc = bpc\r
31     }\r
32 \r
33     fun nodeTypeChained(nodeTypeName: String): NodeType {\r
34 \r
35         val nodeType: NodeType = bpc.nodeTypeByName(nodeTypeName)\r
36         val attributes = hashMapOf<String, AttributeDefinition>()\r
37         val properties = hashMapOf<String, PropertyDefinition>()\r
38         val requirements = hashMapOf<String, RequirementDefinition>()\r
39         val capabilities = hashMapOf<String, CapabilityDefinition>()\r
40         val interfaces = hashMapOf<String, InterfaceDefinition>()\r
41         val artifacts = hashMapOf<String, ArtifactDefinition>()\r
42 \r
43         recNodeTypesChained(nodeTypeName).forEach { nodeType ->\r
44 \r
45             val subAttributes =  bpc.nodeTypeByName(nodeType.id!!).attributes\r
46             if (subAttributes != null) {\r
47                 attributes.putAll(subAttributes)\r
48             }\r
49 \r
50             val subProperties =  bpc.nodeTypeByName(nodeType.id!!).properties\r
51             if (subProperties != null) {\r
52                 properties.putAll(subProperties)\r
53             }\r
54 \r
55             val subRequirements =  bpc.nodeTypeByName(nodeType.id!!).requirements\r
56             if (subRequirements != null) {\r
57                 requirements.putAll(subRequirements)\r
58             }\r
59             val subCapabilities =  bpc.nodeTypeByName(nodeType.id!!).capabilities\r
60             if (subCapabilities != null) {\r
61                 capabilities.putAll(subCapabilities)\r
62             }\r
63             val subInterfaces =  bpc.nodeTypeByName(nodeType.id!!).interfaces\r
64             if (subInterfaces != null) {\r
65                 interfaces.putAll(subInterfaces)\r
66             }\r
67 \r
68             val subArtifacts =  bpc.nodeTypeByName(nodeType.id!!).artifacts\r
69             if (subArtifacts != null) {\r
70                 artifacts.putAll(subArtifacts)\r
71             }\r
72         }\r
73         nodeType.attributes = attributes\r
74         nodeType.properties = properties\r
75         nodeType.requirements = requirements\r
76         nodeType.capabilities = capabilities\r
77         nodeType.interfaces = interfaces\r
78         nodeType.artifacts = artifacts\r
79         return nodeType\r
80     }\r
81 \r
82     fun nodeTypeChainedProperties(nodeTypeName: String): MutableMap<String, PropertyDefinition>? {\r
83         val nodeType =  bpc.nodeTypeByName(nodeTypeName)\r
84         val properties = hashMapOf<String, PropertyDefinition>()\r
85 \r
86         recNodeTypesChained(nodeTypeName).forEach { nodeType ->\r
87             val subProperties =  bpc.nodeTypeByName(nodeType.id!!).properties\r
88             if (subProperties != null) {\r
89                 properties.putAll(subProperties)\r
90             }\r
91         }\r
92         return properties\r
93     }\r
94 \r
95     private fun recNodeTypesChained(nodeTypeName: String, nodeTypes: MutableList<NodeType>? = arrayListOf()): MutableList<NodeType> {\r
96         val nodeType: NodeType =  bpc.nodeTypeByName(nodeTypeName)\r
97         nodeType.id = nodeTypeName\r
98         val derivedFrom: String = nodeType.derivedFrom\r
99         if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {\r
100             recNodeTypesChained(derivedFrom, nodeTypes)\r
101         }\r
102         nodeTypes!!.add(nodeType)\r
103         return nodeTypes\r
104     }\r
105 \r
106     private fun recDataTypesChained(dataTypeName: String, dataTypes: MutableList<DataType>? = arrayListOf()): MutableList<DataType> {\r
107         val dataType: DataType =  bpc.dataTypeByName(dataTypeName)!!\r
108         dataType.id = dataTypeName\r
109         val derivedFrom: String = dataType.derivedFrom\r
110         if (!BluePrintTypes.rootDataTypes().contains(derivedFrom)) {\r
111             recDataTypesChained(derivedFrom, dataTypes)\r
112         }\r
113         dataTypes!!.add(dataType)\r
114         return dataTypes\r
115     }\r
116 \r
117 }