52436da61d802998cdd35436fc66dee0f3f82d78
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf14 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / impl / dataprovider / 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.dataprovider;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Objects;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
27 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.Equipment;
28 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.EquipmentInstance;
29 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.EquipmentType;
30 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ManufacturedThing;
31 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ManufacturerProperties;
32 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ActualEquipment;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
38 import org.opendaylight.yangtools.yang.common.Uint32;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * @author alexs
44  *
45  */
46 public class Onf14ToInternalDataModel {
47
48     private static final Logger LOG = LoggerFactory.getLogger(Onf14ToInternalDataModel.class);
49
50     public Inventory getInternalEquipment(NodeId nodeId, Equipment currentEq, Equipment parentEq, long treeLevel) {
51
52         Objects.requireNonNull(nodeId);
53         Objects.requireNonNull(currentEq);
54
55         InventoryBuilder inventoryBuilder = new InventoryBuilder();
56         String parentUuid = parentEq != null ? parentEq.getUuid().getValue() : "None";
57
58         @Nullable
59         ActualEquipment component = currentEq.getActualEquipment();
60         if (component != null) {
61             // General
62             inventoryBuilder.setNodeId(nodeId.getValue());
63             inventoryBuilder.setTreeLevel(Uint32.valueOf(treeLevel));
64             inventoryBuilder.setUuid(currentEq.getUuid().getValue());
65             inventoryBuilder.setParentUuid(parentUuid);
66
67             List<String> containedHolderKeyList = new ArrayList<String>();
68             @NonNull
69             Collection<ContainedHolder> containedHolderList =
70                     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 }