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