63e89f77fdbaf177290b546f1be01e9b4b709358
[ccsdk/features.git] /
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.Collection;
22 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
26 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.Equipment;
27 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.EquipmentInstance;
28 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.EquipmentType;
29 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ManufacturedThing;
30 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ManufacturerProperties;
31 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
32 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ActualEquipment;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * @author alexs
42  *
43  */
44 public class Onf14ToInternalDataModel {
45
46     private static final Logger log = LoggerFactory.getLogger(Onf14ToInternalDataModel.class);
47
48     public Inventory getInternalEquipment(NodeId nodeId, Equipment currentEq, Equipment parentEq, long treeLevel) {
49
50         InventoryBuilder inventoryBuilder = new InventoryBuilder();
51
52         @Nullable
53         ActualEquipment component = currentEq.getActualEquipment();
54         if (component != null) {
55
56             // General
57             inventoryBuilder.setNodeId(nodeId.getValue());
58
59             inventoryBuilder.setTreeLevel(treeLevel);
60             inventoryBuilder.setUuid(currentEq.getUuid().getValue());
61
62             if (parentEq != null) {
63                 inventoryBuilder.setParentUuid(parentEq.getUuid().getValue());
64             } else {
65                 inventoryBuilder.setParentUuid("None");
66             }
67
68             List<String> containedHolderKeyList = new ArrayList<String>();
69             @NonNull
70             Collection<ContainedHolder> containedHolderList = YangHelper.getCollection(currentEq.nonnullContainedHolder());
71             for (ContainedHolder holder : containedHolderList) {
72                 @Nullable
73                 UniversalId occupyingFru = holder.getOccupyingFru();
74
75                 if (occupyingFru != null) {
76                     containedHolderKeyList.add(occupyingFru.getValue());
77                 }
78             }
79             inventoryBuilder.setContainedHolder(containedHolderKeyList);
80
81             @Nullable
82             ManufacturedThing manThing = component.getManufacturedThing();
83             if (manThing != null) {
84                 // Manufacturer properties
85                 @Nullable
86                 ManufacturerProperties manProp = manThing.getManufacturerProperties();
87                 if (manProp != null) {
88                     inventoryBuilder.setManufacturerName(manProp.getManufacturerName());
89                     inventoryBuilder.setManufacturerIdentifier(manProp.getManufacturerIdentifier());
90                 } else {
91                     log.debug("manufacturer-properties is not present in Equipment with uuid={}",
92                             currentEq.getUuid().getValue());
93                 }
94
95                 // Equipment instance
96                 @Nullable
97                 EquipmentInstance eqInstance = manThing.getEquipmentInstance();
98                 if (eqInstance != null) {
99                     inventoryBuilder.setSerial(eqInstance.getSerialNumber());
100                     inventoryBuilder.setDate(eqInstance.getManufactureDate().getValue());
101                 } else {
102                     log.debug("equipment-instance is not present in Equipment with uuid={}",
103                             currentEq.getUuid().getValue());
104                 }
105
106                 // Equipment type
107                 @Nullable
108                 EquipmentType eqType = manThing.getEquipmentType();
109                 if (eqType != null) {
110                     inventoryBuilder.setVersion(eqType.getVersion());
111                     inventoryBuilder.setDescription(eqType.getDescription());
112                     inventoryBuilder.setPartTypeId(eqType.getPartTypeIdentifier());
113                     inventoryBuilder.setModelIdentifier(eqType.getModelIdentifier());
114                     inventoryBuilder.setTypeName(eqType.getTypeName());
115                 } else {
116                     log.debug("equipment-type is not present in Equipment with uuid={}",
117                             currentEq.getUuid().getValue());
118                 }
119             } else {
120                 log.debug("manufactured-thing is not present in Equipment with uuid={}",
121                         currentEq.getUuid().getValue());
122             }
123         } else {
124             log.debug("actual-equipment is not present in Equipment with uuid={}", currentEq.getUuid().getValue());
125         }
126
127         return inventoryBuilder.build();
128     }
129
130 }