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