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