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