ad42f03caa967fc74ea600043f391207dac93719
[ccsdk/features.git] / sdnr / wt / devicemanager-onf14 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / impl / Onf14ToInternalDataModel.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.Equipment;
25 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.EquipmentInstance;
26 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.EquipmentType;
27 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ManufacturedThing;
28 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ManufacturerProperties;
29 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
30 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ActualEquipment;
31 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * @author alexs
40  *
41  */
42 public class Onf14ToInternalDataModel {
43
44     private static final Logger log = LoggerFactory.getLogger(Onf14ToInternalDataModel.class);
45
46     public Inventory getInternalEquipment(NodeId nodeId, Equipment currentEq, Equipment parentEq, long treeLevel) {
47
48         InventoryBuilder inventoryBuilder = new InventoryBuilder();
49
50         @Nullable
51         ActualEquipment component = currentEq.getActualEquipment();
52         if (component != null) {
53
54             // General
55             inventoryBuilder.setNodeId(nodeId.getValue());
56
57             inventoryBuilder.setTreeLevel(treeLevel);
58             inventoryBuilder.setUuid(currentEq.getUuid().getValue());
59
60             if (parentEq != null) {
61                 inventoryBuilder.setParentUuid(parentEq.getUuid().getValue());
62             } else {
63                 inventoryBuilder.setParentUuid("None");
64             }
65
66             List<String> containedHolderKeyList = new ArrayList<String>();
67             @NonNull
68             List<ContainedHolder> containedHolderList = currentEq.nonnullContainedHolder();
69             for (ContainedHolder holder : containedHolderList) {
70                 @Nullable
71                 UniversalId occupyingFru = holder.getOccupyingFru();
72
73                 if (occupyingFru != null) {
74                     containedHolderKeyList.add(occupyingFru.getValue());
75                 }
76             }
77             inventoryBuilder.setContainedHolder(containedHolderKeyList);
78
79             @Nullable
80             ManufacturedThing manThing = component.getManufacturedThing();
81             if (manThing != null) {
82                 // Manufacturer properties
83                 @Nullable
84                 ManufacturerProperties manProp = manThing.getManufacturerProperties();
85                 if (manProp != null) {
86                     inventoryBuilder.setManufacturerName(manProp.getManufacturerName());
87                     inventoryBuilder.setManufacturerIdentifier(manProp.getManufacturerIdentifier());
88                 } else {
89                     log.debug("manufacturer-properties is not present in Equipment with uuid={}",
90                             currentEq.getUuid().getValue());
91                 }
92
93                 // Equipment instance
94                 @Nullable
95                 EquipmentInstance eqInstance = manThing.getEquipmentInstance();
96                 if (eqInstance != null) {
97                     inventoryBuilder.setSerial(eqInstance.getSerialNumber());
98                     inventoryBuilder.setDate(eqInstance.getManufactureDate().getValue());
99                 } else {
100                     log.debug("equipment-instance is not present in Equipment with uuid={}",
101                             currentEq.getUuid().getValue());
102                 }
103
104                 // Equipment type
105                 @Nullable
106                 EquipmentType eqType = manThing.getEquipmentType();
107                 if (eqType != null) {
108                     inventoryBuilder.setVersion(eqType.getVersion());
109                     inventoryBuilder.setDescription(eqType.getDescription());
110                     inventoryBuilder.setPartTypeId(eqType.getPartTypeIdentifier());
111                     inventoryBuilder.setModelIdentifier(eqType.getModelIdentifier());
112                     inventoryBuilder.setTypeName(eqType.getTypeName());
113                 } else {
114                     log.debug("equipment-type is not present in Equipment with uuid={}",
115                             currentEq.getUuid().getValue());
116                 }
117             } else {
118                 log.debug("manufactured-thing is not present in Equipment with uuid={}",
119                         currentEq.getUuid().getValue());
120             }
121         } else {
122             log.debug("actual-equipment is not present in Equipment with uuid={}", currentEq.getUuid().getValue());
123         }
124
125         return inventoryBuilder.build();
126     }
127
128 }