Merge "YANG Model update for A1 Adapter"
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / base / onfcore / container / ExtendedEquipment.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 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.base.onfcore.container;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.Equipment;
24 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ContainedHolder;
25 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.equipment.g.ManufacturedThing;
26 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentInstance;
27 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.EquipmentType;
28 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.manufactured.thing.g.ManufacturerProperties;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ExtendedEquipment {
35
36     private static final Logger LOG = LoggerFactory.getLogger(ExtendedEquipment.class);
37
38     public static final String ESDATATYPENAME = "inventoryequipment";
39     private final String parentUuid;
40     private final int treeLevel;
41     private final Equipment equipment;
42     private final String nodeId;
43     private final String path;
44     /**
45      * Equipment with additional information beside NETCONF equipment
46      *
47      * @param parentUuid of parent equipment
48      * @param equipment NETCONF Equipment
49      * @param treeLevel level of tree starting with root at 0
50      */
51     public ExtendedEquipment(String nodeId, String parentUuid, Equipment equipment, String path, int treeLevel) {
52         super();
53         this.nodeId = nodeId;
54         this.parentUuid = parentUuid;
55         this.equipment = equipment;
56         this.path = path;
57         this.treeLevel = treeLevel;
58     }
59
60     public String getParentUuid() {
61         return parentUuid;
62     }
63
64     public Equipment getEquipment() {
65         return equipment;
66     }
67
68     public int getTreeLevel() {
69         return treeLevel;
70     }
71     public String getNodeId() {
72         return nodeId;
73     }
74
75     public Inventory getCreateInventoryInput() {
76
77         InventoryBuilder inventoryBuilder = new InventoryBuilder();
78
79         // General
80         inventoryBuilder.setNodeId(getNodeId());
81         inventoryBuilder.setParentUuid(getParentUuid());
82         inventoryBuilder.setTreeLevel(new Long(getTreeLevel()));
83
84         if (equipment != null) {
85             inventoryBuilder.setUuid(equipment.getUuid().getValue());
86             // -- String list with ids of holders
87             List<String> containerHolderKeyList = new ArrayList<>();
88             List<ContainedHolder> containerHolderList = equipment.getContainedHolder();
89             if (containerHolderList != null) {
90                 for (ContainedHolder containerHolder : containerHolderList) {
91                     containerHolderKeyList.add(containerHolder.getUuid().getValue());
92                 }
93             }
94             inventoryBuilder.setContainedHolder(containerHolderKeyList);
95
96             // -- Manufacturer related things
97             ManufacturedThing mThing = equipment.getManufacturedThing();
98             if (mThing != null) {
99                 ManufacturerProperties mProperties = mThing.getManufacturerProperties();
100                 if (mProperties != null) {
101                     inventoryBuilder.setManufacturerName(mProperties.getManufacturerName());
102                     inventoryBuilder.setManufacturerIdentifier(mProperties.getManufacturerIdentifier());
103                 }
104                 EquipmentType mType = mThing.getEquipmentType();
105                 if (mType != null) {
106                     inventoryBuilder.setDescription(mType.getDescription());
107                     inventoryBuilder.setModelIdentifier(mType.getModelIdentifier());
108                     inventoryBuilder.setPartTypeId(mType.getPartTypeIdentifier());
109                     inventoryBuilder.setTypeName(mType.getTypeName());
110                     inventoryBuilder.setVersion(mType.getVersion());
111                 }
112                 EquipmentInstance mInstance = mThing.getEquipmentInstance();
113                 if (mInstance != null) {
114                     String manufacturedDateString = mInstance.getManufactureDate();
115                     if (manufacturedDateString != null && !manufacturedDateString.isEmpty()) {
116                         try {
117                             inventoryBuilder.setDate(mInstance.getManufactureDate());
118                         } catch (IllegalArgumentException e) {
119                             LOG.debug("Format problem", e);
120                         }
121                     }
122                     inventoryBuilder.setSerial(mInstance.getSerialNumber());
123                 }
124             }
125         }
126
127         return inventoryBuilder.build();
128     }
129
130     @Override
131     public String toString() {
132         return "ExtendedEquipment [parentUuid=" + parentUuid + ", treeLevel=" + treeLevel + ", equipment=" + equipment
133                 + ", nodeId=" + nodeId + ", path=" + path + "]";
134     }
135
136 }