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==========================================================================
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() {
41 this.objectId = EMPTY;
44 public MwtNotificationBase(String nodeName, Integer counter, InternalDateAndTime timeStamp, String objectId) {
45 this.nodeName = nodeName;
46 this.counter = String.valueOf(counter);
47 this.timeStamp = timeStamp.getValue();
48 this.objectId = objectId;
49 if (this.objectId == null) {
50 this.objectId = EMPTY;
54 @XmlElement(name = "nodeName")
55 public String getNodeName() {
59 @XmlElement(name = "counter")
60 public String getCounter() {
64 @XmlElement(name = "timeStamp")
65 public String getTimeStamp() {
69 @XmlElement(name = "objectId")
70 public String getObjectId() {
75 * Provide ConnectionlogEntity type
76 * @return ConnectionlogEntity
78 public ConnectionlogEntity getConnectionlogEntity() {
79 return new ConnectionlogBuilder()
81 .setStatus(getStatus())
82 .setTimestamp(new DateAndTime(timeStamp))
87 * Provide connection status for mountpoint log.
88 * TODO Add status disconnected if mountpoint is required, but does not exists.
91 private ConnectionLogStatus getStatus() {
93 if (this instanceof ObjectCreationNotificationXml) {
94 return ConnectionLogStatus.Mounted;
96 } else if (this instanceof ObjectDeletionNotificationXml) {
97 return ConnectionLogStatus.Unmounted;
99 } else if (this instanceof AttributeValueChangedNotificationXml) {
100 String pnx = ((AttributeValueChangedNotificationXml)this).getNewValue();
101 if (pnx.equals(ConnectionStatus.Connected.getName())) {
102 return ConnectionLogStatus.Connected;
104 } else if (pnx.equals(ConnectionStatus.Connecting.getName())) {
105 return ConnectionLogStatus.Connecting;
107 } else if (pnx.equals(ConnectionStatus.UnableToConnect.getName())) {
108 return ConnectionLogStatus.UnableToConnect;
111 return ConnectionLogStatus.Undefined;
115 * Type for the Database to document the the same name that is used in the websockets.
116 * @return String with type name of child class
118 @JsonProperty("type")
119 public String getType() {
120 return this.getClass().getSimpleName();
124 public String toString() {
125 return "MwtNotificationBase [getType()="+ getType() + ", nodeName=" + nodeName + ", counter=" + counter + ", timeStamp=" + timeStamp
126 + ", objectId=" + objectId + "]";