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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac.equipment;
20 import java.util.ArrayList;
21 import java.util.List;
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;
35 * Extend the eqipment type of core model with additional parameters
37 public class ExtendedEquipment {
39 private static final Logger LOG = LoggerFactory.getLogger(ExtendedEquipment.class);
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;
48 * Equipment with additional information beside NETCONF equipment
50 * @param parentUuid of parent equipment
51 * @param equipment NETCONF Equipment
52 * @param treeLevel level of tree starting with root at 0
54 public ExtendedEquipment(String nodeId, String parentUuid, Equipment equipment, String path, int treeLevel) {
57 this.parentUuid = parentUuid;
58 this.equipment = equipment;
60 this.treeLevel = treeLevel;
63 public String getParentUuid() {
67 public Equipment getEquipment() {
71 public int getTreeLevel() {
74 public String getNodeId() {
78 public Inventory getCreateInventoryInput() {
80 InventoryBuilder inventoryBuilder = new InventoryBuilder();
83 inventoryBuilder.setNodeId(getNodeId());
84 inventoryBuilder.setParentUuid(getParentUuid());
85 inventoryBuilder.setTreeLevel(new Long(getTreeLevel()));
87 if (equipment != null) {
88 inventoryBuilder.setUuid(equipment.getUuid().getValue());
89 // -- String list with ids of holders
90 List<String> containerHolderKeyList = new ArrayList<>();
91 List<ContainedHolder> containerHolderList = equipment.getContainedHolder();
92 if (containerHolderList != null) {
93 for (ContainedHolder containerHolder : containerHolderList) {
94 containerHolderKeyList.add(containerHolder.getUuid().getValue());
97 inventoryBuilder.setContainedHolder(containerHolderKeyList);
99 // -- Manufacturer related things
100 ManufacturedThing mThing = equipment.getManufacturedThing();
101 if (mThing != null) {
102 ManufacturerProperties mProperties = mThing.getManufacturerProperties();
103 if (mProperties != null) {
104 inventoryBuilder.setManufacturerName(mProperties.getManufacturerName());
105 inventoryBuilder.setManufacturerIdentifier(mProperties.getManufacturerIdentifier());
107 EquipmentType mType = mThing.getEquipmentType();
109 inventoryBuilder.setDescription(mType.getDescription());
110 inventoryBuilder.setModelIdentifier(mType.getModelIdentifier());
111 inventoryBuilder.setPartTypeId(mType.getPartTypeIdentifier());
112 inventoryBuilder.setTypeName(mType.getTypeName());
113 inventoryBuilder.setVersion(mType.getVersion());
115 EquipmentInstance mInstance = mThing.getEquipmentInstance();
116 if (mInstance != null) {
117 String manufacturedDateString = mInstance.getManufactureDate();
118 if (manufacturedDateString != null && !manufacturedDateString.isEmpty()) {
120 inventoryBuilder.setDate(mInstance.getManufactureDate());
121 } catch (IllegalArgumentException e) {
122 LOG.debug("Format problem", e);
125 inventoryBuilder.setSerial(mInstance.getSerialNumber());
130 return inventoryBuilder.build();
134 public String toString() {
135 return "ExtendedEquipment [parentUuid=" + parentUuid + ", treeLevel=" + treeLevel + ", equipment=" + equipment
136 + ", nodeId=" + nodeId + ", path=" + path + "]";