03c1508f9046f7f9994720d2761c373a9b8d3d92
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / aaiTree / Vnf.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.model.aaiTree;
22
23 import org.onap.vid.aai.util.AAITreeConverter;
24 import org.onap.vid.services.AAITreeNodeBuilder;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import static org.onap.vid.aai.util.AAITreeConverter.VNF_TYPE;
30
31 public class Vnf extends Node {
32
33     private Map<String, Map<String, VfModule>> vfModules = new HashMap<>();
34     private Map<String, Network> networks = new HashMap<>();
35
36     public Vnf(AAITreeNode node) {
37         super(node, AAITreeConverter.ModelType.vnf);
38     }
39
40     public Map<String, Map<String, VfModule>> getVfModules() {
41         return vfModules;
42     }
43
44     public void setVfModules(Map<String, Map<String, VfModule>> vfModules) {
45         this.vfModules = vfModules;
46     }
47
48     public Map<String, Network> getNetworks() {
49         return networks;
50     }
51
52     public void setNetworks(Map<String, Network> networks) {
53         this.networks = networks;
54     }
55
56     public static Vnf from(AAITreeNode node) {
57         Vnf vnf = new Vnf(node);
58         if (node.getAdditionalProperties().get(VNF_TYPE) != null) {
59             vnf.setInstanceType(node.getAdditionalProperties().get(VNF_TYPE).toString());
60         }
61
62         node.getChildren().forEach(child -> {
63             if (child.getType().equals(AAITreeNodeBuilder.VF_MODULE)) {
64                 vnf.getVfModules().putIfAbsent(child.getNodeKey(), new HashMap<>());
65                 vnf.getVfModules().get(child.getNodeKey())
66                                     .put(child.getUniqueNodeKey(), VfModule.from(child));
67             } else if (child.getType().equals(AAITreeNodeBuilder.NETWORK)) {
68                 vnf.getNetworks().put(child.getUniqueNodeKey(), Network.from(child));
69             }
70         });
71
72         return vnf;
73     }
74 }