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.impl.xml;
20 import com.fasterxml.jackson.annotation.JsonProperty;
21 import javax.annotation.Nonnull;
22 import javax.xml.bind.annotation.XmlElement;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionLogStatus;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity;
30 public class MwtNotificationBase {
32 private static String EMPTY = "empty";
34 private String nodeName;
35 private String counter;
36 private String timeStamp;
37 private @Nonnull String objectId;
39 public MwtNotificationBase() {
43 public MwtNotificationBase(String nodeName, Integer counter, InternalDateAndTime timeStamp, String objectId) {
44 this.nodeName = nodeName;
45 this.counter = String.valueOf(counter);
46 this.timeStamp = timeStamp.getValue();
47 this.objectId = objectId;
48 if (this.objectId == null) {
49 this.objectId = EMPTY;
53 @XmlElement(name = "nodeName")
54 public String getNodeName() {
58 @XmlElement(name = "counter")
59 public String getCounter() {
63 @XmlElement(name = "timeStamp")
64 public String getTimeStamp() {
68 @XmlElement(name = "objectId")
69 public String getObjectId() {
74 * Provide ConnectionlogEntity type
75 * @return ConnectionlogEntity
77 public ConnectionlogEntity getConnectionlogEntity() {
78 return new ConnectionlogBuilder()
80 .setStatus(getStatus())
81 .setTimestamp(new DateAndTime(timeStamp))
86 * Provide connection status for mountpoint log.
87 * TODO Add status disconnected if mountpoint is required, but does not exists.
90 private ConnectionLogStatus getStatus() {
92 if (this instanceof ObjectCreationNotificationXml) {
93 return ConnectionLogStatus.Mounted;
95 } else if (this instanceof ObjectDeletionNotificationXml) {
96 return ConnectionLogStatus.Unmounted;
98 } else if (this instanceof AttributeValueChangedNotificationXml) {
99 String pnx = ((AttributeValueChangedNotificationXml)this).getNewValue();
100 if (pnx.equals(ConnectionStatus.Connected.getName())) {
101 return ConnectionLogStatus.Connected;
103 } else if (pnx.equals(ConnectionStatus.Connecting.getName())) {
104 return ConnectionLogStatus.Connecting;
106 } else if (pnx.equals(ConnectionStatus.UnableToConnect.getName())) {
107 return ConnectionLogStatus.UnableToConnect;
110 return ConnectionLogStatus.Undefined;
114 * Type for the Database to document the the same name that is used in the websockets.
115 * @return String with type name of child class
117 @JsonProperty("type")
118 public String getType() {
119 return this.getClass().getSimpleName();
123 public String toString() {
124 return "MwtNotificationBase [getType()="+ getType() + ", nodeName=" + nodeName + ", counter=" + counter + ", timeStamp=" + timeStamp
125 + ", objectId=" + objectId + "]";