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